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