--- Vago/trunk/Vago/packageWizard/packagewizard.cpp 2013/04/04 14:46:11 789 +++ s10k/Vago/packageWizard/packagewizard.cpp 2017/12/30 13:43:28 1092 @@ -1,86 +1,58 @@ #include "packagewizard.h" -PackageWizard::PackageWizard(QString workspaceWizardLocation, QSettings *vagoSettings, Logger *myLogger) +PackageWizard::PackageWizard(const QString &appDir, QString workspaceWizardLocation, QSettings *vagoSettings, Logger *myLogger) + :AbstractWizard(appDir, workspaceWizardLocation, vagoSettings, myLogger, false) { - this->workspaceWizardLocation=workspaceWizardLocation; - this->vagoSettings=vagoSettings; - this->myLogger=myLogger; this->packagesLocation=this->workspaceWizardLocation+"/Packages"; } -int PackageWizard::exec(){ - QWizard myWizard; - - myWizard.setWindowIcon(QIcon(":/new/icons/package.png")); - - //Center and resize QWizard (http://www.thedazzlersinc.com/source/2012/06/04/qt-center-window-in-screen/) - myWizard.resize(640,480); - QRect position = myWizard.frameGeometry(); - position.moveCenter(QDesktopWidget().availableGeometry().center()); - myWizard.move(position.topLeft()); - // - +void PackageWizard::exec(){ PackagePage2 *page2 = new PackagePage2(this->myLogger); PackagePage3 *page3 = new PackagePage3(); PackagePage4 *page4 = new PackagePage4(); + this->page4Pointer = page4; // save the pointer in class variable PackagePageFinal *pageFinal = new PackagePageFinal(this->vagoSettings); - myWizard.addPage(createIntroPage()); + myWizard.addPage( + createIntroPage( + "Welcome to the Anniversary Edition Installer 2 (AIE2) package" + " creator wizard.\n" + "This wizard will allow you to create in a few and simple steps a package for AIE2." + ) + ); myWizard.addPage(page2); myWizard.addPage(page3); myWizard.addPage(page4); myWizard.addPage(pageFinal); - myWizard.setWindowTitle("AIE2 Package Creator"); - - //If wizard finished with sucess - if(myWizard.exec()){ //modal and wait for finalization - createPackage(myWizard, page4); - } - - return 0; + showWizard("AIE2 Package Creator", ":/new/icons/package.png"); } -QWizardPage* PackageWizard::createIntroPage() { - QWizardPage *page = new QWizardPage; - page->setTitle("Introduction"); - - QLabel *label = new QLabel("Welcome to the Anniversary Edition Installer 2 (AIE2) package" - " creator wizard.\n" - "This wizard will allow you to create in a few and simple steps a package for AIE2."); - label->setWordWrap(true); - - QVBoxLayout *layout = new QVBoxLayout; - layout->addWidget(label); - page->setLayout(layout); - - return page; -} -void PackageWizard::createPackage(const QWizard &myWizard, PackagePage4 *page4){ +void PackageWizard::createPackage(){ const QString aeVersion="2.0"; //Get info page 2 - QString modName=myWizard.field("leModName").toString(); - QString authors=myWizard.field("leAuthors").toString(); - QString version=myWizard.field("leVersion").toString(); - QString description=myWizard.field("ptDescription").toString(); - QString packageNumber=myWizard.field("lePackageNumber").toString(); - bool bslReplace=myWizard.field("rbReplace").toBool(); + QString modName=this->myWizard.field("leModName").toString(); + QString authors=this->myWizard.field("leAuthors").toString(); + QString version=this->myWizard.field("leVersion").toString(); + QString description=this->myWizard.field("ptDescription").toString(); + QString packageNumber=this->myWizard.field("lePackageNumber").toString(); + bool bslReplace=this->myWizard.field("rbReplace").toBool(); //Get info page 3 - QString dependentPackages=myWizard.field("leDependentPackages").toString(); - QString incompatiblePackages=myWizard.field("leIncompatiblePackages").toString(); - QString unlockLevels=myWizard.field("leUnlockLevels").toString(); + QString dependentPackages=this->myWizard.field("leDependentPackages").toString(); + QString incompatiblePackages=this->myWizard.field("leIncompatiblePackages").toString(); + QString unlockLevels=this->myWizard.field("leUnlockLevels").toString(); //Get info page 4 - const DropTableWidget *commonTable=page4->commonTable; - const DropTableWidget *windowsTable=page4->windowsTable; - const DropTableWidget *macTable=page4->macTable; + const DropTableWidget *commonTable=this->page4Pointer->commonTable; + const DropTableWidget *windowsTable=this->page4Pointer->windowsTable; + const DropTableWidget *macTable=this->page4Pointer->macTable; //Get info from final page - bool openFolder=myWizard.field("cbOpenFolder").toBool(); - bool createZip=myWizard.field("cbCreateZip").toBool(); + bool openFolder=this->myWizard.field("cbOpenFolder").toBool(); + bool createZip=this->myWizard.field("cbCreateZip").toBool(); //Remember the final page choices to next time this->vagoSettings->setValue("PackageCreator/OpenFolder",openFolder); this->vagoSettings->setValue("PackageCreator/CreateZip",createZip); @@ -112,57 +84,47 @@ void PackageWizard::createPackage(const copyPackageFolders(macTable,"mac_only",modDir,bslExist); } - QFile *modInfo = new QFile(modDir+"Mod_Info.cfg"); + QFile modInfo(modDir+"Mod_Info.cfg"); - if (!modInfo->open(QIODevice::WriteOnly | QIODevice::Text)){ //open to write - Util::showErrorPopUp("Couldn't create Mod_Info.cfg file."); - myLogger->writeString("Couldn't create Mod_Info.cfg file when creating AE Package."); + if (!modInfo.open(QIODevice::WriteOnly | QIODevice::Text)){ //open to write + UtilVago::showAndLogErrorPopUp(this->myLogger, "Couldn't create Mod_Info.cfg file when creating AE Package."); return; } - QTextStream *modWriteStream = new QTextStream (modInfo); - *modWriteStream << "AEInstallVersion -> "+aeVersion+"\n"; - *modWriteStream << "NameOfMod -> "+modName+"\n"; - *modWriteStream << "ModVersion -> "+version+"\n"; - *modWriteStream << "Creator -> "+authors+"\n"; - *modWriteStream << "Readme -> "+description.replace("\n"," \\n ")+"\n"; + QTextStream modWriteStream(&modInfo); + modWriteStream << "AEInstallVersion -> "+aeVersion+"\n"; + modWriteStream << "NameOfMod -> "+modName+"\n"; + modWriteStream << "ModVersion -> "+version+"\n"; + modWriteStream << "Creator -> "+authors+"\n"; + modWriteStream << "Readme -> "+description.replace("\n"," \\n ")+"\n"; if(!incompatiblePackages.isEmpty()){ - *modWriteStream << "IncompatibleWith -> "+incompatiblePackages+"\n"; + modWriteStream << "IncompatibleWith -> "+incompatiblePackages+"\n"; } if(!dependentPackages.isEmpty()){ - *modWriteStream << "DependsOn -> "+dependentPackages+"\n"; + modWriteStream << "DependsOn -> "+dependentPackages+"\n"; } if(bslExist){ if(bslReplace){ - *modWriteStream << "HasBsl -> Yes\n"; + modWriteStream << "HasBsl -> Yes\n"; } else{ - *modWriteStream << "HasBsl -> Addon\n"; + modWriteStream << "HasBsl -> Addon\n"; } } if(!unlockLevels.isEmpty()){ - *modWriteStream << "UnlockLevel -> "+unlockLevels+"\n"; + modWriteStream << "UnlockLevel -> "+unlockLevels+"\n"; } - *modWriteStream << "Vago -> "+GlobalVars::AppVersion; + modWriteStream << "Vago -> "+GlobalVars::AppVersion; - delete modWriteStream; //it auto closes the files/streams - delete modInfo; + modInfo.close(); - //Create zipped package using PKZIP 2.0 (http://osdab.42cows.org/snippets/zip.php?mode=advanced) if(createZip){ - Zip uz; - - Zip::ErrorCode ec = uz.createArchive(this->packagesLocation+"/"+packageName+".zip"); - checkForZipError(ec); - - ec=uz.addDirectory(modDir); - checkForZipError(ec); - - ec = uz.closeArchive(); - checkForZipError(ec); + if(!JlCompress::compressDir(this->packagesLocation+"/"+packageName+".zip", modDir)){ + UtilVago::showAndLogErrorPopUp(this->myLogger, "An error occurred while zipping the package."); + } } if(openFolder){ @@ -199,22 +161,19 @@ void PackageWizard::copyPackageFolders(c } } QDir().mkpath(path); //create path if doesn't exist - if(!Util::cpDir(sourceFolder,path+Util::cutName(sourceFolder))){//copy contents (creates dest destination automatically if not exists yet) - QString errorString="An error occurred while copping the folder/files to the package folder: \n" - "Copying from "+sourceFolder+"\n to "+path+Util::cutName(sourceFolder); - Util::showErrorLogPopUp(errorString); - this->myLogger->writeString(errorString); + if(!Util::copyDir(sourceFolder,path,false)){//copy contents (creates dest destination automatically if not exists yet) + + UtilVago::showAndLogErrorPopUpLogButton(this->myLogger, "An error occurred while copying the folder/files to the package folder: \n" + "Copying from "+sourceFolder+"\n to "+path); } } } -/** - Convenience function for checking for zipping errors - */ -void PackageWizard::checkForZipError(Zip::ErrorCode ec){ - if (ec != Zip::Ok){ - const QString error="Error found while zipping the package. Error number = "+QString::number(ec); - Util::showErrorPopUp(error); - this->myLogger->writeString(error); +void PackageWizard::beforeClose(QDialog::DialogCode resultStatus){ + + //If wizard finished with sucess, create the package + if(resultStatus == QDialog::Accepted){ + createPackage(); } } +