source: AE/Installer/trunk/source/installer.cpp@ 390

Last change on this file since 390 was 379, checked in by iritscen, 15 years ago

Adding GDF switch code to Mac side post-globalization.
Preparing way for new code (search for 'CIP' in proj).
Clarifying re-globalization warning.

File size: 27.8 KB
Line 
1/*
2 AE/Mod Installer
3 by Gumby and Iritscen
4*/
5
6#define DEBUG
7#include <stdio.h>
8//#include <conio.h>
9//#include <process.h>
10#include <string>
11#include <iostream>
12#include <cctype>
13#include <vector>
14#include <fstream>
15#include <errno.h>
16#include <sstream>
17
18#include "boost/filesystem.hpp" // includes all needed Boost.Filesystem declarations
19
20#include "installer.h"
21
22#ifdef WIN32
23#include <windows.h>
24#else // assume we're on Mac
25#include <stdlib.h>
26#include <dirent.h>
27#endif
28
29//const string strInstallerVersion = "1.0";
30const bool SPLIT = 1;
31const bool NOT_SPLIT = 0;
32bool splitInstances = SPLIT;
33
34#ifdef WIN32
35const string strOniSplit = "Onisplit.exe";
36string strImportOption = "-import:nosep";
37const char* strClsCmd = "cls";
38const char* strPauseCmd = "PAUSE";
39#else // set up Mac equivalents since we're in Mac OS
40const string strOniSplit = "mono Onisplit.exe";
41string strImportOption = "-import:sep";
42const char* strClsCmd = "clear";
43const char* strPauseCmd = "read -n 1 -p \"Press any key to continue\"";
44#endif
45
46using namespace boost::filesystem;
47using namespace std;
48
49
50/*
51 int main(void)
52 {
53 if ( exists( "../../GameDataFolder/level0_Final.sep" ) ) splitInstances = NOT_SPLIT;
54 else splitInstances = NOT_SPLIT;
55 // SetConsoleTitle("AE Installer"); windows junk, convert to SDL
56 #ifdef WIN32
57 system("color 0A");
58 #endif
59 cout << "\nWelcome to the AE installer!\n";
60 cout << "\nWhat would you like to do?\n";
61
62 return mainMenu();
63 }
64 */
65
66
67
68int mainMenu(void)
69{
70 char choice = '0';
71 bool exit = false;
72 int err = 0;
73 do
74 {
75 if( exists( "../GameDataFolder" ) ) {
76 cout << "\n1. Add new packages\n";
77 cout << "2. Remove packages\n";
78 cout << "3. See what is installed\n";
79 cout << "4. Globalize data\n";
80 cout << "5. About AE\n";
81 cout << "6. Quit\n\n";
82
83 choice = cin.get();
84 cin.ignore(128, '\n');
85 switch(choice)
86 {
87 case '1':
88 err = installPackages();
89 break;
90 case '2':
91 err = uninstallPackages();
92 break;
93 case '3':
94 err = listInstalledPackages();
95 break;
96 case '4':
97 err = globalizeData();
98 break;
99 case '5':
100 err = printInstallerInfo();
101 break;
102 case '6':
103 exit = true;
104 break;
105 default:
106 cout << "Please choose one of the above numbers, and press Enter.\n\n";
107 }
108 if (err) // if something fatal happened
109 exit = true;
110 }
111 else {
112 cout << "\n1. Globalize data\n";
113 cout << "2. About AE\n";
114 cout << "3. Quit\n\n";
115
116 choice = cin.get();
117 cin.ignore(128, '\n');
118 switch(choice)
119 {
120 case '1':
121 err = globalizeData();
122 break;
123 case '2':
124 err = printInstallerInfo();
125 break;
126 case '3':
127 exit = true;
128 break;
129 default:
130 cout << "Please choose one of the above numbers, and press Enter.\n\n";
131 }
132 if (err) // if something fatal happened
133 exit = true;
134 }
135 } while(!exit);
136
137 return err;
138}
139
140int globalizeData(void)
141{
142 int err = 0;
143
144 try {
145 int levels[15] = {0, 1, 2, 3, 4, 6, 8, 9, 10, 11, 12, 13, 14, 18, 19}; // the levels Oni has
146 char choice = 0;
147
148 //SetCurrentDirectory("C:/Program Files/Oni/edition/install");
149 char levelnum[3];
150 path Characters = "../GameDataFolder/level0_Characters";
151 path Particles = "../GameDataFolder/level0_Particles";
152 path Archive = "../GameDataFolder/Archive";
153 path Textures = "../GameDataFolder/level0_Textures";
154 path Sounds = "../GameDataFolder/level0_Sounds";
155 path Animations = "../GameDataFolder/level0_Animations";
156 path TRAC = Animations / "level0_TRAC";
157 path TRAM = Animations / "level0_TRAM";
158 /*
159 if (exists("../GameDataFolder/"))
160 {
161 //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.)"
162 // << "\n1. Re-globalize"
163 // << "\n2. Return to main menu\n";
164 //choice = cin.get();
165 cin.ignore(128, '\n');
166 if (choice == '1')
167 remove_all("../GameDataFolder"); // remove AE GDF
168 if (choice == '2')
169 return 0;
170 }
171 */
172 create_directory( "../GameDataFolder/" );
173 create_directory( "packages" );
174 if (exists("packages/VanillaDats")) remove_all("packages/VanillaDats");
175 create_directory( "packages/VanillaDats" );
176
177 create_directory( "packages/VanillaDats/level0_Final/" );
178 create_directory( Characters );
179 create_directory( Particles );
180 create_directory( Archive );
181 create_directory( Textures );
182 create_directory( Sounds );
183 create_directory( Animations );
184 create_directory( TRAC );
185 create_directory( TRAM );
186
187 for(int i = 0; i < 15; i++)
188 {
189 sprintf(levelnum,"%d",levels[i]); // int to char array
190 exists("../../GameDataFolder/level" + (string)levelnum + "_Final");
191 system((strOniSplit + " -export ../GameDataFolder/level" + (string)levelnum + "_Final ../../GameDataFolder/level" + (string)levelnum + "_Final.dat").c_str());
192
193 create_directory( "packages/VanillaDats/level" + (string)levelnum + "_Final" ); //remember to cast your arrays as strings :)
194 create_directory( "packages/VanillaDats/level" + (string)levelnum + "_Final/level" + (string)levelnum + "_Final" );
195
196 directory_iterator end_iter;
197 for ( directory_iterator dir_itr( "../GameDataFolder/level" + (string)levelnum + "_Final" ); dir_itr != end_iter; ++dir_itr )
198 {
199 //cout << dir_itr->path().filename();
200 if ( is_regular_file( dir_itr->status() ) )
201 {
202
203 if ( dir_itr->path().filename().substr(0,8) == "TXMPfail" ||
204 dir_itr->path().filename().substr(0,9) == "TXMPlevel" ||
205 ( dir_itr->path().filename().substr(0,4) == "TXMP" && dir_itr->path().filename().find("intro")!=string::npos) ||
206 dir_itr->path().filename().substr(0,4) == "TXMB" ||
207 dir_itr->path().filename() == "M3GMpowerup_lsi.oni" ||
208 dir_itr->path().filename() == "TXMPlsi_icon.oni" ||
209 ( dir_itr->path().filename().substr(0,4) == "TXMB" && dir_itr->path().filename().find("splash_screen.oni")!=string::npos) )
210 {
211 cout <<dir_itr->path().filename() << "\n";
212 create_directory( dir_itr->path().parent_path() / "NoGlobal");
213 if(!exists( dir_itr->path().parent_path() / "NoGlobal" / dir_itr->filename())) rename(dir_itr->path(), dir_itr->path().parent_path() / "NoGlobal" /
214 dir_itr->filename());
215 else remove(dir_itr->path());
216 }
217 else if (dir_itr->path().filename().substr(0,4) == "TRAC") {
218 cout <<dir_itr->path().filename() << "\n";
219 if(!exists( TRAC / dir_itr->filename())) rename(dir_itr->path(), TRAC / dir_itr->filename());
220 else remove(dir_itr->path());
221 }
222 else if (dir_itr->path().filename().substr(0,4) == "TRAM") {
223 cout <<dir_itr->path().filename() << "\n";
224 if(!exists( TRAM / dir_itr->filename())) rename(dir_itr->path(), TRAM / dir_itr->filename());
225 else remove(dir_itr->path());
226 }
227 else if (dir_itr->path().filename().substr(0,4) == "ONSK" ||
228 dir_itr->path().filename().substr(0,4) == "TXMP") {
229 cout <<dir_itr->path().filename() << "\n";\
230 create_directory( dir_itr->path().parent_path() / "TexFix");
231 if(!exists( Textures / dir_itr->filename())) rename(dir_itr->path(), Textures / dir_itr->filename());
232 //rename(dir_itr->path(), dir_itr->path().parent_path() / "TexFix" / dir_itr->filename());
233 }
234 else if (dir_itr->path().filename().substr(0,4) == "ONCC"
235 || dir_itr->path().filename().substr(0,4) == "TRBS"
236 || dir_itr->path().filename().substr(0,4) == "TRMA"
237 || dir_itr->path().filename().substr(0,4) == "TRSC"
238 || dir_itr->path().filename().substr(0,4) == "TRAS") {
239 cout <<dir_itr->path().filename() << "\n";
240 if(!exists( Characters / dir_itr->filename())) rename(dir_itr->path(), Characters / dir_itr->filename());
241 else remove(dir_itr->path());
242 }
243 else if (dir_itr->path().filename().substr(0,4) == "OSBD"
244 || dir_itr->path().filename().substr(0,4) == "SNDD") {
245 cout << dir_itr->path().filename() << "\n";
246 if(!exists( Sounds / dir_itr->filename())) rename(dir_itr->path(), Sounds / dir_itr->filename());
247 else remove(dir_itr->path());
248 }
249 else if (dir_itr->path().filename().substr(0,5) == "BINA3"
250 || dir_itr->path().filename().substr(0,10) == "M3GMdebris"
251 || dir_itr->path().filename() == "M3GMtoxic_bubble.oni"
252 || dir_itr->path().filename().substr(0,8) == "M3GMelec"
253 || dir_itr->path().filename().substr(0,7) == "M3GMrat"
254 || dir_itr->path().filename().substr(0,7) == "M3GMjet"
255 || dir_itr->path().filename().substr(0,9) == "M3GMbomb_"
256 || dir_itr->path().filename() == "M3GMbarab_swave.oni"
257 || dir_itr->path().filename() == "M3GMbloodyfoot.oni"
258 ){
259 cout <<dir_itr->path().filename() << "\n";
260 if(!exists( Particles / dir_itr->filename())) rename(dir_itr->path(), Particles / dir_itr->filename());
261 else remove(dir_itr->path());
262 }
263 else if (dir_itr->path().filename().substr(0,4) == "AGDB"
264 || dir_itr->path().filename().substr(0,4) == "TRCM") {
265 cout <<dir_itr->path().filename() << "\n";
266
267 if(!exists( Archive / dir_itr->filename())) rename(dir_itr->path(), Archive / dir_itr->filename());
268 else remove(dir_itr->path());
269 }
270 }
271
272
273 }
274 system( (strOniSplit + " -move:delete " + Textures.string() + " ../GameDataFolder/level" + (string)levelnum + "_Final/TXMP*.oni").c_str());
275
276 }
277
278 for (int i = 0; i < 15; i++)
279 {
280 sprintf(levelnum,"%d",levels[i]);
281 system( (strOniSplit + " " + strImportOption + " ../GameDataFolder/level" + levelnum + "_Final packages/VanillaDats/level" + levelnum + "_Final/level"
282 + levelnum + "_Final/level" + levelnum + "_Final.oni").c_str());
283 }
284 path VanillaCharacters = "packages/VanillaDats/level0_Final/level0_Characters/level0_Characters.oni";
285 path VanillaParticles = "packages/VanillaDats/level0_Final/level0_Particles/level0_Particles.oni";
286 path VanillaTextures = "packages/VanillaDats/level0_Final/level0_Textures/level0_Textures.oni";
287 path VanillaSounds = "packages/VanillaDats/level0_Final/level0_Sounds/level0_Sounds.oni";
288 path VanillaAnimations = "packages/VanillaDats/level0_Final/level0_Animations/level0_Animations.oni";
289 path VanillaTRAC = "packages/VanillaDats/level0_Final/level0_Animations/level0_TRAC.oni";
290 path VanillaTRAM = "packages/VanillaDats/level0_Final/level0_Animations/level0_TRAM.oni";
291 create_directory( VanillaCharacters.parent_path() );
292 create_directory( VanillaParticles.parent_path() );
293 create_directory( VanillaTextures.parent_path() );
294 create_directory( VanillaSounds.parent_path() );
295 create_directory( VanillaAnimations.remove_filename() );
296 system((strOniSplit + " " + strImportOption + " " + Characters.string() + " " + VanillaCharacters.string()).c_str());
297 system((strOniSplit + " " + strImportOption + " " + Particles.string() + " " + VanillaParticles.string()).c_str());
298 system((strOniSplit + " " + strImportOption + " " + Textures.string() + " " + VanillaTextures.string()).c_str());
299 //system((strOniSplit + " " + strImportOption + (string)" " + Animations.string() + (string)" " + VanillaAnimations.string()).c_str());
300 system((strOniSplit + " " + strImportOption + " " + TRAC.string() + " " + VanillaTRAC.string()).c_str());
301 system((strOniSplit + " " + strImportOption + " " + Sounds.string() + " " + VanillaSounds.string()).c_str());
302 system((strOniSplit + " " + strImportOption + " " + TRAM.string() + " " + VanillaTRAM.string()).c_str());
303
304 create_directory("../GameDataFolder/IGMD");
305 copy((path)"packages/VanillaBSL/IGMD", (path)"../GameDataFolder");
306 }
307 catch (exception ex) {
308 cout << ex.what();
309 }
310 return err;
311}
312
313int installPackages(void)
314{
315 bool installed_something = 0;
316 int err = 0;
317 ModPackage package;
318 vector<string> installed_packages;
319 vector<ModPackage> packages;
320 vector<ModPackage>::iterator iter;
321 vector<string> installString;
322
323 iter = packages.begin();
324 packages = getPackages();
325 vector<string> installedMods = getInstallString();
326
327 if (packages.empty())
328 {
329 cout << "Error: You have no packages!\n";
330 return 0;
331 }
332
333 cout << "Detecting installed packages...\n";
334
335 int index = 1;
336 char choice = '0';
337
338 for (vector<ModPackage>::iterator package_iter = packages.begin(); package_iter != packages.end(); ++package_iter)
339 {
340 if (!binary_search(installedMods.begin(), installedMods.end(), package_iter->modStringName))
341 { //package_iter->isInstalled :< I forgot about this...
342 //cout << index << " ";
343 system(strClsCmd);
344 cout << (*package_iter).name << "\n";
345 for (int character = 1; character <= (*package_iter).name.length() - 1; character++) cout << '-';
346 cout << "\n"
347 << (*package_iter).readme << "\n\n"
348 << "Please enter a number choice\n"
349 << " 1. Add\n"
350 << " 2. Don't Add\n"
351 << "";
352 index++;
353 choice = 0;
354
355 do
356 {
357 choice = cin.get();
358 cin.ignore(1280, '\n');
359 } while(choice == 0);
360
361 if (choice == '1')
362 {
363 cout << "\nInstalling...\n\n";
364 if (package_iter->hasOnis || (package_iter->hasDeltas /*(*package_iter).isUnpacked */ ))
365 {
366 installed_something = 1;
367 installedMods.push_back(package_iter->modStringName);
368 system(strPauseCmd);
369 }
370 }
371 }
372 }
373 if (index == 1)
374 {
375 cout << "Warning: All packages are already installed\n";
376 //would you like to recombine your data?
377 return 0;
378 }
379 if (installed_something == 0)
380 {
381 cout << "Warning: You didn't add anything!\n";
382 //would you like to recombine your data?
383 return 0;
384 }
385
386 sort(installedMods.begin(), installedMods.end());
387 //system(Onisplit.c_str());
388 recompileAll(installedMods);
389 system(strPauseCmd);
390
391 return err;
392}
393
394int uninstallPackages(void)
395{
396 int err = 0;
397 ModPackage package;
398 vector<string> installed_packages;
399 vector<ModPackage> packages;
400 vector<ModPackage>::iterator iter;
401 vector<string> installString;
402
403 iter = packages.begin();
404 packages = getPackages();
405
406
407 cout << "Detecting installed packages...\n";
408
409 vector<string> installedMods = getInstallString();
410
411 if (packages.empty())
412 {
413 cout << "Error: You have no packages!\n";
414 return 0;
415 }
416
417 int index = 0;
418 int uninstalled_something = 0;
419 char choice = '0';
420
421 for (vector<ModPackage>::iterator package_iter = packages.begin(); package_iter != packages.end(); ++package_iter)
422 {
423 if (binary_search(installedMods.begin(), installedMods.end(), package_iter->modStringName))
424 { //package_iter->isInstalled :< I forgot about this...
425 //cout << index << " ";
426 system(strClsCmd);
427 cout << (*package_iter).name << "\n";
428 for (int character = 1; character <= (*package_iter).name.length() - 1; character++) cout << '-';
429 cout << "\n"
430 << (*package_iter).readme << "\n\n"
431 << "Please enter a number choice\n"
432 << " 1. Remove\n"
433 << " 2. Don't Remove\n"
434 << "";
435
436 choice = 0;
437
438 do
439 {
440 choice = cin.get();
441 cin.ignore(1280, '\n');
442 } while(choice == 0);
443
444 if (choice == '1')
445 {
446 cout << "\nUninstalling...\n\n";
447 installedMods.erase( installedMods.begin() + (index) );
448 system(strPauseCmd);
449 uninstalled_something = 1;
450
451 }
452 else {
453 index++;
454 }
455 }
456 }
457 if ( uninstalled_something == 0 )
458 {
459 if (index == 0) //bad practice, I need to implement a second vector or something. Meh.
460 {
461 cout << "\nWarning: You have no installed packages!";
462 }
463 else
464 {
465 cout << "\nWarning: You didn't remove anything!";
466 }
467 //would you like to recombine your data?
468 return 0;
469
470 }
471 sort(installedMods.begin(), installedMods.end());
472 //system(Onisplit.c_str());
473 recompileAll(installedMods);
474 system(strPauseCmd);
475
476 return err;
477}
478
479int listInstalledPackages(void)
480{
481 cout << "\nThis feature not yet implemented.\n\n";
482
483 return 0;
484}
485
486int printInstallerInfo(void)
487{
488 cout << "\nAE/Mod Installer\n";
489 cout << "version " << strInstallerVersion << "\n";
490 cout << "by Gumby & Iritscen\n";
491 cout << "see http://oni.bungie.org/community/forums for more info\n\n";
492
493 return 0;
494}
495
496vector<ModPackage> getPackages(void)
497{
498 vector<ModPackage> packages;
499 packages.reserve(65536); // come on, we shouldn't need this much space...right?!
500 fstream file;
501 string filename = "\0";
502 string MODINFO_CFG = "Mod_Info.cfg";
503
504 try
505 {
506 directory_iterator end_iter;
507 for (directory_iterator dir_itr("./packages"); dir_itr != end_iter; ++dir_itr)
508 {
509 file.open((dir_itr->path().string() + "/" + MODINFO_CFG).c_str());
510 //cout << filename << "\n";
511
512 if(!file.fail())
513 {
514 //cout << dir_itr->path().string() + MODINFO_CFG;
515 //would prefer to push a pointer to a package, but this will do for now
516 packages.push_back(fileToModPackage(file));
517 }
518 file.close();
519 file.clear();
520 }
521 }
522 catch (const std::exception & ex)
523 {
524 cout << "Warning, something odd happened!\n";
525 }
526
527 return packages;
528}
529
530ModPackage fileToModPackage(fstream &file)
531{
532 /*
533 This converts a file to a ModPackage struct.
534
535 A few notes...
536 "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.
537 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
538 slower than reading a variable.
539 */
540 ModPackage package;
541 string line;
542 static string NameOfMod = "NameOfMod"; //used for comparing to the current token...
543 //I could have done it in reverse (*iter).compare("ModString") or
544 static string ARROW = "->"; //did something like "ModString".compare(*iter), and it would have been
545 static string ModString = "ModString"; //functionably the same.
546 static string HasOnis = "HasOnis";
547 static string HasDeltas = "HasDeltas";
548 static string HasBSL = "HasBSL";
549 static string HasDats = "HasDats";
550 static string IsEngine = "IsEngine";
551 static string Readme = "Readme";
552 static string GlobalNeeded = "GlobalNeeded";
553 static string Category = "Category";
554 static string Creator = "Creator";
555 while (! file.eof() )
556 {
557 getline (file,line);
558 vector<string> tokens;
559 vector<string>::iterator iter;
560 tokenize(line, tokens); //string to vector of "words"
561 if (tokens.capacity() >= 2) { //make sure they are using enough stuff
562 iter = tokens.begin(); //what word we are on, starts at first word
563 /*
564 if (!AEInstallVersion.compare(*iter))
565 If mod is too old, skip this mod.
566 */
567 /*else*/if (!NameOfMod.compare(*iter)) { //if it contains the name
568 for ( ; iter !=tokens.end() && SLASHSLASH.compare(*iter); iter++) { //interates through the words, ends if it reaches the end of the line or a "//" comment
569 if (ARROW.compare(*iter) && NameOfMod.compare(*iter)) { //ignores "->" and "NameOfMod"
570 //cout << *iter;
571 //cout << " ";
572 package.name += *iter + " ";
573 }
574 }
575
576 }
577 else if (!ModString.compare(*iter)) {
578 iter++; iter++;
579 package.modStringName = *iter;
580 iter++;
581 package.modStringVersion = atoi((*iter).c_str());
582 }
583 else if (!HasOnis.compare(*iter)) {
584 iter++; iter++;
585 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
586 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,
587 iter++; iter++;} // using "YFR" would probably set it off. :<
588
589 if (toupper((*iter)[0]) + toupper((*iter)[1]) + toupper((*iter)[2]) == 'Y' + 'E' + 'S') package.hasBSL = 1;
590 }
591 else if (!HasDeltas.compare(*iter)) {
592 iter++; iter++;
593 if (toupper((*iter)[0]) + toupper((*iter)[1]) + toupper((*iter)[2]) == 'Y' + 'E' + 'S') package.hasDeltas = 1;
594 }
595 else if (!HasDats.compare(*iter)) {
596 iter++; iter++;
597 if (toupper((*iter)[0]) + toupper((*iter)[1]) + toupper((*iter)[2]) == 'Y' + 'E' + 'S') package.hasDats = 1;
598 }
599 else if (!IsEngine.compare(*iter)) {
600 iter++; iter++;
601 if (toupper((*iter)[0]) + toupper((*iter)[1]) + toupper((*iter)[2]) == 'Y' + 'E' + 'S') package.isEngine = 1;
602 }
603 else if (!GlobalNeeded.compare(*iter)) {
604 iter++; iter++;
605 if (toupper((*iter)[0]) + toupper((*iter)[1]) + toupper((*iter)[2]) == 'Y' + 'E' + 'S') package.globalNeeded = 1;
606 else if (toupper((*iter)[0]) + toupper((*iter)[1]) == 'N' + 'O') package.globalNeeded = 1; //Really the only place where checking for "No" is important atm.
607 }
608 else if (!Category.compare(*iter)) {
609 for ( ; iter !=tokens.end() && SLASHSLASH.compare(*iter); iter++) { //interates through the words, ends if it reaches the end of the line or a "//" comment
610 if (ARROW.compare(*iter) && Category.compare(*iter)) { //ignores "->" and "Category"
611 //cout << *iter;
612 //cout << " ";
613 package.category += *iter + " ";
614 }
615 }
616 }
617 else if (!Creator.compare(*iter)) { //if it contains the name
618 for ( ; iter !=tokens.end() && SLASHSLASH.compare(*iter); iter++) { //interates through the words, ends if it reaches the end of the line or a "//" comment
619 if (ARROW.compare(*iter) && Creator.compare(*iter)) { //ignores "->" and "Category"
620 //cout << *iter;
621 //cout << " ";
622 package.creator += *iter + " ";
623 }
624 }
625 }
626 else if (!Readme.compare(*iter)) { //if it contains the name
627 for ( ; iter !=tokens.end() && SLASHSLASH.compare(*iter); iter++) { //interates through the words, ends if it reaches the end of the line or a "//" comment
628 if (ARROW.compare(*iter) && Readme.compare(*iter)) { //ignores "->" and "Category"
629 if(!(*iter).compare("\\n")) package.readme += '\n';
630 else package.readme += *iter + " ";
631 }
632 }
633 }
634 }
635
636 }
637 package.doOutput();
638 return package;
639}
640
641void recompileAll(vector<string> installedMods)
642{
643#ifdef WIN32
644 RedirectIOToConsole();
645 HWND hWnd = GetConsoleWindow();
646 ShowWindow( hWnd, SW_HIDE );
647#endif
648 setStatusArea("Importing levels...");
649 //setStatusArea("Recompiling Data...");
650 path vanilla_dir = "./packages/VanillaDats/";
651 string importCommand = "";
652 char statusString[128];
653 int numberOfDats = 0;
654 int j = 1;
655 string datString;
656 std::stringstream out;
657
658
659 clearOldDats();
660 remove("Onisplit.log");
661 if(splitInstances == SPLIT){
662 recursive_directory_iterator end_iter;
663
664 for ( recursive_directory_iterator dir_itr( vanilla_dir );
665 dir_itr != end_iter;
666 ++dir_itr )
667 {
668 try{
669 if ( is_directory( dir_itr->status() ) && dir_itr.level() == 1)
670 {
671 numberOfDats++;
672 }
673 }
674 catch(exception ex) {
675
676 }
677 }
678
679 //recursive_directory_iterator end_iter;
680
681
682 out << numberOfDats;
683 datString = out.str();
684 try {
685 for ( recursive_directory_iterator dir_itr( vanilla_dir );
686 dir_itr != end_iter;
687 ++dir_itr )
688 {
689 try
690 {
691 if ( is_directory( dir_itr->status() ) && dir_itr.level() == 1)
692 {
693 importCommand = strOniSplit + " " + strImportOption + " " + dir_itr->path().parent_path().string() + '/' + dir_itr->path().filename();
694 for (int i = 0; i < installedMods.size(); ++i) {
695 if (exists("packages/" + installedMods[i] + "/oni/" + dir_itr->path().parent_path().filename() + '/' + dir_itr->path().filename() ))
696 importCommand += " packages/" + installedMods[i] + "/oni/" + dir_itr->path().parent_path().filename() + '/' + dir_itr->path().filename();
697
698 //else cout << " packages/VanillaDats/" + installedMods[i] + "/oni/";
699 }
700 importCommand += " ../GameDataFolder/" + dir_itr->path().filename() + ".dat >> Onisplit.log";
701
702 sprintf(statusString,"%d/%i\0",j,numberOfDats);
703 setProgressBar( (int)(1000 * (float)(j-1) / (float)numberOfDats) ); //100% * dat we're on / total dats
704 setStatusArea("Importing " + dir_itr->path().filename() + " " + statusString);
705
706 system(importCommand.c_str());
707 //Sleep(1000);
708 //cout << importCommand << "\n";
709 j++;
710
711 }
712 }
713 catch ( const std::exception & ex )
714 {
715 cout << "Warning, exception " << ex.what() << "!";
716 }
717 }
718
719 }
720 catch( const std::exception & ex ) {
721 cout << "Warning, exception " << ex.what() << "!\n"
722 << "You probably need to re-globalize.";
723 //create_directory( "./packages/VanillaDats" );
724 }
725
726 }
727 else if(splitInstances == NOT_SPLIT){
728 directory_iterator end_iter;
729
730 for ( directory_iterator dir_itr( vanilla_dir );
731 dir_itr != end_iter;
732 ++dir_itr )
733 {
734
735 if ( is_directory( dir_itr->status() ) )
736 {
737 numberOfDats++;
738 }
739
740
741 }
742
743 out << numberOfDats;
744 datString = out.str();
745
746 for ( directory_iterator dir_itr( vanilla_dir );
747 dir_itr != end_iter;
748 ++dir_itr )
749 {
750 try
751 {
752 if ( is_directory( dir_itr->status() ) )
753 {
754 importCommand = strOniSplit + " " + strImportOption + " " + vanilla_dir.string() + dir_itr->path().filename() + " " + "../GameDataFolder/" + dir_itr->path().filename()
755 + ".dat";
756 for (int i = 0; i < installedMods.size(); ++i) {
757 if (exists("packages/" + installedMods[i] + "/oni/" + dir_itr->path().filename() ))
758 importCommand += " packages/" + installedMods[i] + "/oni/" + dir_itr->path().filename();
759 }
760 importCommand += " ../GameDataFolder/" + dir_itr->path().filename() + ".dat";
761
762 sprintf(statusString,"%d/%i\0",j,numberOfDats);
763 setProgressBar( (int)(1000 * (float)(j-1) / (float)numberOfDats) ); //100% * dat we're on / total dats
764 setStatusArea("Importing " + dir_itr->path().filename() + " " + statusString);
765
766 system(importCommand.c_str());
767
768 j++;
769 }
770 }
771 catch ( const std::exception & ex )
772 {
773 cout << "Warning, something odd happened!\n";
774 }
775 }
776 }
777 writeInstalledMods(installedMods);
778 setProgressBar(1000);
779 setStatusArea("Done!");
780 sleep(1000);
781 setProgressBar(0);
782
783}
784
785void writeInstalledMods(vector<string> installedMods)
786{
787
788 if ( exists( strInstallCfg ) )
789 {
790 remove( strInstallCfg );
791 }
792
793 ofstream file(strInstallCfg.c_str());
794
795 vector<string>list = installedMods;
796 vector<string>::iterator begin_iter = list.begin();
797 vector<string>::iterator end_iter = list.end();
798
799 sort( list.begin(), list.end() );
800
801 for( ; begin_iter != end_iter; ++begin_iter) {
802 file << *begin_iter << " ";
803 }
804
805 file.close();
806 file.clear();
807
808}
809
810vector<string> getInstallString(string Cfg)
811{
812 //system(strPauseCmd);
813 vector<string> returnval;
814
815 string line;
816 fstream file;
817
818 if (exists( Cfg ))
819 {
820 file.open(Cfg.c_str());
821 getline(file, line);
822 tokenize(line, returnval);
823 file.close();
824 file.clear();
825 sort(returnval.begin(), returnval.end());
826 }
827 else cout << "fail";
828
829 return returnval;
830}
831
832//stolen token function...
833void tokenize(const string& str, vector<string>& tokens, const string& delimiters)
834{
835 // Skip delimiters at beginning.
836 string::size_type lastPos = str.find_first_not_of(delimiters, 0);
837 // Find first "non-delimiter".
838 string::size_type pos = str.find_first_of(delimiters, lastPos);
839
840 while (string::npos != pos || string::npos != lastPos)
841 {
842 // Found a token, add it to the vector.
843 tokens.push_back(str.substr(lastPos, pos - lastPos));
844 // Skip delimiters. Note the "not_of"
845 lastPos = str.find_first_not_of(delimiters, pos);
846 // Find next "non-delimiter"
847 pos = str.find_first_of(delimiters, lastPos);
848 }
849}
850
851void clearOldDats(void) {
852 directory_iterator end_iter_gdf;
853 for ( directory_iterator dir_itr_gdf( "../GameDataFolder" );
854 dir_itr_gdf != end_iter_gdf;
855 ++dir_itr_gdf )
856 {
857 //cout << dir_itr_gdf->path().extension() << "\n";
858 if ( dir_itr_gdf->path().extension() == ".dat" || dir_itr_gdf->path().extension() == ".raw" || dir_itr_gdf->path().extension() == ".sep" ) {
859 remove( dir_itr_gdf->path() );
860 }
861
862 }
863
864}
Note: See TracBrowser for help on using the repository browser.