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

Last change on this file since 376 was 373, checked in by iritscen, 15 years ago

Fixed OptionsPanel->Show refreshing issue.

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