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

Last change on this file since 393 was 393, checked in by iritscen, 16 years ago

Implemented escapePath() to fix path bug on Mac side.

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