source: Vago/trunk/Vago/packageWizard/packagewizard.cpp@ 793

Last change on this file since 793 was 793, checked in by s10k, 12 years ago

mac resolutions usually are higher than in pcs. So I've updated the app
to start as 800x600 (in mac).

File size: 7.7 KB
RevLine 
[771]1#include "packagewizard.h"
2
3PackageWizard::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
11int 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/)
[793]17#ifdef Q_WS_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
49QWizardPage* 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
65void 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
120 QFile *modInfo = new QFile(modDir+"Mod_Info.cfg");
121
122 if (!modInfo->open(QIODevice::WriteOnly | QIODevice::Text)){ //open to write
[789]123 Util::showErrorPopUp("Couldn't create Mod_Info.cfg file.");
124 myLogger->writeString("Couldn't create Mod_Info.cfg file when creating AE Package.");
[771]125 return;
126 }
127
128 QTextStream *modWriteStream = new QTextStream (modInfo);
129 *modWriteStream << "AEInstallVersion -> "+aeVersion+"\n";
130 *modWriteStream << "NameOfMod -> "+modName+"\n";
131 *modWriteStream << "ModVersion -> "+version+"\n";
132 *modWriteStream << "Creator -> "+authors+"\n";
133 *modWriteStream << "Readme -> "+description.replace("\n"," \\n ")+"\n";
134 if(!incompatiblePackages.isEmpty()){
135 *modWriteStream << "IncompatibleWith -> "+incompatiblePackages+"\n";
136 }
137 if(!dependentPackages.isEmpty()){
138 *modWriteStream << "DependsOn -> "+dependentPackages+"\n";
139 }
140
141 if(bslExist){
142 if(bslReplace){
143 *modWriteStream << "HasBsl -> Yes\n";
144 }
145 else{
146 *modWriteStream << "HasBsl -> Addon\n";
147 }
148 }
149
150 if(!unlockLevels.isEmpty()){
151 *modWriteStream << "UnlockLevel -> "+unlockLevels+"\n";
152 }
153
154 *modWriteStream << "Vago -> "+GlobalVars::AppVersion;
155
156 delete modWriteStream; //it auto closes the files/streams
157 delete modInfo;
158
159 //Create zipped package using PKZIP 2.0 (http://osdab.42cows.org/snippets/zip.php?mode=advanced)
160 if(createZip){
161 Zip uz;
162
163 Zip::ErrorCode ec = uz.createArchive(this->packagesLocation+"/"+packageName+".zip");
164 checkForZipError(ec);
165
166 ec=uz.addDirectory(modDir);
167 checkForZipError(ec);
168
169 ec = uz.closeArchive();
170 checkForZipError(ec);
171 }
172
173 if(openFolder){
174 QDesktopServices::openUrl(QUrl("file:///"+this->packagesLocation));
175 }
176}
177
178void PackageWizard::copyPackageFolders(const DropTableWidget *myTable, QString tableDir, QString modDir, bool &bslExist){
179
180 QString sourceFolder;
181 bool onisExist=false;
182 QString path;
183
184 for(int i=0; i<myTable->rowCount(); i++){
185
186 sourceFolder=myTable->item(i,2)->text();
187
188 if(myTable->item(i,1)->text()==".oni"){
189 path=modDir+"oni/"+tableDir;
190 if(!onisExist){
191 onisExist=true;
192 }
193 }
194 else if(myTable->item(i,1)->text()==".bsl"){
195 path=modDir+"bsl/"+tableDir;
196 if(!bslExist){
197 bslExist=true;
198 }
199 }
200 else{
201 path=modDir+"patches/"+tableDir;
202 if(!bslExist){
203 bslExist=true;
204 }
205 }
206 QDir().mkpath(path); //create path if doesn't exist
207 if(!Util::cpDir(sourceFolder,path+Util::cutName(sourceFolder))){//copy contents (creates dest destination automatically if not exists yet)
208 QString errorString="An error occurred while copping the folder/files to the package folder: \n"
209 "Copying from "+sourceFolder+"\n to "+path+Util::cutName(sourceFolder);
210 Util::showErrorLogPopUp(errorString);
211 this->myLogger->writeString(errorString);
212 }
213 }
214}
215
216/**
217 Convenience function for checking for zipping errors
218 */
219void PackageWizard::checkForZipError(Zip::ErrorCode ec){
220 if (ec != Zip::Ok){
221 const QString error="Error found while zipping the package. Error number = "+QString::number(ec);
222 Util::showErrorPopUp(error);
223 this->myLogger->writeString(error);
224 }
225}
Note: See TracBrowser for help on using the repository browser.