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

Last change on this file since 415 was 410, checked in by gumby, 15 years ago

fixed onvl bug

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