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

Comparing AE/Installer/trunk/source/installer.cpp (file contents):
Revision 379 by iritscen, Mon Jun 29 19:23:42 2009 UTC vs.
Revision 502 by iritscen, Mon Mar 22 16:51:50 2010 UTC

# Line 1 | Line 1
1 < /*
2 < AE/Mod Installer
3 < by Gumby and Iritscen
4 < */
5 <
6 < #define DEBUG
7 < #include <stdio.h>
8 < //#include <conio.h>
9 < //#include <process.h>
10 < #include <string>
11 < #include <iostream>
12 < #include <cctype>
13 < #include <vector>
14 < #include <fstream>
15 < #include <errno.h>
16 < #include <sstream>
1 > /***************************************************************************\
2 > | Project: AE Installer                                                                                                         |
3 > | By: Gumby & Iritscen                                                                                                          |
4 > | File: Installer.cpp                                                                                                           |
5 > | Function: Contains the real meat of the installation process. Mm, beefy.      |
6 > | Created: 24/05/2009 19:39:00                                                                                          |
7 > \***************************************************************************/
8  
9 < #include "boost/filesystem.hpp" // includes all needed Boost.Filesystem declarations
10 <
20 < #include "installer.h"
9 > // TODO: Load credits from text resource file
10 > // TODO: Clear mod info fields when mod is de-selected
11  
12 + //#define DEBUG
13   #ifdef WIN32
14 < #include <windows.h>
15 < #else // assume we're on Mac
25 < #include <stdlib.h>
26 < #include <dirent.h>
14 > //#include <windows.h>
15 > #define popen _popen
16   #endif
17 + #include "boost/date_time/gregorian/gregorian.hpp"
18 + #include "boost/date_time/date_parsing.hpp"
19 + #include "boost/date_time/posix_time/posix_time.hpp"
20 + #include "installer.h"
21 + #include "aeinstallerapp.h"
22  
23 < //const string strInstallerVersion = "1.0";
24 < const bool SPLIT = 1;
31 < const bool NOT_SPLIT = 0;
32 < bool splitInstances = SPLIT;
33 <
34 < #ifdef WIN32
35 < const string strOniSplit = "Onisplit.exe";
36 < string strImportOption = "-import:nosep";
37 < const char* strClsCmd = "cls";
38 < const char* strPauseCmd = "PAUSE";
39 < #else // set up Mac equivalents since we're in Mac OS
40 < const string strOniSplit = "mono Onisplit.exe";
41 < string strImportOption = "-import:sep";
42 < const char* strClsCmd = "clear";
43 < const char* strPauseCmd = "read -n 1 -p \"Press any key to continue\"";
44 < #endif
45 <
46 < using namespace boost::filesystem;
47 < using namespace std;
48 <
49 <
50 < /*
51 < int main(void)
52 < {
53 < if ( exists( "../../GameDataFolder/level0_Final.sep" ) ) splitInstances = NOT_SPLIT;
54 < else splitInstances = NOT_SPLIT;
55 < //     SetConsoleTitle("AE Installer"); windows junk, convert to SDL
56 < #ifdef WIN32  
57 < system("color 0A");
58 < #endif
59 < cout << "\nWelcome to the AE installer!\n";
60 < cout << "\nWhat would you like to do?\n";
61 <
62 < return mainMenu();
63 < }
64 < */
65 <
23 > using namespace boost::gregorian;
24 > using namespace boost::posix_time;
25  
26 + // externs declared in installer.h
27 + string strInstallCfg = "../GameDataFolder/Add.cfg";
28 + string strEUFN = "Edition"; // GetUpdateStatus() may set this to "Edition-patch" later, but this is the assumed name of the new Edition folder in Updates/
29  
30 < int mainMenu(void)
30 > int globalizeData(void)
31   {
32 <        char choice = '0';
33 <        bool exit = false;
32 >        busy = 1;
33 >        using boost::lexical_cast;
34 >        using boost::bad_lexical_cast;
35 >        using namespace boost::gregorian;
36 >        using namespace boost::posix_time;
37 >        ptime start_time(second_clock::local_time());
38 >        
39 >        setStatusArea("Globalizing!");
40          int err = 0;
41 <        do
42 <        {
43 <                if( exists( "../GameDataFolder" ) ) {
44 <                        cout << "\n1. Add new packages\n";
45 <                        cout << "2. Remove packages\n";
46 <                        cout << "3. See what is installed\n";
47 <                        cout << "4. Globalize data\n";
48 <                        cout << "5. About AE\n";
49 <                        cout << "6. Quit\n\n";
50 <                        
83 <                        choice = cin.get();
84 <                        cin.ignore(128, '\n');
85 <                        switch(choice)
86 <                        {
87 <                                case '1':
88 <                                        err = installPackages();
89 <                                        break;
90 <                                case '2':
91 <                                        err = uninstallPackages();
92 <                                        break;
93 <                                case '3':
94 <                                        err = listInstalledPackages();
95 <                                        break;
96 <                                case '4':
97 <                                        err = globalizeData();
98 <                                        break;
99 <                                case '5':
100 <                                        err = printInstallerInfo();
101 <                                        break;
102 <                                case '6':
103 <                                        exit = true;
104 <                                        break;
105 <                                default:
106 <                                        cout << "Please choose one of the above numbers, and press Enter.\n\n";
107 <                        }
108 <                        if (err) // if something fatal happened
109 <                                exit = true;
110 <                }
111 <                else {
112 <                        cout << "\n1. Globalize data\n";
113 <                        cout << "2. About AE\n";
114 <                        cout << "3. Quit\n\n";
115 <                        
116 <                        choice = cin.get();
117 <                        cin.ignore(128, '\n');
118 <                        switch(choice)
119 <                        {
120 <                                case '1':
121 <                                        err = globalizeData();
122 <                                        break;
123 <                                case '2':
124 <                                        err = printInstallerInfo();
125 <                                        break;
126 <                                case '3':
127 <                                        exit = true;
128 <                                        break;
129 <                                default:
130 <                                        cout << "Please choose one of the above numbers, and press Enter.\n\n";
131 <                        }
132 <                        if (err) // if something fatal happened
133 <                                exit = true;
41 >        int parts_done = 0;
42 >        remove("Globalize.log");
43 >        ofstream logfile("Globalize.log");
44 >        logfile << "Globalization started " << to_simple_string(start_time) << endl;
45 >        
46 >        try {  // the levels Oni has...probably should have made a string array. Oops.
47 >                char levels_cstr[15][3] = {"0", "1", "2", "3", "4", "6", "8", "9", "10", "11", "12", "13", "14", "18", "19"};
48 >                vector<string> levels;
49 >                for (int f = 0; f < 15; f++) {
50 >                        levels.push_back(levels_cstr[f]);
51                  }
135        } while(!exit);
136        
137        return err;
138 }
52  
140 int globalizeData(void)
141 {
142        int err = 0;
143        
144        try {
145                int levels[15] = {0, 1, 2, 3, 4, 6, 8, 9, 10, 11, 12, 13, 14, 18, 19}; // the levels Oni has
146                char choice = 0;
147                
148                //SetCurrentDirectory("C:/Program Files/Oni/edition/install");
149                char levelnum[3];
53                  path Characters = "../GameDataFolder/level0_Characters";
54                  path Particles = "../GameDataFolder/level0_Particles";
55                  path Archive = "../GameDataFolder/Archive";
# Line 155 | Line 58 | int globalizeData(void)
58                  path Animations = "../GameDataFolder/level0_Animations";
59                  path TRAC = Animations / "level0_TRAC";
60                  path TRAM = Animations / "level0_TRAM";
61 <                /*
62 <                 if (exists("../GameDataFolder/"))
63 <                 {
64 <                 //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.)"
65 <                 //      << "\n1. Re-globalize"
66 <                 //      << "\n2. Return to main menu\n";
67 <                 //choice = cin.get();
68 <                 cin.ignore(128, '\n');
69 <                 if (choice == '1')
70 <                 remove_all("../GameDataFolder"); // remove AE GDF
71 <                 if (choice == '2')
72 <                 return 0;
73 <                 }
74 <                 */
61 >                
62 >                vector<path> GDFPaths;
63 >                GDFPaths.push_back(Particles);
64 >                GDFPaths.push_back(Textures);
65 >                GDFPaths.push_back(Sounds);
66 >                GDFPaths.push_back(TRAC);
67 >                GDFPaths.push_back(TRAM);
68 >                
69 >                path VanillaCharacters = "VanillaDats/level0_Final/level0_Characters/level0_Characters.oni";
70 >                path VanillaParticles = "VanillaDats/level0_Final/level0_Particles/level0_Particles.oni";
71 >                path VanillaTextures  = "VanillaDats/level0_Final/level0_Textures/level0_Textures.oni";
72 >                path VanillaSounds = "VanillaDats/level0_Final/level0_Sounds/level0_Sounds.oni";
73 >                path VanillaAnimations = "VanillaDats/level0_Final/level0_Animations/level0_Animations.oni";
74 >                path VanillaTRAC = "VanillaDats/level0_Final/level0_Animations/level0_TRAC.oni";
75 >                path VanillaTRAM = "VanillaDats/level0_Final/level0_Animations/level0_TRAM.oni";
76 >                
77 >                vector<path> VanillaPaths;
78 >                
79 >                VanillaPaths.push_back(VanillaParticles);
80 >                VanillaPaths.push_back(VanillaTextures);
81 >                VanillaPaths.push_back(VanillaSounds);
82 >                VanillaPaths.push_back(VanillaTRAC);
83 >                VanillaPaths.push_back(VanillaTRAM);
84 >                
85 >                setStatusArea("Removing old GameDataFolder...\n");
86 >                logfile <<  "Removing old GameDataFolder...\n";
87 >                remove_all( "../GameDataFolder/" );
88 >                setStatusArea("Creating needed directories...");
89 >                logfile <<  "Creating needed directories...\n";
90                  create_directory( "../GameDataFolder/" );
91 +                
92                  create_directory( "packages" );
174                if (exists("packages/VanillaDats")) remove_all("packages/VanillaDats");
175                create_directory( "packages/VanillaDats" );
93                  
94 <                create_directory( "packages/VanillaDats/level0_Final/" );
94 >                if (exists("VanillaDats")) remove_all("VanillaDats");
95 >                create_directory( "VanillaDats" );
96 >                create_directory( "VanillaDats/level0_Final/" );
97                  create_directory( Characters );
98                  create_directory( Particles );
99                  create_directory( Archive );
# Line 183 | Line 102 | int globalizeData(void)
102                  create_directory( Animations );
103                  create_directory( TRAC );
104                  create_directory( TRAM );
105 +                int num_levels = 0;
106 +                for(int i = 1; i < 15; i++)
107 +                {
108 +                        if (exists("../../GameDataFolder/level" + levels[i] + "_Final.dat")) {
109 +                                num_levels++;
110 +                                
111 +                        }
112 +                }
113 +                logfile << "Exporting and moving...\n\n";
114 +                int total_steps =  8 + 2 * num_levels;
115                  
116                  for(int i = 0; i < 15; i++)
117 <                {
118 <                        sprintf(levelnum,"%d",levels[i]); // int to char array
119 <                        exists("../../GameDataFolder/level" + (string)levelnum + "_Final");
120 <                        system((strOniSplit + " -export ../GameDataFolder/level" + (string)levelnum + "_Final ../../GameDataFolder/level" + (string)levelnum + "_Final.dat").c_str());
121 <                        
122 <                        create_directory( "packages/VanillaDats/level" + (string)levelnum + "_Final" ); //remember to cast your arrays as strings :)
123 <                        create_directory( "packages/VanillaDats/level" + (string)levelnum + "_Final/level" + (string)levelnum + "_Final" );
124 <                        
125 <                        directory_iterator end_iter;
126 <                        for ( directory_iterator dir_itr( "../GameDataFolder/level" + (string)levelnum + "_Final" ); dir_itr != end_iter; ++dir_itr )
127 <                        {
128 <                                //cout << dir_itr->path().filename();
129 <                                if ( is_regular_file( dir_itr->status() ) )
130 <                                {
117 >                {                      
118 >                        if (exists("../../GameDataFolder/level" + levels[i] + "_Final.dat")) {
119 >                                logfile << "level" << levels[i] << "_Final\n";
120 >                                logfile << "\tExporting level" << levels[i] << "_Final.dat\n";
121 >                                setStatusArea("Step " + lexical_cast<std::string>(parts_done + 1) + "/" + lexical_cast<std::string>(total_steps) + " exporting level" + levels[i]+"_Final.dat");
122 >                                create_directory( "../GameDataFolder/level" + levels[i] + "_Final" );
123 >                                system((strOniSplit + " -export ../GameDataFolder/level" + levels[i] + "_Final ../../GameDataFolder/level" + levels[i] + "_Final.dat").c_str());
124 >                                create_directory( "VanillaDats/level" + levels[i] + "_Final" );
125 >                                create_directory( "VanillaDats/level" + levels[i] + "_Final/level" + levels[i] + "_Final" );
126 >                                
127 >                                //Moves the AKEV and other files into a safe directory so that level specific textures are not globalized...
128 >                                if ( strcmp(levels[i].c_str(), "0") ){
129 >                                        create_directory( "../GameDataFolder/level" + levels[i] + "_Final/AKEV" );
130 >                                        system((strOniSplit + " -move:overwrite ../GameDataFolder/level" + levels[i] + "_Final/AKEV ../GameDataFolder/level" + levels[i] + "_Final/AKEV*.oni").c_str());
131                                          
132 <                                        if ( dir_itr->path().filename().substr(0,8) == "TXMPfail" ||
133 <                                                dir_itr->path().filename().substr(0,9) == "TXMPlevel" ||
134 <                                                ( dir_itr->path().filename().substr(0,4) == "TXMP" && dir_itr->path().filename().find("intro")!=string::npos) ||
135 <                                                dir_itr->path().filename().substr(0,4) == "TXMB" ||
136 <                                                dir_itr->path().filename() == "M3GMpowerup_lsi.oni" ||
137 <                                                dir_itr->path().filename() == "TXMPlsi_icon.oni" ||
209 <                                                ( dir_itr->path().filename().substr(0,4) == "TXMB" && dir_itr->path().filename().find("splash_screen.oni")!=string::npos)       )
132 >                                }
133 >                                
134 >                                directory_iterator end_iter;
135 >                                for ( directory_iterator dir_itr( "../GameDataFolder/level" + levels[i] + "_Final" ); dir_itr != end_iter; ++dir_itr )
136 >                                {
137 >                                        if ( is_regular_file( dir_itr->status() ) )
138                                          {
139 <                                                cout <<dir_itr->path().filename() << "\n";
140 <                                                create_directory( dir_itr->path().parent_path() / "NoGlobal");  
141 <                                                if(!exists( dir_itr->path().parent_path() / "NoGlobal" / dir_itr->filename())) rename(dir_itr->path(), dir_itr->path().parent_path() / "NoGlobal" /
142 <                                                                                                                                                                                                                          dir_itr->filename());
143 <                                                else remove(dir_itr->path());
144 <                                        }
145 <                                        else if (dir_itr->path().filename().substr(0,4) == "TRAC") {
146 <                                                cout <<dir_itr->path().filename() << "\n";
147 <                                                if(!exists( TRAC / dir_itr->filename())) rename(dir_itr->path(), TRAC / dir_itr->filename());
148 <                                                else remove(dir_itr->path());
149 <                                        }
150 <                                        else if (dir_itr->path().filename().substr(0,4) == "TRAM") {
151 <                                                cout <<dir_itr->path().filename() << "\n";
152 <                                                if(!exists( TRAM / dir_itr->filename())) rename(dir_itr->path(), TRAM / dir_itr->filename());
153 <                                                else remove(dir_itr->path());
154 <                                        }
155 <                                        else if (dir_itr->path().filename().substr(0,4) == "ONSK" ||
156 <                                                         dir_itr->path().filename().substr(0,4) == "TXMP") {
157 <                                                cout <<dir_itr->path().filename() << "\n";\
158 <                                                create_directory( dir_itr->path().parent_path() / "TexFix");    
159 <                                                if(!exists( Textures / dir_itr->filename())) rename(dir_itr->path(), Textures / dir_itr->filename());
160 <                                                //rename(dir_itr->path(), dir_itr->path().parent_path() / "TexFix" / dir_itr->filename());
161 <                                        }
162 <                                        else if (dir_itr->path().filename().substr(0,4) == "ONCC"
163 <                                                         || dir_itr->path().filename().substr(0,4) == "TRBS"
164 <                                                         || dir_itr->path().filename().substr(0,4) == "TRMA"
165 <                                                         || dir_itr->path().filename().substr(0,4) == "TRSC"
166 <                                                         || dir_itr->path().filename().substr(0,4) == "TRAS") {
167 <                                                cout <<dir_itr->path().filename() << "\n";
168 <                                                if(!exists( Characters / dir_itr->filename())) rename(dir_itr->path(), Characters / dir_itr->filename());
169 <                                                else remove(dir_itr->path());
170 <                                        }
171 <                                        else if (dir_itr->path().filename().substr(0,4) == "OSBD"
172 <                                                         || dir_itr->path().filename().substr(0,4) == "SNDD") {
173 <                                                cout << dir_itr->path().filename() << "\n";
174 <                                                if(!exists( Sounds / dir_itr->filename())) rename(dir_itr->path(), Sounds / dir_itr->filename());
175 <                                                else remove(dir_itr->path());
176 <                                        }
177 <                                        else if (dir_itr->path().filename().substr(0,5) == "BINA3"
178 <                                                         || dir_itr->path().filename().substr(0,10) == "M3GMdebris"
179 <                                                         || dir_itr->path().filename() == "M3GMtoxic_bubble.oni"
180 <                                                         || dir_itr->path().filename().substr(0,8) == "M3GMelec"
181 <                                                         || dir_itr->path().filename().substr(0,7) == "M3GMrat"
182 <                                                         || dir_itr->path().filename().substr(0,7) == "M3GMjet"
183 <                                                         || dir_itr->path().filename().substr(0,9) == "M3GMbomb_"
184 <                                                         || dir_itr->path().filename() == "M3GMbarab_swave.oni"
185 <                                                         || dir_itr->path().filename() == "M3GMbloodyfoot.oni"
186 <                                                         ){
187 <                                                cout <<dir_itr->path().filename() << "\n";
188 <                                                if(!exists( Particles / dir_itr->filename())) rename(dir_itr->path(), Particles / dir_itr->filename());
189 <                                                else remove(dir_itr->path());
190 <                                        }
191 <                                        else if (dir_itr->path().filename().substr(0,4) == "AGDB"
192 <                                                         || dir_itr->path().filename().substr(0,4) == "TRCM") {
193 <                                                cout <<dir_itr->path().filename() << "\n";
139 >                                                if ( dir_itr->path().filename().substr(0,8) == "TXMPfail" ||
140 >                                                        dir_itr->path().filename().substr(0,9) == "TXMPlevel" ||
141 >                                                        ( dir_itr->path().filename().substr(0,4) == "TXMP" && dir_itr->path().filename().find("intro")!=string::npos) ||
142 >                                                        dir_itr->path().filename().substr(0,4) == "TXMB" ||
143 >                                                        dir_itr->path().filename() == "M3GMpowerup_lsi.oni" ||
144 >                                                        dir_itr->path().filename() == "TXMPlsi_icon.oni" ||
145 >                                                        ( dir_itr->path().filename().substr(0,4) == "TXMB" && dir_itr->path().filename().find("splash_screen.oni")!=string::npos)       )
146 >                                                {
147 >                                                        cout <<dir_itr->path().filename() << "\n";
148 >                                                        create_directory( dir_itr->path().parent_path() / "NoGlobal");  
149 >                                                        if(!exists( dir_itr->path().parent_path() / "NoGlobal" / dir_itr->filename())) rename(dir_itr->path(), dir_itr->path().parent_path() / "NoGlobal" /
150 >                                                                                                                                                                                                                                  dir_itr->filename());
151 >                                                        else remove(dir_itr->path());
152 >                                                }
153 >                                                else if (dir_itr->path().filename().substr(0,4) == "TRAC"
154 >                                                                 ) {
155 >                                                        cout <<dir_itr->path().filename() << "\n";
156 >                                                        if(!exists( TRAC / dir_itr->filename())) rename(dir_itr->path(), TRAC / dir_itr->filename());
157 >                                                        else remove(dir_itr->path());
158 >                                                }
159 >                                                else if (dir_itr->path().filename().substr(0,4) == "TRAM") {
160 >                                                        cout <<dir_itr->path().filename() << "\n";
161 >                                                        if(!exists( TRAM / dir_itr->filename())) rename(dir_itr->path(), TRAM / dir_itr->filename());
162 >                                                        else remove(dir_itr->path());
163 >                                                }
164 >                                                else if (dir_itr->path().filename().substr(0,4) == "ONSK" ||
165 >                                                                 dir_itr->path().filename().substr(0,4) == "TXMP") {
166 >                                                        cout <<dir_itr->path().filename() << "\n";\
167 >                                                        create_directory( dir_itr->path().parent_path() / "TexFix");    
168 >                                                        if(!exists( Textures / dir_itr->filename())) rename(dir_itr->path(), Textures / dir_itr->filename());
169 >                                                }
170 >                                                else if (dir_itr->path().filename().substr(0,4) == "ONCC"
171 >                                                                 || dir_itr->path().filename().substr(0,4) == "TRBS"
172 >                                                                 || dir_itr->path().filename().substr(0,4) == "ONCV"
173 >                                                                 || dir_itr->path().filename().substr(0,4) == "ONVL"
174 >                                                                 || dir_itr->path().filename().substr(0,4) == "TRMA"
175 >                                                                 || dir_itr->path().filename().substr(0,4) == "TRSC"
176 >                                                                 || dir_itr->path().filename().substr(0,4) == "TRAS") {
177 >                                                        cout <<dir_itr->path().filename() << "\n";
178 >                                                        if(!exists( Characters / dir_itr->filename())) rename(dir_itr->path(), Characters / dir_itr->filename());
179 >                                                        else remove(dir_itr->path());
180 >                                                }
181 >                                                else if (dir_itr->path().filename().substr(0,4) == "OSBD"
182 >                                                                 || dir_itr->path().filename().substr(0,4) == "SNDD") {
183 >                                                        cout << dir_itr->path().filename() << "\n";
184 >                                                        if(!exists( Sounds / dir_itr->filename())) rename(dir_itr->path(), Sounds / dir_itr->filename());
185 >                                                        else remove(dir_itr->path());
186 >                                                }
187 >                                                else if (dir_itr->path().filename().substr(0,5) == "BINA3"
188 >                                                                 || dir_itr->path().filename().substr(0,10) == "M3GMdebris"
189 >                                                                 || dir_itr->path().filename() == "M3GMtoxic_bubble.oni"
190 >                                                                 || dir_itr->path().filename().substr(0,8) == "M3GMelec"
191 >                                                                 || dir_itr->path().filename().substr(0,7) == "M3GMrat"
192 >                                                                 || dir_itr->path().filename().substr(0,7) == "M3GMjet"
193 >                                                                 || dir_itr->path().filename().substr(0,9) == "M3GMbomb_"
194 >                                                                 || dir_itr->path().filename() == "M3GMbarab_swave.oni"
195 >                                                                 || dir_itr->path().filename() == "M3GMbloodyfoot.oni"
196 >                                                                 ){
197 >                                                        cout <<dir_itr->path().filename() << "\n";
198 >                                                        if(!exists( Particles / dir_itr->filename())) rename(dir_itr->path(), Particles / dir_itr->filename());
199 >                                                        else remove(dir_itr->path());
200 >                                                }
201 >                                                else if (dir_itr->path().filename().substr(0,4) == "AGDB"
202 >                                                                 || dir_itr->path().filename().substr(0,4) == "TRCM") {
203 >                                                        cout <<dir_itr->path().filename() << "\n";
204 >                                                        
205 >                                                        if(!exists( Archive / dir_itr->filename())) rename(dir_itr->path(), Archive / dir_itr->filename());
206 >                                                        else remove(dir_itr->path());
207 >                                                }
208 >                                                else if (dir_itr->path().filename().substr(0,4) == "ONWC") { //fix for buggy ONWC overriding
209 >                                                        cout <<dir_itr->path().filename() << "\n";
210 >                                                        
211 >                                                        if(!exists( "VanillaDats/level0_Final/level0_Final/" +  dir_itr->filename()))
212 >                                                                rename(dir_itr->path(), "VanillaDats/level0_Final/level0_Final/" +  dir_itr->filename());
213 >                                                        else remove(dir_itr->path());
214 >                                                }
215                                                  
216 <                                                if(!exists( Archive / dir_itr->filename())) rename(dir_itr->path(), Archive / dir_itr->filename());
217 <                                                else remove(dir_itr->path());
216 >                                                if (exists(dir_itr->path())) {
217 >                                                        
218 >                                                }
219 >                                                else {
220 >                                                        //logfile << "\tMoved file: " << dir_itr->path().filename() << "\n";
221 >                                                }
222                                          }
223 +                                        
224 +                                        
225 +                                        
226                                  }
227                                  
228 +                                logfile << "\tCleaning up TXMPs...\n";
229 +                                system( (strOniSplit + " -move:delete " + Textures.string() + " ../GameDataFolder/level" + levels[i] + "_Final/TXMP*.oni").c_str());
230 +                                
231 +                                
232 +                                if ( strcmp(levels[i].c_str(), "0") ){
233 +                                        system((strOniSplit + " -move:overwrite ../GameDataFolder/level" + levels[i] + "_Final ../GameDataFolder/level" + levels[i] + "_Final/AKEV/AKEV*.oni").c_str());
234 +                                        remove(  "../GameDataFolder/level" + levels[i] + "_Final/AKEV" );
235 +                                }
236 +                                
237 +                                parts_done++;
238 +                                
239 +                                setProgressBar( (int)(1000 * (float)(parts_done) / (float)(total_steps) ));
240                                  
241                          }
274                        system( (strOniSplit + " -move:delete " + Textures.string() + " ../GameDataFolder/level" + (string)levelnum + "_Final/TXMP*.oni").c_str());
275                        
242                  }
243 <                
243 >                logfile << "Reimporting levels\n";
244                  for (int i = 0; i < 15; i++)
245                  {
246 <                        sprintf(levelnum,"%d",levels[i]);
247 <                        system( (strOniSplit + " " + strImportOption + " ../GameDataFolder/level" + levelnum + "_Final packages/VanillaDats/level" + levelnum + "_Final/level"
248 <                                         + levelnum + "_Final/level" + levelnum + "_Final.oni").c_str());
249 <                }
250 <                path VanillaCharacters = "packages/VanillaDats/level0_Final/level0_Characters/level0_Characters.oni";
251 <                path VanillaParticles = "packages/VanillaDats/level0_Final/level0_Particles/level0_Particles.oni";
252 <                path VanillaTextures  = "packages/VanillaDats/level0_Final/level0_Textures/level0_Textures.oni";
253 <                path VanillaSounds = "packages/VanillaDats/level0_Final/level0_Sounds/level0_Sounds.oni";
254 <                path VanillaAnimations = "packages/VanillaDats/level0_Final/level0_Animations/level0_Animations.oni";
255 <                path VanillaTRAC = "packages/VanillaDats/level0_Final/level0_Animations/level0_TRAC.oni";
290 <                path VanillaTRAM = "packages/VanillaDats/level0_Final/level0_Animations/level0_TRAM.oni";
291 <                create_directory( VanillaCharacters.parent_path() );
246 >                        logfile << "\tReimporting level" << levels[i] << "_Final.oni\n";
247 >                        setStatusArea("Step " + lexical_cast<std::string>(parts_done + 1) + "/" + lexical_cast<std::string>(total_steps) + " reimporting level" + levels[i]+"_Final.oni");
248 >                        logfile << (strOniSplit + " " + strImportOption + " ../GameDataFolder/level" + levels[i] + "_Final VanillaDats/level" + levels[i] + "_Final/level"
249 >                                                + levels[i] + "_Final/level" + levels[i] + "_Final.oni >> Globalize.log").c_str() << '\n';
250 >                        string sys_str = (strOniSplit + " " + strImportOption + " ../GameDataFolder/level" + levels[i] + "_Final VanillaDats/level" + levels[i] + "_Final/level"
251 >                                                          + levels[i] + "_Final/level" + levels[i] + "_Final.oni");
252 >                        system(sys_str.c_str() );
253 >                        setProgressBar( (int)(1000 * (float)(parts_done) / (float)(total_steps) ));
254 >                        parts_done++;
255 >                }
256                  create_directory( VanillaParticles.parent_path() );
257                  create_directory( VanillaTextures.parent_path() );
258                  create_directory( VanillaSounds.parent_path() );
259                  create_directory( VanillaAnimations.remove_filename() );
296                system((strOniSplit + " " + strImportOption + " " + Characters.string() + " " + VanillaCharacters.string()).c_str());
297                system((strOniSplit + " " + strImportOption + " " + Particles.string() + " " + VanillaParticles.string()).c_str());
298                system((strOniSplit + " " + strImportOption + " " + Textures.string() + " " + VanillaTextures.string()).c_str());
299                //system((strOniSplit   + " " + strImportOption + (string)" " + Animations.string() + (string)" " + VanillaAnimations.string()).c_str());
300                system((strOniSplit + " " + strImportOption + " " + TRAC.string() + " " + VanillaTRAC.string()).c_str());
301                system((strOniSplit + " " + strImportOption + " " + Sounds.string() + " " + VanillaSounds.string()).c_str());
302                system((strOniSplit + " " + strImportOption + " " + TRAM.string() + " " + VanillaTRAM.string()).c_str());
260                  
261 <                create_directory("../GameDataFolder/IGMD");
262 <                copy((path)"packages/VanillaBSL/IGMD", (path)"../GameDataFolder");
263 <        }
264 <        catch (exception ex) {
265 <                cout << ex.what();
266 <        }
267 <        return err;
268 < }
269 <
270 < int installPackages(void)
271 < {
272 <        bool installed_something = 0;
273 <        int err = 0;
274 <        ModPackage package;
275 <        vector<string> installed_packages;
319 <        vector<ModPackage> packages;
320 <        vector<ModPackage>::iterator iter;
321 <        vector<string> installString;
322 <        
323 <        iter = packages.begin();
324 <        packages = getPackages();
325 <        vector<string> installedMods = getInstallString();
326 <        
327 <        if (packages.empty())
328 <        {
329 <                cout << "Error: You have no packages!\n";
330 <                return 0;
331 <        }
332 <        
333 <        cout << "Detecting installed packages...\n";
334 <        
335 <        int index = 1;
336 <        char choice = '0';
337 <        
338 <        for (vector<ModPackage>::iterator package_iter = packages.begin(); package_iter != packages.end(); ++package_iter)
339 <        {
340 <                if (!binary_search(installedMods.begin(), installedMods.end(), package_iter->modStringName))
341 <                { //package_iter->isInstalled :< I forgot about this...
342 <                        //cout << index << " ";
343 <                        system(strClsCmd);
344 <                        cout << (*package_iter).name << "\n";
345 <                        for (int character = 1; character <= (*package_iter).name.length() - 1; character++) cout << '-';
346 <                        cout << "\n"
347 <                        << (*package_iter).readme << "\n\n"
348 <                        << "Please enter a number choice\n"
349 <                        << " 1. Add\n"
350 <                        << " 2. Don't Add\n"
351 <                        << "";
352 <                        index++;
353 <                        choice = 0;
354 <                        
355 <                        do
356 <                        {
357 <                                choice = cin.get();
358 <                                cin.ignore(1280, '\n');
359 <                        } while(choice == 0);
360 <                        
361 <                        if (choice == '1')
261 >                for(unsigned int j = 0; j < GDFPaths.size(); j++) {
262 >                        logfile << "\tReimporting " << GDFPaths[j].filename() << ".oni\n";
263 >                        setStatusArea("Step " + lexical_cast<std::string>(parts_done + 1) + "/" + lexical_cast<std::string>(total_steps) + ": reimporting " + GDFPaths[j].filename() );
264 >                        system((strOniSplit + " " + strImportOption + " " + GDFPaths[j].string() + " " + VanillaPaths[j].string()).c_str());
265 >                        parts_done++;
266 >                        setProgressBar( (int)(1000 * (float)(parts_done) / (float)(total_steps) ));
267 >                }
268 >                logfile << "\nMoving level0_Characters\n";
269 >                setStatusArea("Step " + lexical_cast<std::string>(parts_done + 1) + "/" + lexical_cast<std::string>(total_steps) + ": moving level0_Characters" );      
270 >                copy((path)"../GameDataFolder/level0_Characters", (path)("VanillaDats/level0_Final"));
271 >                GDFPaths.push_back( Characters );
272 >                for(int i = 0; i < GDFPaths.size(); i++)
273 >                {
274 >                        directory_iterator end_iter;
275 >                        for ( directory_iterator dir_itr( GDFPaths[i] ); dir_itr != end_iter; ++dir_itr )
276                          {
277 <                                cout << "\nInstalling...\n\n";
364 <                                if (package_iter->hasOnis || (package_iter->hasDeltas /*(*package_iter).isUnpacked */ ))
277 >                                try
278                                  {
279 <                                        installed_something = 1;
280 <                                        installedMods.push_back(package_iter->modStringName);
281 <                                        system(strPauseCmd);
279 >                                        rename(dir_itr->path(), "../GameDataFolder/level0_Final/" + dir_itr->path().filename() );
280 >                                }
281 >                                catch(exception &ex) {
282 >                                        
283                                  }
284                          }
285                  }
372        }
373        if (index == 1)
374        {
375                cout << "Warning: All packages are already installed\n";
376                //would you like to recombine your data?
377                return 0;
378        }
379        if (installed_something == 0)
380        {
381                cout << "Warning: You didn't add anything!\n";
382                //would you like to recombine your data?
383                return 0;
384        }
385        
386        sort(installedMods.begin(), installedMods.end());
387        //system(Onisplit.c_str());
388        recompileAll(installedMods);
389        system(strPauseCmd);
390        
391        return err;
392 }
286  
287 < int uninstallPackages(void)
288 < {
289 <        int err = 0;
290 <        ModPackage package;
291 <        vector<string> installed_packages;
292 <        vector<ModPackage> packages;
400 <        vector<ModPackage>::iterator iter;
401 <        vector<string> installString;
402 <        
403 <        iter = packages.begin();
404 <        packages = getPackages();
405 <        
406 <        
407 <        cout << "Detecting installed packages...\n";
408 <        
409 <        vector<string> installedMods = getInstallString();
410 <        
411 <        if (packages.empty())
412 <        {
413 <                cout << "Error: You have no packages!\n";
414 <                return 0;
415 <        }
416 <        
417 <        int index = 0;
418 <        int uninstalled_something = 0;
419 <        char choice = '0';
420 <        
421 <        for (vector<ModPackage>::iterator package_iter = packages.begin(); package_iter != packages.end(); ++package_iter)
422 <        {
423 <                if (binary_search(installedMods.begin(), installedMods.end(), package_iter->modStringName))
424 <                { //package_iter->isInstalled :< I forgot about this...
425 <                        //cout << index << " ";
426 <                        system(strClsCmd);
427 <                        cout << (*package_iter).name << "\n";
428 <                        for (int character = 1; character <= (*package_iter).name.length() - 1; character++) cout << '-';
429 <                        cout << "\n"
430 <                        << (*package_iter).readme << "\n\n"
431 <                        << "Please enter a number choice\n"
432 <                        << " 1. Remove\n"
433 <                        << " 2. Don't Remove\n"
434 <                        << "";
435 <                        
436 <                        choice = 0;
287 >                create_directory((path)"../GameDataFolder/IGMD");
288 >                copy((path)"packages/VanillaBSL/IGMD", (path)"../GameDataFolder");
289 >                setProgressBar( 1000 );
290 >                
291 >                if(exists("../../persist.dat"))
292 >                        if(!exists("../persist.dat"))
293                          
294 <                        do
439 <                        {
440 <                                choice = cin.get();
441 <                                cin.ignore(1280, '\n');
442 <                        } while(choice == 0);
294 >                        //TODO: Concatenate level0 Dirs.
295                          
296 <                        if (choice == '1')
297 <                        {
298 <                                cout << "\nUninstalling...\n\n";
299 <                                installedMods.erase( installedMods.begin() + (index) );
300 <                                system(strPauseCmd);
301 <                                uninstalled_something = 1;
302 <                                
303 <                        }
304 <                        else {
305 <                                index++;
306 <                        }
307 <                }
308 <        }
309 <        if ( uninstalled_something == 0 )
310 <        {
459 <                if (index == 0) //bad practice, I need to implement a second vector or something. Meh.
460 <                {
461 <                        cout << "\nWarning: You have no installed packages!";
462 <                }
463 <                else
464 <                {
465 <                        cout << "\nWarning: You didn't remove anything!";
466 <                }
467 <                //would you like to recombine your data?
468 <                return 0;
296 >                                copy("../../persist.dat","..");
297 >                if(exists("../../key_config.txt"))
298 >                        if(!exists("../key_config.txt"))
299 >                                copy("../../key_config.txt","..");
300 >                
301 > #ifndef WIN32
302 >                /* On Mac only, set the current GDF to the AE GDF by writing to Oni's global preferences file (thankfully a standard OS X ".plist" XML file).
303 >                 Tests for presence of prefs with [ -f ] before doing anything so it doesn't create a partial prefs file -- just in case user has never
304 >                 run Oni before :-p */
305 >                string fullAEpath = escapePath(system_complete(".").parent_path().parent_path().string()); // get full path for Edition/ (Oni wants the folder that *contains* the GDF)
306 >                char prefsCommand[300] = "[ -f ~/Library/Preferences/com.godgames.oni.plist ] && defaults write com.godgames.oni RetailInstallationPath -string '";
307 >                strcat(prefsCommand, fullAEpath.c_str());
308 >                strcat(prefsCommand, "'"); // path string is enclosed in single quotes to avoid the need to escape UNIX-unfriendly characters
309 >                system(prefsCommand);
310 > #endif
311                  
312 <        }      
313 <        sort(installedMods.begin(), installedMods.end());
314 <        //system(Onisplit.c_str());
315 <        recompileAll(installedMods);
316 <        system(strPauseCmd);
312 >                setStatusArea((string)"Done! Now select your mod packages and click install.");
313 >        }
314 >        catch (exception & ex) {
315 >                setStatusArea("Warning, handled exception: " + (string)ex.what());
316 >        }
317          
318 +        ptime end_time(second_clock::local_time());
319 +        time_period total_time (start_time, end_time);
320 +        logfile << "\n\nGlobalization ended " << to_simple_string(end_time) << "\nThe process took " << total_time.length();
321 +        logfile.close();
322 +        busy = 0;
323          return err;
324   }
325  
326 < int listInstalledPackages(void)
480 < {
481 <        cout << "\nThis feature not yet implemented.\n\n";
482 <        
483 <        return 0;
484 < }
485 <
486 < int printInstallerInfo(void)
487 < {
488 <        cout << "\nAE/Mod Installer\n";
489 <        cout << "version " << strInstallerVersion << "\n";
490 <        cout << "by Gumby & Iritscen\n";
491 <        cout << "see http://oni.bungie.org/community/forums for more info\n\n";
492 <        
493 <        return 0;
494 < }
495 <
496 < vector<ModPackage> getPackages(void)
326 > vector<ModPackage> getPackages(string packageDir)
327   {
328          vector<ModPackage> packages;
329 <        packages.reserve(65536); // come on, we shouldn't need this much space...right?!
329 >        ModPackage package;
330 >        packages.reserve(256);
331          fstream file;
332          string filename = "\0";
333          string MODINFO_CFG = "Mod_Info.cfg";
334          
335          try
336          {
337 <                directory_iterator end_iter;
507 <                for (directory_iterator dir_itr("./packages"); dir_itr != end_iter; ++dir_itr)
337 >                for (directory_iterator dir_itr(packageDir), end_itr; dir_itr != end_itr; ++dir_itr)
338                  {
339                          file.open((dir_itr->path().string() + "/" + MODINFO_CFG).c_str());
510                        //cout << filename << "\n";
340                          
341 <                        if(!file.fail())
341 >                        if (!file.fail())
342                          {
343 <                                //cout << dir_itr->path().string() + MODINFO_CFG;
344 <                                //would prefer to push a pointer to a package, but this will do for now
345 <                                packages.push_back(fileToModPackage(file));
343 >                                package = fileToModPackage(file);
344 >                                if (package.installerVersion.compare(INSTALLER_VERSION) < 1)  // if mod requires newer version of the Installer, we won't add it to the list
345 >                                {
346 > #ifdef WIN32
347 >                                        if (!package.platform.compare("Windows") || !package.platform.compare("Both")) // don't show package if it's not for the right OS
348 > #else
349 >                                        if (!package.platform.compare("Macintosh") || !package.platform.compare("Both"))
350 > #endif
351 >                                                packages.push_back(package);
352 >                                }
353                          }      
354                          file.close();
355                          file.clear();
356                  }
357 +                sort(packages.begin(), packages.end());
358          }
359          catch (const std::exception & ex)
360          {
# Line 539 | Line 376 | ModPackage fileToModPackage(fstream &fil
376           */
377          ModPackage package;
378          string line;
379 <        static string NameOfMod = "NameOfMod";  //used for comparing to the current token...
380 <        //I could have done it in reverse (*iter).compare("ModString") or  
381 <        static string ARROW = "->";                             //did something like "ModString".compare(*iter), and it would have been
382 <        static string ModString = "ModString";  //functionably the same.
379 >        static string AEInstallVersion = "AEInstallVersion"; // used for comparing to the current token...
380 >        static string NameOfMod = "NameOfMod";
381 >        static string ARROW = "->";
382 >        static string ModString = "ModString";
383 >        static string Platform = "Platform";
384          static string HasOnis = "HasOnis";
385          static string HasDeltas = "HasDeltas";
386          static string HasBSL = "HasBSL";
# Line 552 | Line 390 | ModPackage fileToModPackage(fstream &fil
390          static string GlobalNeeded = "GlobalNeeded";
391          static string Category = "Category";
392          static string Creator = "Creator";
393 <        while (! file.eof() )
393 >        while (!file.eof())
394          {
395 <                getline (file,line);
395 >                getline(file,line);
396                  vector<string> tokens;
397                  vector<string>::iterator iter;
398 <                tokenize(line, tokens);                                 //string to vector of "words"
399 <                if (tokens.capacity() >= 2) {                   //make sure they are using enough stuff
400 <                        iter = tokens.begin();                          //what word we are on, starts at first word
401 <                        /*
402 <                         if (!AEInstallVersion.compare(*iter))
403 <                         If mod is too old, skip this mod.
404 <                         */
405 <                        /*else*/if (!NameOfMod.compare(*iter))  {       //if it contains the name
406 <                                for ( ; iter !=tokens.end() && SLASHSLASH.compare(*iter); iter++) {     //interates through the words, ends if it reaches the end of the line or a "//" comment
407 <                                        if (ARROW.compare(*iter) && NameOfMod.compare(*iter)) {                 //ignores "->" and "NameOfMod"
408 <                                                //cout << *iter;
409 <                                                //cout << " ";
398 >                tokenize(line, tokens);
399 >                if (tokens.capacity() >= 3)
400 >                {
401 >                        iter = tokens.begin();
402 >
403 >                        if (!AEInstallVersion.compare(*iter))
404 >                        {
405 >                                iter++; iter++;
406 >                                package.installerVersion = *iter;
407 >                        }
408 >                        else if (!NameOfMod.compare(*iter))
409 >                        {
410 >                                for ( ; iter !=tokens.end() && SLASHSLASH.compare(*iter); iter++) // iterates through the words, ends if it reaches the end of the line or a "//" comment
411 >                                {
412 >                                        if (ARROW.compare(*iter) && NameOfMod.compare(*iter)) // ignores "->" and "NameOfMod"
413                                                  package.name += *iter + " ";
573                                        }
414                                  }
575                                
415                          }
416 <                        else if (!ModString.compare(*iter)) {
416 >                        else if (!ModString.compare(*iter))
417 >                        {
418                                  iter++; iter++;
419                                  package.modStringName = *iter;
420                                  iter++;
421                                  package.modStringVersion = atoi((*iter).c_str());
422                          }
423 <                        else if (!HasOnis.compare(*iter)) {
423 >                        else if (!Platform.compare(*iter))
424 >                        {
425 >                                iter++; iter++;
426 >                                package.platform = *iter;
427 >                        }
428 >                        else if (!HasOnis.compare(*iter))
429 >                        {
430                                  iter++; iter++;  
431 <                                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
432 <                                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,
433 <                                iter++; iter++;}  // using "YFR" would probably set it off. :<
434 <                                
435 <                                if (toupper((*iter)[0]) + toupper((*iter)[1]) + toupper((*iter)[2]) == 'Y' + 'E' + 'S') package.hasBSL = 1;
431 >                                if (boost::iequals(*iter, "Yes")) package.hasOnis = 1;
432 >                        }      
433 >                        else if (!HasBSL.compare(*iter))
434 >                        {
435 >                                iter++; iter++;
436 >                                if (toupper((*iter)[0]) == 'Y' && toupper((*iter)[1]) == 'E' && toupper((*iter)[2]) == 'S') package.hasBSL = true;
437 >                                else if (boost::iequals(*iter, "Addon")) package.hasAddon = true;
438                          }
439 <                        else if (!HasDeltas.compare(*iter)) {
439 >                        else if (!HasDeltas.compare(*iter))
440 >                        {
441                                  iter++; iter++;  
442 <                                if (toupper((*iter)[0]) + toupper((*iter)[1]) + toupper((*iter)[2]) == 'Y' + 'E' + 'S') package.hasDeltas = 1;
442 >                                if (toupper((*iter)[0]) == 'Y' && toupper((*iter)[1]) == 'E' && toupper((*iter)[2]) == 'S') package.hasDeltas = 1;
443                          }
444 <                        else if (!HasDats.compare(*iter)) {
444 >                        else if (!HasDats.compare(*iter))
445 >                        {
446                                  iter++; iter++;  
447 <                                if (toupper((*iter)[0]) + toupper((*iter)[1]) + toupper((*iter)[2]) == 'Y' + 'E' + 'S') package.hasDats = 1;
447 >                                if (toupper((*iter)[0]) == 'Y' && toupper((*iter)[1]) == 'E' && toupper((*iter)[2]) == 'S') package.hasDats = 1;
448                          }
449 <                        else if (!IsEngine.compare(*iter)) {
449 >                        else if (!IsEngine.compare(*iter))
450 >                        {
451                                  iter++; iter++;  
452 <                                if (toupper((*iter)[0]) + toupper((*iter)[1]) + toupper((*iter)[2]) == 'Y' + 'E' + 'S') package.isEngine = 1;
452 >                                if (toupper((*iter)[0]) == 'Y' && toupper((*iter)[1]) == 'E' && toupper((*iter)[2]) == 'S') package.isEngine = 1;
453                          }
454 <                        else if (!GlobalNeeded.compare(*iter)) {
454 >                        else if (!GlobalNeeded.compare(*iter))
455 >                        {
456                                  iter++; iter++;  
457 <                                if (toupper((*iter)[0]) + toupper((*iter)[1]) + toupper((*iter)[2]) == 'Y' + 'E' + 'S') package.globalNeeded = 1;
458 <                                else if (toupper((*iter)[0]) + toupper((*iter)[1]) == 'N' + 'O') package.globalNeeded = 1; //Really the only place where checking for "No" is important atm.
457 >                                if (toupper((*iter)[0]) == 'Y' && toupper((*iter)[1]) == 'E' && toupper((*iter)[2]) == 'S') package.globalNeeded = 1;
458 >                                else if (toupper((*iter)[0]) == 'N' && toupper((*iter)[1]) == 'O') package.globalNeeded = 1; // only place where checking for "No" is important atm
459                          }
460 <                        else if (!Category.compare(*iter))  {  
461 <                                for ( ; iter !=tokens.end() && SLASHSLASH.compare(*iter); iter++) {     //interates through the words, ends if it reaches the end of the line or a "//" comment
462 <                                        if (ARROW.compare(*iter) && Category.compare(*iter)) {                  //ignores "->" and "Category"
463 <                                                //cout << *iter;
464 <                                                //cout << " ";
460 >                        else if (!Category.compare(*iter))
461 >                        {      
462 >                                for ( ; iter !=tokens.end() && SLASHSLASH.compare(*iter); iter++)
463 >                                {
464 >                                        if (ARROW.compare(*iter) && Category.compare(*iter)) // ignores "->" and "Category"
465                                                  package.category += *iter + " ";
614                                        }
466                                  }
467                          }
468 <                        else if (!Creator.compare(*iter))  {    //if it contains the name
469 <                                for ( ; iter !=tokens.end() && SLASHSLASH.compare(*iter); iter++) {     //interates through the words, ends if it reaches the end of the line or a "//" comment
470 <                                        if (ARROW.compare(*iter) && Creator.compare(*iter)) {                   //ignores "->" and "Category"
471 <                                                //cout << *iter;
472 <                                                //cout << " ";
468 >                        else if (!Creator.compare(*iter))
469 >                        {
470 >                                for ( ; iter !=tokens.end() && SLASHSLASH.compare(*iter); iter++)
471 >                                {
472 >                                        if (ARROW.compare(*iter) && Creator.compare(*iter)) // ignores "->" and "Creator"
473                                                  package.creator += *iter + " ";
623                                        }
474                                  }
475                          }
476 <                        else if (!Readme.compare(*iter))  {     //if it contains the name
477 <                                for ( ; iter !=tokens.end() && SLASHSLASH.compare(*iter); iter++) {     //interates through the words, ends if it reaches the end of the line or a "//" comment
478 <                                        if (ARROW.compare(*iter) && Readme.compare(*iter)) {                    //ignores "->" and "Category"
479 <                                                if(!(*iter).compare("\\n")) package.readme += '\n';
476 >                        else if (!Readme.compare(*iter))
477 >                        {
478 >                                for ( ; iter !=tokens.end() && SLASHSLASH.compare(*iter); iter++)
479 >                                {
480 >                                        if (ARROW.compare(*iter) && Readme.compare(*iter)) // ignores "->" and "Readme"
481 >                                        {
482 >                                                if (!(*iter).compare("\\n")) package.readme += '\n';
483                                                  else package.readme += *iter + " ";
484                                          }
485                                  }
486                          }
487                  }
635                
488          }
489 <        package.doOutput();
489 >
490          return package;
491   }
492  
493   void recompileAll(vector<string> installedMods)
494 < {
495 < #ifdef WIN32
496 <        RedirectIOToConsole();
497 <        HWND hWnd = GetConsoleWindow();
498 <        ShowWindow( hWnd, SW_HIDE );
499 < #endif
500 <        setStatusArea("Importing levels...");
649 <        //setStatusArea("Recompiling Data...");
650 <        path vanilla_dir = "./packages/VanillaDats/";
494 > {try {
495 >        busy = 1;
496 >        using namespace boost::gregorian;
497 >        using namespace boost::posix_time;
498 >        using boost::lexical_cast;
499 >        using boost::bad_lexical_cast;
500 >        path vanilla_dir = "./VanillaDats/";
501          string importCommand = "";
652        char statusString[128];
502          int numberOfDats = 0;
503          int j = 1;
504          string datString;
505 <        std::stringstream out;
505 >                
506 >        setStatusArea("Importing levels...");
507          
508 +        std::stringstream out;
509          
510 +        ptime start_time(second_clock::local_time());
511          clearOldDats();
512 <        remove("Onisplit.log");
513 <        if(splitInstances == SPLIT){
512 >        
513 >        if(exists("Install.log")) remove("Install.log");
514 >        ofstream logfile("Install.log");
515 >        logfile << "Mod Installation started " << to_simple_string(start_time) << endl;
516 >        logfile.close();
517 >        
518 >        if(splitInstances == true)
519 >        {
520                  recursive_directory_iterator end_iter;
521                  
522                  for ( recursive_directory_iterator dir_itr( vanilla_dir );
# Line 671 | Line 529 | void recompileAll(vector<string> install
529                                          numberOfDats++;
530                                  }
531                          }
532 <                        catch(exception ex) {
532 >                        catch(exception & ex) {
533 >                                remove("Install.log");
534 >                                ofstream logfile("Install.log");
535                                  
536 +                                logfile << "Warning, exception " << ex.what() << "!";
537 +                                setStatusArea("Warning, exception " + (string)ex.what() + "!");
538 +                                logfile.close();        
539                          }
540                  }
678                
679                //recursive_directory_iterator end_iter;
680                
681                
682                out << numberOfDats;
683                datString = out.str();
541                  try {
542 +                        out << numberOfDats;
543 +                        datString = out.str();
544                          for ( recursive_directory_iterator dir_itr( vanilla_dir );
545                                   dir_itr != end_iter;
546                                   ++dir_itr )
# Line 691 | Line 550 | void recompileAll(vector<string> install
550                                          if ( is_directory( dir_itr->status() ) &&  dir_itr.level() == 1)
551                                          {
552                                                  importCommand = strOniSplit + " " + strImportOption + " " + dir_itr->path().parent_path().string() + '/' + dir_itr->path().filename();
553 <                                                for (int i = 0; i < installedMods.size(); ++i) {
553 >                                                for (unsigned int i = 0; i < installedMods.size(); ++i) {
554                                                          if (exists("packages/" + installedMods[i] + "/oni/" + dir_itr->path().parent_path().filename() + '/' + dir_itr->path().filename()  ))
555                                                                  importCommand += " packages/" + installedMods[i] + "/oni/" + dir_itr->path().parent_path().filename() + '/' + dir_itr->path().filename();
697                                                        
698                                                        //else cout << " packages/VanillaDats/" + installedMods[i] + "/oni/";
556                                                  }
557 <                                                importCommand += " ../GameDataFolder/" + dir_itr->path().filename() + ".dat >> Onisplit.log";
557 >                                                importCommand += " ../GameDataFolder/" + dir_itr->path().filename() + ".dat >> Install.log";
558 >                                                
559                                                  
702                                                sprintf(statusString,"%d/%i\0",j,numberOfDats);
560                                                  setProgressBar( (int)(1000 * (float)(j-1) / (float)numberOfDats) ); //100% * dat we're on / total dats
561 <                                                setStatusArea("Importing " +  dir_itr->path().filename() + " " + statusString);
561 >                                                setStatusArea("Step " + lexical_cast<std::string>(j) + '/' + lexical_cast<std::string>(numberOfDats)+ ": Importing " +  dir_itr->path().filename() + " ");
562                                                  
563                                                  system(importCommand.c_str());
564 <                                                //Sleep(1000);
708 <                                                //cout << importCommand << "\n";
709 <                                                j++;
710 <                                                
564 >                                                j++;                                            
565                                          }
566                                  }
567                                  catch ( const std::exception & ex )
568                                  {
569 <                                        cout << "Warning, exception " << ex.what() << "!";
569 >                                        remove("Install.log");
570 >                                        ofstream logfile("Install.log");
571 >                                        logfile << "Warning, exception " << ex.what() << "!";
572 >                                        setStatusArea("Warning, exception " + (string)ex.what() + "!");
573 >                                        logfile.close();        
574                                  }
575                          }
718                        
576                  }
577                  catch( const std::exception & ex ) {
578 <                        cout << "Warning, exception " << ex.what() << "!\n"
579 <                        << "You probably need to re-globalize.";
580 <                        //create_directory( "./packages/VanillaDats" );
578 >                        remove("Install.log");
579 >                        ofstream logfile("Install.log");
580 >                        logfile << "Warning, exception " << ex.what() << "!";
581 >                        setStatusArea("Warning, exception " + (string)ex.what() + "!");
582 >                        logfile.close();
583                  }
725                
584          }
585 <        else if(splitInstances == NOT_SPLIT){
585 >        else if(splitInstances == false){
586                  directory_iterator end_iter;
587                  
588                  for ( directory_iterator dir_itr( vanilla_dir );
589                           dir_itr != end_iter;
590                           ++dir_itr )
591                  {
734                        
592                          if ( is_directory( dir_itr->status() ) )
593                          {
594                                  numberOfDats++;
595                          }
739                        
740                        
596                  }
597                  
598                  out << numberOfDats;
# Line 751 | Line 606 | void recompileAll(vector<string> install
606                          {
607                                  if ( is_directory( dir_itr->status() ) )
608                                  {
609 <                                        importCommand = strOniSplit + " " + strImportOption + " " + vanilla_dir.string() + dir_itr->path().filename() + " " + "../GameDataFolder/" + dir_itr->path().filename()
610 <                                        + ".dat";
756 <                                        for (int i = 0; i < installedMods.size(); ++i) {
609 >                                        importCommand = strOniSplit + " " + strImportOption + " " + vanilla_dir.string() + dir_itr->path().filename() + " ";
610 >                                        for (unsigned int i = 0; i < installedMods.size(); ++i) {
611                                                  if (exists("packages/" + installedMods[i] + "/oni/" + dir_itr->path().filename()  ))
612                                                          importCommand += " packages/" + installedMods[i] + "/oni/" + dir_itr->path().filename();
613                                          }
614 <                                        importCommand += " ../GameDataFolder/" + dir_itr->path().filename() + ".dat";
614 >                                        importCommand += " ../GameDataFolder/" + dir_itr->path().filename() + ".dat >> Install.log";
615                                          
762                                        sprintf(statusString,"%d/%i\0",j,numberOfDats);
616                                          setProgressBar( (int)(1000 * (float)(j-1) / (float)numberOfDats) ); //100% * dat we're on / total dats
617 <                                        setStatusArea("Importing " +  dir_itr->path().filename() + " " + statusString);
765 <                                        
617 >                                        setStatusArea("Step " + lexical_cast<std::string>(j) + '/' + lexical_cast<std::string>(numberOfDats)+ ": Importing " +  dir_itr->path().filename() + " ");
618                                          system(importCommand.c_str());
767                                        
619                                          j++;
620                                  }
621                          }
622                          catch ( const std::exception & ex )
623                          {
624 <                                cout << "Warning, something odd happened!\n";
624 >                                remove("Install.log");
625 >                                ofstream logfile("Install.log");
626 >                                logfile << "Warning, exception " << ex.what() << "!";
627 >                                setStatusArea("Warning, exception " + (string)ex.what() + "!");
628 >                                logfile.close();
629                          }
630                  }
631          }
632 +        
633 +        vector<string> BSLfolders;
634 +        vector<string> skippedfolders;
635 +
636 +        ofstream BSLlog("BSL.log");
637 +        for ( directory_iterator dir_itr( "../GameDataFolder/IGMD/" ), end_itr;
638 +                 dir_itr != end_itr;
639 +                 ++dir_itr ) {
640 +                if( exists(dir_itr->path().string() + "/ignore.txt") ){
641 +                        BSLfolders.push_back(dir_itr->path().filename());
642 +                        skippedfolders.push_back(dir_itr->path().filename());
643 +                }
644 +        }
645 +        
646 +        for (int i = installedMods.size() - 1; i >= 0; i--) {                                                   //Iterates through the installed mods (backwards :P)
647 +                for (unsigned int j = 0; j < globalPackages.size(); ++j) {                              //looking in the global packages
648 +                        if (globalPackages[j].modStringName == installedMods[i]) {      //for a mod that has BSL in it
649 +                                if(!(globalPackages[j].hasAddon || globalPackages[j].hasBSL)) break; //skip non-BSL
650 +                                if( exists( "packages/" + globalPackages[j].modStringName + "/BSL/" ) ) {
651 +                                        copyBSL("packages/" + globalPackages[j].modStringName + "/BSL", BSLfolders, globalPackages[j] );
652 +                                        BSLlog << "Copied " <<  globalPackages[j].modStringName << "!\n";
653 +                                }
654 +                        }
655 +                }
656 +        }
657 +        
658 +        ModPackage emptyPackage;
659 +        emptyPackage.modStringName = "VanillaBSL";
660 +        emptyPackage.hasBSL = 1;
661 +        copyBSL("packages/VanillaBSL/IGMD", BSLfolders, emptyPackage);
662 +        BSLlog.close();
663 +        
664 +        logfile << "Writing config file";
665          writeInstalledMods(installedMods);
666          setProgressBar(1000);
779        setStatusArea("Done!");
780        sleep(1000);
781        setProgressBar(0);
667          
668 +        string finallyDone = "Done! You can now play Oni.";
669 +        setStatusArea(finallyDone);
670 +        
671 +        ptime end_time(second_clock::local_time());
672 +        time_period total_time (start_time, end_time);
673 +        ofstream logfile2("Install.log", ios::app | ios::ate);
674 +        string outstring = (string)"\n\nGlobalization ended " + to_simple_string(end_time) + "\nThe process took ";// + (string)total_time.length();
675 +        
676 +        logfile2 << "\nInstallation ended " << to_simple_string(end_time) << "\nThe process took " << total_time.length();
677 +        logfile2.close();
678 +        
679 +        Sleep(1000);
680 +        setProgressBar(0);
681 + }
682 +        catch(exception & ex) {
683 +                remove("Install.log"); //why did we do this? :|
684 +                ofstream logfile("Install.log");
685 +                logfile << "Warning, exception " << ex.what() << "!";
686 +                setStatusArea("Warning, exception " + (string)ex.what() + "!");
687 +                logfile.close();
688 +        }
689 +        busy = 0;
690   }
691  
692 < void writeInstalledMods(vector<string> installedMods)
692 > void copyBSL(string copypath, vector<string>& BSLfolders, ModPackage pkg)
693   {
694 +        ofstream BSLlog("BSL2.log", ios::app );
695          
696 +        try {
697 +                for ( directory_iterator dir_itr( copypath ), end_itr;
698 +                         dir_itr != end_itr;
699 +                         ++dir_itr ) {
700 +                        
701 +                        if ( is_directory( dir_itr->path() ) && dir_itr->path().string() != ".svn" ) {  
702 +                                BSLlog << "Testing " << dir_itr->path().string() << " HasBSL: " << pkg.hasBSL << " HasAddon: " << pkg.hasAddon << "\n";
703 +                                int skip_folder = 0;
704 +                                
705 +                                for(unsigned int k = 0; k < BSLfolders.size(); k++)             {//iterate through already found BSL folders    
706 +                                        BSLlog << "testing " << dir_itr->path().filename() << " vs " << BSLfolders[k] << "\n";
707 +                                        if(dir_itr->path().filename() == BSLfolders[k]) {
708 +                                                skip_folder = 1;
709 +                                                BSLlog << "skipping " << BSLfolders[k] << " in " << pkg.modStringName << "\n";
710 +                                                break;
711 +                                        }
712 +                                }
713 +                                if (!skip_folder && !exists("../GameDataFolder/IGMD/" + dir_itr->path().filename() + "/ignore.txt")) {
714 +                                        remove_all( "../GameDataFolder/IGMD/" + dir_itr->path().filename() );
715 +                                        Sleep(100);
716 +                                        create_directory( "../GameDataFolder/IGMD/" + dir_itr->path().filename());
717 +                                        BSLlog << "Copied " << dir_itr->path().string() << " in " << pkg.modStringName << "!\n";
718 +                                        for ( directory_iterator bsl_itr( dir_itr->path() );
719 +                                                 bsl_itr != end_itr;
720 +                                                 bsl_itr++ ) {
721 +                                                if ( bsl_itr->path().extension() == ".bsl" ) {
722 +                                                        copy_file(bsl_itr->path(),  "../GameDataFolder/IGMD/" + dir_itr->path().filename() + "/" + bsl_itr->path().filename());
723 +                                                }
724 +                                        }
725 +                                        BSLfolders.push_back( dir_itr->path().filename() ); //add back check for addon
726 +                                        BSLlog << "Pushing " << dir_itr->path().filename() << "\n" ;
727 +                                }
728 +                        }
729 +                }
730 +        }
731 +        catch ( const std::exception & ex )
732 +        {
733 +                setStatusArea("Warning, exception " + (string)ex.what() + "!");
734 +                while(1) Sleep(1000);
735 +        }
736 +        BSLlog.close();
737 +        
738 + }
739 +
740 +
741 + void writeInstalledMods(vector<string> installedMods)
742 + {      
743          if ( exists( strInstallCfg ) )
744          {
745                  remove( strInstallCfg );
# Line 804 | Line 759 | void writeInstalledMods(vector<string> i
759          
760          file.close();
761          file.clear();
807        
762   }
763  
764   vector<string> getInstallString(string Cfg)
765   {
766 <        //system(strPauseCmd);
813 <        vector<string> returnval;
814 <        
766 >        vector<string> returnval;      
767          string line;
768          fstream file;
769          
# Line 829 | Line 781 | vector<string> getInstallString(string C
781          return returnval;
782   }
783  
784 + /* GetUpdateStatus determines whether there is an update available. It is called once, *\
785 + |  on launch, by AEInstallerApp::OnInit(), and not only passes back a #defined result   |
786 + |  code, but also oversees the setting of data in the global structures currentAE and   |
787 + |  updateAE, which tell the Installer all the version information it needs to know.             |
788 + |                                       ---Return Values---                                                                                                     |
789 + |  UPDATE_LOG_READ_ERR          -- A log file could not be opened                                                       |
790 + |  UPDATE_INST_REPL_ERR         -- The Installer self-updating process failed                           |
791 + |  UPDATE_MNTH_REQD_ERR         -- The update is a patch, and the monthly release it            |
792 + |                                                          patches is not installed                                                                     |
793 + |  UPDATE_NO_UPD_AVAIL          -- Either there isn't an update in place, or it's not           |
794 + |                                                          newer than what's installed                                                          |
795 + |  UPDATE_SIMP_AVAIL            -- An update is available                                                                       |
796 + |  UPDATE_GLOB_AVAIL            -- An update is available that requires re-globalization        |
797 + |                                                          afterwards (because of some notable change in the AE)        |
798 + |  UPDATE_INST_AVAIL            -- An update is available that first requires the                       |
799 + |                                                          Installer to be replaced (when the new Installer                     |
800 + |                                                          launches, this function will be called again but will        |
801 + |                                                          return UPDATE_SIMP_AVAIL or UPDATE_GLOB_AVAIL)                       |
802 + \* UPDATE_CONT_UPD                      -- Currently unused                                                                                */
803 + int GetUpdateStatus(Install_info_cfg *currentAE, Install_info_cfg *updateAE, bool *installerJustUpdated)
804 + {
805 +        fstream currentAECfg, updateAECfg, updateLog;
806 +        string strInstaller = "Installer";
807 +        string strBeing = "being";
808 +        string strWas = "was"; // lol
809 + #ifdef WIN32
810 +        string strInstallerName = "AEInstaller.exe";
811 + #else
812 +        string strInstallerName = "Installer.app";
813 + #endif
814 +        
815 +        // Try to get current AE's version info; if it doesn't exist, then the default version data for 2009-07 remains in place
816 +        if (exists("packages/Globalize/Install_Info.cfg"))
817 +        {
818 +                currentAECfg.open("packages/Globalize/Install_Info.cfg");
819 +                if (!currentAECfg.fail())
820 +                {
821 +                        if (!ReadInstallInfoCfg(&currentAECfg, currentAE))
822 +                                return UPDATE_LOG_READ_ERR;
823 +                        
824 +                        currentAECfg.close();
825 +                        currentAECfg.clear();
826 +                }
827 +                else
828 +                        return UPDATE_LOG_READ_ERR;
829 +        }
830 +        
831 +        // Is there an update folder, and is it a monthly release or a patch?
832 +        if (!exists("../updates/Edition"))
833 +        {
834 +                strEUFN = "Edition-patch";
835 +                if (!exists("../updates/Edition-patch"))
836 +                        return UPDATE_NO_UPD_AVAIL;
837 +        }
838 +        
839 +        // Unlike the current AE's version info, we *need* to find the update's version info or we won't continue
840 +        string updateCfgPath = ("../updates/" + strEUFN + "/install/packages/Globalize/Install_Info.cfg");
841 +        updateAECfg.open(updateCfgPath.c_str());
842 +        if (!updateAECfg.fail())
843 +        {
844 +                if (!ReadInstallInfoCfg(&updateAECfg, updateAE))
845 +                        return UPDATE_LOG_READ_ERR;
846 +                
847 +                updateAECfg.close();
848 +                updateAECfg.clear();
849 +        }
850 +        else
851 +                return UPDATE_LOG_READ_ERR;
852 +
853 +        // Now we check for an Installer update in progress
854 +        if (exists("Update.log"))
855 +        {
856 +                updateLog.open("Update.log");
857 +                if (!updateLog.fail())
858 +                {
859 +                        vector<string> lines;
860 +                        string line;
861 +                        int num_lines = 0;
862 +                        bool readingInstallerVersion = false, doneReadingFile = false;
863 +                        
864 +                        while (!updateLog.eof() && !doneReadingFile)
865 +                        {
866 +                                getline(updateLog, line);
867 +                                lines.push_back(line);
868 +                                num_lines++;
869 +                                vector<string> tokens;
870 +                                vector<string>::iterator iter;
871 +                                tokenize(line, tokens);
872 +                                iter = tokens.begin();
873 +                                if (!readingInstallerVersion && tokens.capacity() >= 4)
874 +                                {
875 +                                        if (!strInstaller.compare(*iter))
876 +                                        {
877 +                                                if (!strBeing.compare(*++iter))
878 +                                                        readingInstallerVersion = true;
879 +                                                else if (!strWas.compare(*iter))
880 +                                                        *installerJustUpdated = true; // our third indirect return value after currentAE and updateAE
881 +                                        }
882 +                                }
883 +                                else if (readingInstallerVersion && tokens.capacity() >= 3)
884 +                                {
885 +                                        readingInstallerVersion = false;
886 +                                        string installerVersion = INSTALLER_VERSION;
887 +                                        if (installerVersion.compare(*iter)) // then the shell script-powered replacement failed
888 +                                                return UPDATE_INST_REPL_ERR;
889 +                                        else
890 +                                        {
891 +                                                updateLog.close();
892 +                                                updateLog.clear();
893 +                                                Sleep(1000);
894 +                                                remove("Update.log");
895 +                                                ofstream newUpdateLog("Update.log");
896 +                                                if (!newUpdateLog.fail())
897 +                                                {
898 +                                                        // Write over old log with updated information
899 +                                                        ptime startTime(second_clock::local_time());
900 +                                                        string strStartTime = to_simple_string(startTime);
901 +                                                        string newUpdateLine = installerVersion + " on " + strStartTime;
902 +                                                        for (int a = 0; a < lines.capacity() - 2; a++) // if there were even lines in the log before this at all
903 +                                                        {
904 +                                                                newUpdateLog << lines[a].c_str();
905 +                                                                newUpdateLog << "\n";
906 +                                                        }
907 +                                                        newUpdateLog << "Installer was updated to:\n";
908 +                                                        newUpdateLog << newUpdateLine.c_str();
909 +                                                        *installerJustUpdated = true; // this value is indirectly returned to AEInstallerAp::OnInit()
910 +                                                        doneReadingFile = true;
911 +                                                        newUpdateLog.close();
912 +                                                        newUpdateLog.clear();
913 +                                                        //return UPDATE_CONT_UPD; // as noted above, we are not using this return value; in fact, we want...
914 +                                                        //                                                       ...the code to continue running down through the Edition version check
915 +                                                }
916 +                                                else
917 +                                                        return UPDATE_LOG_READ_ERR;
918 +                                        }
919 +                                }
920 +                        }
921 +                        updateLog.close();
922 +                        updateLog.clear();
923 +                }
924 +                else
925 +                        return UPDATE_LOG_READ_ERR;
926 +        }
927 +        
928 +        if (updateAE->AEVersion.compare(currentAE->AEVersion) >= 1) // is the release update newer than what's installed?
929 +        {
930 +                if (!strEUFN.compare("Edition-patch")) // if update is a patch...
931 +                {
932 +                        if (currentAE->AEVersion.compare(updateAE->AEVersion.substr(0, updateAE->AEVersion.length() - 1))) // ...is it for a different month?
933 +                                return UPDATE_MNTH_REQD_ERR;
934 +                }
935 +                string strNewInstallerPath = "../updates/" + strEUFN + "/install/" + strInstallerName;
936 +                string installerVersion = INSTALLER_VERSION;
937 +                if (updateAE->InstallerVersion.compare(installerVersion) >= 1)
938 +                {
939 +                        if (exists(strNewInstallerPath))
940 +                                return UPDATE_INST_AVAIL;
941 +                }
942 +                else if (updateAE->globalizationRequired)
943 +                        return UPDATE_GLOB_AVAIL;
944 +                else
945 +                        return UPDATE_SIMP_AVAIL;
946 +        }
947 +        else
948 +                return UPDATE_NO_UPD_AVAIL;
949 +        
950 +        return UPDATE_NO_UPD_AVAIL;
951 + }
952 +
953 + bool ReadInstallInfoCfg(fstream *fileHandler, Install_info_cfg *info_cfg)
954 + {
955 +        vector<string> tokens;
956 +        vector<string>::iterator iter;
957 +        string line;
958 +        string strAEVersion = "AE_Version";
959 +        string strInstallerVersion = "Installer_Version";
960 +        string strDaodanVersion = "Daodan_Version";
961 +        string strOniSplitVersion = "OniSplit_Version";
962 +        string strGUIWinVersion = "GUI_Win_Version";
963 +        string strGUIMacVersion = "GUI_Mac_Version";
964 +        string strReglobalize = "Reglobalize";
965 +        string strDeleteList = "Delete_List";
966 +        string strArrow = "->";
967 +        string strDoubleSlash = "//";
968 +        string strYes = "Yes"; // this is getting silly
969 +        
970 +        while (getline(*fileHandler, line))
971 +        {
972 +                StripNewlines(&line);
973 +                tokenize(line, tokens);
974 +                iter = tokens.begin();
975 +                
976 +                if (tokens.size() >= 3)
977 +                {
978 +                        if (!strAEVersion.compare(*iter))
979 +                        {
980 +                                if (!strArrow.compare(*++iter))
981 +                                        info_cfg->AEVersion = *++iter;
982 +                                else
983 +                                        return false;
984 +                        }
985 +                        else if (!strInstallerVersion.compare(*iter))
986 +                        {
987 +                                if (!strArrow.compare(*++iter))
988 +                                        info_cfg->InstallerVersion = *++iter;
989 +                                else
990 +                                        return false;
991 +                        }
992 +                        else if (!strDaodanVersion.compare(*iter))
993 +                        {
994 +                                if (!strArrow.compare(*++iter))
995 +                                        info_cfg->DaodanVersion = *++iter;
996 +                                else
997 +                                        return false;
998 +                        }
999 +                        else if (!strOniSplitVersion.compare(*iter))
1000 +                        {
1001 +                                if (!strArrow.compare(*++iter))
1002 +                                        info_cfg->OniSplitVersion = *++iter;
1003 +                                else
1004 +                                        return false;
1005 +                        }
1006 +                        else if (!strGUIWinVersion.compare(*iter))
1007 +                        {
1008 +                                if (!strArrow.compare(*++iter))
1009 +                                        info_cfg->WinGUIVersion = *++iter;
1010 +                                else
1011 +                                        return false;
1012 +                        }
1013 +                        else if (!strGUIMacVersion.compare(*iter))
1014 +                        {
1015 +                                if (!strArrow.compare(*++iter))
1016 +                                        info_cfg->MacGUIVersion = *++iter;
1017 +                                else
1018 +                                        return false;
1019 +                        }
1020 +                        else if (!strReglobalize.compare(*iter))
1021 +                        {
1022 +                                if (!strArrow.compare(*++iter))
1023 +                                {
1024 +                                        if (!strYes.compare(*++iter))
1025 +                                                info_cfg->globalizationRequired = true;
1026 +                                }
1027 +                                else
1028 +                                        return false;
1029 +                        }
1030 +                        else if (!strDeleteList.compare(*iter))
1031 +                        {
1032 +                                // We need to perform a totally customized parsing process on this data
1033 +                                if (!strArrow.compare(*++iter))
1034 +                                {
1035 +                                        vector<string> tokens2;
1036 +                                        tokenize(line, tokens2, ","); // the paths on this line are comma-delimited, so we parse it again
1037 +                                        vector<string>::iterator iter2 = tokens2.begin();
1038 +                                        string finalPath = "";
1039 +                                        for (; iter2 != tokens2.end(); iter2++)
1040 +                                        {
1041 +                                                finalPath = finalPath + *iter2;
1042 +                                                
1043 +                                                string::size_type loc = finalPath.find("->", 0); // the first word will have "Delete_List ->" at the front, so let's cut that off
1044 +                                                if (loc != string::npos)
1045 +                                                        finalPath = finalPath.substr(loc + 3, finalPath.size());
1046 +                                                
1047 +                                                // If a path has '//' in it, it must contain some optional comments that were at the end of the Delete_List line
1048 +                                                loc = finalPath.find("//", 0);
1049 +                                                if (loc != string::npos)
1050 +                                                        finalPath = finalPath.substr(0, loc);
1051 +                                                
1052 +                                                // Trim a single space if it exists at the start or finish; putting more than one space after a comma will break this
1053 +                                                if (finalPath.at(0) == ' ')
1054 +                                                        finalPath = finalPath.substr(1, finalPath.size());
1055 +                                                if (finalPath.at(finalPath.size() - 1) == ' ')
1056 +                                                        finalPath = finalPath.substr(0, finalPath.size() - 1);
1057 +
1058 +                                                // If the tokenized path ends with a '\', then we assume it was followed by a comma
1059 +                                                if (finalPath.at(finalPath.size() - 1) == '\\')
1060 +                                                {
1061 +                                                        finalPath = finalPath.substr(0, finalPath.size() - 1); // clip the '\' off the end of the string now that it served its purpose...
1062 +                                                        finalPath = finalPath + ","; // ...and add the actual comma back at the end
1063 +                                                }
1064 +                                                else // we can add the path to deleteList, and clear the path; otherwise it will be added to on the next iteration
1065 +                                                {
1066 +                                                        if (StringIsLegalPathForDeletion(finalPath)) // ...and it's not violating any of our security rules as to what can be deleted...
1067 +                                                                info_cfg->deleteList.push_back(finalPath); // ...then add it to our deleteList in memory
1068 +                                                        finalPath.clear(); // clear the token we were building up before the next pass
1069 +                                                }
1070 +                                        }
1071 +                                }
1072 +                                else
1073 +                                        return false;
1074 +                        }
1075 +                }
1076 +                tokens.clear();
1077 +        }
1078 +        
1079 +        return true;
1080 + }
1081 +
1082 + // TODO: Fix security holes here
1083 + /* There is currently a security hole in this function; the first occurrence of a '.' not followed by a second '.' will prevent the function from
1084 + noticing an actual occurrence of '..' later in the string; iow, it only looks after the first period it finds for a second period.
1085 + A second hole is that the last slash will be trimmed from the path, but one could still use ".//" and it would get past this function, and
1086 + possibly be interpreted by the Boost file functions as "the current directory". Iow, both of these checks need to be iterative, not one-time.
1087 + Not too concerned about this at the moment, as only we of the AE Team are supplying the install_info file that this function is connected to. -I */
1088 +
1089 + /* This function serves as a barrier against the Installer deleting files it shouldn't. *\
1090 + |  It tests for each of the following conditions in the path it is passed:                               |
1091 + |   A. '..' as the whole path or '/..', '\..' anywhere in the path                                               |
1092 + |        Reason: Moving up from the parent directory, the Edition folder, would allow one        |
1093 + |        to delete anything on the hard drive, so all "parent path" references are illegal.      |
1094 + |   B. '/' at the beginning of the path                                                                                                  |
1095 + |        Reason: In Unix, this means the path starts from root level, as opposed to the          |
1096 + |        directory we will evaluate these paths as being relative to, which is Edition/.         |
1097 + |   C. '.' as the whole path                                                                                                                     |
1098 + |        Reason: This would mean "the Edition folder", which is not allowed to be deleted.       |
1099 + |   D. 'GameDataFolder' at the end of the path                                                                                   |
1100 + |        Reason: We don't allow the entire GDF to be deleted, only specific files in it.         |
1101 + |   E. '*' anywhere in the path                                                                                                                  |
1102 + |        Reason: We don't want this interpreted as a wildcard; it's best to only delete          |
1103 + *\       files by name.                                                                                                                                         */
1104 + bool StringIsLegalPathForDeletion(string word)
1105 + {
1106 +        string::size_type loc1, loc2;
1107 +        
1108 +        // Trim ending slashes in order to simplify the test
1109 +        // Note that we're only altering the local copy of the string here
1110 +        loc1 = word.find_last_of("\\", word.size());
1111 +        if (loc1 == word.size() - 1)
1112 +                word.resize(word.size() - 1);
1113 +        loc1 = word.find_last_of("/", word.size());
1114 +        if (loc1 == word.size() - 1)
1115 +                word.resize(word.size() - 1);
1116 +        
1117 +        // Test B
1118 +        loc1 = word.find_first_of("\\", 0);
1119 +        if (loc1 == 0)
1120 +                return false; // path begins with a slash, meaning root level of HD in Unix, an illegal path
1121 +        loc1 = word.find_first_of("/", 0);
1122 +        if (loc1 == 0)
1123 +                return false; // path begins with a slash, meaning root level of HD in Unix, an illegal path
1124 +        
1125 +        // Test E
1126 +        loc1 = word.find("*", 0);
1127 +        if (loc1 != string::npos) // if we found our character before reaching the end of the string
1128 +                return false; // path cannot contain the '*' character
1129 +        
1130 +        // Tests A (part 1) and C
1131 +        loc1 = word.find(".", 0);
1132 +        if (loc1 != string::npos)
1133 +        {
1134 +                if (word.size() == 1)
1135 +                        return false; // path cannot be simply '.', referring to Edition folder itself
1136 +                loc2 = word.find(".", loc1 + 1);
1137 +                if (loc2 == loc1 + 1) // make sure this second period comes after the first one
1138 +                        if (word.size() == 2)
1139 +                                return false; // not allowed to reference a parent directory
1140 +        }
1141 +        
1142 +        // Test A (part 2)
1143 +        loc1 = word.find("/..", 0);
1144 +        if (loc1 != string::npos)
1145 +                return false; // not allowed to reference a parent directory
1146 +        loc1 = word.find("\\..", 0);
1147 +        if (loc1 != string::npos)
1148 +                return false; // not allowed to reference a parent directory
1149 +        
1150 +        // Test D
1151 +        loc1 = word.find("GameDataFolder", 0);
1152 +        if (loc1 == word.size() - 14) // if "GameDataFolder" is the last 14 characters of the string...
1153 +                return false; // not allowed to delete the GDF
1154 +
1155 +        return true;
1156 + }
1157 +
1158 + bool ProcessInstallerUpdate(Install_info_cfg *currentAE, Install_info_cfg *updateAE)
1159 + {
1160 +        ofstream file;
1161 +        string shellScript;
1162 +        
1163 +        ptime startTime(second_clock::local_time());
1164 +        string strStartTime = to_simple_string(startTime);
1165 +        string progressMsg = "Installer being updated to:\n" +
1166 +                                                 updateAE->InstallerVersion + " on " + strStartTime;
1167 +        file.open("Update.log");
1168 +        if (!file.fail())
1169 +                file << progressMsg.c_str();
1170 +        file.close();
1171 +        file.clear();
1172 +        
1173 +        string popenCommand = "../updates/" + strEUFN + "/install/";
1174 + #ifdef WIN32
1175 +        // TODO: Fill in Windows equivalent of code below :-3
1176 +        popenCommand = "replace_installer.bat";
1177 + #else
1178 +        // We can't just use '~' to mean "the home directory" because we need to check the path in C...
1179 +        // ...so we actually get the current user's shortname and manually construct the path to home
1180 +        FILE *fUserName = NULL;
1181 +        char chrUserName[32];
1182 +        fUserName = popen("whoami", "r");
1183 +        fgets(chrUserName, sizeof(chrUserName), fUserName);
1184 +        pclose(fUserName);
1185 +        string strUserName = (string)chrUserName; // stringsblaaarrrgggghhhh
1186 +        int endOfName = strUserName.find("\n", 0);
1187 +        string pathToTrash = "/Users/" + strUserName.substr(0, endOfName) + "/.Trash/";
1188 +        tm tmStartTime = to_tm(startTime);
1189 +        pathToTrash = pathToTrash + "Old_Edition_files_" + currentAE->AEVersion + "_" + boost::lexical_cast<string>(tmStartTime.tm_hour) + "-" +
1190 +        boost::lexical_cast<string>(tmStartTime.tm_min) + "-" + boost::lexical_cast<string>(tmStartTime.tm_sec); // lol
1191 +        create_directory(pathToTrash);
1192 +        // The script takes as a parameter the path the old Installer should go to, in quotes
1193 +        popenCommand = "bash " + popenCommand + "replace_installer.sh " + pathToTrash + "/Installer.app";
1194 +                                  
1195 + #endif
1196 +        file.close();
1197 +        file.clear();
1198 + #ifdef WIN32
1199 +        system(popenCommand.c_str());
1200 + #else
1201 +        popen(popenCommand.c_str(), "r");
1202 + #endif
1203 +        return true; // returning 'true' tells the Installer to quit itself ASAP so it can be replaced by the process that is now running
1204 + }
1205 +
1206 + bool ProcessAEUpdate(Install_info_cfg *currentAE, Install_info_cfg *updateAE, bool *installerJustUpdated)
1207 + {
1208 +        fstream file;
1209 +        string line;
1210 +        vector<string> tokens, updateStarted;
1211 +        string strInstaller = "Installer";
1212 +        string strWas = "was";
1213 +        string strPathToEUFN = ("../updates/" + strEUFN + "/"); // strEUFN is set by GetUpdateStatus()
1214 +        string strPathToEUFNInstall = ("../updates/" + strEUFN + "/install/");
1215 +        string strPathToEUFNPackages = ("../updates/" + strEUFN + "/install/packages/");
1216 +        string strPathToPackages = "packages/";
1217 +        string strGlobalize = "Globalize/";
1218 +        string strOniSplit = "OniSplit.exe";
1219 +        string strDaodan = "binkw32.dll";
1220 +        string strWinGUI = "onisplit_gui.exe";
1221 +        string strWinGUILang = "ospgui_lang.ini";
1222 +        string strMacGUI = "AETools.app";
1223 + #ifdef WIN32
1224 +        string strOniApp = "Oni.exe";
1225 + #else
1226 +        string strOniApp = "Oni.app";
1227 + #endif
1228 +        bool needNewTrashDir = false;
1229 +        bool readingVerAndDate = false;
1230 +        
1231 +        // TODO: Fill in Windows equivalent of code below
1232 + #ifdef WIN32
1233 +        string strTrashDir = "Trash\\";
1234 + #else
1235 +        FILE *fUserName = NULL;
1236 +        char chrUserName[32];
1237 +        fUserName = popen("whoami", "r");
1238 +        fgets(chrUserName, sizeof(chrUserName), fUserName);
1239 +        pclose(fUserName);
1240 +        string strUserName = (string)chrUserName; // stringsblaaarrrgggghhhh
1241 +        int endOfName = strUserName.find("\n", 0);
1242 +        string strTrashDir = "/Users/" + strUserName.substr(0, endOfName) + "/.Trash/";
1243 + #endif
1244 +        
1245 +        // Write to log that we are beginning the update process
1246 +        ptime startTime(second_clock::local_time());
1247 +        string strStartTime = to_simple_string(startTime);
1248 +        string progressMsg = "\nEdition being updated to:\n" +
1249 +                                                 updateAE->AEVersion + " on " + strStartTime;
1250 +        file.open("Update.log");
1251 +        if (!file.fail())
1252 +                file << progressMsg.c_str();
1253 +        
1254 +        if (*installerJustUpdated) // then we want to know what folder in the Trash the Installer was placed in...
1255 +        {
1256 +                while (!file.eof()) // ...so we read the log to get the timestamp so we know the name of the folder that should be in the Trash
1257 +                {
1258 +                        getline(file, line);
1259 +                        tokenize(line, tokens);
1260 +                        
1261 +                        if (tokens.capacity() >= 4)
1262 +                                if (!strInstaller.compare(tokens[0]))
1263 +                                        if (!strWas.compare(tokens[1]))
1264 +                                                readingVerAndDate = true;
1265 +                        if (readingVerAndDate && tokens.capacity() >= 3)
1266 +                                tokenize(tokens[2], updateStarted, "-");
1267 +                }
1268 +                if (updateStarted.capacity() < 3)
1269 +                        needNewTrashDir = true;
1270 +                else
1271 +                {
1272 +                        strTrashDir = strTrashDir + "Old_Edition_files_" + currentAE->AEVersion + "-" +
1273 +                                                  updateStarted[0] + "-" + updateStarted[1] + "-" + updateStarted[2] + "/";
1274 +                        if (!exists(strTrashDir))
1275 +                                needNewTrashDir = true;
1276 +                }
1277 +        }
1278 + #ifndef WIN32
1279 +        if (!*installerJustUpdated || needNewTrashDir) // prepare a new directory for deleted files to go to
1280 +        {
1281 +                tm tmStartTime = to_tm(startTime);
1282 +                strTrashDir = strTrashDir + "Old_Edition_files_" + currentAE->AEVersion + "_" + boost::lexical_cast<string>(tmStartTime.tm_hour) + "-" +
1283 +                                          boost::lexical_cast<string>(tmStartTime.tm_min) + "-" + boost::lexical_cast<string>(tmStartTime.tm_sec) + "/";
1284 +                create_directory(strTrashDir);
1285 +        }
1286 + #endif
1287 +        file.close();
1288 +        file.clear();
1289 +
1290 +        // Special code to replace our special files -- the Oni app, OniSplit, the Daodan DLL, and the GUI for OniSplit
1291 +        if (exists(strPathToEUFN + strOniApp))
1292 +        {
1293 +                if (exists(strOniApp))
1294 +                        rename((path)strOniApp, (path)(strTrashDir + strOniApp));
1295 +                rename((path)(strPathToEUFN + strOniApp), (path)strOniApp);
1296 +        }
1297 +        if (updateAE->OniSplitVersion.compare(currentAE->OniSplitVersion) >= 1)
1298 +        {
1299 +                if (exists(strPathToEUFNInstall + strOniSplit))
1300 +                {
1301 +                        if (exists(strOniSplit))
1302 +                                rename((path)strOniSplit, (path)(strTrashDir + strOniSplit));
1303 +                        rename((path)(strPathToEUFNInstall + strOniSplit), (path)strOniSplit);
1304 +                }
1305 +        }
1306 + #ifdef WIN32
1307 +        if (updateAE->DaodanVersion.compare(currentAE->DaodanVersion) >= 1)
1308 +        {
1309 +                if (exists(strPathToEUFN + strDaodan))
1310 +                {
1311 +                        if (exists(("../" + strDaodan)))
1312 +                                rename((path)("../" + strDaodan), (path)(strTrashDir + strDaodan));
1313 +                        rename((path)(strPathToEUFN + strDaodan), (path)("../" + strDaodan));
1314 +                }
1315 +        }
1316 +        if (updateAE->WinGUIVersion.compare(currentAE->WinGUIVersion) >= 1)
1317 +        {
1318 +                if (exists(strPathToEUFNInstall + strWinGUI))
1319 +                {
1320 +                        if (exists((path)strWinGUI))
1321 +                                rename((path)strWinGUI, (path)(strTrashDir + strWinGUI));
1322 +                        if (exists(strWinGUILang))
1323 +                                rename((path)strWinGUILang, (path)(strTrashDir + strWinGUILang));
1324 +                        rename((path)(strPathToEUFNInstall + strWinGUI), (path)strWinGUI);
1325 +                        rename((path)(strPathToEUFNInstall + strWinGUILang), (path)strWinGUILang);
1326 +                }
1327 +        }
1328 + #else
1329 +        if (updateAE->MacGUIVersion.compare(currentAE->MacGUIVersion) >= 1)
1330 +        {
1331 +                if (exists(strPathToEUFN + strMacGUI))
1332 +                {
1333 +                        if (exists(("../" + strMacGUI)))
1334 +                                rename((path)("../" + strMacGUI), (path)(strTrashDir + strMacGUI));
1335 +                        rename((path)(strPathToEUFN + strMacGUI), (path)("../" + strMacGUI));
1336 +                }
1337 +        }
1338 + #endif
1339 +        
1340 +        // Now we trash whatever's in DeleteList; this allows us to clear out obsolete files in the previous AE install
1341 +        // Before moving a file to the Trash, we need to make sure each of the file's parent paths exists in the Trash...
1342 +        // ...so we iterate through the hierarchy of the file path, checking for each one and creating it if necessary
1343 +        for (vector<string>::iterator iter = updateAE->deleteList.begin(); iter != updateAE->deleteList.end(); iter++)
1344 +        {
1345 +                string thePath = *iter;
1346 +                if (exists((path)("../" + thePath)))
1347 +                {
1348 +                        string aParentPath;
1349 +                        string::size_type curPos = thePath.find("/", 0);
1350 +                        if (curPos != string::npos)
1351 +                                aParentPath = thePath.substr(0, curPos);
1352 +                        string::size_type lastPos = curPos;
1353 +                        while (curPos != string::npos && curPos < thePath.size())
1354 +                        {
1355 +                                aParentPath = aParentPath + thePath.substr(lastPos, curPos - lastPos);
1356 +                                if (!exists(strTrashDir + aParentPath))
1357 +                                        create_directory(strTrashDir + aParentPath);
1358 +                                lastPos = curPos + 1;
1359 +                                curPos = thePath.find("/", lastPos);
1360 +                                aParentPath = aParentPath + "/";
1361 +                        }
1362 + #ifndef WIN32
1363 +                        rename((path)("../" + thePath), (path)(strTrashDir + thePath));
1364 + #else
1365 +                        remove((path)("../" + thePath));
1366 + #endif
1367 +                }
1368 +        }
1369 +        
1370 +        // Now we crawl the update's package folders for newer versions and move them over, trashing ones that are already present
1371 +        vector<ModPackage> updatePackages, currentPackages;
1372 +        bool matchFound;
1373 +        updatePackages.reserve(256);
1374 +        currentPackages.reserve(256);
1375 +        
1376 +        currentPackages = getPackages();
1377 +        updatePackages = getPackages(strPathToEUFNPackages);
1378 +
1379 +        for (vector<ModPackage>::iterator iter1 = updatePackages.begin(); iter1 != updatePackages.end(); iter1++)
1380 +        {
1381 +                matchFound = false;
1382 +                for (vector<ModPackage>::iterator iter2 = currentPackages.begin(); iter2 != currentPackages.end(); iter2++)
1383 +                {
1384 +                        if (!iter1->modStringName.compare(iter2->modStringName))
1385 +                        {
1386 +                                matchFound = true;
1387 +                                if (iter1->modStringVersion > iter2->modStringVersion)
1388 +                                {
1389 + #ifndef WIN32
1390 +                                        rename((path)(strPathToPackages + iter2->modStringName), (path)(strTrashDir + iter2->modStringName));
1391 + #else
1392 +                                        remove((path)(strPathToPackages + iter2->modStringName));
1393 + #endif
1394 +                                        rename((path)(strPathToEUFNPackages + iter1->modStringName), (path)(strPathToPackages + iter1->modStringName));
1395 +                                }
1396 +                        }
1397 +                }
1398 +                if (!matchFound) // then there's no old package in the way, so just move in the one from the update
1399 +                        rename((path)(strPathToEUFNPackages + iter1->modStringName), (path)(strPathToPackages + iter1->modStringName));
1400 +        }
1401 +        
1402 +        // Next, we get a list of which files and folders in the update's Globalize folder to move over; all files not starting with '.' will be moved...
1403 +        // ...and folders which do not exist in the current AE will be created there
1404 +        vector<string> foldersToMake, filesToMove;
1405 +        string thePath;
1406 +        for (recursive_directory_iterator dir_itr(strPathToEUFNPackages + strGlobalize), end_itr; dir_itr != end_itr; ++dir_itr)
1407 +        {
1408 +                thePath = dir_itr->path().string();
1409 +                MakePathLocalToGlobalize(&thePath);
1410 +                if (is_regular_file(dir_itr->status()))
1411 +                {
1412 +                        if (dir_itr->filename().at(0) != '.') // skip over dot-files, which are invisible in Unix
1413 +                                filesToMove.push_back(thePath);
1414 +                }
1415 +                else if (is_directory(dir_itr->status()))
1416 +                {
1417 +                        if (!exists(strPathToPackages + strGlobalize + thePath))
1418 +                                foldersToMake.push_back(thePath);
1419 +                }
1420 +        }
1421 +        // Sort the foldersToMake strings by length, which is a fast solution to the problem of "How do we make sure we create folder 'parent/'...
1422 +        // ...before folder 'parent/child/'"?
1423 +        sort(foldersToMake.begin(), foldersToMake.end(), SortBySize); // SortBySize is a custom comparison function found later in this source file
1424 +        // First make the folders that don't exist in the current AE, so all the files have a place to go
1425 +        for (vector<string>::iterator iter = foldersToMake.begin(); iter != foldersToMake.end(); iter++)
1426 +        {
1427 +                create_directory(strPathToPackages + strGlobalize + *iter);
1428 +        }
1429 +        for (vector<string>::iterator iter = filesToMove.begin(); iter != filesToMove.end(); iter++)
1430 +        {
1431 +                if (exists(strPathToPackages + strGlobalize + *iter))
1432 +                        rename((path)(strPathToPackages + strGlobalize + *iter), (path)(strTrashDir + *iter));
1433 +                rename((path)(strPathToEUFNPackages + strGlobalize + *iter), (path)(strPathToPackages + strGlobalize + *iter));
1434 +        }
1435 +        
1436 +        // Clean up after ourselves, trashing any packages or programs in the update package that are not newer than the current AE
1437 +        create_directory(strTrashDir + "Unneeded update files");
1438 +        rename((path)strPathToEUFN, (path)(strTrashDir + "Unneeded update files/" + strEUFN));
1439 +        
1440 +        // Write to log that we are finished with update
1441 +        ptime end_time(second_clock::local_time());
1442 +        string progressMsg2 = "Edition was updated to:\n" +
1443 +                                                  updateAE->AEVersion + " on " + to_simple_string(end_time);
1444 +        
1445 +        file.open("Update.log");
1446 +        
1447 +        if(!file.fail())
1448 +                file.write(progressMsg2.c_str(), sizeof(progressMsg2.c_str()));
1449 +        
1450 +        file.close();
1451 +        file.clear();
1452 +        
1453 +        if (updateAE->globalizationRequired)
1454 +                CheckForGlobalization(true); // the 'true' value forces re-globalization
1455 +        
1456 +        globalPackages = getPackages(); // refresh the list in memory
1457 +        
1458 +        // TODO: Refresh the packages list in the window
1459 +
1460 +        return true;
1461 + }
1462 +
1463 + /* MakePathLocalToGlobalize is a function used once by ProcessAEUpdate() that takes a file in an        \
1464 + |  update's Globalize folder and changes its path, originally relative to the Installer, to be          |
1465 + |  relative to the structure of the Globalize folder; this makes it easier to have the Installer        |
1466 + \  move said file from an update's Globalize folder to the current Globalize folder.               */
1467 + void MakePathLocalToGlobalize(string *installerBasedPath)
1468 + {
1469 +        int deleteToHere = 0;
1470 +        deleteToHere = installerBasedPath->find("Globalize/");
1471 +        if (deleteToHere != 0)
1472 +        {
1473 +                deleteToHere += strlen("Globalize/");
1474 +                installerBasedPath->erase(0, deleteToHere);
1475 +        }
1476 + }
1477 +
1478 + /* SortBySize is a custom comparison function that we call when using the C++ sort() function in \
1479 + \  ProcessAEUpdate() on some strings that we want to sort by length.                                                    */
1480 + bool SortBySize(string a, string b)
1481 + {
1482 +        return (a.size() < b.size());
1483 + }
1484 +
1485   //stolen token function...
1486   void tokenize(const string& str, vector<string>& tokens, const string& delimiters)
1487   {
# Line 848 | Line 1501 | void tokenize(const string& str, vector<
1501          }
1502   }
1503  
1504 + /* StripNewlines() gets rids of any linebreaks that come from text returned by getline(); \
1505 + |  getline() should be stripping those out, but Windows CR/LF files seem to be sneaking   |
1506 + \  some extra return characters into strings in the ReadInstallInfoCfg() function.               */
1507 + void StripNewlines(string *theLine)
1508 + {
1509 +        int deleteFromHere = 0;
1510 +        deleteFromHere = theLine->find("\r");
1511 +        if (deleteFromHere > 0)
1512 +                theLine->erase(deleteFromHere, theLine->size());
1513 + }
1514 +
1515   void clearOldDats(void) {
1516          directory_iterator end_iter_gdf;
1517          for ( directory_iterator dir_itr_gdf( "../GameDataFolder" );
1518                   dir_itr_gdf != end_iter_gdf;
1519                   ++dir_itr_gdf )
1520          {
857                //cout << dir_itr_gdf->path().extension() << "\n";
1521                  if ( dir_itr_gdf->path().extension() == ".dat" || dir_itr_gdf->path().extension() == ".raw" || dir_itr_gdf->path().extension() == ".sep" ) {
1522                          remove( dir_itr_gdf->path() );
1523                  }
1524                  
1525          }
1526          
1527 < }
1527 > }
1528 >
1529 > // this function copies files and directories. If copying a
1530 > // directory to a directory, it copies recursively.
1531 >
1532 > //pardon the mess, I did this at midnight, and had to fix a bug
1533 > void copy( const path & from_ph,
1534 >                  const path & to_ph )
1535 > {
1536 >        cout << to_ph.string() << "\n";
1537 >        // Make sure that the destination, if it exists, is a directory
1538 >        if((exists(to_ph) && !is_directory(to_ph)) || (!exists(from_ph))) cout << "error";
1539 >        if(!is_directory(from_ph))
1540 >        {
1541 >                
1542 >                if(exists(to_ph))
1543 >                {
1544 >                        copy_file(from_ph,to_ph/from_ph.filename());
1545 >                }
1546 >                else
1547 >                {
1548 >                        try{
1549 >                                
1550 >                                copy_file(from_ph,to_ph);
1551 >                        }
1552 >                        catch (exception ex){
1553 >                                cout << from_ph.string() << " to " << to_ph.string() << "\n";
1554 >                        }
1555 >                }
1556 >                
1557 >        }
1558 >        else if(from_ph.filename() != ".svn")
1559 >        {
1560 >                path destination;
1561 >                if(!exists(to_ph))
1562 >                {
1563 >                        destination=to_ph;
1564 >                }
1565 >                else
1566 >                {
1567 >                        destination=to_ph/from_ph.filename();
1568 >                }
1569 >                
1570 >                for(directory_iterator i(from_ph); i!=directory_iterator(); ++i)
1571 >                {
1572 >                        //the idiot who coded this in the first place (not me)
1573 >                        //forgot to make a new directory. Exception city. x_x
1574 >                        create_directory(destination);
1575 >                        copy(*i,destination/i->filename());
1576 >                }
1577 >        }
1578 > }
1579 >
1580 > void copy_directory( const path &from_dir_ph,
1581 >                                        const path &to_dir_ph)
1582 > {
1583 >        if(!exists(from_dir_ph) || !is_directory(from_dir_ph)
1584 >           || exists(to_dir_ph))
1585 >                cout << !exists(from_dir_ph) << " " << !is_directory(from_dir_ph)
1586 >                << " " << exists(to_dir_ph);
1587 >        
1588 > # ifdef BOOST_POSIX
1589 >        struct stat from_stat;
1590 >        if ( (::stat( from_dir_ph.string().c_str(), &from_stat ) != 0)
1591 >                || ::mkdir(to_dir_ph.native_directory_string().c_str(),
1592 >                                   from_stat.st_mode)!=0)
1593 > # endif
1594 >                }
1595 >
1596 > string escapePath(string input)
1597 > {
1598 >        string output;
1599 >        string escape_me = "& ;()|<>\"'\\#*?$";
1600 >        for (unsigned int i = 0; i < input.size(); i++)
1601 >        {
1602 >                for (unsigned int j = 0; j < escape_me.size(); j++)
1603 >                        if (input[i] == escape_me[j])
1604 >                                output += '\\';
1605 >                output += input[i];
1606 >        }
1607 >        return output;
1608 > }
1609 >
1610 > Install_info_cfg::Install_info_cfg()
1611 > {
1612 >        AEVersion = "2009-07b";
1613 >        InstallerVersion = "1.0.1";
1614 >        DaodanVersion = "1.0";
1615 >        OniSplitVersion = "0.9.38.0";
1616 >        WinGUIVersion = "0";
1617 >        MacGUIVersion = "0";
1618 >        patch = false;
1619 >        globalizationRequired = false;
1620 >        deleteList.reserve(255);
1621 > }
1622 >
1623 > ModPackage::ModPackage()
1624 > {
1625 >        isInstalled = true; // replace with function
1626 >        name = "";
1627 >        modStringName = "";
1628 >        modStringVersion = 0;
1629 >        platform = "Both";
1630 >        hasOnis = false;
1631 >        hasDeltas = false;
1632 >        hasBSL = false;
1633 >        hasAddon = false;
1634 >        hasDats = false;
1635 >        category = "";
1636 >        creator = "";
1637 >        isEngine = false;
1638 >        readme = "";
1639 >        globalNeeded = true;
1640 > }
1641 > #ifndef WIN32
1642 > void Sleep(int ms)
1643 > {
1644 >        sleep(ms / 1000);
1645 > }
1646 > #endif
1647 > #ifdef WIN32
1648 >
1649 > void RedirectIOToConsole()
1650 > {
1651 >        int hConHandle;
1652 >        long lStdHandle;
1653 >        CONSOLE_SCREEN_BUFFER_INFO coninfo;
1654 >        FILE *fp;
1655 >        
1656 >        // allocate a console for this app
1657 >        AllocConsole();
1658 >        
1659 >        // set the screen buffer to be big enough to let us scroll text
1660 >        GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE),
1661 >                                                           &coninfo);
1662 >        coninfo.dwSize.Y = MAX_CONSOLE_LINES;
1663 >        SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE),
1664 >                                                           coninfo.dwSize);
1665 >        
1666 >        // redirect unbuffered STDOUT to the console
1667 >        lStdHandle = (long)GetStdHandle(STD_OUTPUT_HANDLE);
1668 >        hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
1669 >        fp = _fdopen( hConHandle, "w" );
1670 >        *stdout = *fp;
1671 >        setvbuf( stdout, NULL, _IONBF, 0 );
1672 >        
1673 >        // redirect unbuffered STDIN to the console
1674 >        lStdHandle = (long)GetStdHandle(STD_INPUT_HANDLE);
1675 >        hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
1676 >        fp = _fdopen( hConHandle, "r" );
1677 >        *stdin = *fp;
1678 >        setvbuf( stdin, NULL, _IONBF, 0 );
1679 >        
1680 >        // redirect unbuffered STDERR to the console
1681 >        lStdHandle = (long)GetStdHandle(STD_ERROR_HANDLE);
1682 >        hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
1683 >        fp = _fdopen( hConHandle, "w" );
1684 >        *stderr = *fp;
1685 >        setvbuf( stderr, NULL, _IONBF, 0 );
1686 >        
1687 >        // make cout, wcout, cin, wcin, wcerr, cerr, wclog and clog
1688 >        // point to console as well
1689 >        ios::sync_with_stdio();
1690 > }
1691 > #endif

Diff Legend

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