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