[771] | 1 | #include "packagewizard.h"
|
---|
| 2 |
|
---|
| 3 | PackageWizard::PackageWizard(QString workspaceWizardLocation, QSettings *vagoSettings, Logger *myLogger)
|
---|
| 4 | {
|
---|
| 5 | this->workspaceWizardLocation=workspaceWizardLocation;
|
---|
| 6 | this->vagoSettings=vagoSettings;
|
---|
| 7 | this->myLogger=myLogger;
|
---|
| 8 | this->packagesLocation=this->workspaceWizardLocation+"/Packages";
|
---|
| 9 | }
|
---|
| 10 |
|
---|
| 11 | 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/)
|
---|
[998] | 17 | #ifdef Q_OS_WIN
|
---|
[771] | 18 | myWizard.resize(640,480);
|
---|
[793] | 19 | #else
|
---|
| 20 | myWizard.resize(800,600); // Mac OS pcs should be able to render this resolution without any problem. It's also better
|
---|
| 21 | // because the components on mac use more space
|
---|
| 22 | #endif
|
---|
[771] | 23 | QRect position = myWizard.frameGeometry();
|
---|
| 24 | position.moveCenter(QDesktopWidget().availableGeometry().center());
|
---|
| 25 | myWizard.move(position.topLeft());
|
---|
| 26 | //
|
---|
| 27 |
|
---|
| 28 | PackagePage2 *page2 = new PackagePage2(this->myLogger);
|
---|
| 29 | PackagePage3 *page3 = new PackagePage3();
|
---|
| 30 | PackagePage4 *page4 = new PackagePage4();
|
---|
| 31 | PackagePageFinal *pageFinal = new PackagePageFinal(this->vagoSettings);
|
---|
| 32 |
|
---|
| 33 | myWizard.addPage(createIntroPage());
|
---|
| 34 | myWizard.addPage(page2);
|
---|
| 35 | myWizard.addPage(page3);
|
---|
| 36 | myWizard.addPage(page4);
|
---|
| 37 | myWizard.addPage(pageFinal);
|
---|
| 38 |
|
---|
| 39 | myWizard.setWindowTitle("AIE2 Package Creator");
|
---|
| 40 |
|
---|
| 41 | //If wizard finished with sucess
|
---|
| 42 | if(myWizard.exec()){ //modal and wait for finalization
|
---|
| 43 | createPackage(myWizard, page4);
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | return 0;
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | QWizardPage* PackageWizard::createIntroPage() {
|
---|
| 50 | QWizardPage *page = new QWizardPage;
|
---|
| 51 | page->setTitle("Introduction");
|
---|
| 52 |
|
---|
| 53 | QLabel *label = new QLabel("Welcome to the Anniversary Edition Installer 2 (AIE2) package"
|
---|
| 54 | " creator wizard.\n"
|
---|
| 55 | "This wizard will allow you to create in a few and simple steps a package for AIE2.");
|
---|
| 56 | label->setWordWrap(true);
|
---|
| 57 |
|
---|
| 58 | QVBoxLayout *layout = new QVBoxLayout;
|
---|
| 59 | layout->addWidget(label);
|
---|
| 60 | page->setLayout(layout);
|
---|
| 61 |
|
---|
| 62 | return page;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | void PackageWizard::createPackage(const QWizard &myWizard, PackagePage4 *page4){
|
---|
| 66 | const QString aeVersion="2.0";
|
---|
| 67 |
|
---|
| 68 | //Get info page 2
|
---|
| 69 | QString modName=myWizard.field("leModName").toString();
|
---|
| 70 | QString authors=myWizard.field("leAuthors").toString();
|
---|
| 71 | QString version=myWizard.field("leVersion").toString();
|
---|
| 72 | QString description=myWizard.field("ptDescription").toString();
|
---|
| 73 | QString packageNumber=myWizard.field("lePackageNumber").toString();
|
---|
| 74 | bool bslReplace=myWizard.field("rbReplace").toBool();
|
---|
| 75 |
|
---|
| 76 | //Get info page 3
|
---|
| 77 | QString dependentPackages=myWizard.field("leDependentPackages").toString();
|
---|
| 78 | QString incompatiblePackages=myWizard.field("leIncompatiblePackages").toString();
|
---|
| 79 | QString unlockLevels=myWizard.field("leUnlockLevels").toString();
|
---|
| 80 |
|
---|
| 81 | //Get info page 4
|
---|
| 82 | const DropTableWidget *commonTable=page4->commonTable;
|
---|
| 83 | const DropTableWidget *windowsTable=page4->windowsTable;
|
---|
| 84 | const DropTableWidget *macTable=page4->macTable;
|
---|
| 85 |
|
---|
| 86 | //Get info from final page
|
---|
| 87 | bool openFolder=myWizard.field("cbOpenFolder").toBool();
|
---|
| 88 | bool createZip=myWizard.field("cbCreateZip").toBool();
|
---|
| 89 | //Remember the final page choices to next time
|
---|
| 90 | this->vagoSettings->setValue("PackageCreator/OpenFolder",openFolder);
|
---|
| 91 | this->vagoSettings->setValue("PackageCreator/CreateZip",createZip);
|
---|
| 92 |
|
---|
| 93 | const QString packageName=packageNumber+Util::fullTrim(modName);
|
---|
| 94 |
|
---|
| 95 | // Start package creation...
|
---|
| 96 |
|
---|
| 97 | // Create Packages folder if it doesn't exist
|
---|
| 98 | if(!QDir(this->packagesLocation).exists()){
|
---|
| 99 | QDir().mkpath(this->packagesLocation);
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | QString modDir=this->packagesLocation+"/"+packageName+"/";
|
---|
| 103 |
|
---|
| 104 | QDir().mkdir(modDir);
|
---|
| 105 |
|
---|
| 106 | bool bslExist=false;
|
---|
| 107 |
|
---|
| 108 | if(commonTable->rowCount()>0){
|
---|
| 109 | copyPackageFolders(commonTable,"common",modDir,bslExist);
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | if(windowsTable->rowCount()>0){
|
---|
| 113 | copyPackageFolders(windowsTable,"win_only",modDir,bslExist);
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | if(macTable->rowCount()>0){
|
---|
| 117 | copyPackageFolders(macTable,"mac_only",modDir,bslExist);
|
---|
| 118 | }
|
---|
| 119 |
|
---|
[1047] | 120 | QFile modInfo(modDir+"Mod_Info.cfg");
|
---|
[771] | 121 |
|
---|
[1047] | 122 | if (!modInfo.open(QIODevice::WriteOnly | QIODevice::Text)){ //open to write
|
---|
| 123 | UtilVago::showAndLogErrorPopUp(this->myLogger, "Couldn't create Mod_Info.cfg file when creating AE Package.");
|
---|
[771] | 124 | return;
|
---|
| 125 | }
|
---|
| 126 |
|
---|
[1047] | 127 | QTextStream modWriteStream(&modInfo);
|
---|
| 128 | modWriteStream << "AEInstallVersion -> "+aeVersion+"\n";
|
---|
| 129 | modWriteStream << "NameOfMod -> "+modName+"\n";
|
---|
| 130 | modWriteStream << "ModVersion -> "+version+"\n";
|
---|
| 131 | modWriteStream << "Creator -> "+authors+"\n";
|
---|
| 132 | modWriteStream << "Readme -> "+description.replace("\n"," \\n ")+"\n";
|
---|
[771] | 133 | if(!incompatiblePackages.isEmpty()){
|
---|
[1047] | 134 | modWriteStream << "IncompatibleWith -> "+incompatiblePackages+"\n";
|
---|
[771] | 135 | }
|
---|
| 136 | if(!dependentPackages.isEmpty()){
|
---|
[1047] | 137 | modWriteStream << "DependsOn -> "+dependentPackages+"\n";
|
---|
[771] | 138 | }
|
---|
| 139 |
|
---|
| 140 | if(bslExist){
|
---|
| 141 | if(bslReplace){
|
---|
[1047] | 142 | modWriteStream << "HasBsl -> Yes\n";
|
---|
[771] | 143 | }
|
---|
| 144 | else{
|
---|
[1047] | 145 | modWriteStream << "HasBsl -> Addon\n";
|
---|
[771] | 146 | }
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | if(!unlockLevels.isEmpty()){
|
---|
[1047] | 150 | modWriteStream << "UnlockLevel -> "+unlockLevels+"\n";
|
---|
[771] | 151 | }
|
---|
| 152 |
|
---|
[1047] | 153 | modWriteStream << "Vago -> "+GlobalVars::AppVersion;
|
---|
[771] | 154 |
|
---|
[1047] | 155 | modInfo.close();
|
---|
[771] | 156 |
|
---|
| 157 | if(createZip){
|
---|
[1047] | 158 | if(!JlCompress::compressDir(this->packagesLocation+"/"+packageName+".zip", modDir)){
|
---|
| 159 | UtilVago::showAndLogErrorPopUp(this->myLogger, "An error occurred while zipping the package.");
|
---|
| 160 | }
|
---|
[771] | 161 | }
|
---|
| 162 |
|
---|
| 163 | if(openFolder){
|
---|
| 164 | QDesktopServices::openUrl(QUrl("file:///"+this->packagesLocation));
|
---|
| 165 | }
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 | void PackageWizard::copyPackageFolders(const DropTableWidget *myTable, QString tableDir, QString modDir, bool &bslExist){
|
---|
| 169 |
|
---|
| 170 | QString sourceFolder;
|
---|
| 171 | bool onisExist=false;
|
---|
| 172 | QString path;
|
---|
| 173 |
|
---|
| 174 | for(int i=0; i<myTable->rowCount(); i++){
|
---|
| 175 |
|
---|
| 176 | sourceFolder=myTable->item(i,2)->text();
|
---|
| 177 |
|
---|
| 178 | if(myTable->item(i,1)->text()==".oni"){
|
---|
| 179 | path=modDir+"oni/"+tableDir;
|
---|
| 180 | if(!onisExist){
|
---|
| 181 | onisExist=true;
|
---|
| 182 | }
|
---|
| 183 | }
|
---|
| 184 | else if(myTable->item(i,1)->text()==".bsl"){
|
---|
| 185 | path=modDir+"bsl/"+tableDir;
|
---|
| 186 | if(!bslExist){
|
---|
| 187 | bslExist=true;
|
---|
| 188 | }
|
---|
| 189 | }
|
---|
| 190 | else{
|
---|
| 191 | path=modDir+"patches/"+tableDir;
|
---|
| 192 | if(!bslExist){
|
---|
| 193 | bslExist=true;
|
---|
| 194 | }
|
---|
| 195 | }
|
---|
| 196 | QDir().mkpath(path); //create path if doesn't exist
|
---|
[1047] | 197 | if(!Util::copyDir(sourceFolder,path,false)){//copy contents (creates dest destination automatically if not exists yet)
|
---|
| 198 |
|
---|
| 199 | UtilVago::showAndLogErrorPopUpLogButton(this->myLogger, "An error occurred while copying the folder/files to the package folder: \n"
|
---|
| 200 | "Copying from "+sourceFolder+"\n to "+path);
|
---|
[771] | 201 | }
|
---|
| 202 | }
|
---|
| 203 | }
|
---|