source: s10k/Vago/packageWizard/packagewizard.cpp@ 1140

Last change on this file since 1140 was 1093, checked in by s10k, 7 years ago

Vago 1.4

File size: 6.2 KB
RevLine 
[771]1#include "packagewizard.h"
2
[1093]3PackageWizard::PackageWizard(const QString &appDir, QString workspaceWizardLocation, QSettings *vagoSettings)
4 :AbstractWizard(appDir, workspaceWizardLocation, vagoSettings, false)
[771]5{
6 this->packagesLocation=this->workspaceWizardLocation+"/Packages";
7}
8
[1061]9void PackageWizard::exec(){
[1093]10 PackagePage2 *page2 = new PackagePage2();
[771]11 PackagePage3 *page3 = new PackagePage3();
12 PackagePage4 *page4 = new PackagePage4();
[1061]13 this->page4Pointer = page4; // save the pointer in class variable
[771]14 PackagePageFinal *pageFinal = new PackagePageFinal(this->vagoSettings);
15
[1061]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 );
[771]23 myWizard.addPage(page2);
24 myWizard.addPage(page3);
25 myWizard.addPage(page4);
26 myWizard.addPage(pageFinal);
27
[1061]28 showWizard("AIE2 Package Creator", ":/new/icons/package.png");
[771]29}
30
31
[1061]32void PackageWizard::createPackage(){
[771]33 const QString aeVersion="2.0";
34
35 //Get info page 2
[1061]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();
[771]42
43 //Get info page 3
[1061]44 QString dependentPackages=this->myWizard.field("leDependentPackages").toString();
45 QString incompatiblePackages=this->myWizard.field("leIncompatiblePackages").toString();
46 QString unlockLevels=this->myWizard.field("leUnlockLevels").toString();
[771]47
48 //Get info page 4
[1061]49 const DropTableWidget *commonTable=this->page4Pointer->commonTable;
50 const DropTableWidget *windowsTable=this->page4Pointer->windowsTable;
51 const DropTableWidget *macTable=this->page4Pointer->macTable;
[771]52
53 //Get info from final page
[1061]54 bool openFolder=this->myWizard.field("cbOpenFolder").toBool();
55 bool createZip=this->myWizard.field("cbCreateZip").toBool();
[771]56 //Remember the final page choices to next time
57 this->vagoSettings->setValue("PackageCreator/OpenFolder",openFolder);
58 this->vagoSettings->setValue("PackageCreator/CreateZip",createZip);
59
[1093]60 const QString packageName=packageNumber+Util::String::fullTrim(modName);
[771]61
62 // Start package creation...
63
64 // Create Packages folder if it doesn't exist
65 if(!QDir(this->packagesLocation).exists()){
66 QDir().mkpath(this->packagesLocation);
67 }
68
69 QString modDir=this->packagesLocation+"/"+packageName+"/";
70
71 QDir().mkdir(modDir);
72
73 bool bslExist=false;
74
75 if(commonTable->rowCount()>0){
76 copyPackageFolders(commonTable,"common",modDir,bslExist);
77 }
78
79 if(windowsTable->rowCount()>0){
80 copyPackageFolders(windowsTable,"win_only",modDir,bslExist);
81 }
82
83 if(macTable->rowCount()>0){
84 copyPackageFolders(macTable,"mac_only",modDir,bslExist);
85 }
86
[1047]87 QFile modInfo(modDir+"Mod_Info.cfg");
[771]88
[1047]89 if (!modInfo.open(QIODevice::WriteOnly | QIODevice::Text)){ //open to write
[1093]90 UtilVago::showAndLogErrorPopUp("Couldn't create Mod_Info.cfg file when creating AE Package.");
[771]91 return;
92 }
93
[1047]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";
[771]100 if(!incompatiblePackages.isEmpty()){
[1047]101 modWriteStream << "IncompatibleWith -> "+incompatiblePackages+"\n";
[771]102 }
103 if(!dependentPackages.isEmpty()){
[1047]104 modWriteStream << "DependsOn -> "+dependentPackages+"\n";
[771]105 }
106
107 if(bslExist){
108 if(bslReplace){
[1047]109 modWriteStream << "HasBsl -> Yes\n";
[771]110 }
111 else{
[1047]112 modWriteStream << "HasBsl -> Addon\n";
[771]113 }
114 }
115
116 if(!unlockLevels.isEmpty()){
[1047]117 modWriteStream << "UnlockLevel -> "+unlockLevels+"\n";
[771]118 }
119
[1047]120 modWriteStream << "Vago -> "+GlobalVars::AppVersion;
[771]121
[1047]122 modInfo.close();
[771]123
124 if(createZip){
[1047]125 if(!JlCompress::compressDir(this->packagesLocation+"/"+packageName+".zip", modDir)){
[1093]126 UtilVago::showAndLogErrorPopUp("An error occurred while zipping the package.");
[1047]127 }
[771]128 }
129
130 if(openFolder){
131 QDesktopServices::openUrl(QUrl("file:///"+this->packagesLocation));
132 }
133}
134
135void PackageWizard::copyPackageFolders(const DropTableWidget *myTable, QString tableDir, QString modDir, bool &bslExist){
136
137 QString sourceFolder;
138 bool onisExist=false;
139 QString path;
140
141 for(int i=0; i<myTable->rowCount(); i++){
142
143 sourceFolder=myTable->item(i,2)->text();
144
145 if(myTable->item(i,1)->text()==".oni"){
146 path=modDir+"oni/"+tableDir;
147 if(!onisExist){
148 onisExist=true;
149 }
150 }
151 else if(myTable->item(i,1)->text()==".bsl"){
152 path=modDir+"bsl/"+tableDir;
153 if(!bslExist){
154 bslExist=true;
155 }
156 }
157 else{
158 path=modDir+"patches/"+tableDir;
159 if(!bslExist){
160 bslExist=true;
161 }
162 }
163 QDir().mkpath(path); //create path if doesn't exist
[1093]164 if(!Util::FileSystem::copyDir(sourceFolder,path,false)){//copy contents (creates dest destination automatically if not exists yet)
[1047]165
[1093]166 UtilVago::showAndLogErrorPopUpLogButton("An error occurred while copying the folder/files to the package folder: \n"
[1047]167 "Copying from "+sourceFolder+"\n to "+path);
[771]168 }
169 }
170}
[1061]171
172void 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
Note: See TracBrowser for help on using the repository browser.