source: AE/Installer/trunk/source/main_window.cpp@ 387

Last change on this file since 387 was 385, checked in by gumby, 15 years ago
  • Property svn:executable set to *
File size: 54.8 KB
Line 
1/*
2 AE/Mod Installer
3 by Gumby and Iritscen
4*/
5
6// To-do: - Load credits from text resource file
7// - Institute lots of checks into file-handling
8// - Clear mod info fields when mod is de-selected
9
10#define DEBUG
11#include <stdio.h>
12//#include <conio.h>
13//#include <process.h>
14#include <string>
15#include <iostream>
16#include <cctype>
17#include <vector>
18#include <fstream>
19#include <errno.h>
20#include <sstream>
21
22#include "boost/filesystem.hpp" // includes all needed Boost.Filesystem declarations
23#include "boost/lexical_cast.hpp" //int -> string
24#include "installer.h"
25
26#ifdef WIN32
27#include <windows.h>
28#else // assume we're on Mac
29#include <stdlib.h>
30#include <dirent.h>
31#endif
32
33//const string strInstallerVersion = "1.0";
34const bool SPLIT = 1;
35const bool NOT_SPLIT = 0;
36bool splitInstances = SPLIT;
37bool busy = 0;
38#ifdef WIN32
39const string strOniSplit = "Onisplit.exe";
40string strImportOption = "-import:nosep";
41const char* strClsCmd = "cls";
42const char* strPauseCmd = "PAUSE";
43#else // set up Mac equivalents since we're in Mac OS
44const string strOniSplit = "mono Onisplit.exe";
45string strImportOption = "-import:sep";
46const char* strClsCmd = "clear";
47const char* strPauseCmd = "read -n 1 -p \"Press any key to continue\"";
48void Sleep(int ms) { sleep( ms / 1000 ); }
49#endif
50
51using namespace boost::filesystem;
52using namespace std;
53
54
55
56
57#include "boost/date_time/gregorian/gregorian.hpp"
58#include "boost/date_time/date_parsing.hpp"
59#include "boost/date_time/posix_time/posix_time.hpp"
60
61int globalizeData(void)
62{
63 busy = 1;
64 using boost::lexical_cast;
65 using boost::bad_lexical_cast;
66 // using namespace boost::posix_time;
67 using namespace boost::gregorian;
68 using namespace boost::posix_time;
69 ptime start_time(second_clock::local_time());
70
71 setStatusArea("Globalizing!");
72 int err = 0;
73 int parts_done = 0;
74 char Step_x_x[300];
75 //char levels[i][5];
76 remove("Globalize.log");
77 ofstream logfile("Globalize.log");
78 logfile << "Globalization started " << to_simple_string(start_time) << endl;
79 try {
80
81 char levels_cstr[15][3] = {"0", "1", "2", "3", "4", "6", "8", "9", "10", "11", "12", "13", "14", "18", "19"}; // the levels Oni has...probably should have made a string array. Oops.
82 //const vector<double> ck(cv, &cv[CvSize]);
83 vector<string> levels;
84 for (int f = 0; f < 15; f++) {
85 levels.push_back(levels_cstr[f]);
86 }
87 char choice = 0;
88
89 //SetCurrentDirectory("C:/Program Files/Oni/edition/install");
90 ///char levels[i][3];
91 path Characters = "../GameDataFolder/level0_Characters";
92 path Particles = "../GameDataFolder/level0_Particles";
93 path Archive = "../GameDataFolder/Archive";
94 path Textures = "../GameDataFolder/level0_Textures";
95 path Sounds = "../GameDataFolder/level0_Sounds";
96 path Animations = "../GameDataFolder/level0_Animations";
97 path TRAC = Animations / "level0_TRAC";
98 path TRAM = Animations / "level0_TRAM";
99
100 vector<path> GDFPaths;
101 GDFPaths.push_back(Characters);
102 GDFPaths.push_back(Particles);
103 GDFPaths.push_back(Textures);
104 GDFPaths.push_back(Sounds);
105 GDFPaths.push_back(TRAC);
106 GDFPaths.push_back(TRAM);
107
108
109 path VanillaCharacters = "packages/VanillaDats/level0_Final/level0_Characters/level0_Characters.oni";
110 path VanillaParticles = "packages/VanillaDats/level0_Final/level0_Particles/level0_Particles.oni";
111 path VanillaTextures = "packages/VanillaDats/level0_Final/level0_Textures/level0_Textures.oni";
112 path VanillaSounds = "packages/VanillaDats/level0_Final/level0_Sounds/level0_Sounds.oni";
113 path VanillaAnimations = "packages/VanillaDats/level0_Final/level0_Animations/level0_Animations.oni";
114 path VanillaTRAC = "packages/VanillaDats/level0_Final/level0_Animations/level0_TRAC.oni";
115 path VanillaTRAM = "packages/VanillaDats/level0_Final/level0_Animations/level0_TRAM.oni";
116
117 vector<path> VanillaPaths;
118
119 VanillaPaths.push_back(VanillaCharacters);
120 VanillaPaths.push_back(VanillaParticles);
121 VanillaPaths.push_back(VanillaTextures);
122 VanillaPaths.push_back(VanillaSounds);
123 VanillaPaths.push_back(VanillaTRAC);
124 VanillaPaths.push_back(VanillaTRAM);
125
126 /*
127 if (exists("../GameDataFolder/"))
128 {
129 //cout << "\nIt looks like you've already globalized Oni's data.\nDo you want to re-globalize?\n(This will erase existing mods installed to the AE's game data.)"
130 // << "\n1. Re-globalize"
131 // << "\n2. Return to main menu\n";
132 //choice = cin.get();
133 cin.ignore(128, '\n');
134 if (choice == '1')
135 remove_all("../GameDataFolder"); // remove AE GDF
136 if (choice == '2')
137 return 0;
138 }
139 */
140 setStatusArea("Removing old GameDataFolder...\n");
141 logfile << "Removing old GameDataFolder...\n";
142 remove_all( "../GameDataFolder/" );
143 setStatusArea("Creating needed directories...");
144 logfile << "Creating needed directories...\n";
145 create_directory( "../GameDataFolder/" );
146
147 create_directory( "packages" );
148
149 if (exists("packages/VanillaDats")) remove_all("packages/VanillaDats");
150 create_directory( "packages/VanillaDats" );
151
152 create_directory( "packages/VanillaDats/level0_Final/" );
153 //blah blah finish this.
154 //logfile << "packages/VanillaDats/level0_Final/ created";
155 create_directory( Characters );
156 create_directory( Particles );
157 create_directory( Archive );
158 create_directory( Textures );
159 create_directory( Sounds );
160 create_directory( Animations );
161 create_directory( TRAC );
162 create_directory( TRAM );
163 int num_levels = 0;
164 for(int i = 1; i < 15; i++)
165 {
166 if (exists("../../GameDataFolder/level" + levels[i] + "_Final.dat")) {
167 num_levels++;
168
169 }
170 }
171 logfile << "Exporting and moving...\n\n";
172 int total_steps = 8 + 2 * num_levels;
173 for(int i = 0; i < 15; i++)
174 {
175
176 //printf(levels[i],"%d",levels[i]); // int to char array
177
178 if (exists("../../GameDataFolder/level" + levels[i] + "_Final.dat")) {
179 logfile << "level" << levels[i] << "_Final\n";
180 logfile << "\tExporting level" << levels[i] << "_Final.dat\n";
181 //printf(Step_x_x,"Step %d/%d: exporting level%d_final.dat", parts_done + 1,, levels[i]); setStatusArea((string)Step_x_x);
182 setStatusArea("Step " + lexical_cast<std::string>(parts_done + 1) + "/" + lexical_cast<std::string>(total_steps) + " exporting level" + levels[i]+"_Final.dat");
183 create_directory( "../GameDataFolder/level" + levels[i] + "_Final" );
184 // setStatusArea(strOniSplit + " -export ../GameDataFolder/level" + levels[i] + "_Final ../../GameDataFolder/level" + levels[i] + "_Final.dat");
185 system((strOniSplit + " -export ../GameDataFolder/level" + levels[i] + "_Final ../../GameDataFolder/level" + levels[i] + "_Final.dat").c_str());
186 create_directory( "packages/VanillaDats/level" + levels[i] + "_Final" );
187 create_directory( "packages/VanillaDats/level" + levels[i] + "_Final/level" + levels[i] + "_Final" );
188
189 directory_iterator end_iter;
190 for ( directory_iterator dir_itr( "../GameDataFolder/level" + levels[i] + "_Final" ); dir_itr != end_iter; ++dir_itr )
191 {
192 //cout << dir_itr->path().filename();
193 if ( is_regular_file( dir_itr->status() ) )
194 {
195 if ( dir_itr->path().filename().substr(0,8) == "TXMPfail" ||
196 dir_itr->path().filename().substr(0,9) == "TXMPlevel" ||
197 ( dir_itr->path().filename().substr(0,4) == "TXMP" && dir_itr->path().filename().find("intro")!=string::npos) ||
198 dir_itr->path().filename().substr(0,4) == "TXMB" ||
199 dir_itr->path().filename() == "M3GMpowerup_lsi.oni" ||
200 dir_itr->path().filename() == "TXMPlsi_icon.oni" ||
201 ( dir_itr->path().filename().substr(0,4) == "TXMB" && dir_itr->path().filename().find("splash_screen.oni")!=string::npos) )
202 {
203 cout <<dir_itr->path().filename() << "\n";
204 create_directory( dir_itr->path().parent_path() / "NoGlobal");
205 if(!exists( dir_itr->path().parent_path() / "NoGlobal" / dir_itr->filename())) rename(dir_itr->path(), dir_itr->path().parent_path() / "NoGlobal" /
206 dir_itr->filename());
207 else remove(dir_itr->path());
208 }
209 else if (dir_itr->path().filename().substr(0,4) == "TRAC"
210 || dir_itr->path().filename().substr(0,4) == "ONVL") {
211 cout <<dir_itr->path().filename() << "\n";
212 if(!exists( TRAC / dir_itr->filename())) rename(dir_itr->path(), TRAC / dir_itr->filename());
213 else remove(dir_itr->path());
214 }
215 else if (dir_itr->path().filename().substr(0,4) == "TRAM") {
216 cout <<dir_itr->path().filename() << "\n";
217 if(!exists( TRAM / dir_itr->filename())) rename(dir_itr->path(), TRAM / dir_itr->filename());
218 else remove(dir_itr->path());
219 }
220 else if (dir_itr->path().filename().substr(0,4) == "ONSK" ||
221 dir_itr->path().filename().substr(0,4) == "TXMP") {
222 cout <<dir_itr->path().filename() << "\n";\
223 create_directory( dir_itr->path().parent_path() / "TexFix");
224 if(!exists( Textures / dir_itr->filename())) rename(dir_itr->path(), Textures / dir_itr->filename());
225 //rename(dir_itr->path(), dir_itr->path().parent_path() / "TexFix" / dir_itr->filename());
226 }
227 else if (dir_itr->path().filename().substr(0,4) == "ONCC"
228 || dir_itr->path().filename().substr(0,4) == "TRBS"
229 || dir_itr->path().filename().substr(0,4) == "ONCV"
230 || dir_itr->path().filename().substr(0,4) == "TRMA"
231 || dir_itr->path().filename().substr(0,4) == "TRSC"
232 || dir_itr->path().filename().substr(0,4) == "TRAS") {
233 cout <<dir_itr->path().filename() << "\n";
234 if(!exists( Characters / dir_itr->filename())) rename(dir_itr->path(), Characters / dir_itr->filename());
235 else remove(dir_itr->path());
236 }
237 else if (dir_itr->path().filename().substr(0,4) == "OSBD"
238 || dir_itr->path().filename().substr(0,4) == "SNDD") {
239 cout << dir_itr->path().filename() << "\n";
240 if(!exists( Sounds / dir_itr->filename())) rename(dir_itr->path(), Sounds / dir_itr->filename());
241 else remove(dir_itr->path());
242 }
243 else if (dir_itr->path().filename().substr(0,5) == "BINA3"
244 || dir_itr->path().filename().substr(0,10) == "M3GMdebris"
245 || dir_itr->path().filename() == "M3GMtoxic_bubble.oni"
246 || dir_itr->path().filename().substr(0,8) == "M3GMelec"
247 || dir_itr->path().filename().substr(0,7) == "M3GMrat"
248 || dir_itr->path().filename().substr(0,7) == "M3GMjet"
249 || dir_itr->path().filename().substr(0,9) == "M3GMbomb_"
250 || dir_itr->path().filename() == "M3GMbarab_swave.oni"
251 || dir_itr->path().filename() == "M3GMbloodyfoot.oni"
252 ){
253 cout <<dir_itr->path().filename() << "\n";
254 if(!exists( Particles / dir_itr->filename())) rename(dir_itr->path(), Particles / dir_itr->filename());
255 else remove(dir_itr->path());
256 }
257 else if (dir_itr->path().filename().substr(0,4) == "AGDB"
258 || dir_itr->path().filename().substr(0,4) == "TRCM") {
259 cout <<dir_itr->path().filename() << "\n";
260
261 if(!exists( Archive / dir_itr->filename())) rename(dir_itr->path(), Archive / dir_itr->filename());
262 else remove(dir_itr->path());
263 }
264 if (exists(dir_itr->path())) {
265
266 }
267 else {
268 //logfile << "\tMoved file: " << dir_itr->path().filename() << "\n";
269 }
270 }
271
272
273
274 }
275 logfile << "\tCleaning up TXMPs...\n";
276 system( (strOniSplit + " -move:delete " + Textures.string() + " ../GameDataFolder/level" + levels[i] + "_Final/TXMP*.oni").c_str());
277 parts_done++;
278
279 setProgressBar( (int)(1000 * (float)(parts_done) / (float)(total_steps) ));
280
281 }
282 }
283 logfile << "Reimporting levels\n";
284 for (int i = 0; i < 15; i++)
285 {
286 logfile << "\tReimporting level" << levels[i] << "_Final.oni\n";
287 //printf(levels[i],"%d",levels[i]);
288 //printf(Step_x_x,"Step %d/%d: reimporting level", parts_done + 1, 7 + 2 * num_levels); setStatusArea((string)Step_x_x + levels[i] + (string)"_Final.dat");
289 setStatusArea("Step " + lexical_cast<std::string>(parts_done + 1) + "/" + lexical_cast<std::string>(total_steps) + " reimporting level" + levels[i]+"_Final.oni");
290 logfile << (strOniSplit + " " + strImportOption + " ../GameDataFolder/level" + levels[i] + "_Final packages/VanillaDats/level" + levels[i] + "_Final/level"
291 + levels[i] + "_Final/level" + levels[i] + "_Final.oni >> Globalize.log").c_str() << '\n';
292 string sys_str = (strOniSplit + " " + strImportOption + " ../GameDataFolder/level" + levels[i] + "_Final packages/VanillaDats/level" + levels[i] + "_Final/level"
293 + levels[i] + "_Final/level" + levels[i] + "_Final.oni >> Globalize2.log");
294 system(sys_str.c_str() );
295 setProgressBar( (int)(1000 * (float)(parts_done) / (float)(total_steps) ));
296 parts_done++;
297 }
298 create_directory( VanillaCharacters.parent_path() );
299 create_directory( VanillaParticles.parent_path() );
300 create_directory( VanillaTextures.parent_path() );
301 create_directory( VanillaSounds.parent_path() );
302 create_directory( VanillaAnimations.remove_filename() );
303
304 for(int j = 0; j < GDFPaths.size(); j++) {
305 logfile << "\tReimporting " << GDFPaths[j].filename() << ".oni\n";
306 setStatusArea("Step " + lexical_cast<std::string>(parts_done + 1) + "/" + lexical_cast<std::string>(total_steps) + ": reimporting " + GDFPaths[j].filename() );
307 system((strOniSplit + " " + strImportOption + " " + GDFPaths[j].string() + " " + VanillaPaths[j].string()).c_str());
308 parts_done++;
309 setProgressBar( (int)(1000 * (float)(parts_done) / (float)(total_steps) ));
310 }
311 /*
312 printf(Step_x_x,"Step %d/%d: reimporting level0_Characters", parts_done,7 + 2 * num_levels); setStatusArea((string)Step_x_x);setProgressBar( (int)(1000 * (float)(parts_done) / (float)(7 + 2 * num_levels) ));
313 system((strOniSplit + " " + strImportOption + " " + Characters.string() + " " + VanillaCharacters.string()).c_str());
314 parts_done++; printf(Step_x_x,"Step %d/%d: reimporting level0_Particles", parts_done,7 + 2 * num_levels); setStatusArea((string)Step_x_x);setProgressBar( (int)(1000 * (float)(parts_done) / (float)(7 + 2 * num_levels) ));
315 system((strOniSplit + " " + strImportOption + " " + Particles.string() + " " + VanillaParticles.string()).c_str());
316 parts_done++; printf(Step_x_x,"Step %d/%d: reimporting level0_Textures", parts_done,7 + 2 * num_levels); setStatusArea((string)Step_x_x);setProgressBar( (int)(1000 * (float)(parts_done) / (float)(7 + 2 * num_levels) ));
317 system((strOniSplit + " " + strImportOption + " " + Textures.string() + " " + VanillaTextures.string()).c_str());
318 //system((strOniSplit + " " + strImportOption + (string)" " + Animations.string() + (string)" " + VanillaAnimations.string()).c_str());
319 parts_done++; printf(Step_x_x,"Step %d/%d: reimporting level0_TRAC", parts_done,7 + 2 * num_levels); setStatusArea((string)Step_x_x);setProgressBar( (int)(1000 * (float)(parts_done) / (float)(7 + 2 * num_levels) ));
320 system((strOniSplit + " " + strImportOption + " " + TRAC.string() + " " + VanillaTRAC.string()).c_str());
321 parts_done++; printf(Step_x_x,"Step %d/%d: reimporting level0_Sounds", parts_done,7 + 2 * num_levels); setStatusArea((string)Step_x_x);setProgressBar( (int)(1000 * (float)(parts_done) / (float)(7 + 2 * num_levels) ));
322 system((strOniSplit + " " + strImportOption + " " + Sounds.string() + " " + VanillaSounds.string()).c_str());
323 parts_done++; printf(Step_x_x,"Step %d/%d: reimporting level0_TRAM", parts_done,7 + 2 * num_levels); setStatusArea((string)Step_x_x);setProgressBar( (int)(1000 * (float)(parts_done) / (float)(7 + 2 * num_levels) ));
324 system((strOniSplit + " " + strImportOption + " " + TRAM.string() + " " + VanillaTRAM.string()).c_str());
325 //parts_done++; setStatusArea((string)"Copying level scripts...");setProgressBar( (int)(1000 * (float)(parts_done) / (float)(7 + 2 * num_levels) ));
326 if (exists("../GameDataFolder/IGMD")) remove_all("../GameDataFolder/IGMD");
327 */
328 create_directory((path)"../GameDataFolder/IGMD");
329 copy((path)"packages/VanillaBSL/IGMD", (path)"../GameDataFolder");
330 setProgressBar( 1000 );
331
332 // CIP:last of all, set up the edition folder as a playable Oni installation by placing the latest application (+ Daodan DLL on Windows) in edition/
333
334 // CIP:then copy persist.dat and keyconfig.txt into edition/ as well
335
336#ifndef WIN32
337 /* On Mac only, set the current GDF to the AE GDF by writing to Oni's global preferences file (thankfully a standard OS X ".plist" XML file).
338 If there are no Oni prefs (only possible if Oni has not been run even once), then the above line will fail silently, no harm done,
339 and when the user does run Oni for the first time, using the copy of the app in the AE GDF, Oni will set the prefs to use that GDF at that point */
340 path fullAEpath = system_complete("."); // get full path for Installer
341 char prefsCommand[300] = "defaults write com.godgames.oni RetailInstallationPath -string '";
342 strcat(prefsCommand, fullAEpath.parent_path().parent_path().string().c_str()); // get path of edition/ folder (Oni wants the folder that *contains* the GDF)
343 strcat(prefsCommand, "'"); // path string is enclosed in single quotes to avoid the need to escape UNIX-unfriendly characters
344 system(prefsCommand);
345
346#endif
347
348 setStatusArea((string)"Done! Now select your mod packages and click install.");
349 // while(1) Sleep(-1);
350
351 }
352 catch (exception ex) {
353 setStatusArea("Warning, handled exception: " + (string)ex.what());
354 }
355
356 ptime end_time(second_clock::local_time());
357 time_period total_time (start_time, end_time);
358 logfile << "\n\nGlobalization ended " << to_simple_string(end_time) << "\nThe process took " << total_time.length();
359 //total_time.length().hours();
360 logfile.close();
361 busy = 0;
362 return err;
363}
364
365
366vector<ModPackage> getPackages(void)
367{
368 vector<ModPackage> packages;
369 packages.reserve(65536); // come on, we shouldn't need this much space...right?!
370 fstream file;
371 string filename = "\0";
372 string MODINFO_CFG = "Mod_Info.cfg";
373
374 try
375 {
376 directory_iterator end_iter;
377 for (directory_iterator dir_itr("./packages"); dir_itr != end_iter; ++dir_itr)
378 {
379 file.open((dir_itr->path().string() + "/" + MODINFO_CFG).c_str());
380 //cout << filename << "\n";
381
382 if(!file.fail())
383 {
384 //cout << dir_itr->path().string() + MODINFO_CFG;
385 //would prefer to push a pointer to a package, but this will do for now
386 packages.push_back(fileToModPackage(file));
387 }
388 file.close();
389 file.clear();
390 }
391 sort(packages.begin(), packages.end());
392 }
393 catch (const std::exception & ex)
394 {
395 cout << "Warning, something odd happened!\n";
396 }
397
398 return packages;
399}
400
401ModPackage fileToModPackage(fstream &file)
402{
403 /*
404 This converts a file to a ModPackage struct.
405
406 A few notes...
407 "iter" is the current word we are on. I should have named it "token" or something, but I don't have multiple iterators, so its ok.
408 I refer to (*iter) at the beginning of each if statement block. I could probably store it as a variable, but I'm pretty sure that dereferencing a pointer\iterator isn't much
409 slower than reading a variable.
410 */
411 ModPackage package;
412 string line;
413 static string NameOfMod = "NameOfMod"; //used for comparing to the current token...
414 //I could have done it in reverse (*iter).compare("ModString") or
415 static string ARROW = "->"; //did something like "ModString".compare(*iter), and it would have been
416 static string ModString = "ModString"; //functionably the same.
417 static string HasOnis = "HasOnis";
418 static string HasDeltas = "HasDeltas";
419 static string HasBSL = "HasBSL";
420 static string HasDats = "HasDats";
421 static string IsEngine = "IsEngine";
422 static string Readme = "Readme";
423 static string GlobalNeeded = "GlobalNeeded";
424 static string Category = "Category";
425 static string Creator = "Creator";
426 while (! file.eof() )
427 {
428 getline (file,line);
429 vector<string> tokens;
430 vector<string>::iterator iter;
431 tokenize(line, tokens); //string to vector of "words"
432 if (tokens.capacity() >= 2) { //make sure they are using enough stuff
433 iter = tokens.begin(); //what word we are on, starts at first word
434 /*
435 if (!AEInstallVersion.compare(*iter))
436 If mod is too old, skip this mod.
437 */
438 /*else*/if (!NameOfMod.compare(*iter)) { //if it contains the name
439 for ( ; iter !=tokens.end() && SLASHSLASH.compare(*iter); iter++) { //interates through the words, ends if it reaches the end of the line or a "//" comment
440 if (ARROW.compare(*iter) && NameOfMod.compare(*iter)) { //ignores "->" and "NameOfMod"
441 //cout << *iter;
442 //cout << " ";
443 package.name += *iter + " ";
444 }
445 }
446
447 }
448 else if (!ModString.compare(*iter)) {
449 iter++; iter++;
450 package.modStringName = *iter;
451 iter++;
452 package.modStringVersion = atoi((*iter).c_str());
453 }
454 else if (!HasOnis.compare(*iter)) {
455 iter++; iter++;
456 if (toupper((*iter)[0]) + toupper((*iter)[1]) + toupper((*iter)[2]) == 'Y' + 'E' + 'S') package.hasOnis = 1; //Gotta love c++'s lack of a standard case-insensitive
457 else if (!HasBSL.compare(*iter)) { // string comparer...I know my implementation here sucks. I need to change it to check each character one by one. At the moment,
458 iter++; iter++;} // using "YFR" would probably set it off. :<
459
460 if (toupper((*iter)[0]) + toupper((*iter)[1]) + toupper((*iter)[2]) == 'Y' + 'E' + 'S') package.hasBSL = 1;
461 }
462 else if (!HasDeltas.compare(*iter)) {
463 iter++; iter++;
464 if (toupper((*iter)[0]) + toupper((*iter)[1]) + toupper((*iter)[2]) == 'Y' + 'E' + 'S') package.hasDeltas = 1;
465 }
466 else if (!HasDats.compare(*iter)) {
467 iter++; iter++;
468 if (toupper((*iter)[0]) + toupper((*iter)[1]) + toupper((*iter)[2]) == 'Y' + 'E' + 'S') package.hasDats = 1;
469 }
470 else if (!IsEngine.compare(*iter)) {
471 iter++; iter++;
472 if (toupper((*iter)[0]) + toupper((*iter)[1]) + toupper((*iter)[2]) == 'Y' + 'E' + 'S') package.isEngine = 1;
473 }
474 else if (!GlobalNeeded.compare(*iter)) {
475 iter++; iter++;
476 if (toupper((*iter)[0]) + toupper((*iter)[1]) + toupper((*iter)[2]) == 'Y' + 'E' + 'S') package.globalNeeded = 1;
477 else if (toupper((*iter)[0]) + toupper((*iter)[1]) == 'N' + 'O') package.globalNeeded = 1; //Really the only place where checking for "No" is important atm.
478 }
479 else if (!Category.compare(*iter)) {
480 for ( ; iter !=tokens.end() && SLASHSLASH.compare(*iter); iter++) { //interates through the words, ends if it reaches the end of the line or a "//" comment
481 if (ARROW.compare(*iter) && Category.compare(*iter)) { //ignores "->" and "Category"
482 //cout << *iter;
483 //cout << " ";
484 package.category += *iter + " ";
485 }
486 }
487 }
488 else if (!Creator.compare(*iter)) { //if it contains the name
489 for ( ; iter !=tokens.end() && SLASHSLASH.compare(*iter); iter++) { //interates through the words, ends if it reaches the end of the line or a "//" comment
490 if (ARROW.compare(*iter) && Creator.compare(*iter)) { //ignores "->" and "Category"
491 //cout << *iter;
492 //cout << " ";
493 package.creator += *iter + " ";
494 }
495 }
496 }
497 else if (!Readme.compare(*iter)) { //if it contains the name
498 for ( ; iter !=tokens.end() && SLASHSLASH.compare(*iter); iter++) { //interates through the words, ends if it reaches the end of the line or a "//" comment
499 if (ARROW.compare(*iter) && Readme.compare(*iter)) { //ignores "->" and "Category"
500 if(!(*iter).compare("\\n")) package.readme += '\n';
501 else package.readme += *iter + " ";
502 }
503 }
504 }
505 }
506
507 }
508 package.doOutput();
509 return package;
510}
511
512void recompileAll(vector<string> installedMods)
513{
514 busy = 1;
515 using namespace boost::gregorian;
516 using namespace boost::posix_time;
517 using boost::lexical_cast;
518 using boost::bad_lexical_cast;
519
520 setStatusArea("Importing levels...");
521 //setStatusArea("Recompiling Data...");
522 path vanilla_dir = "./packages/VanillaDats/";
523 string importCommand = "";
524 char statusString[128];
525 int numberOfDats = 0;
526 int j = 1;
527 string datString;
528 std::stringstream out;
529
530 ptime start_time(second_clock::local_time());
531 clearOldDats();
532 remove("Install.log");
533 ofstream logfile("Install.log");
534 logfile << "Mod Installation started " << to_simple_string(start_time) << endl;
535 logfile.close();
536 if(splitInstances == SPLIT){
537 recursive_directory_iterator end_iter;
538
539 for ( recursive_directory_iterator dir_itr( vanilla_dir );
540 dir_itr != end_iter;
541 ++dir_itr )
542 {
543 try{
544 if ( is_directory( dir_itr->status() ) && dir_itr.level() == 1)
545 {
546 numberOfDats++;
547 }
548 }
549 catch(exception ex) {
550
551 }
552 }
553
554 //recursive_directory_iterator end_iter;
555
556
557 out << numberOfDats;
558 datString = out.str();
559 try {
560 for ( recursive_directory_iterator dir_itr( vanilla_dir );
561 dir_itr != end_iter;
562 ++dir_itr )
563 {
564 try
565 {
566 if ( is_directory( dir_itr->status() ) && dir_itr.level() == 1)
567 {
568 importCommand = strOniSplit + " " + strImportOption + " " + dir_itr->path().parent_path().string() + '/' + dir_itr->path().filename();
569 for (int i = 0; i < installedMods.size(); ++i) {
570 if (exists("packages/" + installedMods[i] + "/oni/" + dir_itr->path().parent_path().filename() + '/' + dir_itr->path().filename() ))
571 importCommand += " packages/" + installedMods[i] + "/oni/" + dir_itr->path().parent_path().filename() + '/' + dir_itr->path().filename();
572
573 //else cout << " packages/VanillaDats/" + installedMods[i] + "/oni/";
574 }
575 importCommand += " ../GameDataFolder/" + dir_itr->path().filename() + ".dat >> Install.log";
576
577
578 setProgressBar( (int)(1000 * (float)(j-1) / (float)numberOfDats) ); //100% * dat we're on / total dats
579 setStatusArea("Step " + lexical_cast<std::string>(j) + '/' + lexical_cast<std::string>(numberOfDats)+ ": Importing " + dir_itr->path().filename() + " ");
580
581 system(importCommand.c_str());
582 //Sleep(1000);
583 //cout << importCommand << "\n";
584 j++;
585
586 }
587 }
588 catch ( const std::exception & ex )
589 {
590
591 remove("Install.log");
592 ofstream logfile("Install.log");
593
594
595 logfile << "Warning, exception " << ex.what() << "!";
596 setStatusArea("Warning, exception " + (string)ex.what() + "!");
597 logfile.close();
598 }
599 }
600
601 }
602 catch( const std::exception & ex ) {
603
604 remove("Install.log");
605 ofstream logfile("Install.log");
606
607
608 logfile << "Warning, exception " << ex.what() << "!";
609 setStatusArea("Warning, exception " + (string)ex.what() + "!");
610 logfile.close();
611 }
612
613 }
614 else if(splitInstances == NOT_SPLIT){
615 directory_iterator end_iter;
616
617 for ( directory_iterator dir_itr( vanilla_dir );
618 dir_itr != end_iter;
619 ++dir_itr )
620 {
621
622 if ( is_directory( dir_itr->status() ) )
623 {
624 numberOfDats++;
625 }
626
627
628 }
629
630 out << numberOfDats;
631 datString = out.str();
632
633 for ( directory_iterator dir_itr( vanilla_dir );
634 dir_itr != end_iter;
635 ++dir_itr )
636 {
637 try
638 {
639 if ( is_directory( dir_itr->status() ) )
640 {
641 importCommand = strOniSplit + " " + strImportOption + " " + vanilla_dir.string() + dir_itr->path().filename() + " ";
642 for (int i = 0; i < installedMods.size(); ++i) {
643 if (exists("packages/" + installedMods[i] + "/oni/" + dir_itr->path().filename() ))
644 importCommand += " packages/" + installedMods[i] + "/oni/" + dir_itr->path().filename();
645 }
646 importCommand += " ../GameDataFolder/" + dir_itr->path().filename() + ".dat >> Install.log";
647
648
649 setProgressBar( (int)(1000 * (float)(j-1) / (float)numberOfDats) ); //100% * dat we're on / total dats
650 setStatusArea("Step " + lexical_cast<std::string>(j) + '/' + lexical_cast<std::string>(numberOfDats)+ ": Importing " + dir_itr->path().filename() + " ");
651
652 system(importCommand.c_str());
653
654 j++;
655 }
656 }
657 catch ( const std::exception & ex )
658 {
659
660 remove("Install.log");
661 ofstream logfile("Install.log");
662
663
664 logfile << "Warning, exception " << ex.what() << "!";
665 setStatusArea("Warning, exception " + (string)ex.what() + "!");
666 logfile.close();
667 }}
668 }
669 logfile << "Writing config file";
670 writeInstalledMods(installedMods);
671 setProgressBar(1000);
672 setStatusArea("Done! You can now play Oni.");
673
674 ptime end_time(second_clock::local_time());
675 time_period total_time (start_time, end_time);
676
677
678 ofstream logfile2("Install.log", ios::app | ios::ate);
679 string outstring = (string)"\n\nGlobalization ended " + to_simple_string(end_time) + "\nThe process took ";// + (string)total_time.length();
680
681 logfile2 << "\nGlobalization ended " << to_simple_string(end_time) << "\nThe process took " << total_time.length();
682
683 //logfile2.write(outstring.c_str(), outstring.length());
684 logfile2.close();
685
686 //total_time.length().hours();
687
688 Sleep(1000);
689 setProgressBar(0);
690 busy = 0;
691}
692
693void writeInstalledMods(vector<string> installedMods)
694{
695
696 if ( exists( strInstallCfg ) )
697 {
698 remove( strInstallCfg );
699 }
700
701 ofstream file(strInstallCfg.c_str());
702
703 vector<string>list = installedMods;
704 vector<string>::iterator begin_iter = list.begin();
705 vector<string>::iterator end_iter = list.end();
706
707 sort( list.begin(), list.end() );
708
709 for( ; begin_iter != end_iter; ++begin_iter) {
710 file << *begin_iter << " ";
711 }
712
713 file.close();
714 file.clear();
715
716}
717
718vector<string> getInstallString(string Cfg)
719{
720 //system(strPauseCmd);
721 vector<string> returnval;
722
723 string line;
724 fstream file;
725
726 if (exists( Cfg ))
727 {
728 file.open(Cfg.c_str());
729 getline(file, line);
730 tokenize(line, returnval);
731 file.close();
732 file.clear();
733 sort(returnval.begin(), returnval.end());
734 }
735 else cout << "fail";
736
737 return returnval;
738}
739
740//stolen token function...
741void tokenize(const string& str, vector<string>& tokens, const string& delimiters)
742{
743 // Skip delimiters at beginning.
744 string::size_type lastPos = str.find_first_not_of(delimiters, 0);
745 // Find first "non-delimiter".
746 string::size_type pos = str.find_first_of(delimiters, lastPos);
747
748 while (string::npos != pos || string::npos != lastPos)
749 {
750 // Found a token, add it to the vector.
751 tokens.push_back(str.substr(lastPos, pos - lastPos));
752 // Skip delimiters. Note the "not_of"
753 lastPos = str.find_first_not_of(delimiters, pos);
754 // Find next "non-delimiter"
755 pos = str.find_first_of(delimiters, lastPos);
756 }
757}
758
759void clearOldDats(void) {
760 directory_iterator end_iter_gdf;
761 for ( directory_iterator dir_itr_gdf( "../GameDataFolder" );
762 dir_itr_gdf != end_iter_gdf;
763 ++dir_itr_gdf )
764 {
765 //cout << dir_itr_gdf->path().extension() << "\n";
766 if ( dir_itr_gdf->path().extension() == ".dat" || dir_itr_gdf->path().extension() == ".raw" || dir_itr_gdf->path().extension() == ".sep" ) {
767 remove( dir_itr_gdf->path() );
768 }
769
770 }
771
772}
773
774vector<string> globalInstalledMods;
775vector<ModPackage> globalPackages;
776#include "boost/thread.hpp"
777#include <boost/thread/mutex.hpp>
778
779/////////////////////////////////////////////////////////////////////////////
780// Name: main_window.cpp
781// Purpose:
782// Author:
783// Modified by:
784// Created: 07/05/2009 20:38:25
785// RCS-ID:
786// Copyright:
787// Licence:
788/////////////////////////////////////////////////////////////////////////////
789
790// For compilers that support precompilation, includes "wx/wx.h".
791#include "wx/wxprec.h"
792
793#ifdef __BORLANDC__
794#pragma hdrstop
795#endif
796
797#ifndef WX_PRECOMP
798#include "wx/wx.h"
799#endif
800
801////@begin includes
802#include "about.h"
803////@end includes
804
805#include "main_window.h"
806
807////@begin XPM images
808#include "aelogosmall.xpm"
809#include "undo.xpm"
810#include "fileopen.xpm"
811#include "filesaveas.xpm"
812#include "quit.xpm"
813////@end XPM images
814
815//#define wxDebug 1;
816//#define wxUSE_UNICODE 1;
817
818/*
819* MainWindow type definition
820*/
821
822IMPLEMENT_CLASS( MainWindow, wxFrame )
823
824
825/*
826* MainWindow event table definition
827*/
828
829BEGIN_EVENT_TABLE( MainWindow, wxFrame )
830
831////@begin MainWindow event table entries
832 EVT_CHECKBOX( SelectAll_Checkbox, MainWindow::OnSelectAllCheckboxClick )
833
834 EVT_BUTTON( Refresh_Button, MainWindow::OnRefreshButtonClick )
835
836 EVT_LISTBOX( Mods_CheckboxList1, MainWindow::OnModsCheckboxList1Selected )
837 EVT_CHECKLISTBOX( Mods_CheckboxList1, MainWindow::OnModsCheckboxList1Toggled )
838
839 EVT_UPDATE_UI( ID_STATUSBAR, MainWindow::OnStatusbarUpdate )
840
841 EVT_BUTTON( Install_Button, MainWindow::OnInstallButtonClick )
842
843 EVT_RADIOBUTTON( Sep_RadioButton, MainWindow::OnSepRadioButtonSelected )
844
845 EVT_RADIOBUTTON( NoSep_RadioButton, MainWindow::OnNoSepRadioButtonSelected )
846
847 EVT_RADIOBUTTON( Seperated_RadioButton, MainWindow::OnSeperatedRadioButtonSelected )
848
849 EVT_RADIOBUTTON( Complete_RadioButton, MainWindow::OnCompleteRadioButtonSelected )
850
851 EVT_BUTTON( ReGlobalize_Button, MainWindow::OnReGlobalizeButtonClick )
852
853 EVT_MENU( wxID_LOAD, MainWindow::OnLoadClick )
854
855 EVT_MENU( wxID_SAVE, MainWindow::OnSaveClick )
856
857 EVT_MENU( wxID_EXIT, MainWindow::OnExitClick )
858
859 EVT_MENU( wxID_OPTIONS, MainWindow::OnOptionsClick )
860
861 EVT_MENU( wxID_ABOUT, MainWindow::OnAboutClick )
862
863////@end MainWindow event table entries
864
865END_EVENT_TABLE()
866
867
868/*
869* MainWindow constructors
870*/
871
872MainWindow::MainWindow()
873{
874 Init();
875}
876
877MainWindow::MainWindow( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
878{
879 Init();
880 Create( parent, id, caption, pos, size, style );
881}
882
883
884/*
885* MainWindow creator
886*/
887
888bool MainWindow::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
889{
890 ////@begin MainWindow creation
891 wxFrame::Create( parent, id, caption, pos, size, style );
892
893 CreateControls();
894 SetIcon(GetIconResource(wxT("aelogosmall.png")));
895 Centre();
896 ////@end MainWindow creation
897 return true;
898}
899
900
901/*
902* MainWindow destructor
903*/
904
905MainWindow::~MainWindow()
906{
907 ////@begin MainWindow destruction
908 ////@end MainWindow destruction
909}
910
911
912/*
913* Member initialisation
914*/
915
916void MainWindow::Init()
917{
918 ////@begin MainWindow member initialisation
919 MainSplitter = NULL;
920 SelectAll = NULL;
921 RefreshButton = NULL;
922 Mods_CheckboxList = NULL;
923 titleText = NULL;
924 creatorText = NULL;
925 descriptionText = NULL;
926 StatusArea = NULL;
927 ProgressBar = NULL;
928 InstallButton = NULL;
929 OptionsPanel = NULL;
930 SepRadio = NULL;
931 NoSepRadio = NULL;
932 SeperatedRadio = NULL;
933 CompleteRadio = NULL;
934 ReglobalizeButton = NULL;
935 ////@end MainWindow member initialisation
936
937}
938
939
940/*
941* Control creation for MainWindow
942*/
943wxStatusBar **TheStatusBar;
944wxButton* TheInstallButton;
945wxGauge* TheProgressBar;
946void MainWindow::CreateControls()
947{
948 ////@begin MainWindow content construction
949 MainWindow* itemFrame1 = this;
950
951 wxMenuBar* menuBar = new wxMenuBar;
952 wxMenu* itemMenu37 = new wxMenu;
953 {
954 wxMenuItem* menuItem = new wxMenuItem(itemMenu37, wxID_LOAD, _("&Load Configuration..."), wxEmptyString, wxITEM_NORMAL);
955 wxBitmap bitmap(itemFrame1->GetBitmapResource(wxT("fileopen.xpm")));
956 menuItem->SetBitmap(bitmap);
957 itemMenu37->Append(menuItem);
958 }
959 {
960 wxMenuItem* menuItem = new wxMenuItem(itemMenu37, wxID_SAVE, _("&Save Configuration..."), wxEmptyString, wxITEM_NORMAL);
961 wxBitmap bitmap(itemFrame1->GetBitmapResource(wxT("filesaveas.xpm")));
962 menuItem->SetBitmap(bitmap);
963 itemMenu37->Append(menuItem);
964 }
965 itemMenu37->AppendSeparator();
966 {
967 wxMenuItem* menuItem = new wxMenuItem(itemMenu37, wxID_EXIT, _("Exit"), wxEmptyString, wxITEM_NORMAL);
968 wxBitmap bitmap(itemFrame1->GetBitmapResource(wxT("quit.xpm")));
969 menuItem->SetBitmap(bitmap);
970 itemMenu37->Append(menuItem);
971 }
972 menuBar->Append(itemMenu37, _("&File"));
973 wxMenu* itemMenu42 = new wxMenu;
974 itemMenu42->Append(wxID_OPTIONS, _("Show Advanced Options..."), wxEmptyString, wxITEM_CHECK);
975 menuBar->Append(itemMenu42, _("Options"));
976 wxMenu* itemMenu44 = new wxMenu;
977 itemMenu44->Append(wxID_ABOUT, _("About"), wxEmptyString, wxITEM_NORMAL);
978 menuBar->Append(itemMenu44, _("Help"));
979 itemFrame1->SetMenuBar(menuBar);
980
981 wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
982 itemFrame1->SetSizer(itemBoxSizer2);
983
984 MainSplitter = new wxSplitterWindow( itemFrame1, ID_SPLITTERWINDOW, wxDefaultPosition, wxSize(100, 100), wxSP_LIVE_UPDATE|wxNO_BORDER );
985 MainSplitter->SetMinimumPaneSize(1);
986 MainSplitter->SetName(_T("MainSplitter"));
987
988 wxPanel* itemPanel4 = new wxPanel( MainSplitter, ID_PANEL, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER|wxTAB_TRAVERSAL );
989 wxBoxSizer* itemBoxSizer5 = new wxBoxSizer(wxVERTICAL);
990 itemPanel4->SetSizer(itemBoxSizer5);
991
992 wxBoxSizer* itemBoxSizer6 = new wxBoxSizer(wxHORIZONTAL);
993 itemBoxSizer5->Add(itemBoxSizer6, 0, wxGROW|wxALL, 0);
994 SelectAll = new wxCheckBox( itemPanel4, SelectAll_Checkbox, _("Select All/None"), wxDefaultPosition, wxDefaultSize, wxCHK_3STATE );
995 SelectAll->SetValue(false);
996 SelectAll->SetName(_T("SelectAll_Checkbox"));
997 itemBoxSizer6->Add(SelectAll, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
998
999 RefreshButton = new wxBitmapButton( itemPanel4, Refresh_Button, itemFrame1->GetBitmapResource(wxT("undo.xpm")), wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW );
1000 RefreshButton->SetName(_T("RefreshButton"));
1001 itemBoxSizer6->Add(RefreshButton, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxTOP|wxBOTTOM, 5);
1002
1003 wxArrayString Mods_CheckboxListStrings;
1004 Mods_CheckboxList = new wxCheckListBox( itemPanel4, Mods_CheckboxList1, wxDefaultPosition, wxDefaultSize, Mods_CheckboxListStrings, wxLB_HSCROLL );
1005 Mods_CheckboxList->SetName(_T("Mods_CheckboxList"));
1006 itemBoxSizer5->Add(Mods_CheckboxList, 1, wxGROW|wxALL, 0);
1007
1008 wxPanel* itemPanel10 = new wxPanel( MainSplitter, DescriptionHolder_Panel, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER|wxTAB_TRAVERSAL );
1009 itemPanel10->SetName(_T("DescriptionHolder_Panel"));
1010 wxBoxSizer* itemBoxSizer11 = new wxBoxSizer(wxVERTICAL);
1011 itemPanel10->SetSizer(itemBoxSizer11);
1012
1013 wxBoxSizer* itemBoxSizer12 = new wxBoxSizer(wxHORIZONTAL);
1014 itemBoxSizer11->Add(itemBoxSizer12, 0, wxGROW|wxALL, 0);
1015 wxBoxSizer* itemBoxSizer13 = new wxBoxSizer(wxVERTICAL);
1016 itemBoxSizer12->Add(itemBoxSizer13, 1, wxALIGN_CENTER_VERTICAL|wxALL, 0);
1017 titleText = new wxTextCtrl( itemPanel10, Title_Text, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY );
1018 titleText->SetName(_T("Title_Text"));
1019 titleText->SetBackgroundColour(wxColour(240, 240, 240));
1020 itemBoxSizer13->Add(titleText, 1, wxGROW|wxLEFT, 5);
1021
1022 wxBoxSizer* itemBoxSizer15 = new wxBoxSizer(wxVERTICAL);
1023 itemBoxSizer12->Add(itemBoxSizer15, 1, wxGROW|wxALL, 0);
1024 creatorText = new wxTextCtrl( itemPanel10, Author_Text, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY|wxTE_RIGHT );
1025 creatorText->SetName(_T("Author_Text"));
1026 creatorText->SetBackgroundColour(wxColour(240, 240, 240));
1027 itemBoxSizer15->Add(creatorText, 1, wxGROW|wxRIGHT, 5);
1028
1029 wxStaticLine* itemStaticLine17 = new wxStaticLine( itemPanel10, wxID_STATIC, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
1030 itemStaticLine17->Show(false);
1031 itemBoxSizer11->Add(itemStaticLine17, 0, wxGROW|wxALL, 5);
1032
1033 descriptionText = new wxTextCtrl( itemPanel10, Description_Text, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_READONLY|wxTE_RICH|wxTE_RICH2 );
1034 descriptionText->SetName(_T("DescriptionName"));
1035 descriptionText->SetBackgroundColour(wxColour(240, 240, 240));
1036 itemBoxSizer11->Add(descriptionText, 1, wxGROW|wxLEFT|wxRIGHT, 5);
1037
1038 MainSplitter->SplitVertically(itemPanel4, itemPanel10, 200);
1039 itemBoxSizer2->Add(MainSplitter, 1, wxGROW|wxALL, 0);
1040
1041 StatusArea = new wxStatusBar( itemFrame1, ID_STATUSBAR, 0 );
1042 StatusArea->SetName(_T("StatusArea"));
1043 StatusArea->SetFieldsCount(1);
1044 StatusArea->SetStatusText(_("AE Installer v1.0"), 0);
1045 itemBoxSizer2->Add(StatusArea, 0, wxGROW|wxALL, 0);
1046
1047 wxBoxSizer* itemBoxSizer20 = new wxBoxSizer(wxHORIZONTAL);
1048 itemBoxSizer2->Add(itemBoxSizer20, 0, wxGROW|wxALL, 0);
1049
1050 ProgressBar = new wxGauge( itemFrame1, ProgressBar_Gauge, 1000, wxDefaultPosition, wxDefaultSize, wxGA_SMOOTH );
1051 ProgressBar->SetValue(0);
1052 itemBoxSizer20->Add(ProgressBar, 1, wxGROW|wxALL, 0);
1053
1054 InstallButton = new wxButton( itemFrame1, Install_Button, _("Install!"), wxDefaultPosition, wxDefaultSize, 0 );
1055 itemBoxSizer20->Add(InstallButton, 0, wxGROW|wxALL, 0);
1056
1057 wxBoxSizer* itemBoxSizer23 = new wxBoxSizer(wxVERTICAL);
1058 itemBoxSizer2->Add(itemBoxSizer23, 0, wxGROW|wxALL, 0);
1059
1060 OptionsPanel = new wxPanel( itemFrame1, ID_PANEL1, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER|wxTAB_TRAVERSAL );
1061 itemBoxSizer2->Add(OptionsPanel, 0, wxGROW, 0);
1062
1063 wxBoxSizer* itemBoxSizer25 = new wxBoxSizer(wxHORIZONTAL);
1064 OptionsPanel->SetSizer(itemBoxSizer25);
1065
1066 wxBoxSizer* itemBoxSizer26 = new wxBoxSizer(wxVERTICAL);
1067 itemBoxSizer25->Add(itemBoxSizer26, 0, wxGROW|wxALL, 5);
1068
1069 SepRadio = new wxRadioButton( OptionsPanel, Sep_RadioButton, _("Sep"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP );
1070 SepRadio->SetValue(false);
1071 if (MainWindow::ShowToolTips())
1072 SepRadio->SetToolTip(_("For PC Demo and Mac"));
1073 itemBoxSizer26->Add(SepRadio, 0, wxALIGN_LEFT|wxALL, 5);
1074
1075 NoSepRadio = new wxRadioButton( OptionsPanel, NoSep_RadioButton, _("NoSep"), wxDefaultPosition, wxDefaultSize, 0 );
1076 NoSepRadio->SetValue(false);
1077 if (MainWindow::ShowToolTips())
1078 NoSepRadio->SetToolTip(_("For PC Retail"));
1079 itemBoxSizer26->Add(NoSepRadio, 0, wxALIGN_LEFT|wxALL, 5);
1080
1081 wxStaticLine* itemStaticLine29 = new wxStaticLine( OptionsPanel, wxID_STATIC, wxDefaultPosition, wxDefaultSize, wxLI_VERTICAL );
1082 itemBoxSizer25->Add(itemStaticLine29, 0, wxGROW|wxALL, 5);
1083
1084 wxBoxSizer* itemBoxSizer30 = new wxBoxSizer(wxVERTICAL);
1085 itemBoxSizer25->Add(itemBoxSizer30, 0, wxGROW|wxALL, 5);
1086
1087 SeperatedRadio = new wxRadioButton( OptionsPanel, Seperated_RadioButton, _("Separated Level0"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP );
1088 SeperatedRadio->SetValue(false);
1089 SeperatedRadio->SetName(_T("Seperated_RadioButton"));
1090 itemBoxSizer30->Add(SeperatedRadio, 0, wxALIGN_LEFT|wxALL, 5);
1091
1092 CompleteRadio = new wxRadioButton( OptionsPanel, Complete_RadioButton, _("Complete Level0"), wxDefaultPosition, wxDefaultSize, 0 );
1093 CompleteRadio->SetValue(false);
1094 CompleteRadio->SetName(_T("Complete_RadioButton"));
1095 itemBoxSizer30->Add(CompleteRadio, 0, wxALIGN_LEFT|wxALL, 5);
1096
1097 wxStaticLine* itemStaticLine33 = new wxStaticLine( OptionsPanel, wxID_STATIC, wxDefaultPosition, wxDefaultSize, wxLI_VERTICAL );
1098 itemBoxSizer25->Add(itemStaticLine33, 0, wxGROW|wxALL, 5);
1099
1100 wxBoxSizer* itemBoxSizer34 = new wxBoxSizer(wxVERTICAL);
1101 itemBoxSizer25->Add(itemBoxSizer34, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
1102
1103 ReglobalizeButton = new wxButton( OptionsPanel, ReGlobalize_Button, _("Reglobalize"), wxDefaultPosition, wxDefaultSize, 0 );
1104 ReglobalizeButton->SetName(_T("Reglobalize_Button"));
1105 itemBoxSizer34->Add(ReglobalizeButton, 0, wxGROW|wxALL, 5);
1106
1107 // Connect events and objects
1108 Mods_CheckboxList->Connect(Mods_CheckboxList1, wxEVT_CREATE, wxWindowCreateEventHandler(MainWindow::ModList_OnCreate), NULL, this);
1109 ////@end MainWindow content construction
1110
1111 if ( exists( "../../GameDataFolder/level0_Final.sep" ) ) {
1112 strImportOption = "-import:sep";
1113 splitInstances = NOT_SPLIT;
1114 }
1115 else {
1116 strImportOption = "-import:nosep";
1117 splitInstances = SPLIT;
1118 }
1119
1120 globalPackages = getPackages();
1121 globalInstalledMods = getInstallString();
1122 for (int i = 0; i < globalPackages.size(); i++) {
1123 Mods_CheckboxList->Append(globalPackages[i].name.c_str());
1124 if( binary_search(globalInstalledMods.begin(), globalInstalledMods.end(), globalPackages[i].modStringName ) ) Mods_CheckboxList->Check(i);
1125 }
1126
1127 TheStatusBar = &StatusArea;
1128 TheInstallButton = InstallButton;
1129 TheProgressBar = ProgressBar;
1130 OptionsPanel->Hide();
1131 if(splitInstances == SPLIT) SeperatedRadio->SetValue(true);
1132 else CompleteRadio->SetValue(true);
1133
1134
1135
1136 if(strImportOption == "-import:nosep") NoSepRadio->SetValue(true);
1137 else SepRadio->SetValue(true);
1138
1139
1140#ifdef WIN32
1141 RedirectIOToConsole();
1142 HWND hWnd = GetConsoleWindow();
1143 ShowWindow( hWnd, SW_HIDE );
1144#endif
1145
1146 //MainWindow::SetSize(MainWindow::GetRect().GetWidth(), MainWindow::GetRect().GetHeight()-OptionsPanel->GetRect().GetHeight() );
1147}
1148
1149
1150/*
1151* wxEVT_COMMAND_CHECKBOX_CLICKED event handler for SelectAll_Checkbox
1152*/
1153
1154void MainWindow::OnSelectAllCheckboxClick( wxCommandEvent& event )
1155{
1156 switch(SelectAll->Get3StateValue()) {
1157 case wxCHK_UNCHECKED:
1158 for(int i = 0; i < globalPackages.size(); i++) Mods_CheckboxList->Check(i, false);
1159 //SelectAll->Set3StateValue(wxCHK_CHECKED);
1160 break;
1161 case wxCHK_CHECKED:
1162 for(int i = 0; i < globalPackages.size(); i++) Mods_CheckboxList->Check(i, true);
1163 //SelectAll->Set3StateValue(wxCHK_UNCHECKED);
1164 break;
1165 case wxCHK_UNDETERMINED:
1166 for(int i = 0; i < globalPackages.size(); i++) Mods_CheckboxList->Check(i, false);
1167 //SelectAll->Set3StateValue(wxCHK_CHECKED);
1168 break;
1169
1170 }
1171
1172}
1173
1174
1175/*
1176* wxEVT_CREATE event handler for Mods_CheckboxList
1177*/
1178
1179void MainWindow::ModList_OnCreate( wxWindowCreateEvent& event )
1180{
1181
1182
1183}
1184
1185
1186/*
1187* Should we show tooltips?
1188*/
1189
1190bool MainWindow::ShowToolTips()
1191{
1192 return true;
1193}
1194
1195/*
1196* Get bitmap resources
1197*/
1198
1199wxBitmap MainWindow::GetBitmapResource( const wxString& name )
1200{
1201 // Bitmap retrieval
1202 ////@begin MainWindow bitmap retrieval
1203 wxUnusedVar(name);
1204 if (name == _T("undo.xpm"))
1205 {
1206 wxBitmap bitmap( undo_xpm);
1207 return bitmap;
1208 }
1209 else if (name == _T("fileopen.xpm"))
1210 {
1211 wxBitmap bitmap( fileopen_xpm);
1212 return bitmap;
1213 }
1214 else if (name == _T("filesaveas.xpm"))
1215 {
1216 wxBitmap bitmap( filesaveas_xpm);
1217 return bitmap;
1218 }
1219 else if (name == _T("quit.xpm"))
1220 {
1221 wxBitmap bitmap( quit_xpm);
1222 return bitmap;
1223 }
1224 return wxNullBitmap;
1225 ////@end MainWindow bitmap retrieval
1226}
1227
1228/*
1229* Get icon resources
1230*/
1231
1232wxIcon MainWindow::GetIconResource( const wxString& name )
1233{
1234
1235 // Icon retrieval
1236 ////@begin MainWindow icon retrieval
1237 wxUnusedVar(name);
1238 if (name == _T("aelogosmall.png"))
1239 {
1240 wxIcon icon(aelogosmall_xpm);
1241 return icon;
1242 }
1243 return wxNullIcon;
1244 ////@end MainWindow icon retrieval
1245}
1246
1247
1248/*
1249* wxEVT_COMMAND_LISTBOX_SELECTED event handler for Mods_CheckboxList1
1250*/
1251
1252void MainWindow::OnModsCheckboxList1Selected( wxCommandEvent& event )
1253{
1254 //event.GetSelection
1255 titleText->SetValue(globalPackages[event.GetSelection()].name.c_str());
1256 creatorText->SetValue(globalPackages[event.GetSelection()].creator.c_str());
1257 descriptionText->SetValue(globalPackages[event.GetSelection()].readme.c_str());
1258
1259 //creatorText->Refresh();
1260}
1261
1262
1263/*
1264* wxEVT_COMMAND_CHECKLISTBOX_TOGGLED event handler for Mods_CheckboxList1
1265*/
1266
1267void MainWindow::OnModsCheckboxList1Toggled( wxCommandEvent& event )
1268{
1269 SelectAll->Set3StateValue(wxCHK_UNDETERMINED);
1270 if(event.GetInt()) {
1271 /*
1272 switch(SelectAll->Get3StateValue()) {
1273 case wxCHK_UNCHECKED:
1274 break;
1275 case wxCHK_CHECKED:
1276 break;
1277 case wxCHK_UNDETERMINED :
1278 break;
1279 }
1280 */
1281 }
1282}
1283
1284
1285/*
1286* wxEVT_COMMAND_MENU_SELECTED event handler for wxID_OPTIONS
1287*/
1288
1289void MainWindow::OnOptionsClick( wxCommandEvent& event )
1290{
1291 if (!event.GetInt() ) {
1292 OptionsPanel->Hide();
1293
1294 this->SetSize(this->GetRect().GetWidth(), this->GetRect().GetHeight()-OptionsPanel->GetRect().GetHeight());}
1295 else {
1296// Uncomment this when we release, it gets annoying if you are testing globalization a lot ;)
1297 wxMessageDialog* YesNoDialog = new wxMessageDialog(this, "WARNING: These options are for advanced users only, use with caution.",
1298 "AE Installer Alert", wxOK | wxICON_EXCLAMATION , wxDefaultPosition);
1299 YesNoDialog->ShowModal();
1300 OptionsPanel->Show();
1301 this->SetSize(this->GetRect().GetWidth(), this->GetRect().GetHeight()+OptionsPanel->GetRect().GetHeight()+1);
1302 this->SetSize(this->GetRect().GetWidth(), this->GetRect().GetHeight()-1);
1303 }
1304}
1305
1306
1307/*
1308* wxEVT_COMMAND_MENU_SELECTED event handler for wxID_EXIT
1309*/
1310
1311void MainWindow::OnExitClick( wxCommandEvent& event )
1312{
1313 exit(0);
1314}
1315
1316
1317/*
1318* wxEVT_COMMAND_BUTTON_CLICKED event handler for Install_Button
1319*/
1320
1321
1322struct recompile
1323{
1324 recompile(vector<string> localPackages) : thePackages(localPackages) { }
1325 void operator()()
1326 {
1327 TheInstallButton->Disable();
1328 recompileAll(thePackages);
1329 TheInstallButton->Enable();
1330 }
1331
1332 vector<string> thePackages;
1333};
1334
1335void MainWindow::OnInstallButtonClick( wxCommandEvent& event )
1336{
1337
1338 vector<string> localPackages;
1339 localPackages.push_back("Globalize");
1340 for(int i = 0; i < globalPackages.size(); i++) if(Mods_CheckboxList->IsChecked(i)) localPackages.push_back( globalPackages[i].modStringName );
1341 if ( !localPackages.empty() ) {
1342
1343 //MainWindow::MainWindow().Hide();
1344 // boost::thread thrd2(recompileAll(localPackages) );
1345 //MainWindow::MainWindow().Show();
1346 this->InstallButton->Disable();
1347 this->ReglobalizeButton->Disable();
1348#ifdef WIN32
1349 recompile packages(localPackages);
1350 boost::thread thrd(packages);
1351#else
1352 recompileAll(localPackages);
1353#endif
1354
1355 this->InstallButton->Enable();
1356 this->ReglobalizeButton->Enable();
1357 }
1358
1359
1360}
1361
1362/*void setStatusArea( string s ) {
1363//TheStatusBar = MainWindow::StatusArea;
1364(**TheStatusBar).SetStatusText(_(s.c_str()), 0);
1365
1366//MainWindow::MainWindow().SetSize(MainWindow::MainWindow().GetRect().GetWidth(), MainWindow::MainWindow().GetRect().GetHeight()+1);
1367
1368//MainWindow::StatusBar->SetLabel("Importing Files...");
1369//StatusBar->SetLabel(s);
1370//->SetLabel(s);
1371
1372}*/
1373
1374void setProgressBar( int i ) {
1375 //TheProgressBar->SetValue(
1376
1377 TheProgressBar->SetValue(i);
1378
1379}
1380
1381
1382/*
1383* wxEVT_UPDATE_UI event handler for ID_STATUSBAR
1384*/
1385
1386void MainWindow::OnStatusbarUpdate( wxUpdateUIEvent& event )
1387{
1388 ////@begin wxEVT_UPDATE_UI event handler for ID_STATUSBAR in MainWindow.
1389 // Before editing this code, remove the block markers.
1390 event.Skip();
1391 ////@end wxEVT_UPDATE_UI event handler for ID_STATUSBAR in MainWindow.
1392}
1393
1394
1395/*
1396* wxEVT_COMMAND_MENU_SELECTED event handler for wxID_ABOUT
1397*/
1398
1399void MainWindow::OnAboutClick( wxCommandEvent& event )
1400{
1401 ////@begin wxEVT_COMMAND_MENU_SELECTED event handler for wxID_ABOUT in MainWindow.
1402 // Before editing this code, remove the block markers.
1403 About* window = new About(this);
1404 int returnValue = window->ShowModal();
1405 window->Destroy();
1406 ////@end wxEVT_COMMAND_MENU_SELECTED event handler for wxID_ABOUT in MainWindow.
1407}
1408
1409
1410/*
1411* wxEVT_COMMAND_RADIOBUTTON_SELECTED event handler for NoSep_RadioButton
1412*/
1413
1414void MainWindow::OnNoSepRadioButtonSelected( wxCommandEvent& event )
1415{
1416 static_cast<string>("-import:nosep");
1417}
1418
1419
1420/*
1421* wxEVT_COMMAND_RADIOBUTTON_SELECTED event handler for Sep_RadioButton
1422*/
1423
1424void MainWindow::OnSepRadioButtonSelected( wxCommandEvent& event )
1425{
1426 static_cast<string>("-import:sep");
1427}
1428
1429
1430/*
1431* wxEVT_COMMAND_RADIOBUTTON_SELECTED event handler for Separated_RadioButton
1432*/
1433
1434/*
1435* wxEVT_COMMAND_RADIOBUTTON_SELECTED event handler for Complete_RadioButton
1436*/
1437
1438void MainWindow::OnCompleteRadioButtonSelected( wxCommandEvent& event )
1439{
1440 splitInstances = NOT_SPLIT;
1441
1442}
1443
1444
1445/*
1446* wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BITMAPBUTTON
1447*/
1448
1449void MainWindow::OnRefreshButtonClick( wxCommandEvent& event )
1450{
1451 refreshMods(globalInstalledMods);
1452}
1453
1454
1455/*
1456* wxEVT_COMMAND_MENU_SELECTED event handler for wxID_LOAD
1457*/
1458
1459
1460
1461
1462void MainWindow::refreshMods (vector<string> s) {
1463
1464 Mods_CheckboxList->Clear();
1465 //globalInstalledMods = getPackages();
1466 for (int i = 0; i < globalPackages.size(); i++) {
1467 Mods_CheckboxList->Append(globalPackages[i].name.c_str());
1468 if( binary_search(s.begin(), s.end(), globalPackages[i].modStringName ) ) Mods_CheckboxList->Check(i);
1469 //else Mods_CheckboxList->Check(i,0);
1470
1471 }
1472}
1473
1474void MainWindow::OnLoadClick( wxCommandEvent& event )
1475{
1476 if (busy == 1) return;
1477 static const wxChar *FILETYPES = _T(
1478 "Mod Loadouts (*.cfg)|*.cfg|"
1479 "All files (*.*)|*.*"
1480 );
1481
1482 wxFileDialog* openFileDialog =
1483 new wxFileDialog( this, _("Open Mod Loadout"), "", "", FILETYPES,
1484 wxOPEN, wxDefaultPosition);
1485
1486 if ( openFileDialog->ShowModal() == wxID_OK )
1487 {
1488 refreshMods(getInstallString( string(openFileDialog->GetPath()) ));
1489 }
1490
1491
1492}
1493
1494
1495/*
1496* wxEVT_COMMAND_MENU_SELECTED event handler for wxID_SAVE
1497*/
1498
1499void MainWindow::OnSaveClick( wxCommandEvent& event )
1500{
1501 if (busy == 1) return;
1502 static const wxChar *FILETYPES = _T(
1503 "Mod Loadouts (*.cfg)|*.cfg|"
1504 "All files (*.*)|*.*"
1505 );
1506
1507 wxFileDialog* openFileDialog =
1508 new wxFileDialog( this, _("Open file"), "", "", FILETYPES,
1509 wxSAVE, wxDefaultPosition);
1510
1511 if ( openFileDialog->ShowModal() == wxID_OK )
1512 {
1513
1514
1515 //Mods_CheckboxList->
1516
1517
1518
1519 //
1520
1521 if ( exists( openFileDialog->GetPath().c_str() ) )
1522 {
1523 remove( openFileDialog->GetPath().c_str() );
1524 }
1525
1526 ofstream file(openFileDialog->GetPath().c_str());
1527
1528 vector<string>list;
1529 for(int i = 0; i < globalPackages.size(); i++) if(Mods_CheckboxList->IsChecked(i)) list.push_back( globalPackages[i].modStringName );
1530 vector<string>::iterator begin_iter = list.begin();
1531 vector<string>::iterator end_iter = list.end();
1532
1533 sort( list.begin(), list.end() );
1534
1535 for( ; begin_iter != end_iter; ++begin_iter) {
1536 file << *begin_iter << " ";
1537 }
1538
1539 file.close();
1540 file.clear();
1541
1542 //SetCurrentFilename(openFileDialog->GetFilename());
1543 //theText->LoadFile(openFileDialog->GetFilename());
1544 //SetStatusText(GetCurrentFilename(), 0);
1545 //SetStatusText(openFileDialog->GetDirectory(),1);
1546 }
1547}
1548
1549
1550
1551/*
1552* wxEVT_COMMAND_BUTTON_CLICKED event handler for ReGlobalize_Button
1553*/
1554
1555void MainWindow::OnReGlobalizeButtonClick( wxCommandEvent& event )
1556{
1557 wxMessageDialog* YesNoDialog = new wxMessageDialog(this, "WARNING: This will DELETE the Edition's GameDataFolder and recreate it from the vanilla Oni game data. \n Are you SURE you want to do this? ", "AE Installer Alert", wxYES_NO | wxICON_EXCLAMATION , wxDefaultPosition);
1558
1559 if (YesNoDialog->ShowModal() == wxID_NO) { //if the user said no...
1560
1561 }
1562 else {
1563
1564 this->InstallButton->Disable();
1565 this->ReglobalizeButton->Disable();
1566
1567#ifdef WIN32
1568
1569 boost::thread thrd2(globalizeData);
1570 //globalizeData();
1571 //boost::thread::create_thread(&globalizeData);
1572 // boost::thread_group Tg;
1573 // Tg.create_thread( &globalizeData(), this );
1574#else
1575 globalizeData();
1576#endif
1577
1578 this->InstallButton->Enable();
1579 this->ReglobalizeButton->Enable();
1580 }
1581
1582}
1583/*
1584* wxEVT_COMMAND_RADIOBUTTON_SELECTED event handler for Separated_RadioButton
1585*/
1586
1587/*void MainWindow::OnSeparatedRadioButtonSelected( wxCommandEvent& event )
1588{
1589////@begin wxEVT_COMMAND_RADIOBUTTON_SELECTED event handler for Separated_RadioButton in MainWindow.
1590// Before editing this code, remove the block markers.
1591event.Skip();
1592////@end wxEVT_COMMAND_RADIOBUTTON_SELECTED event handler for Separated_RadioButton in MainWindow.
1593}*/
1594
1595
1596/*
1597 * wxEVT_COMMAND_RADIOBUTTON_SELECTED event handler for Seperated_RadioButton
1598 */
1599
1600void MainWindow::OnSeperatedRadioButtonSelected( wxCommandEvent& event )
1601{
1602splitInstances = SPLIT;
1603}
1604
Note: See TracBrowser for help on using the repository browser.