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