Changeset 298 for AE/Installer/trunk/source
- Timestamp:
- Apr 28, 2009, 4:45:43 PM (16 years ago)
- Location:
- AE/Installer/trunk/source
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
AE/Installer/trunk/source/methods.h
r294 r298 4 4 5 5 using namespace std; 6 6 static string SLASHSLASH = "//"; 7 static string DIRSLASH = "\\"; 7 8 struct ModPackage { 8 9 bool isInstalled; //replace with function … … 21 22 ModPackage(); 22 23 void doOutput() { 23 24 25 26 27 28 29 30 31 32 33 34 35 }24 cout << "Mod: " << name; cout << "\n"; //remove this when done 25 cout << " String: " << modStringName << " v." << modStringVersion << "\n"; 26 cout << " Category: " << category << "\n"; 27 cout << " Creator: " << creator << "\n"; 28 cout << " HasOnis: " << hasOnis << "\n"; 29 cout << " HasBSL: " << hasBSL << "\n"; 30 cout << " HasDeltas: " << hasDeltas << "\n"; 31 cout << " HasDats: " << hasDats << "\n"; 32 cout << " IsEngine: " << isEngine << "\n"; 33 cout << " GlobalNeeded: " << globalNeeded << "\n"; 34 cout << " Readme: " << readme << "\n"; 35 cout << "\n"; 36 } 36 37 37 38 }; 38 39 //Initialization 39 40 ModPackage::ModPackage() { 40 isInstalled = 0; //replace with function41 42 43 44 45 46 47 48 49 50 51 52 53 // void doOutput() const54 // { };41 isInstalled = 1; //replace with function 42 name = ""; 43 modStringName = ""; 44 modStringVersion = 0; 45 hasOnis = 0; 46 hasDeltas = 0; 47 hasBSL = 0; 48 hasDats = 0; 49 category = ""; 50 creator = ""; 51 isEngine = 0; 52 readme = ""; 53 globalNeeded = 1; 54 // void doOutput() const 55 // { }; 55 56 } 56 57 57 58 int mainMenu(); 58 59 vector<ModPackage> getPackages(); 60 vector<string> getInstallString(); 59 61 ModPackage fileToModPackage(fstream&); 60 62 … … 62 64 void uninstallPackages(); 63 65 void getInstalledPackages(); 66 void RecompileAll( vector<string>); 64 67 65 68 bool getDirectoryContents(char , char &); 66 69 67 70 //stolen token function... 68 71 void Tokenize(const string& str, 69 72 vector<string>& tokens, … … 85 88 } 86 89 } 90 -
AE/Installer/trunk/source/subs.cpp
r294 r298 1 #define DEBUG 1 2 /* 2 3 AE\Mod Installer. … … 4 5 Needs getPackages() now! 5 6 */ 6 7 //#include <dir.h> 7 8 #include <string> 8 //#include <string.h> 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 9 19 #include <cctype> 10 20 #include <iostream> … … 13 23 #include <fstream> 14 24 25 26 15 27 #include <errno.h> 16 28 #ifdef WIN32 17 #include "Include\dirent.h" 29 #include "Include\dirent.h" 30 #include <windows.h> 31 static const string Onisplit = "Onisplit.exe"; 32 string import = "-import:nosep"; 18 33 #else 34 #include <stdlib.h> 19 35 #include <dirent.h> //??? is this included for Macs? 36 string import = "-import:sep"; 37 static const string Onisplit = "./mono Onisplit.exe"; 20 38 #endif 21 #include <stdio.h> 22 #include <stdlib.h> 23 24 39 40 41 42 using namespace boost::filesystem; 25 43 using namespace std; 26 bool FALSE = 0; 27 bool TRUE = 0; 28 44 //bool FALSE = 0; 45 //bool TRUE = 0; 46 47 const bool SPLIT = 1; 48 const bool NOT_SPLIT = 0; 49 50 bool splitInstances = SPLIT; 29 51 30 52 int main(void) 31 53 { 32 54 33 55 // SetConsoleTitle("AE Installer"); windows junk, convert to SDL 34 56 // system("color 0A"); … … 43 65 vector<ModPackage> getPackages(void) { 44 66 vector<ModPackage> packages; 45 packages.reserve(256); //thats 63 or 64 pointers to packages...i think. :P Reserving this improves performance when we add new pointers 46 67 packages.reserve(65536); //comeon, we shouldn't need this much space...right?! 47 68 fstream file; 48 69 #ifdef DEBUG 49 70 #ifdef WIN32 50 string path = "K:\\Oni\\edition\\install\\packages"; //only for my build. :P 71 string path = ".\\packages"; //only for my build. :P 72 _chdir(path.c_str()); 73 74 _chdir(".."); 75 cout << path; 51 76 #else 52 77 string path = "K:\\Oni\\edition\\install\\packages"; //change this, 'scen. 53 78 #endif 79 #else 80 string path = "."; 81 #endif 54 82 55 83 string filename = "\0"; … … 63 91 pdir = opendir( path.c_str() ); //"." refers to the current dir 64 92 if (!pdir){ 65 printf (" opendir() failure; terminating");93 printf ("\nopendir() failure; terminating"); 66 94 exit(1); 67 95 } … … 103 131 ModPackage fileToModPackage(fstream &file) { 104 132 /* 105 106 107 108 109 133 This converts a file to a ModPackage struct. 134 135 A few notes... 136 "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. 137 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. 110 138 */ 111 139 ModPackage package; 112 140 string line; 113 141 static string NameOfMod = "NameOfMod"; //used for comparing to the current token... 114 static string SLASHSLASH = "//";//I could have done it in reverse (*iter).compare("ModString") or142 //I could have done it in reverse (*iter).compare("ModString") or 115 143 static string ARROW = "->"; //did something like "ModString".compare(*iter), and it would have been 116 144 static string ModString = "ModString"; //functionably the same. … … 144 172 } 145 173 } 146 174 147 175 } 148 176 else if (!ModString.compare(*iter)) { … … 223 251 ok = TRUE; 224 252 choice = cin.get(); 225 cin.ignore(1 );253 cin.ignore(128, '\n'); 226 254 switch(choice) { 227 255 case '1': … … 247 275 ModPackage package; 248 276 vector<string> installed_packages; 249 vector<ModPackage> packages; // = getPackages()277 vector<ModPackage> packages; 250 278 vector<ModPackage>::iterator iter; 251 279 iter = packages.begin(); 252 253 getPackages(); 280 vector<string> installString; 281 packages = getPackages(); 282 vector<string> installedMods = getInstallString(); 254 283 255 284 if (packages.empty()) { … … 257 286 return; 258 287 } 259 260 288 cout << "Detecting installed packages...\n"; 261 262 for(int i = 0; i < packages.size();) { 263 package = *iter; 264 if(!package.isInstalled){ 265 packages.erase(iter); 266 } 267 else { 268 i++; 269 iter++; 270 } 271 272 } 273 274 if (packages.empty()) { 275 cout << "Error: You have no installed packages!\n"; 289 290 int index = 1; 291 char choice = '0'; 292 for (vector<ModPackage>::iterator package_iter = packages.begin(); package_iter != packages.end(); ++package_iter) { 293 if (!binary_search(installedMods.begin(), installedMods.end(), package_iter->modStringName)) { //package_iter->isInstalled :< I forgot about this... 294 //cout << index << " "; 295 system("cls"); 296 cout << (*package_iter).name <<"\n"; 297 for( int character = 1; character <= (*package_iter).name.length() - 1; character++) cout << char(196); //does extended ASCII work in UNIX? 298 cout << "\n" 299 << (*package_iter).readme << "\n" 300 << "\n" 301 << "Please enter a number choice\n" 302 << " 1. Install\n" 303 << " 2. Don't Install\n" 304 << ""; 305 index++; 306 choice = 0; 307 308 do { 309 choice = cin.get(); 310 cin.ignore(1280, '\n'); 311 } while(choice == 0); 312 if (choice == '1') { 313 cout << "\nInstalling...\n\n"; 314 if ( package_iter->hasOnis || ( package_iter->hasDeltas /*(*package_iter).isUnpacked */ )) { 315 installedMods.push_back(package_iter->modStringName); 316 317 system("PAUSE"); 318 319 320 } 321 } 322 323 } 324 } 325 if (index == 1) { 326 cout << "Error: All packages are already installed\n"; 276 327 return; 277 328 } 278 279 //listInstalledPackages(packages); 280 329 sort(installedMods.begin(), installedMods.end()); 330 331 //system(Onisplit.c_str()); 332 RecompileAll(installedMods); 333 system("PAUSE"); 281 334 } 282 335 void uninstallPackages() { … … 287 340 ; 288 341 } 342 343 void RecompileAll(vector<string> installedMods) { 344 cout << "Recompiling Data...\n"; 345 path vanilla_dir = "./packages/VanillaDats/"; 346 string importCommand = ""; 347 if(splitInstances == SPLIT){ 348 recursive_directory_iterator end_iter; 349 try { 350 for ( recursive_directory_iterator dir_itr( vanilla_dir ); 351 dir_itr != end_iter; 352 ++dir_itr ) 353 { 354 try 355 { 356 if ( is_directory( dir_itr->status() ) && dir_itr.level() == 1) 357 { 358 importCommand = Onisplit + " " + import + " " + dir_itr->path().parent_path().string() + '/' + dir_itr->path().filename(); 359 for (int i = 0; i < installedMods.size(); ++i) { 360 if (exists("packages/" + installedMods[i] + "/oni/" + dir_itr->path().parent_path().filename() + '/' + dir_itr->path().filename() )) 361 importCommand += " packages/" + installedMods[i] + "/oni/" + dir_itr->path().parent_path().filename() + '/' + dir_itr->path().filename(); 362 363 //else cout << " packages/VanillaDats/" + installedMods[i] + "/oni/"; 364 } 365 importCommand += " ../GameDataFolder/" + dir_itr->path().filename() + ".dat"; 366 system(importCommand.c_str()); 367 //cout << importCommand << "\n"; 368 } 369 } 370 catch ( const std::exception & ex ) 371 { 372 cout << "Warning, exception " << ex.what() << "!"; 373 } 374 } 375 } 376 catch( const std::exception & ex ) { 377 cout << "Warning, exception " << ex.what() << "!\n" 378 << "You probably need to reGlobalize.; 379 create_directory( "./packages/VanillaDats" ); 380 } 381 382 } 383 else if(splitInstances == NOT_SPLIT){ 384 directory_iterator end_iter; 385 for ( directory_iterator dir_itr( vanilla_dir ); 386 dir_itr != end_iter; 387 ++dir_itr ) 388 { 389 try 390 { 391 if ( is_directory( dir_itr->status() ) ) 392 { 393 system((Onisplit + " " + import + " " + vanilla_dir.string() + dir_itr->path().filename() + " " + "../GameDataFolder/" + dir_itr->path().filename() + ".dat").c_str()); 394 } 395 } 396 catch ( const std::exception & ex ) 397 { 398 cout << "Warning, something odd happened!\n"; 399 } 400 } 401 402 403 404 } 405 } 406 407 vector<string> getInstallString() { 408 system("PAUSE"); 409 vector<string> returnval; 410 string file_name = "../GameDataFolder/ImportList.cfg"; 411 string line; 412 fstream file; 413 if( exists(file_name) ) { 414 file.open(file_name.c_str()); 415 getline (file,line); 416 Tokenize(line, returnval); 417 file.close(); 418 file.clear(); 419 sort(returnval.begin(), returnval.end()); 420 421 } 422 else cout << "fail"; 423 424 return returnval; 425 }
Note:
See TracChangeset
for help on using the changeset viewer.