#include "packagewizard.h" PackageWizard::PackageWizard(QString workspaceWizardLocation, QSettings *vagoSettings, Logger *myLogger) { 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/) #ifdef Q_OS_WIN myWizard.resize(640,480); #else myWizard.resize(800,600); // Mac OS pcs should be able to render this resolution without any problem. It's also better // because the components on mac use more space #endif QRect position = myWizard.frameGeometry(); position.moveCenter(QDesktopWidget().availableGeometry().center()); myWizard.move(position.topLeft()); // PackagePage2 *page2 = new PackagePage2(this->myLogger); PackagePage3 *page3 = new PackagePage3(); PackagePage4 *page4 = new PackagePage4(); PackagePageFinal *pageFinal = new PackagePageFinal(this->vagoSettings); myWizard.addPage(createIntroPage()); 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; } 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){ 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(); //Get info page 3 QString dependentPackages=myWizard.field("leDependentPackages").toString(); QString incompatiblePackages=myWizard.field("leIncompatiblePackages").toString(); QString unlockLevels=myWizard.field("leUnlockLevels").toString(); //Get info page 4 const DropTableWidget *commonTable=page4->commonTable; const DropTableWidget *windowsTable=page4->windowsTable; const DropTableWidget *macTable=page4->macTable; //Get info from final page bool openFolder=myWizard.field("cbOpenFolder").toBool(); bool createZip=myWizard.field("cbCreateZip").toBool(); //Remember the final page choices to next time this->vagoSettings->setValue("PackageCreator/OpenFolder",openFolder); this->vagoSettings->setValue("PackageCreator/CreateZip",createZip); const QString packageName=packageNumber+Util::fullTrim(modName); // Start package creation... // Create Packages folder if it doesn't exist if(!QDir(this->packagesLocation).exists()){ QDir().mkpath(this->packagesLocation); } QString modDir=this->packagesLocation+"/"+packageName+"/"; QDir().mkdir(modDir); bool bslExist=false; if(commonTable->rowCount()>0){ copyPackageFolders(commonTable,"common",modDir,bslExist); } if(windowsTable->rowCount()>0){ copyPackageFolders(windowsTable,"win_only",modDir,bslExist); } if(macTable->rowCount()>0){ copyPackageFolders(macTable,"mac_only",modDir,bslExist); } QFile modInfo(modDir+"Mod_Info.cfg"); 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(&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"; } if(!dependentPackages.isEmpty()){ modWriteStream << "DependsOn -> "+dependentPackages+"\n"; } if(bslExist){ if(bslReplace){ modWriteStream << "HasBsl -> Yes\n"; } else{ modWriteStream << "HasBsl -> Addon\n"; } } if(!unlockLevels.isEmpty()){ modWriteStream << "UnlockLevel -> "+unlockLevels+"\n"; } modWriteStream << "Vago -> "+GlobalVars::AppVersion; modInfo.close(); if(createZip){ if(!JlCompress::compressDir(this->packagesLocation+"/"+packageName+".zip", modDir)){ UtilVago::showAndLogErrorPopUp(this->myLogger, "An error occurred while zipping the package."); } } if(openFolder){ QDesktopServices::openUrl(QUrl("file:///"+this->packagesLocation)); } } void PackageWizard::copyPackageFolders(const DropTableWidget *myTable, QString tableDir, QString modDir, bool &bslExist){ QString sourceFolder; bool onisExist=false; QString path; for(int i=0; irowCount(); i++){ sourceFolder=myTable->item(i,2)->text(); if(myTable->item(i,1)->text()==".oni"){ path=modDir+"oni/"+tableDir; if(!onisExist){ onisExist=true; } } else if(myTable->item(i,1)->text()==".bsl"){ path=modDir+"bsl/"+tableDir; if(!bslExist){ bslExist=true; } } else{ path=modDir+"patches/"+tableDir; if(!bslExist){ bslExist=true; } } QDir().mkpath(path); //create path if doesn't exist 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); } } }