1 | #include "packagewizard.h"
|
---|
2 |
|
---|
3 | PackageWizard::PackageWizard(const QString &appDir, QString workspaceWizardLocation, QSettings *vagoSettings)
|
---|
4 | :AbstractWizard(appDir, workspaceWizardLocation, vagoSettings, false)
|
---|
5 | {
|
---|
6 | this->packagesLocation=this->workspaceWizardLocation+"/Packages";
|
---|
7 | }
|
---|
8 |
|
---|
9 | void PackageWizard::exec(){
|
---|
10 | PackagePage2 *page2 = new PackagePage2();
|
---|
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(
|
---|
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 | showWizard("AIE2 Package Creator", ":/new/icons/package.png");
|
---|
29 | }
|
---|
30 |
|
---|
31 |
|
---|
32 | void PackageWizard::createPackage(){
|
---|
33 | const QString aeVersion="2.0";
|
---|
34 |
|
---|
35 | //Get info page 2
|
---|
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=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=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=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);
|
---|
59 |
|
---|
60 | const QString packageName=packageNumber+Util::String::fullTrim(modName);
|
---|
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 |
|
---|
87 | QFile modInfo(modDir+"Mod_Info.cfg");
|
---|
88 |
|
---|
89 | if (!modInfo.open(QIODevice::WriteOnly | QIODevice::Text)){ //open to write
|
---|
90 | UtilVago::showAndLogErrorPopUp("Couldn't create Mod_Info.cfg file when creating AE Package.");
|
---|
91 | return;
|
---|
92 | }
|
---|
93 |
|
---|
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";
|
---|
102 | }
|
---|
103 | if(!dependentPackages.isEmpty()){
|
---|
104 | modWriteStream << "DependsOn -> "+dependentPackages+"\n";
|
---|
105 | }
|
---|
106 |
|
---|
107 | if(bslExist){
|
---|
108 | if(bslReplace){
|
---|
109 | modWriteStream << "HasBsl -> Yes\n";
|
---|
110 | }
|
---|
111 | else{
|
---|
112 | modWriteStream << "HasBsl -> Addon\n";
|
---|
113 | }
|
---|
114 | }
|
---|
115 |
|
---|
116 | if(!unlockLevels.isEmpty()){
|
---|
117 | modWriteStream << "UnlockLevel -> "+unlockLevels+"\n";
|
---|
118 | }
|
---|
119 |
|
---|
120 | modWriteStream << "Vago -> "+GlobalVars::AppVersion;
|
---|
121 |
|
---|
122 | modInfo.close();
|
---|
123 |
|
---|
124 | if(createZip){
|
---|
125 | if(!JlCompress::compressDir(this->packagesLocation+"/"+packageName+".zip", modDir)){
|
---|
126 | UtilVago::showAndLogErrorPopUp("An error occurred while zipping the package.");
|
---|
127 | }
|
---|
128 | }
|
---|
129 |
|
---|
130 | if(openFolder){
|
---|
131 | QDesktopServices::openUrl(QUrl("file:///"+this->packagesLocation));
|
---|
132 | }
|
---|
133 | }
|
---|
134 |
|
---|
135 | void 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
|
---|
164 | if(!Util::FileSystem::copyDir(sourceFolder,path,false)){//copy contents (creates dest destination automatically if not exists yet)
|
---|
165 |
|
---|
166 | UtilVago::showAndLogErrorPopUpLogButton("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 | 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 |
|
---|