ff7tk  0.02
Toolkit for making FF7 Tools
MetadataCreator.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // copyright 2012 -2016 Chris Rizzitello <sithlord48@gmail.com> //
3 // //
4 // This file is part of FF7tk. //
5 // //
6 // FF7tk is free software: you can redistribute it and/or modify //
7 // it under the terms of the GNU General Public License as published by //
8 // the Free Software Foundation, either version 3 of the License, or //
9 // (at your option) any later version. //
10 // //
11 // FF7tk is distributed in the hope that it will be useful, //
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
14 // GNU General Public License for more details. //
15 /****************************************************************************/
16 /*~~~~~~~~~~~Includes~~~~~~~~*/
17 
18 #include "MetadataCreator.h"
19 #include <QFileDialog>
20 #include <QVBoxLayout>
21 #include <QHBoxLayout>
22 #include <QMessageBox>
23 
24 MetadataCreator::MetadataCreator(QWidget *parent,FF7Save *ff7save) : QDialog(parent)
25 {
26  initDisplay();
28  for(int i=0;i<15;i++){InFiles.append(QString(""));}
29  ff7 = ff7save;
30  buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
31  this->setWindowTitle(tr("Create Cloud Save Folder"));
32  this->setFocus();// prevents lineOutPath from Having Focus and hiding its placeholder text.
33 }
35 {
36  this->setMinimumSize(458*qApp->desktop()->logicalDpiX()/96,438*qApp->desktop()->logicalDpiY()/96);
37  lblOut= new QLabel(tr("Output Path:"));
38  lineOutPath = new QLineEdit;
39  lineOutPath->setPlaceholderText(tr("Folder To Write Files Into"));
40 
41  btnOutPath = new QPushButton("...");
42 
43  QHBoxLayout *outpathLayout = new QHBoxLayout;
44  outpathLayout->addWidget(lblOut);
45  outpathLayout->addWidget(lineOutPath);
46  outpathLayout->addWidget(btnOutPath);
47 
48  lblUserID=new QLabel(tr("Sign With User Id"));
49  lineUserID = new QLineEdit;
50  lineUserID->setPlaceholderText(tr("Your SE Id number"));
51  IDSpacer= new QSpacerItem(0,0,QSizePolicy::Expanding,QSizePolicy::Minimum);
52 
53  QHBoxLayout *userIDLayout = new QHBoxLayout;
54  userIDLayout->addWidget(lblUserID);
55  userIDLayout->addWidget(lineUserID);
56  userIDLayout->addSpacerItem(IDSpacer);
57 
58  lblSave00=new QLabel(tr("Save00"));
59  lineSave00= new QLineEdit;
60  btnSave00= new QPushButton("...");
61 
62  QHBoxLayout *savegroup00 = new QHBoxLayout;
63  savegroup00->addWidget(lblSave00);
64  savegroup00->addWidget(lineSave00);
65  savegroup00->addWidget(btnSave00);
66 
67  lblSave01=new QLabel(tr("Save01"));
68  lineSave01= new QLineEdit;
69  btnSave01= new QPushButton("...");
70 
71  QHBoxLayout *savegroup01 = new QHBoxLayout;
72  savegroup01->addWidget(lblSave01);
73  savegroup01->addWidget(lineSave01);
74  savegroup01->addWidget(btnSave01);
75 
76  lblSave02=new QLabel(tr("Save02"));
77  lineSave02= new QLineEdit;
78  btnSave02= new QPushButton("...");
79 
80  QHBoxLayout *savegroup02 = new QHBoxLayout;
81  savegroup02->addWidget(lblSave02);
82  savegroup02->addWidget(lineSave02);
83  savegroup02->addWidget(btnSave02);
84 
85  lblSave03=new QLabel(tr("Save03"));
86  lineSave03= new QLineEdit;
87  btnSave03= new QPushButton("...");
88 
89  QHBoxLayout *savegroup03 = new QHBoxLayout;
90  savegroup03->addWidget(lblSave03);
91  savegroup03->addWidget(lineSave03);
92  savegroup03->addWidget(btnSave03);
93 
94  lblSave04=new QLabel(tr("Save04"));
95  lineSave04= new QLineEdit;
96  btnSave04= new QPushButton("...");
97 
98  QHBoxLayout *savegroup04 = new QHBoxLayout;
99  savegroup04->addWidget(lblSave04);
100  savegroup04->addWidget(lineSave04);
101  savegroup04->addWidget(btnSave04);
102 
103  lblSave05=new QLabel(tr("Save05"));
104  lineSave05= new QLineEdit;
105  btnSave05= new QPushButton("...");
106 
107  QHBoxLayout *savegroup05 = new QHBoxLayout;
108  savegroup05->addWidget(lblSave05);
109  savegroup05->addWidget(lineSave05);
110  savegroup05->addWidget(btnSave05);
111 
112  lblSave06=new QLabel(tr("Save06"));
113  lineSave06= new QLineEdit;
114  lineSave06->setPlaceholderText(tr("Add Files For each Save you want in your cloud data."));
115  btnSave06= new QPushButton("...");
116 
117  QHBoxLayout *savegroup06 = new QHBoxLayout;
118  savegroup06->addWidget(lblSave06);
119  savegroup06->addWidget(lineSave06);
120  savegroup06->addWidget(btnSave06);
121 
122  lblSave07=new QLabel(tr("Save07"));
123  lineSave07= new QLineEdit;
124  lineSave07->setPlaceholderText(tr("You Can Use Any Format That Black Chocobo Can Open"));
125  btnSave07= new QPushButton("...");
126 
127  QHBoxLayout *savegroup07 = new QHBoxLayout;
128  savegroup07->addWidget(lblSave07);
129  savegroup07->addWidget(lineSave07);
130  savegroup07->addWidget(btnSave07);
131 
132  lblSave08=new QLabel(tr("Save08"));
133  lineSave08= new QLineEdit;
134  lineSave08->setPlaceholderText(tr("Unused files will be Looked for in the Save Path"));
135  btnSave08= new QPushButton("...");
136 
137  QHBoxLayout *savegroup08 = new QHBoxLayout;
138  savegroup08->addWidget(lblSave08);
139  savegroup08->addWidget(lineSave08);
140  savegroup08->addWidget(btnSave08);
141 
142  lblSave09=new QLabel(tr("Save09"));
143  lineSave09= new QLineEdit;
144  lineSave09->setPlaceholderText(tr("Pressing Ok Will Overwrite Any Metadata in the save path"));
145  btnSave09= new QPushButton("...");
146 
147  QHBoxLayout *savegroup09 = new QHBoxLayout;
148  savegroup09->addWidget(lblSave09);
149  savegroup09->addWidget(lineSave09);
150  savegroup09->addWidget(btnSave09);
151 
152  QVBoxLayout *SaveGroupLayout = new QVBoxLayout;
153  SaveGroupLayout->addLayout(savegroup00);
154  SaveGroupLayout->addLayout(savegroup01);
155  SaveGroupLayout->addLayout(savegroup02);
156  SaveGroupLayout->addLayout(savegroup03);
157  SaveGroupLayout->addLayout(savegroup04);
158  SaveGroupLayout->addLayout(savegroup05);
159  SaveGroupLayout->addLayout(savegroup06);
160  SaveGroupLayout->addLayout(savegroup07);
161  SaveGroupLayout->addLayout(savegroup08);
162  SaveGroupLayout->addLayout(savegroup09);
163 
164  SaveGroup = new QGroupBox(tr(""));
165  SaveGroup->setLayout(SaveGroupLayout);
166 
167  buttonBox = new QDialogButtonBox;
168  buttonBox->addButton(QDialogButtonBox::Ok);
169  buttonBox->addButton(QDialogButtonBox::Cancel);
170 
171  QVBoxLayout *FinalLayout=new QVBoxLayout;
172  FinalLayout->addLayout(outpathLayout);
173  FinalLayout->addLayout(userIDLayout);
174  FinalLayout->addWidget(SaveGroup);
175  FinalLayout->addWidget(buttonBox);
176 
177  setLayout(FinalLayout);
178 }
180 {
181  connect(lineOutPath,SIGNAL(textChanged(QString)),this,SLOT(on_lineOutPath_textChanged(QString)));
182  connect(btnOutPath,SIGNAL(clicked()),this,SLOT(on_btnOutPath_clicked()));
183 
184  connect(lineSave00,SIGNAL(textChanged(QString)),this,SLOT(on_lineSave00_textChanged(QString)));
185  connect(btnSave00,SIGNAL(clicked()),this,SLOT(on_btnSave00_clicked()));
186 
187  connect(lineSave01,SIGNAL(textChanged(QString)),this,SLOT(on_lineSave01_textChanged(QString)));
188  connect(btnSave01,SIGNAL(clicked()),this,SLOT(on_btnSave01_clicked()));
189 
190  connect(lineSave02,SIGNAL(textChanged(QString)),this,SLOT(on_lineSave02_textChanged(QString)));
191  connect(btnSave02,SIGNAL(clicked()),this,SLOT(on_btnSave02_clicked()));
192 
193  connect(lineSave03,SIGNAL(textChanged(QString)),this,SLOT(on_lineSave03_textChanged(QString)));
194  connect(btnSave03,SIGNAL(clicked()),this,SLOT(on_btnSave03_clicked()));
195 
196  connect(lineSave04,SIGNAL(textChanged(QString)),this,SLOT(on_lineSave04_textChanged(QString)));
197  connect(btnSave04,SIGNAL(clicked()),this,SLOT(on_btnSave04_clicked()));
198 
199  connect(lineSave05,SIGNAL(textChanged(QString)),this,SLOT(on_lineSave05_textChanged(QString)));
200  connect(btnSave05,SIGNAL(clicked()),this,SLOT(on_btnSave05_clicked()));
201 
202  connect(lineSave06,SIGNAL(textChanged(QString)),this,SLOT(on_lineSave06_textChanged(QString)));
203  connect(btnSave06,SIGNAL(clicked()),this,SLOT(on_btnSave06_clicked()));
204 
205  connect(lineSave07,SIGNAL(textChanged(QString)),this,SLOT(on_lineSave07_textChanged(QString)));
206  connect(btnSave07,SIGNAL(clicked()),this,SLOT(on_btnSave07_clicked()));
207 
208  connect(lineSave08,SIGNAL(textChanged(QString)),this,SLOT(on_lineSave08_textChanged(QString)));
209  connect(btnSave08,SIGNAL(clicked()),this,SLOT(on_btnSave08_clicked()));
210 
211  connect(lineSave09,SIGNAL(textChanged(QString)),this,SLOT(on_lineSave09_textChanged(QString)));
212  connect(btnSave09,SIGNAL(clicked()),this,SLOT(on_btnSave09_clicked()));
213 
214  connect(buttonBox,SIGNAL(accepted()),this,SLOT(on_buttonBox_accepted()));
215  connect(buttonBox,SIGNAL(rejected()),this,SLOT(on_buttonBox_rejected()));
216 }
217 
219 {
220  if(!load){OutPath=arg1;}
221  if(arg1.isEmpty()){buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);}
222  else{buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);}
223 }
225 {
226  load = true;
227  QString temp = QFileDialog::getExistingDirectory(this,tr("Select A Directory To Save Into"),QString("%1/Square Enix/FINAL FANTASY VII/").arg(QDir::homePath()));
228  if(!temp.isNull()){OutPath=temp;}
229  lineOutPath->setText(OutPath);
230  lineUserID->setText(temp.remove(0,temp.lastIndexOf("_")+1));
231  load=false;
232 }
233 
234 void MetadataCreator::on_lineSave00_textChanged(const QString &arg1){if(!load){InFiles.replace(0,arg1);}}
236 {
237  load = true;
238  QString temp = QFileDialog::getOpenFileName(this,tr("Select A File To Use As Save00"),QDir::homePath());
239  if(ff7->loadFile(temp)){InFiles.replace(0,temp); lineSave00->setText(InFiles.at(0));}
240  else{lineSave00->clear();}
241  load=false;
242 }
243 
244 void MetadataCreator::on_lineSave01_textChanged(const QString &arg1){if(!load){InFiles.replace(1,arg1);}}
246 {
247  load = true;
248  QString temp = QFileDialog::getOpenFileName(this,tr("Select A File To Use As Save01"),QDir::homePath());
249  if(ff7->loadFile(temp)){InFiles.replace(1,temp); lineSave01->setText(InFiles.at(1));}
250  else{lineSave01->clear();}
251  load=false;
252 }
253 
254 void MetadataCreator::on_lineSave02_textChanged(const QString &arg1){if(!load){InFiles.replace(2,arg1);}}
256 {
257  load = true;
258  QString temp = QFileDialog::getOpenFileName(this,tr("Select A File To Use As Save02"),QDir::homePath());
259  if(ff7->loadFile(temp)){InFiles.replace(2,temp); lineSave02->setText(InFiles.at(2));}
260  else{lineSave02->clear();}
261  load=false;
262 }
263 
264 void MetadataCreator::on_lineSave03_textChanged(const QString &arg1){if(!load){InFiles.replace(3,arg1);}}
266 {
267  load = true;
268  QString temp = QFileDialog::getOpenFileName(this,tr("Select A File To Use As Save03"),QDir::homePath());
269  if(ff7->loadFile(temp)){InFiles.replace(3,temp); lineSave03->setText(InFiles.at(3));}
270  else{lineSave03->clear();}
271  load=false;
272 }
273 
274 void MetadataCreator::on_lineSave04_textChanged(const QString &arg1){if(!load){InFiles.replace(4,arg1);}}
276 {
277  load = true;
278  QString temp = QFileDialog::getOpenFileName(this,tr("Select A File To Use As Save04"),QDir::homePath());
279  if(ff7->loadFile(temp)){InFiles.replace(4,temp); lineSave04->setText(InFiles.at(4));}
280  else{lineSave04->clear();}
281  load=false;
282 }
283 
284 void MetadataCreator::on_lineSave05_textChanged(const QString &arg1){if(!load){InFiles.replace(5,arg1);}}
286 {
287  load = true;
288  QString temp = QFileDialog::getOpenFileName(this,tr("Select A File To Use As Save05"),QDir::homePath());
289  if(ff7->loadFile(temp)){InFiles.replace(5,temp); lineSave05->setText(InFiles.at(5));}
290  else{lineSave05->clear();}
291  load=false;
292 }
293 
294 void MetadataCreator::on_lineSave06_textChanged(const QString &arg1){if(!load){InFiles.replace(6,arg1);}}
296 {
297  load = true;
298  QString temp = QFileDialog::getOpenFileName(this,tr("Select A File To Use As Save06"),QDir::homePath());
299  if(ff7->loadFile(temp)){InFiles.replace(6,temp); lineSave06->setText(InFiles.at(6));}
300  else{lineSave06->clear();}
301  load=false;
302 }
303 
304 void MetadataCreator::on_lineSave07_textChanged(const QString &arg1){if(!load){InFiles.replace(7,arg1);}}
306 {
307  load = true;
308  QString temp = QFileDialog::getOpenFileName(this,tr("Select A File To Use As Save07"),QDir::homePath());
309  if(ff7->loadFile(temp)){InFiles.replace(7,temp);lineSave07->setText(InFiles.at(7));}
310  else{lineSave07->clear();}
311  load=false;
312 }
313 
314 void MetadataCreator::on_lineSave08_textChanged(const QString &arg1){if(!load){InFiles.replace(8,arg1);}}
316 {
317  load = true;
318  QString temp = QFileDialog::getOpenFileName(this,tr("Select A File To Use As Save08"),QDir::homePath());
319  if(ff7->loadFile(temp)){InFiles.replace(8,temp); lineSave08->setText(InFiles.at(8));}
320  else{lineSave08->clear();}
321  load=false;
322 }
323 
324 void MetadataCreator::on_lineSave09_textChanged(const QString &arg1){if(!load){InFiles.replace(9,arg1);}}
326 {
327  load = true;
328  QString temp = QFileDialog::getOpenFileName(this,tr("Select A File To Use As Save09"),QDir::homePath());
329  if(ff7->loadFile(temp)){InFiles.replace(9,temp); lineSave09->setText(InFiles.at(9));}
330  else{lineSave09->clear();}
331  load=false;
332 }
333 
335 {
336  for(int i=0;i<10;i++)
337  {
338  QString OutFile =QString("%1/save0%2.ff7").arg(OutPath,QString::number(i));
339 
340  if(InFiles.at(i) =="")
341  {//No File Supplied Look in OutPath to see if there is a file.
342  QFile tempFile(OutFile);
343  if(tempFile.exists())
344  {
345  //If we find the file put its path in InFiles
346  InFiles.replace(i,OutFile);
347  }
348 
349  else{ff7->fixMetaData(OutFile,OutPath,lineUserID->text());continue;}//empty and not found
350  }
351  if(!ff7->loadFile(InFiles.at(i))){return;}
352  if(ff7->type()!="PC"){ff7->exportPC(OutFile);}
353  else
354  {
355  if(ff7->saveFile(OutFile)){/*Do Nothing*/}
356  else{QMessageBox::critical(this,QString(tr("File Error")),QString(tr("Failure to write the File: %1")).arg(OutFile));}
357  }
358  ff7->fixMetaData(OutFile,OutPath,lineUserID->text());
359  }
360  QString achievement(QString("%1/achievement.dat").arg(OutPath));
361  QFile file(achievement);
362  qint64 size=0;
363  if(file.exists())
364  {
365  if(!file.open(QIODevice::ReadOnly)){return;}
366  else
367  {
368  size=file.size();
369  file.close();
370  }
371  }
372  if(size!=8)
373  {
374  if(!file.open(QIODevice::WriteOnly)){return;}
375  else
376  {
377  file.write(QByteArray("\x00\x00\x00\x00\x00\x00\x00\x00"));
378  file.close();
379  }
380  }
381  this->close();
382 }
QLineEdit * lineSave04
QPushButton * btnSave05
QPushButton * btnSave09
QLineEdit * lineOutPath
QPushButton * btnSave00
QLineEdit * lineSave02
void on_lineSave09_textChanged(const QString &arg1)
QPushButton * btnOutPath
void on_lineSave06_textChanged(const QString &arg1)
QPushButton * btnSave07
QSpacerItem * IDSpacer
void on_lineOutPath_textChanged(const QString &arg1)
void on_lineSave04_textChanged(const QString &arg1)
QPushButton * btnSave02
bool exportPC(const QString &fileName)
attempt to save fileName as a PC ff7save
Definition: FF7Save.cpp:285
QString type(void)
Definition: FF7Save.cpp:1329
QLineEdit * lineSave09
MetadataCreator(QWidget *parent=0, FF7Save *ff7save=0)
QLineEdit * lineSave08
void on_lineSave02_textChanged(const QString &arg1)
void on_lineSave03_textChanged(const QString &arg1)
QGroupBox * SaveGroup
QPushButton * btnSave03
void on_lineSave08_textChanged(const QString &arg1)
QLineEdit * lineUserID
QLineEdit * lineSave06
QPushButton * btnSave01
QLineEdit * lineSave05
bool loadFile(const QString &fileName)
attempt to load fileName as ff7save
Definition: FF7Save.cpp:50
QLineEdit * lineSave00
edit saves from Final Fantasy 7
Definition: FF7Save.h:58
bool fixMetaData(QString fileName="", QString OutPath="", QString UserID="")
parse the metadata for 2012 / 2013 release
Definition: FF7Save.cpp:2442
QDialogButtonBox * buttonBox
QLineEdit * lineSave07
QPushButton * btnSave08
QPushButton * btnSave04
QLineEdit * lineSave01
void on_lineSave01_textChanged(const QString &arg1)
QPushButton * btnSave06
void on_lineSave05_textChanged(const QString &arg1)
QLineEdit * lineSave03
bool saveFile(const QString &fileName)
attempt to save fileName as ff7save
Definition: FF7Save.cpp:237
void on_lineSave07_textChanged(const QString &arg1)
QStringList InFiles
void on_lineSave00_textChanged(const QString &arg1)