ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/AE/Installer/trunk/source/subs.cpp
(Generate patch)

Comparing AE/Installer/trunk/source/subs.cpp (file contents):
Revision 307 by gumby, Sat May 2 16:55:16 2009 UTC vs.
Revision 308 by iritscen, Sat May 2 22:24:03 2009 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)