Changeset 294 for AE/Installer/trunk/source
- Timestamp:
- Apr 6, 2009, 5:13:01 AM (16 years ago)
- Location:
- AE/Installer/trunk/source
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
AE/Installer/trunk/source/methods.h
r293 r294 8 8 bool isInstalled; //replace with function 9 9 string name; 10 string modString; 10 string modStringName; 11 int modStringVersion; 11 12 bool hasOnis; 12 13 bool hasDeltas; 13 14 bool hasBSL; 14 15 bool hasDats; 15 boolcategory;16 string category; 16 17 string creator; 17 18 bool isEngine; 18 19 string readme; 19 20 bool globalNeeded; 21 ModPackage(); 22 void doOutput() { 23 cout << "Mod: " << name; cout << "\n"; //remove this when done 24 cout << " String: " << modStringName << " v." << modStringVersion << "\n"; 25 cout << " Category: " << category << "\n"; 26 cout << " Creator: " << creator << "\n"; 27 cout << " HasOnis: " << hasOnis << "\n"; 28 cout << " HasBSL: " << hasBSL << "\n"; 29 cout << " HasDeltas: " << hasDeltas << "\n"; 30 cout << " HasDats: " << hasDats << "\n"; 31 cout << " IsEngine: " << isEngine << "\n"; 32 cout << " GlobalNeeded: " << globalNeeded << "\n"; 33 cout << " Readme: " << readme << "\n"; 34 cout << "\n"; 35 } 36 20 37 }; 38 //Initialization 39 ModPackage::ModPackage() { 40 isInstalled = 0; //replace with function 41 name = ""; 42 modStringName = ""; 43 modStringVersion = 0; 44 hasOnis = 0; 45 hasDeltas = 0; 46 hasBSL = 0; 47 hasDats = 0; 48 category = ""; 49 creator = ""; 50 isEngine = 0; 51 readme = ""; 52 globalNeeded = 1; 53 // void doOutput() const 54 // { }; 55 } 21 56 22 57 int mainMenu(); … … 32 67 33 68 void Tokenize(const string& str, 34 35 69 vector<string>& tokens, 70 const string& delimiters = " ") 36 71 { 37 38 39 40 72 // Skip delimiters at beginning. 73 string::size_type lastPos = str.find_first_not_of(delimiters, 0); 74 // Find first "non-delimiter". 75 string::size_type pos = str.find_first_of(delimiters, lastPos); 41 76 42 43 44 45 46 47 48 49 50 77 while (string::npos != pos || string::npos != lastPos) 78 { 79 // Found a token, add it to the vector. 80 tokens.push_back(str.substr(lastPos, pos - lastPos)); 81 // Skip delimiters. Note the "not_of" 82 lastPos = str.find_first_not_of(delimiters, pos); 83 // Find next "non-delimiter" 84 pos = str.find_first_of(delimiters, lastPos); 85 } 51 86 } -
AE/Installer/trunk/source/subs.cpp
r293 r294 6 6 7 7 #include <string> 8 //#include <string.h> 9 #include <cctype> 8 10 #include <iostream> 9 11 #include "methods.h" … … 13 15 #include <errno.h> 14 16 #ifdef WIN32 15 17 #include "Include\dirent.h" 16 18 #else 17 19 #include <dirent.h> //??? is this included for Macs? 18 20 #endif 19 21 #include <stdio.h> … … 31 33 // SetConsoleTitle("AE Installer"); windows junk, convert to SDL 32 34 // system("color 0A"); 33 35 34 36 cout << "\nWelcome to the AE installer!\n"; 35 37 36 38 cout << "\nWhat would you like to do?\n"; 37 39 38 40 return mainMenu(); 39 41 } 40 42 41 43 vector<ModPackage> getPackages(void) { 42 44 vector<ModPackage> packages; 43 45 packages.reserve(256); //thats 63 or 64 pointers to packages...i think. :P Reserving this improves performance when we add new pointers 44 46 45 47 fstream file; 46 47 48 49 50 51 48 49 #ifdef WIN32 50 string path = "K:\\Oni\\edition\\install\\packages"; //only for my build. :P 51 #else 52 string path = "K:\\Oni\\edition\\install\\packages"; //change this, 'scen. 53 #endif 52 54 53 55 string filename = "\0"; 54 56 string MODINFO_CFG = "\\Mod_Info.cfg"; 55 57 56 58 57 59 58 60 DIR *pdir; … … 67 69 68 70 while (( pent = readdir(pdir) )){ 69 71 70 72 filename = path + '\\' + pent->d_name + MODINFO_CFG; 71 73 file.open(filename.c_str()); … … 76 78 { 77 79 //file.open(filename.c_str(), fstream::out); 78 80 79 81 //do stuff like adding to vector :P 80 82 81 83 //would prefer to push a pointer to a package, but this will do for now 82 84 packages.push_back( fileToModPackage(file) ); 83 85 84 86 } 85 87 file.close(); 86 88 file.clear(); 87 88 } 89 90 89 90 } 91 92 91 93 if (errno){ 92 94 printf ("readdir() failure; terminating"); 93 exit(1);95 exit(1); 94 96 } 95 97 closedir(pdir); 96 97 98 99 98 100 return packages; 99 101 } 100 102 101 103 ModPackage fileToModPackage(fstream &file) { 102 ModPackage package = {0, ""}; 104 /* 105 This converts a file to a ModPackage struct. 106 107 A few notes... 108 "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. 109 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 */ 111 ModPackage package; 103 112 string line; 104 static string NameOfMod = "NameOfMod"; //used for comparing to the current token 105 static string SLASHSLASH = "//"; 106 static string ARROW = "->"; 107 while (! file.eof() ) 108 { 109 getline (file,line); 110 vector<string> tokens; 111 vector<string>::iterator iter; 112 Tokenize(line, tokens); //string to vector of "words" 113 if (tokens.capacity() >= 2) { //make sure they are using enough stuff 114 iter = tokens.begin(); //what word we are on, starts at first word 115 /* 116 if (!AEInstallVersion.compare(*iter)) 117 If mod is too old, skip this mod. 118 */ 119 /*else*/if (!NameOfMod.compare(*iter)) { //if it contains the name 120 for ( ; iter !=tokens.end() && SLASHSLASH.compare(*iter); iter++) { //interates through the words, ends if it reaches the end of the line or a "//" comment 121 if (ARROW.compare(*iter) && NameOfMod.compare(*iter)) { //ignores "->" and "NameOfMod" 122 //cout << *iter; 123 //cout << " "; 124 package.name += *iter + " "; 125 } 126 } 127 cout << package.name; cout << "\n"; //remove this when done 128 /* 129 else if (!ModString.compare(*iter) 130 else if (!HasOnis.compare(*iter) 131 else if (!HasDeltas.compare(*iter) 132 else if (!HasBSL.compare(*iter) 133 else if (!HasDats.compare(*iter) 134 else if (!Category.compare(*iter) 135 else if (!Creator.compare(*iter) 136 else if (!IsEngine.compare(*iter) 137 else if (!Readme.compare(*iter) 138 else if (!GlobalNeeded.compare(*iter) 139 */ 140 } 141 //cout << *iter; 142 } 143 144 } 145 113 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") or 115 static string ARROW = "->"; //did something like "ModString".compare(*iter), and it would have been 116 static string ModString = "ModString"; //functionably the same. 117 static string HasOnis = "HasOnis"; 118 static string HasDeltas = "HasDeltas"; 119 static string HasBSL = "HasBSL"; 120 static string HasDats = "HasDats"; 121 static string IsEngine = "IsEngine"; 122 static string Readme = "Readme"; 123 static string GlobalNeeded = "GlobalNeeded"; 124 static string Category = "Category"; 125 static string Creator = "Creator"; 126 while (! file.eof() ) 127 { 128 getline (file,line); 129 vector<string> tokens; 130 vector<string>::iterator iter; 131 Tokenize(line, tokens); //string to vector of "words" 132 if (tokens.capacity() >= 2) { //make sure they are using enough stuff 133 iter = tokens.begin(); //what word we are on, starts at first word 134 /* 135 if (!AEInstallVersion.compare(*iter)) 136 If mod is too old, skip this mod. 137 */ 138 /*else*/if (!NameOfMod.compare(*iter)) { //if it contains the name 139 for ( ; iter !=tokens.end() && SLASHSLASH.compare(*iter); iter++) { //interates through the words, ends if it reaches the end of the line or a "//" comment 140 if (ARROW.compare(*iter) && NameOfMod.compare(*iter)) { //ignores "->" and "NameOfMod" 141 //cout << *iter; 142 //cout << " "; 143 package.name += *iter + " "; 144 } 145 } 146 147 } 148 else if (!ModString.compare(*iter)) { 149 iter++; iter++; 150 package.modStringName = *iter; 151 iter++; 152 package.modStringVersion = atoi((*iter).c_str()); 153 } 154 else if (!HasOnis.compare(*iter)) { 155 iter++; iter++; 156 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. :< 157 } 158 else if (!HasBSL.compare(*iter)) { 159 iter++; iter++; 160 if (toupper((*iter)[0]) + toupper((*iter)[1]) + toupper((*iter)[2]) == 'Y' + 'E' + 'S') package.hasBSL = 1; 161 } 162 else if (!HasDeltas.compare(*iter)) { 163 iter++; iter++; 164 if (toupper((*iter)[0]) + toupper((*iter)[1]) + toupper((*iter)[2]) == 'Y' + 'E' + 'S') package.hasDeltas = 1; 165 } 166 else if (!HasDats.compare(*iter)) { 167 iter++; iter++; 168 if (toupper((*iter)[0]) + toupper((*iter)[1]) + toupper((*iter)[2]) == 'Y' + 'E' + 'S') package.hasDats = 1; 169 } 170 else if (!IsEngine.compare(*iter)) { 171 iter++; iter++; 172 if (toupper((*iter)[0]) + toupper((*iter)[1]) + toupper((*iter)[2]) == 'Y' + 'E' + 'S') package.isEngine = 1; 173 } 174 else if (!GlobalNeeded.compare(*iter)) { 175 iter++; iter++; 176 if (toupper((*iter)[0]) + toupper((*iter)[1]) + toupper((*iter)[2]) == 'Y' + 'E' + 'S') package.globalNeeded = 1; 177 else if (toupper((*iter)[0]) + toupper((*iter)[1]) == 'N' + 'O') package.globalNeeded = 1; //Really the only place where checking for "No" is important atm. 178 } 179 else if (!Category.compare(*iter)) { 180 for ( ; iter !=tokens.end() && SLASHSLASH.compare(*iter); iter++) { //interates through the words, ends if it reaches the end of the line or a "//" comment 181 if (ARROW.compare(*iter) && Category.compare(*iter)) { //ignores "->" and "Category" 182 //cout << *iter; 183 //cout << " "; 184 package.category += *iter + " "; 185 } 186 } 187 } 188 else if (!Creator.compare(*iter)) { //if it contains the name 189 for ( ; iter !=tokens.end() && SLASHSLASH.compare(*iter); iter++) { //interates through the words, ends if it reaches the end of the line or a "//" comment 190 if (ARROW.compare(*iter) && Creator.compare(*iter)) { //ignores "->" and "Category" 191 //cout << *iter; 192 //cout << " "; 193 package.creator += *iter + " "; 194 } 195 } 196 } 197 else if (!Readme.compare(*iter)) { //if it contains the name 198 for ( ; iter !=tokens.end() && SLASHSLASH.compare(*iter); iter++) { //interates through the words, ends if it reaches the end of the line or a "//" comment 199 if (ARROW.compare(*iter) && Readme.compare(*iter)) { //ignores "->" and "Category" 200 //cout << *iter; 201 //cout << " "; 202 package.readme += *iter + " "; 203 } 204 } 205 } 206 } 207 208 } 209 package.doOutput(); 146 210 return package; 147 211 } … … 155 219 cout << "4. About AE\n"; 156 220 cout << "5. Quit\n\n"; 157 221 158 222 do { 159 223 ok = TRUE; … … 186 250 vector<ModPackage>::iterator iter; 187 251 iter = packages.begin(); 188 252 189 253 getPackages(); 190 254 … … 193 257 return; 194 258 } 195 259 196 260 cout << "Detecting installed packages...\n"; 197 198 261 262 for(int i = 0; i < packages.size();) { 199 263 package = *iter; 200 264 if(!package.isInstalled){ … … 205 269 iter++; 206 270 } 207 208 } 209 271 272 } 273 210 274 if (packages.empty()) { 211 275 cout << "Error: You have no installed packages!\n"; 212 276 return; 213 277 } 214 278 215 279 //listInstalledPackages(packages); 216 280 217 281 } 218 282 void uninstallPackages() { 219 ;283 ; 220 284 } 221 285 222 286 void getInstalledPackages() { 223 ;224 } 287 ; 288 }
Note:
See TracChangeset
for help on using the changeset viewer.