| 1 |
|
#include "packagewizard.h" |
| 2 |
|
|
| 3 |
< |
PackageWizard::PackageWizard(QString workspaceWizardLocation, QSettings *vagoSettings, Logger *myLogger) |
| 3 |
> |
PackageWizard::PackageWizard(const QString &appDir, QString workspaceWizardLocation, QSettings *vagoSettings, Logger *myLogger) |
| 4 |
> |
:AbstractWizard(appDir, workspaceWizardLocation, vagoSettings, myLogger, false) |
| 5 |
|
{ |
| 5 |
– |
this->workspaceWizardLocation=workspaceWizardLocation; |
| 6 |
– |
this->vagoSettings=vagoSettings; |
| 7 |
– |
this->myLogger=myLogger; |
| 6 |
|
this->packagesLocation=this->workspaceWizardLocation+"/Packages"; |
| 7 |
|
} |
| 8 |
|
|
| 9 |
< |
int PackageWizard::exec(){ |
| 12 |
< |
QWizard myWizard; |
| 13 |
< |
|
| 14 |
< |
myWizard.setWindowIcon(QIcon(":/new/icons/package.png")); |
| 15 |
< |
|
| 16 |
< |
//Center and resize QWizard (http://www.thedazzlersinc.com/source/2012/06/04/qt-center-window-in-screen/) |
| 17 |
< |
myWizard.resize(640,480); |
| 18 |
< |
QRect position = myWizard.frameGeometry(); |
| 19 |
< |
position.moveCenter(QDesktopWidget().availableGeometry().center()); |
| 20 |
< |
myWizard.move(position.topLeft()); |
| 21 |
< |
// |
| 22 |
< |
|
| 9 |
> |
void PackageWizard::exec(){ |
| 10 |
|
PackagePage2 *page2 = new PackagePage2(this->myLogger); |
| 11 |
|
PackagePage3 *page3 = new PackagePage3(); |
| 12 |
|
PackagePage4 *page4 = new PackagePage4(); |
| 13 |
+ |
this->page4Pointer = page4; // save the pointer in class variable |
| 14 |
|
PackagePageFinal *pageFinal = new PackagePageFinal(this->vagoSettings); |
| 15 |
|
|
| 16 |
< |
myWizard.addPage(createIntroPage()); |
| 16 |
> |
myWizard.addPage( |
| 17 |
> |
createIntroPage( |
| 18 |
> |
"Welcome to the Anniversary Edition Installer 2 (AIE2) package" |
| 19 |
> |
" creator wizard.\n" |
| 20 |
> |
"This wizard will allow you to create in a few and simple steps a package for AIE2." |
| 21 |
> |
) |
| 22 |
> |
); |
| 23 |
|
myWizard.addPage(page2); |
| 24 |
|
myWizard.addPage(page3); |
| 25 |
|
myWizard.addPage(page4); |
| 26 |
|
myWizard.addPage(pageFinal); |
| 27 |
|
|
| 28 |
< |
myWizard.setWindowTitle("AIE2 Package Creator"); |
| 35 |
< |
|
| 36 |
< |
//If wizard finished with sucess |
| 37 |
< |
if(myWizard.exec()){ //modal and wait for finalization |
| 38 |
< |
createPackage(myWizard, page4); |
| 39 |
< |
} |
| 40 |
< |
|
| 41 |
< |
return 0; |
| 28 |
> |
showWizard("AIE2 Package Creator", ":/new/icons/package.png"); |
| 29 |
|
} |
| 30 |
|
|
| 44 |
– |
QWizardPage* PackageWizard::createIntroPage() { |
| 45 |
– |
QWizardPage *page = new QWizardPage; |
| 46 |
– |
page->setTitle("Introduction"); |
| 47 |
– |
|
| 48 |
– |
QLabel *label = new QLabel("Welcome to the Anniversary Edition Installer 2 (AIE2) package" |
| 49 |
– |
" creator wizard.\n" |
| 50 |
– |
"This wizard will allow you to create in a few and simple steps a package for AIE2."); |
| 51 |
– |
label->setWordWrap(true); |
| 52 |
– |
|
| 53 |
– |
QVBoxLayout *layout = new QVBoxLayout; |
| 54 |
– |
layout->addWidget(label); |
| 55 |
– |
page->setLayout(layout); |
| 56 |
– |
|
| 57 |
– |
return page; |
| 58 |
– |
} |
| 31 |
|
|
| 32 |
< |
void PackageWizard::createPackage(const QWizard &myWizard, PackagePage4 *page4){ |
| 32 |
> |
void PackageWizard::createPackage(){ |
| 33 |
|
const QString aeVersion="2.0"; |
| 34 |
|
|
| 35 |
|
//Get info page 2 |
| 36 |
< |
QString modName=myWizard.field("leModName").toString(); |
| 37 |
< |
QString authors=myWizard.field("leAuthors").toString(); |
| 38 |
< |
QString version=myWizard.field("leVersion").toString(); |
| 39 |
< |
QString description=myWizard.field("ptDescription").toString(); |
| 40 |
< |
QString packageNumber=myWizard.field("lePackageNumber").toString(); |
| 41 |
< |
bool bslReplace=myWizard.field("rbReplace").toBool(); |
| 36 |
> |
QString modName=this->myWizard.field("leModName").toString(); |
| 37 |
> |
QString authors=this->myWizard.field("leAuthors").toString(); |
| 38 |
> |
QString version=this->myWizard.field("leVersion").toString(); |
| 39 |
> |
QString description=this->myWizard.field("ptDescription").toString(); |
| 40 |
> |
QString packageNumber=this->myWizard.field("lePackageNumber").toString(); |
| 41 |
> |
bool bslReplace=this->myWizard.field("rbReplace").toBool(); |
| 42 |
|
|
| 43 |
|
//Get info page 3 |
| 44 |
< |
QString dependentPackages=myWizard.field("leDependentPackages").toString(); |
| 45 |
< |
QString incompatiblePackages=myWizard.field("leIncompatiblePackages").toString(); |
| 46 |
< |
QString unlockLevels=myWizard.field("leUnlockLevels").toString(); |
| 44 |
> |
QString dependentPackages=this->myWizard.field("leDependentPackages").toString(); |
| 45 |
> |
QString incompatiblePackages=this->myWizard.field("leIncompatiblePackages").toString(); |
| 46 |
> |
QString unlockLevels=this->myWizard.field("leUnlockLevels").toString(); |
| 47 |
|
|
| 48 |
|
//Get info page 4 |
| 49 |
< |
const DropTableWidget *commonTable=page4->commonTable; |
| 50 |
< |
const DropTableWidget *windowsTable=page4->windowsTable; |
| 51 |
< |
const DropTableWidget *macTable=page4->macTable; |
| 49 |
> |
const DropTableWidget *commonTable=this->page4Pointer->commonTable; |
| 50 |
> |
const DropTableWidget *windowsTable=this->page4Pointer->windowsTable; |
| 51 |
> |
const DropTableWidget *macTable=this->page4Pointer->macTable; |
| 52 |
|
|
| 53 |
|
//Get info from final page |
| 54 |
< |
bool openFolder=myWizard.field("cbOpenFolder").toBool(); |
| 55 |
< |
bool createZip=myWizard.field("cbCreateZip").toBool(); |
| 54 |
> |
bool openFolder=this->myWizard.field("cbOpenFolder").toBool(); |
| 55 |
> |
bool createZip=this->myWizard.field("cbCreateZip").toBool(); |
| 56 |
|
//Remember the final page choices to next time |
| 57 |
|
this->vagoSettings->setValue("PackageCreator/OpenFolder",openFolder); |
| 58 |
|
this->vagoSettings->setValue("PackageCreator/CreateZip",createZip); |
| 84 |
|
copyPackageFolders(macTable,"mac_only",modDir,bslExist); |
| 85 |
|
} |
| 86 |
|
|
| 87 |
< |
QFile *modInfo = new QFile(modDir+"Mod_Info.cfg"); |
| 87 |
> |
QFile modInfo(modDir+"Mod_Info.cfg"); |
| 88 |
|
|
| 89 |
< |
if (!modInfo->open(QIODevice::WriteOnly | QIODevice::Text)){ //open to write |
| 90 |
< |
Util::showErrorPopUp("Couldn't' create Mod_Info.cfg file."); |
| 119 |
< |
myLogger->writeString("Couldn't' create Mod_Info.cfg file when creating AE Package."); |
| 89 |
> |
if (!modInfo.open(QIODevice::WriteOnly | QIODevice::Text)){ //open to write |
| 90 |
> |
UtilVago::showAndLogErrorPopUp(this->myLogger, "Couldn't create Mod_Info.cfg file when creating AE Package."); |
| 91 |
|
return; |
| 92 |
|
} |
| 93 |
|
|
| 94 |
< |
QTextStream *modWriteStream = new QTextStream (modInfo); |
| 95 |
< |
*modWriteStream << "AEInstallVersion -> "+aeVersion+"\n"; |
| 96 |
< |
*modWriteStream << "NameOfMod -> "+modName+"\n"; |
| 97 |
< |
*modWriteStream << "ModVersion -> "+version+"\n"; |
| 98 |
< |
*modWriteStream << "Creator -> "+authors+"\n"; |
| 99 |
< |
*modWriteStream << "Readme -> "+description.replace("\n"," \\n ")+"\n"; |
| 94 |
> |
QTextStream modWriteStream(&modInfo); |
| 95 |
> |
modWriteStream << "AEInstallVersion -> "+aeVersion+"\n"; |
| 96 |
> |
modWriteStream << "NameOfMod -> "+modName+"\n"; |
| 97 |
> |
modWriteStream << "ModVersion -> "+version+"\n"; |
| 98 |
> |
modWriteStream << "Creator -> "+authors+"\n"; |
| 99 |
> |
modWriteStream << "Readme -> "+description.replace("\n"," \\n ")+"\n"; |
| 100 |
|
if(!incompatiblePackages.isEmpty()){ |
| 101 |
< |
*modWriteStream << "IncompatibleWith -> "+incompatiblePackages+"\n"; |
| 101 |
> |
modWriteStream << "IncompatibleWith -> "+incompatiblePackages+"\n"; |
| 102 |
|
} |
| 103 |
|
if(!dependentPackages.isEmpty()){ |
| 104 |
< |
*modWriteStream << "DependsOn -> "+dependentPackages+"\n"; |
| 104 |
> |
modWriteStream << "DependsOn -> "+dependentPackages+"\n"; |
| 105 |
|
} |
| 106 |
|
|
| 107 |
|
if(bslExist){ |
| 108 |
|
if(bslReplace){ |
| 109 |
< |
*modWriteStream << "HasBsl -> Yes\n"; |
| 109 |
> |
modWriteStream << "HasBsl -> Yes\n"; |
| 110 |
|
} |
| 111 |
|
else{ |
| 112 |
< |
*modWriteStream << "HasBsl -> Addon\n"; |
| 112 |
> |
modWriteStream << "HasBsl -> Addon\n"; |
| 113 |
|
} |
| 114 |
|
} |
| 115 |
|
|
| 116 |
|
if(!unlockLevels.isEmpty()){ |
| 117 |
< |
*modWriteStream << "UnlockLevel -> "+unlockLevels+"\n"; |
| 117 |
> |
modWriteStream << "UnlockLevel -> "+unlockLevels+"\n"; |
| 118 |
|
} |
| 119 |
|
|
| 120 |
< |
*modWriteStream << "Vago -> "+GlobalVars::AppVersion; |
| 120 |
> |
modWriteStream << "Vago -> "+GlobalVars::AppVersion; |
| 121 |
|
|
| 122 |
< |
delete modWriteStream; //it auto closes the files/streams |
| 152 |
< |
delete modInfo; |
| 122 |
> |
modInfo.close(); |
| 123 |
|
|
| 154 |
– |
//Create zipped package using PKZIP 2.0 (http://osdab.42cows.org/snippets/zip.php?mode=advanced) |
| 124 |
|
if(createZip){ |
| 125 |
< |
Zip uz; |
| 126 |
< |
|
| 127 |
< |
Zip::ErrorCode ec = uz.createArchive(this->packagesLocation+"/"+packageName+".zip"); |
| 159 |
< |
checkForZipError(ec); |
| 160 |
< |
|
| 161 |
< |
ec=uz.addDirectory(modDir); |
| 162 |
< |
checkForZipError(ec); |
| 163 |
< |
|
| 164 |
< |
ec = uz.closeArchive(); |
| 165 |
< |
checkForZipError(ec); |
| 125 |
> |
if(!JlCompress::compressDir(this->packagesLocation+"/"+packageName+".zip", modDir)){ |
| 126 |
> |
UtilVago::showAndLogErrorPopUp(this->myLogger, "An error occurred while zipping the package."); |
| 127 |
> |
} |
| 128 |
|
} |
| 129 |
|
|
| 130 |
|
if(openFolder){ |
| 161 |
|
} |
| 162 |
|
} |
| 163 |
|
QDir().mkpath(path); //create path if doesn't exist |
| 164 |
< |
if(!Util::cpDir(sourceFolder,path+Util::cutName(sourceFolder))){//copy contents (creates dest destination automatically if not exists yet) |
| 165 |
< |
QString errorString="An error occurred while copping the folder/files to the package folder: \n" |
| 166 |
< |
"Copying from "+sourceFolder+"\n to "+path+Util::cutName(sourceFolder); |
| 167 |
< |
Util::showErrorLogPopUp(errorString); |
| 206 |
< |
this->myLogger->writeString(errorString); |
| 164 |
> |
if(!Util::copyDir(sourceFolder,path,false)){//copy contents (creates dest destination automatically if not exists yet) |
| 165 |
> |
|
| 166 |
> |
UtilVago::showAndLogErrorPopUpLogButton(this->myLogger, "An error occurred while copying the folder/files to the package folder: \n" |
| 167 |
> |
"Copying from "+sourceFolder+"\n to "+path); |
| 168 |
|
} |
| 169 |
|
} |
| 170 |
|
} |
| 171 |
|
|
| 172 |
< |
/** |
| 173 |
< |
Convenience function for checking for zipping errors |
| 174 |
< |
*/ |
| 175 |
< |
void PackageWizard::checkForZipError(Zip::ErrorCode ec){ |
| 176 |
< |
if (ec != Zip::Ok){ |
| 216 |
< |
const QString error="Error found while zipping the package. Error number = "+QString::number(ec); |
| 217 |
< |
Util::showErrorPopUp(error); |
| 218 |
< |
this->myLogger->writeString(error); |
| 172 |
> |
void PackageWizard::beforeClose(QDialog::DialogCode resultStatus){ |
| 173 |
> |
|
| 174 |
> |
//If wizard finished with sucess, create the package |
| 175 |
> |
if(resultStatus == QDialog::Accepted){ |
| 176 |
> |
createPackage(); |
| 177 |
|
} |
| 178 |
|
} |
| 179 |
+ |
|