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