1 |
/* |
2 |
AE/Mod Installer |
3 |
v1.0 |
4 |
by Gumby and Iritscen |
5 |
*/ |
6 |
|
7 |
#define DEBUG |
8 |
|
9 |
#include <string> |
10 |
#include <iostream> |
11 |
#include <cctype> |
12 |
#include <vector> |
13 |
#include <fstream> |
14 |
#include <errno.h> |
15 |
#include "boost/filesystem.hpp" // includes all needed Boost.Filesystem declarations |
16 |
#include "methods.h" |
17 |
|
18 |
#ifdef WIN32 |
19 |
#include <windows.h> |
20 |
#else // assume we're on Mac |
21 |
#include <stdlib.h> |
22 |
#include <dirent.h> |
23 |
#endif |
24 |
|
25 |
#ifdef WIN32 |
26 |
const string strOniSplit = "Onisplit.exe"; |
27 |
const string strImportOption = "-import:nosep"; |
28 |
const char* strClsCmd = "cls"; |
29 |
const char* strPauseCmd = "PAUSE"; |
30 |
#else // set up Mac equivalents since we're in Mac OS |
31 |
const string strOniSplit = "mono Onisplit.exe"; |
32 |
const string strImportOption = "-import:sep"; |
33 |
const char* strClsCmd = "clear"; |
34 |
const char* strPauseCmd = "read -n 1 -p \"Press any key to continue\""; |
35 |
#endif |
36 |
|
37 |
using namespace boost::filesystem; |
38 |
using namespace std; |
39 |
|
40 |
const string strInstallerVersion = "1.0"; |
41 |
const bool SPLIT = 1; |
42 |
const bool NOT_SPLIT = 0; |
43 |
bool splitInstances = SPLIT; |
44 |
|
45 |
int main(void) |
46 |
{ |
47 |
// SetConsoleTitle("AE Installer"); windows junk, convert to SDL |
48 |
#ifdef WIN32 |
49 |
system("color 0A"); |
50 |
#endif |
51 |
cout << "\nWelcome to the AE installer!\n"; |
52 |
cout << "\nWhat would you like to do?\n"; |
53 |
|
54 |
return mainMenu(); |
55 |
} |
56 |
|
57 |
int mainMenu(void) |
58 |
{ |
59 |
char choice = '0'; |
60 |
bool exit = false; |
61 |
int err = 0; |
62 |
do |
63 |
{ |
64 |
if( exists( "../GameDataFolder" ) ) { |
65 |
cout << "\n1. Install new packages\n"; |
66 |
cout << "2. Uninstall packages\n"; |
67 |
cout << "3. See what is installed\n"; |
68 |
cout << "4. Globalize data\n"; |
69 |
cout << "5. About AE\n"; |
70 |
cout << "6. Quit\n\n"; |
71 |
|
72 |
choice = cin.get(); |
73 |
cin.ignore(128, '\n'); |
74 |
switch(choice) |
75 |
{ |
76 |
case '1': |
77 |
err = installPackages(); |
78 |
break; |
79 |
case '2': |
80 |
err = uninstallPackages(); |
81 |
break; |
82 |
case '3': |
83 |
err = listInstalledPackages(); |
84 |
break; |
85 |
case '4': |
86 |
err = globalizeData(); |
87 |
break; |
88 |
case '5': |
89 |
err = printInstallerInfo(); |
90 |
break; |
91 |
case '6': |
92 |
exit = true; |
93 |
break; |
94 |
default: |
95 |
cout << "Please choose one of the above numbers, and press Enter.\n\n"; |
96 |
} |
97 |
if (err) // if something fatal happened |
98 |
exit = true; |
99 |
} |
100 |
else { |
101 |
cout << "\n1. Globalize data\n"; |
102 |
cout << "2. About AE\n"; |
103 |
cout << "3. Quit\n\n"; |
104 |
|
105 |
choice = cin.get(); |
106 |
cin.ignore(128, '\n'); |
107 |
switch(choice) |
108 |
{ |
109 |
case '1': |
110 |
err = globalizeData(); |
111 |
break; |
112 |
case '2': |
113 |
err = printInstallerInfo(); |
114 |
break; |
115 |
case '3': |
116 |
exit = true; |
117 |
break; |
118 |
default: |
119 |
cout << "Please choose one of the above numbers, and press Enter.\n\n"; |
120 |
} |
121 |
if (err) // if something fatal happened |
122 |
exit = true; |
123 |
} |
124 |
} while(!exit); |
125 |
|
126 |
return err; |
127 |
} |
128 |
|
129 |
int globalizeData(void) |
130 |
{ |
131 |
int err = 0; |
132 |
|
133 |
try { |
134 |
int levels[15] = {0, 1, 2, 3, 4, 6, 8, 9, 10, 11, 12, 13, 14, 18, 19}; // the levels Oni has |
135 |
char choice = 0; |
136 |
|
137 |
//SetCurrentDirectory("C:/Program Files/Oni/edition/install"); |
138 |
char levelnum[3]; |
139 |
path Characters = "../GameDataFolder/level0_Characters"; |
140 |
path Particles = "../GameDataFolder/level0_Particles"; |
141 |
path Archive = "../GameDataFolder/Archive"; |
142 |
path Textures = "../GameDataFolder/level0_Textures"; |
143 |
path Sounds = "../GameDataFolder/level0_Sounds"; |
144 |
path Animations = "../GameDataFolder/level0_Animations"; |
145 |
path TRAC = Animations / "level0_TRAC"; |
146 |
path TRAM = Animations / "level0_TRAM"; |
147 |
|
148 |
if (exists("../GameDataFolder/")) |
149 |
{ |
150 |
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.)" |
151 |
<< "\n1. Re-globalize" |
152 |
<< "\n2. Return to main menu\n"; |
153 |
choice = cin.get(); |
154 |
cin.ignore(128, '\n'); |
155 |
if (choice == '1') |
156 |
remove_all("../GameDataFolder"); // remove AE GDF |
157 |
if (choice == '2') |
158 |
return 0; |
159 |
} |
160 |
|
161 |
create_directory( "../GameDataFolder/" ); |
162 |
create_directory( "packages" ); |
163 |
if (exists("packages/VanillaDats")) remove_all("packages/VanillaDats"); |
164 |
create_directory( "packages/VanillaDats" ); |
165 |
|
166 |
create_directory( "packages/VanillaDats/level0_Final/" ); |
167 |
create_directory( Characters ); |
168 |
create_directory( Particles ); |
169 |
create_directory( Archive ); |
170 |
create_directory( Textures ); |
171 |
create_directory( Sounds ); |
172 |
create_directory( Animations ); |
173 |
create_directory( TRAC ); |
174 |
create_directory( TRAM ); |
175 |
|
176 |
for(int i = 0; i < 15; i++) |
177 |
{ |
178 |
sprintf(levelnum,"%d",levels[i]); // int to char array |
179 |
exists("../../GameDataFolder/level" + (string)levelnum + "_Final"); |
180 |
system((strOniSplit + " -export ../GameDataFolder/level" + (string)levelnum + "_Final ../../GameDataFolder/level" + (string)levelnum + "_Final.dat").c_str()); |
181 |
|
182 |
create_directory( "packages/VanillaDats/level" + (string)levelnum + "_Final" ); //remember to cast your arrays as strings :) |
183 |
create_directory( "packages/VanillaDats/level" + (string)levelnum + "_Final/level" + (string)levelnum + "_Final" ); |
184 |
|
185 |
directory_iterator end_iter; |
186 |
for ( directory_iterator dir_itr( "../GameDataFolder/level" + (string)levelnum + "_Final" ); dir_itr != end_iter; ++dir_itr ) |
187 |
{ |
188 |
//cout << dir_itr->path().filename(); |
189 |
if ( is_regular_file( dir_itr->status() ) ) |
190 |
{ |
191 |
|
192 |
if ( dir_itr->path().filename().substr(0,8) == "TXMPfail" || |
193 |
dir_itr->path().filename().substr(0,9) == "TXMPlevel" || |
194 |
( dir_itr->path().filename().substr(0,4) == "TXMP" && dir_itr->path().filename().find("intro")!=string::npos) || |
195 |
dir_itr->path().filename().substr(0,4) == "TXMB" || |
196 |
dir_itr->path().filename() == "M3GMpowerup_lsi.oni" || |
197 |
dir_itr->path().filename() == "TXMPlsi_icon.oni" || |
198 |
( dir_itr->path().filename().substr(0,4) == "TXMB" && dir_itr->path().filename().find("splash_screen.oni")!=string::npos) ) |
199 |
{ |
200 |
cout <<dir_itr->path().filename() << "\n"; |
201 |
create_directory( dir_itr->path().parent_path() / "NoGlobal"); |
202 |
if(!exists( dir_itr->path().parent_path() / "NoGlobal" / dir_itr->filename())) rename(dir_itr->path(), dir_itr->path().parent_path() / "NoGlobal" / |
203 |
dir_itr->filename()); |
204 |
else remove(dir_itr->path()); |
205 |
} |
206 |
else if (dir_itr->path().filename().substr(0,4) == "TRAC") { |
207 |
cout <<dir_itr->path().filename() << "\n"; |
208 |
if(!exists( TRAC / dir_itr->filename())) rename(dir_itr->path(), TRAC / dir_itr->filename()); |
209 |
else remove(dir_itr->path()); |
210 |
} |
211 |
else if (dir_itr->path().filename().substr(0,4) == "TRAM") { |
212 |
cout <<dir_itr->path().filename() << "\n"; |
213 |
if(!exists( TRAM / dir_itr->filename())) rename(dir_itr->path(), TRAM / dir_itr->filename()); |
214 |
else remove(dir_itr->path()); |
215 |
} |
216 |
else if (dir_itr->path().filename().substr(0,4) == "ONSK" || |
217 |
dir_itr->path().filename().substr(0,4) == "TXMP") { |
218 |
cout <<dir_itr->path().filename() << "\n";\ |
219 |
create_directory( dir_itr->path().parent_path() / "TexFix"); |
220 |
if(!exists( Textures / dir_itr->filename())) rename(dir_itr->path(), Textures / dir_itr->filename()); |
221 |
//rename(dir_itr->path(), dir_itr->path().parent_path() / "TexFix" / dir_itr->filename()); |
222 |
} |
223 |
else if (dir_itr->path().filename().substr(0,4) == "ONCC" |
224 |
|| dir_itr->path().filename().substr(0,4) == "TRBS" |
225 |
|| dir_itr->path().filename().substr(0,4) == "TRMA" |
226 |
|| dir_itr->path().filename().substr(0,4) == "TRSC" |
227 |
|| dir_itr->path().filename().substr(0,4) == "TRAS") { |
228 |
cout <<dir_itr->path().filename() << "\n"; |
229 |
if(!exists( Characters / dir_itr->filename())) rename(dir_itr->path(), Characters / dir_itr->filename()); |
230 |
else remove(dir_itr->path()); |
231 |
} |
232 |
else if (dir_itr->path().filename().substr(0,4) == "OSBD" |
233 |
|| dir_itr->path().filename().substr(0,4) == "SNDD") { |
234 |
cout << dir_itr->path().filename() << "\n"; |
235 |
if(!exists( Sounds / dir_itr->filename())) rename(dir_itr->path(), Sounds / dir_itr->filename()); |
236 |
else remove(dir_itr->path()); |
237 |
} |
238 |
else if (dir_itr->path().filename().substr(0,5) == "BINA3" |
239 |
|| dir_itr->path().filename().substr(0,10) == "M3GMdebris" |
240 |
|| dir_itr->path().filename() == "M3GMtoxic_bubble.oni" |
241 |
|| dir_itr->path().filename().substr(0,8) == "M3GMelec" |
242 |
|| dir_itr->path().filename().substr(0,7) == "M3GMrat" |
243 |
|| dir_itr->path().filename().substr(0,7) == "M3GMjet" |
244 |
|| dir_itr->path().filename().substr(0,9) == "M3GMbomb_" |
245 |
|| dir_itr->path().filename() == "M3GMbarab_swave.oni" |
246 |
|| dir_itr->path().filename() == "M3GMbloodyfoot.oni" |
247 |
){ |
248 |
cout <<dir_itr->path().filename() << "\n"; |
249 |
if(!exists( Particles / dir_itr->filename())) rename(dir_itr->path(), Particles / dir_itr->filename()); |
250 |
else remove(dir_itr->path()); |
251 |
} |
252 |
else if (dir_itr->path().filename().substr(0,4) == "AGDB" |
253 |
|| dir_itr->path().filename().substr(0,4) == "TRCM") { |
254 |
cout <<dir_itr->path().filename() << "\n"; |
255 |
|
256 |
if(!exists( Archive / dir_itr->filename())) rename(dir_itr->path(), Archive / dir_itr->filename()); |
257 |
else remove(dir_itr->path()); |
258 |
} |
259 |
} |
260 |
|
261 |
|
262 |
} |
263 |
system( (strOniSplit + " -move:delete " + Textures.string() + " ../GameDataFolder/level" + (string)levelnum + "_Final/TXMP*.oni").c_str()); |
264 |
|
265 |
} |
266 |
|
267 |
for (int i = 0; i < 15; i++) |
268 |
{ |
269 |
sprintf(levelnum,"%d",levels[i]); |
270 |
system( (strOniSplit + " " + strImportOption + " ../GameDataFolder/level" + levelnum + "_Final packages/VanillaDats/level" + levelnum + "_Final/level" |
271 |
+ levelnum + "_Final/level" + levelnum + "_Final.oni").c_str()); |
272 |
} |
273 |
path VanillaCharacters = "packages/VanillaDats/level0_Final/level0_Characters/level0_Characters.oni"; |
274 |
path VanillaParticles = "packages/VanillaDats/level0_Final/level0_Particles/level0_Particles.oni"; |
275 |
path VanillaTextures = "packages/VanillaDats/level0_Final/level0_Textures/level0_Textures.oni"; |
276 |
path VanillaSounds = "packages/VanillaDats/level0_Final/level0_Sounds/level0_Sounds.oni"; |
277 |
path VanillaAnimations = "packages/VanillaDats/level0_Final/level0_Animations/level0_Animations.oni"; |
278 |
path VanillaTRAC = "packages/VanillaDats/level0_Final/level0_Animations/level0_TRAC.oni"; |
279 |
path VanillaTRAM = "packages/VanillaDats/level0_Final/level0_Animations/level0_TRAM.oni"; |
280 |
create_directory( VanillaCharacters.parent_path() ); |
281 |
create_directory( VanillaParticles.parent_path() ); |
282 |
create_directory( VanillaTextures.parent_path() ); |
283 |
create_directory( VanillaSounds.parent_path() ); |
284 |
create_directory( VanillaAnimations.remove_filename() ); |
285 |
system((strOniSplit + " " + strImportOption + " " + Characters.string() + " " + VanillaCharacters.string()).c_str()); |
286 |
system((strOniSplit + " " + strImportOption + " " + Particles.string() + " " + VanillaParticles.string()).c_str()); |
287 |
system((strOniSplit + " " + strImportOption + " " + Textures.string() + " " + VanillaTextures.string()).c_str()); |
288 |
//system((strOniSplit + " " + strImportOption + (string)" " + Animations.string() + (string)" " + VanillaAnimations.string()).c_str()); |
289 |
system((strOniSplit + " " + strImportOption + " " + TRAC.string() + " " + VanillaTRAC.string()).c_str()); |
290 |
system((strOniSplit + " " + strImportOption + " " + Sounds.string() + " " + VanillaSounds.string()).c_str()); |
291 |
system((strOniSplit + " " + strImportOption + " " + TRAM.string() + " " + VanillaTRAM.string()).c_str()); |
292 |
|
293 |
create_directory("../GameDataFolder/IGMD"); |
294 |
copy((path)"packages/VanillaBSL/IGMD", (path)"../GameDataFolder"); |
295 |
} |
296 |
catch (exception ex) { |
297 |
cout << ex.what(); |
298 |
} |
299 |
return err; |
300 |
} |
301 |
|
302 |
int installPackages(void) |
303 |
{ |
304 |
int err = 0; |
305 |
ModPackage package; |
306 |
vector<string> installed_packages; |
307 |
vector<ModPackage> packages; |
308 |
vector<ModPackage>::iterator iter; |
309 |
vector<string> installString; |
310 |
|
311 |
iter = packages.begin(); |
312 |
packages = getPackages(); |
313 |
vector<string> installedMods = getInstallString(); |
314 |
|
315 |
if (packages.empty()) |
316 |
{ |
317 |
cout << "Error: You have no packages!\n"; |
318 |
return 0; |
319 |
} |
320 |
|
321 |
cout << "Detecting installed packages...\n"; |
322 |
|
323 |
int index = 1; |
324 |
char choice = '0'; |
325 |
|
326 |
for (vector<ModPackage>::iterator package_iter = packages.begin(); package_iter != packages.end(); ++package_iter) |
327 |
{ |
328 |
if (!binary_search(installedMods.begin(), installedMods.end(), package_iter->modStringName)) |
329 |
{ //package_iter->isInstalled :< I forgot about this... |
330 |
//cout << index << " "; |
331 |
system(strClsCmd); |
332 |
cout << (*package_iter).name << "\n"; |
333 |
for (int character = 1; character <= (*package_iter).name.length() - 1; character++) cout << '-'; |
334 |
cout << "\n" |
335 |
<< (*package_iter).readme << "\n\n" |
336 |
<< "Please enter a number choice\n" |
337 |
<< " 1. Install\n" |
338 |
<< " 2. Don't Install\n" |
339 |
<< ""; |
340 |
index++; |
341 |
choice = 0; |
342 |
|
343 |
do |
344 |
{ |
345 |
choice = cin.get(); |
346 |
cin.ignore(1280, '\n'); |
347 |
} while(choice == 0); |
348 |
|
349 |
if (choice == '1') |
350 |
{ |
351 |
cout << "\nInstalling...\n\n"; |
352 |
if (package_iter->hasOnis || (package_iter->hasDeltas /*(*package_iter).isUnpacked */ )) |
353 |
{ |
354 |
installedMods.push_back(package_iter->modStringName); |
355 |
system(strPauseCmd); |
356 |
} |
357 |
} |
358 |
} |
359 |
} |
360 |
if (index == 1) |
361 |
{ |
362 |
cout << "Error: All packages are already installed\n"; |
363 |
return 0; |
364 |
} |
365 |
|
366 |
sort(installedMods.begin(), installedMods.end()); |
367 |
//system(Onisplit.c_str()); |
368 |
recompileAll(installedMods); |
369 |
system(strPauseCmd); |
370 |
|
371 |
return err; |
372 |
} |
373 |
|
374 |
int uninstallPackages(void) |
375 |
{ |
376 |
cout << "\nThis feature not yet implemented.\n\n"; |
377 |
|
378 |
return 0; |
379 |
} |
380 |
|
381 |
int listInstalledPackages(void) |
382 |
{ |
383 |
cout << "\nThis feature not yet implemented.\n\n"; |
384 |
|
385 |
return 0; |
386 |
} |
387 |
|
388 |
int printInstallerInfo(void) |
389 |
{ |
390 |
cout << "\nAE/Mod Installer\n"; |
391 |
cout << "version " << strInstallerVersion << "\n"; |
392 |
cout << "by Gumby & Iritscen\n"; |
393 |
cout << "see http://oni.bungie.org/community/forums for more info\n\n"; |
394 |
|
395 |
return 0; |
396 |
} |
397 |
|
398 |
vector<ModPackage> getPackages(void) |
399 |
{ |
400 |
vector<ModPackage> packages; |
401 |
packages.reserve(65536); // come on, we shouldn't need this much space...right?! |
402 |
fstream file; |
403 |
string filename = "\0"; |
404 |
string MODINFO_CFG = "Mod_Info.cfg"; |
405 |
|
406 |
try |
407 |
{ |
408 |
directory_iterator end_iter; |
409 |
for (directory_iterator dir_itr("./packages"); dir_itr != end_iter; ++dir_itr) |
410 |
{ |
411 |
file.open((dir_itr->path().string() + "/" + MODINFO_CFG).c_str()); |
412 |
//cout << filename << "\n"; |
413 |
|
414 |
if(!file.fail()) |
415 |
{ |
416 |
cout << dir_itr->path().string() + MODINFO_CFG; |
417 |
//would prefer to push a pointer to a package, but this will do for now |
418 |
packages.push_back(fileToModPackage(file)); |
419 |
} |
420 |
file.close(); |
421 |
file.clear(); |
422 |
} |
423 |
} |
424 |
catch (const std::exception & ex) |
425 |
{ |
426 |
cout << "Warning, something odd happened!\n"; |
427 |
} |
428 |
|
429 |
return packages; |
430 |
} |
431 |
|
432 |
ModPackage fileToModPackage(fstream &file) |
433 |
{ |
434 |
/* |
435 |
This converts a file to a ModPackage struct. |
436 |
|
437 |
A few notes... |
438 |
"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. |
439 |
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 |
440 |
slower than reading a variable. |
441 |
*/ |
442 |
ModPackage package; |
443 |
string line; |
444 |
static string NameOfMod = "NameOfMod"; //used for comparing to the current token... |
445 |
//I could have done it in reverse (*iter).compare("ModString") or |
446 |
static string ARROW = "->"; //did something like "ModString".compare(*iter), and it would have been |
447 |
static string ModString = "ModString"; //functionably the same. |
448 |
static string HasOnis = "HasOnis"; |
449 |
static string HasDeltas = "HasDeltas"; |
450 |
static string HasBSL = "HasBSL"; |
451 |
static string HasDats = "HasDats"; |
452 |
static string IsEngine = "IsEngine"; |
453 |
static string Readme = "Readme"; |
454 |
static string GlobalNeeded = "GlobalNeeded"; |
455 |
static string Category = "Category"; |
456 |
static string Creator = "Creator"; |
457 |
while (! file.eof() ) |
458 |
{ |
459 |
getline (file,line); |
460 |
vector<string> tokens; |
461 |
vector<string>::iterator iter; |
462 |
tokenize(line, tokens); //string to vector of "words" |
463 |
if (tokens.capacity() >= 2) { //make sure they are using enough stuff |
464 |
iter = tokens.begin(); //what word we are on, starts at first word |
465 |
/* |
466 |
if (!AEInstallVersion.compare(*iter)) |
467 |
If mod is too old, skip this mod. |
468 |
*/ |
469 |
/*else*/if (!NameOfMod.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) && NameOfMod.compare(*iter)) { //ignores "->" and "NameOfMod" |
472 |
//cout << *iter; |
473 |
//cout << " "; |
474 |
package.name += *iter + " "; |
475 |
} |
476 |
} |
477 |
|
478 |
} |
479 |
else if (!ModString.compare(*iter)) { |
480 |
iter++; iter++; |
481 |
package.modStringName = *iter; |
482 |
iter++; |
483 |
package.modStringVersion = atoi((*iter).c_str()); |
484 |
} |
485 |
else if (!HasOnis.compare(*iter)) { |
486 |
iter++; iter++; |
487 |
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 |
488 |
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, |
489 |
iter++; iter++;} // using "YFR" would probably set it off. :< |
490 |
|
491 |
if (toupper((*iter)[0]) + toupper((*iter)[1]) + toupper((*iter)[2]) == 'Y' + 'E' + 'S') package.hasBSL = 1; |
492 |
} |
493 |
else if (!HasDeltas.compare(*iter)) { |
494 |
iter++; iter++; |
495 |
if (toupper((*iter)[0]) + toupper((*iter)[1]) + toupper((*iter)[2]) == 'Y' + 'E' + 'S') package.hasDeltas = 1; |
496 |
} |
497 |
else if (!HasDats.compare(*iter)) { |
498 |
iter++; iter++; |
499 |
if (toupper((*iter)[0]) + toupper((*iter)[1]) + toupper((*iter)[2]) == 'Y' + 'E' + 'S') package.hasDats = 1; |
500 |
} |
501 |
else if (!IsEngine.compare(*iter)) { |
502 |
iter++; iter++; |
503 |
if (toupper((*iter)[0]) + toupper((*iter)[1]) + toupper((*iter)[2]) == 'Y' + 'E' + 'S') package.isEngine = 1; |
504 |
} |
505 |
else if (!GlobalNeeded.compare(*iter)) { |
506 |
iter++; iter++; |
507 |
if (toupper((*iter)[0]) + toupper((*iter)[1]) + toupper((*iter)[2]) == 'Y' + 'E' + 'S') package.globalNeeded = 1; |
508 |
else if (toupper((*iter)[0]) + toupper((*iter)[1]) == 'N' + 'O') package.globalNeeded = 1; //Really the only place where checking for "No" is important atm. |
509 |
} |
510 |
else if (!Category.compare(*iter)) { |
511 |
for ( ; iter !=tokens.end() && SLASHSLASH.compare(*iter); iter++) { //interates through the words, ends if it reaches the end of the line or a "//" comment |
512 |
if (ARROW.compare(*iter) && Category.compare(*iter)) { //ignores "->" and "Category" |
513 |
//cout << *iter; |
514 |
//cout << " "; |
515 |
package.category += *iter + " "; |
516 |
} |
517 |
} |
518 |
} |
519 |
else if (!Creator.compare(*iter)) { //if it contains the name |
520 |
for ( ; iter !=tokens.end() && SLASHSLASH.compare(*iter); iter++) { //interates through the words, ends if it reaches the end of the line or a "//" comment |
521 |
if (ARROW.compare(*iter) && Creator.compare(*iter)) { //ignores "->" and "Category" |
522 |
//cout << *iter; |
523 |
//cout << " "; |
524 |
package.creator += *iter + " "; |
525 |
} |
526 |
} |
527 |
} |
528 |
else if (!Readme.compare(*iter)) { //if it contains the name |
529 |
for ( ; iter !=tokens.end() && SLASHSLASH.compare(*iter); iter++) { //interates through the words, ends if it reaches the end of the line or a "//" comment |
530 |
if (ARROW.compare(*iter) && Readme.compare(*iter)) { //ignores "->" and "Category" |
531 |
//cout << *iter; |
532 |
//cout << " "; |
533 |
package.readme += *iter + " "; |
534 |
} |
535 |
} |
536 |
} |
537 |
} |
538 |
|
539 |
} |
540 |
package.doOutput(); |
541 |
return package; |
542 |
} |
543 |
|
544 |
void recompileAll(vector<string> installedMods) |
545 |
{ |
546 |
cout << "Recompiling Data...\n"; |
547 |
path vanilla_dir = "./packages/VanillaDats/"; |
548 |
string importCommand = ""; |
549 |
if(splitInstances == SPLIT){ |
550 |
recursive_directory_iterator end_iter; |
551 |
try { |
552 |
for ( recursive_directory_iterator dir_itr( vanilla_dir ); |
553 |
dir_itr != end_iter; |
554 |
++dir_itr ) |
555 |
{ |
556 |
try |
557 |
{ |
558 |
if ( is_directory( dir_itr->status() ) && dir_itr.level() == 1) |
559 |
{ |
560 |
importCommand = strOniSplit + " " + strImportOption + " " + dir_itr->path().parent_path().string() + '/' + dir_itr->path().filename(); |
561 |
for (int i = 0; i < installedMods.size(); ++i) { |
562 |
if (exists("packages/" + installedMods[i] + "/oni/" + dir_itr->path().parent_path().filename() + '/' + dir_itr->path().filename() )) |
563 |
importCommand += " packages/" + installedMods[i] + "/oni/" + dir_itr->path().parent_path().filename() + '/' + dir_itr->path().filename(); |
564 |
|
565 |
//else cout << " packages/VanillaDats/" + installedMods[i] + "/oni/"; |
566 |
} |
567 |
importCommand += " ../GameDataFolder/" + dir_itr->path().filename() + ".dat"; |
568 |
system(importCommand.c_str()); |
569 |
//cout << importCommand << "\n"; |
570 |
} |
571 |
} |
572 |
catch ( const std::exception & ex ) |
573 |
{ |
574 |
cout << "Warning, exception " << ex.what() << "!"; |
575 |
} |
576 |
} |
577 |
} |
578 |
catch( const std::exception & ex ) { |
579 |
cout << "Warning, exception " << ex.what() << "!\n" |
580 |
<< "You probably need to re-globalize."; |
581 |
create_directory( "./packages/VanillaDats" ); |
582 |
} |
583 |
|
584 |
} |
585 |
else if(splitInstances == NOT_SPLIT){ |
586 |
directory_iterator end_iter; |
587 |
for ( directory_iterator dir_itr( vanilla_dir ); |
588 |
dir_itr != end_iter; |
589 |
++dir_itr ) |
590 |
{ |
591 |
try |
592 |
{ |
593 |
if ( is_directory( dir_itr->status() ) ) |
594 |
{ |
595 |
system((strOniSplit + " " + strImportOption + " " + vanilla_dir.string() + dir_itr->path().filename() + " " + "../GameDataFolder/" + dir_itr->path().filename() |
596 |
+ ".dat").c_str()); |
597 |
} |
598 |
} |
599 |
catch ( const std::exception & ex ) |
600 |
{ |
601 |
cout << "Warning, something odd happened!\n"; |
602 |
} |
603 |
} |
604 |
} |
605 |
} |
606 |
|
607 |
vector<string> getInstallString(void) |
608 |
{ |
609 |
system(strPauseCmd); |
610 |
vector<string> returnval; |
611 |
string file_name = "../GameDataFolder/ImportList.cfg"; |
612 |
string line; |
613 |
fstream file; |
614 |
|
615 |
if (exists(file_name)) |
616 |
{ |
617 |
file.open(file_name.c_str()); |
618 |
getline(file, line); |
619 |
tokenize(line, returnval); |
620 |
file.close(); |
621 |
file.clear(); |
622 |
sort(returnval.begin(), returnval.end()); |
623 |
} |
624 |
else cout << "fail"; |
625 |
|
626 |
return returnval; |
627 |
} |
628 |
|
629 |
//stolen token function... |
630 |
void tokenize(const string& str, vector<string>& tokens, const string& delimiters) |
631 |
{ |
632 |
// Skip delimiters at beginning. |
633 |
string::size_type lastPos = str.find_first_not_of(delimiters, 0); |
634 |
// Find first "non-delimiter". |
635 |
string::size_type pos = str.find_first_of(delimiters, lastPos); |
636 |
|
637 |
while (string::npos != pos || string::npos != lastPos) |
638 |
{ |
639 |
// Found a token, add it to the vector. |
640 |
tokens.push_back(str.substr(lastPos, pos - lastPos)); |
641 |
// Skip delimiters. Note the "not_of" |
642 |
lastPos = str.find_first_not_of(delimiters, pos); |
643 |
// Find next "non-delimiter" |
644 |
pos = str.find_first_of(delimiters, lastPos); |
645 |
} |
646 |
} |