| 1 |
< |
/* |
| 2 |
< |
AE\Mod Installer. |
| 3 |
< |
|
| 4 |
< |
Needs getPackages() now! |
| 5 |
< |
*/ |
| 6 |
< |
|
| 7 |
< |
#include <string> |
| 8 |
< |
#include <iostream> |
| 9 |
< |
#include "methods.h" |
| 10 |
< |
#include <vector> |
| 11 |
< |
#include <fstream> |
| 12 |
< |
|
| 1 |
> |
/* |
| 2 |
> |
AE\Mod Installer. |
| 3 |
> |
|
| 4 |
> |
Needs getPackages() now! |
| 5 |
> |
*/ |
| 6 |
> |
|
| 7 |
> |
#include <string> |
| 8 |
> |
//#include <string.h> |
| 9 |
> |
#include <cctype> |
| 10 |
> |
#include <iostream> |
| 11 |
> |
#include "methods.h" |
| 12 |
> |
#include <vector> |
| 13 |
> |
#include <fstream> |
| 14 |
> |
|
| 15 |
|
#include <errno.h> |
| 16 |
|
#ifdef WIN32 |
| 17 |
< |
#include "Include\dirent.h" |
| 17 |
> |
#include "Include\dirent.h" |
| 18 |
|
#else |
| 19 |
< |
#include <dirent.h> //??? is this included for Macs? |
| 19 |
> |
#include <dirent.h> //??? is this included for Macs? |
| 20 |
|
#endif |
| 21 |
|
#include <stdio.h> |
| 22 |
< |
#include <stdlib.h> |
| 23 |
< |
|
| 24 |
< |
|
| 25 |
< |
using namespace std; |
| 26 |
< |
bool FALSE = 0; |
| 27 |
< |
bool TRUE = 0; |
| 28 |
< |
|
| 29 |
< |
|
| 30 |
< |
int main(void) |
| 31 |
< |
{ |
| 32 |
< |
|
| 33 |
< |
// SetConsoleTitle("AE Installer"); windows junk, convert to SDL |
| 34 |
< |
// system("color 0A"); |
| 35 |
< |
|
| 36 |
< |
cout << "\nWelcome to the AE installer!\n"; |
| 37 |
< |
|
| 38 |
< |
cout << "\nWhat would you like to do?\n"; |
| 39 |
< |
|
| 40 |
< |
return mainMenu(); |
| 41 |
< |
} |
| 42 |
< |
|
| 43 |
< |
vector<ModPackage> getPackages(void) { |
| 44 |
< |
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 |
< |
|
| 47 |
< |
fstream file; |
| 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 |
| 54 |
< |
|
| 55 |
< |
string filename = "\0"; |
| 56 |
< |
string MODINFO_CFG = "\\Mod_Info.cfg"; |
| 57 |
< |
|
| 58 |
< |
|
| 59 |
< |
|
| 22 |
> |
#include <stdlib.h> |
| 23 |
> |
|
| 24 |
> |
|
| 25 |
> |
using namespace std; |
| 26 |
> |
bool FALSE = 0; |
| 27 |
> |
bool TRUE = 0; |
| 28 |
> |
|
| 29 |
> |
|
| 30 |
> |
int main(void) |
| 31 |
> |
{ |
| 32 |
> |
|
| 33 |
> |
// SetConsoleTitle("AE Installer"); windows junk, convert to SDL |
| 34 |
> |
// system("color 0A"); |
| 35 |
> |
|
| 36 |
> |
cout << "\nWelcome to the AE installer!\n"; |
| 37 |
> |
|
| 38 |
> |
cout << "\nWhat would you like to do?\n"; |
| 39 |
> |
|
| 40 |
> |
return mainMenu(); |
| 41 |
> |
} |
| 42 |
> |
|
| 43 |
> |
vector<ModPackage> getPackages(void) { |
| 44 |
> |
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 |
> |
|
| 47 |
> |
fstream file; |
| 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 |
| 54 |
> |
|
| 55 |
> |
string filename = "\0"; |
| 56 |
> |
string MODINFO_CFG = "\\Mod_Info.cfg"; |
| 57 |
> |
|
| 58 |
> |
|
| 59 |
> |
|
| 60 |
|
DIR *pdir; |
| 61 |
|
struct dirent *pent; |
| 62 |
|
|
| 68 |
|
errno=0; |
| 69 |
|
|
| 70 |
|
while (( pent = readdir(pdir) )){ |
| 71 |
< |
|
| 71 |
> |
|
| 72 |
|
filename = path + '\\' + pent->d_name + MODINFO_CFG; |
| 73 |
|
file.open(filename.c_str()); |
| 74 |
|
|
| 77 |
|
if(!file.fail() ) |
| 78 |
|
{ |
| 79 |
|
//file.open(filename.c_str(), fstream::out); |
| 80 |
< |
|
| 80 |
> |
|
| 81 |
|
//do stuff like adding to vector :P |
| 82 |
|
|
| 83 |
|
//would prefer to push a pointer to a package, but this will do for now |
| 84 |
|
packages.push_back( fileToModPackage(file) ); |
| 85 |
< |
|
| 85 |
> |
|
| 86 |
|
} |
| 87 |
|
file.close(); |
| 88 |
|
file.clear(); |
| 89 |
< |
|
| 89 |
> |
|
| 90 |
|
} |
| 91 |
|
|
| 92 |
< |
|
| 92 |
> |
|
| 93 |
|
if (errno){ |
| 94 |
|
printf ("readdir() failure; terminating"); |
| 95 |
< |
exit(1); |
| 95 |
> |
exit(1); |
| 96 |
|
} |
| 97 |
< |
closedir(pdir); |
| 98 |
< |
|
| 99 |
< |
|
| 100 |
< |
return packages; |
| 101 |
< |
} |
| 102 |
< |
|
| 103 |
< |
ModPackage fileToModPackage(fstream &file) { |
| 104 |
< |
ModPackage package = {0, ""}; |
| 105 |
< |
string line; |
| 106 |
< |
static string NameOfMod = "NameOfMod"; //used for comparing to the current token |
| 107 |
< |
static string SLASHSLASH = "//"; |
| 108 |
< |
static string ARROW = "->"; |
| 109 |
< |
while (! file.eof() ) |
| 110 |
< |
{ |
| 111 |
< |
getline (file,line); |
| 112 |
< |
vector<string> tokens; |
| 113 |
< |
vector<string>::iterator iter; |
| 114 |
< |
Tokenize(line, tokens); //string to vector of "words" |
| 115 |
< |
if (tokens.capacity() >= 2) { //make sure they are using enough stuff |
| 116 |
< |
iter = tokens.begin(); //what word we are on, starts at first word |
| 117 |
< |
/* |
| 118 |
< |
if (!AEInstallVersion.compare(*iter)) |
| 119 |
< |
If mod is too old, skip this mod. |
| 120 |
< |
*/ |
| 121 |
< |
/*else*/if (!NameOfMod.compare(*iter)) { //if it contains the name |
| 122 |
< |
for ( ; iter !=tokens.end() && SLASHSLASH.compare(*iter); iter++) { //interates through the words, ends if it reaches the end of the line or a "//" comment |
| 123 |
< |
if (ARROW.compare(*iter) && NameOfMod.compare(*iter)) { //ignores "->" and "NameOfMod" |
| 124 |
< |
//cout << *iter; |
| 125 |
< |
//cout << " "; |
| 126 |
< |
package.name += *iter + " "; |
| 127 |
< |
} |
| 128 |
< |
} |
| 129 |
< |
cout << package.name; cout << "\n"; //remove this when done |
| 130 |
< |
/* |
| 131 |
< |
else if (!ModString.compare(*iter) |
| 132 |
< |
else if (!HasOnis.compare(*iter) |
| 133 |
< |
else if (!HasDeltas.compare(*iter) |
| 134 |
< |
else if (!HasBSL.compare(*iter) |
| 135 |
< |
else if (!HasDats.compare(*iter) |
| 136 |
< |
else if (!Category.compare(*iter) |
| 137 |
< |
else if (!Creator.compare(*iter) |
| 138 |
< |
else if (!IsEngine.compare(*iter) |
| 139 |
< |
else if (!Readme.compare(*iter) |
| 140 |
< |
else if (!GlobalNeeded.compare(*iter) |
| 141 |
< |
*/ |
| 97 |
> |
closedir(pdir); |
| 98 |
> |
|
| 99 |
> |
|
| 100 |
> |
return packages; |
| 101 |
> |
} |
| 102 |
> |
|
| 103 |
> |
ModPackage fileToModPackage(fstream &file) { |
| 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; |
| 112 |
> |
string line; |
| 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 |
|
} |
| 141 |
– |
//cout << *iter; |
| 204 |
|
} |
| 205 |
< |
|
| 206 |
< |
} |
| 207 |
< |
|
| 208 |
< |
return package; |
| 209 |
< |
} |
| 210 |
< |
|
| 211 |
< |
int mainMenu(void) { |
| 212 |
< |
int choice = '0'; |
| 213 |
< |
bool ok = FALSE; |
| 214 |
< |
cout << "1. Install new packages\n"; |
| 215 |
< |
cout << "2. Uninstall packages\n"; |
| 216 |
< |
cout << "3. See what is installed\n"; |
| 217 |
< |
cout << "4. About AE\n"; |
| 218 |
< |
cout << "5. Quit\n\n"; |
| 219 |
< |
|
| 220 |
< |
do { |
| 221 |
< |
ok = TRUE; |
| 222 |
< |
choice = cin.get(); |
| 223 |
< |
cin.ignore(1); |
| 224 |
< |
switch(choice) { |
| 225 |
< |
case '1': |
| 226 |
< |
installPackages(); |
| 227 |
< |
break; |
| 228 |
< |
case '2': |
| 229 |
< |
uninstallPackages(); |
| 230 |
< |
break; |
| 231 |
< |
case '3': |
| 232 |
< |
//listInstalledPackages(); |
| 233 |
< |
break; |
| 234 |
< |
case '5': |
| 235 |
< |
return 0; |
| 236 |
< |
default: |
| 237 |
< |
ok = FALSE; |
| 238 |
< |
} |
| 239 |
< |
} while(ok == FALSE); |
| 240 |
< |
return 0; |
| 241 |
< |
} |
| 242 |
< |
|
| 243 |
< |
|
| 244 |
< |
void installPackages() { |
| 245 |
< |
ModPackage package; |
| 246 |
< |
vector<string> installed_packages; |
| 247 |
< |
vector<ModPackage> packages; // = getPackages() |
| 248 |
< |
vector<ModPackage>::iterator iter; |
| 249 |
< |
iter = packages.begin(); |
| 250 |
< |
|
| 251 |
< |
getPackages(); |
| 252 |
< |
|
| 253 |
< |
if (packages.empty()) { |
| 254 |
< |
cout << "Error: You have no packages!\n"; |
| 255 |
< |
return; |
| 256 |
< |
} |
| 257 |
< |
|
| 258 |
< |
cout << "Detecting installed packages...\n"; |
| 259 |
< |
|
| 260 |
< |
for(int i = 0; i < packages.size();) { |
| 261 |
< |
package = *iter; |
| 262 |
< |
if(!package.isInstalled){ |
| 263 |
< |
packages.erase(iter); |
| 264 |
< |
} |
| 265 |
< |
else { |
| 266 |
< |
i++; |
| 267 |
< |
iter++; |
| 268 |
< |
} |
| 269 |
< |
|
| 270 |
< |
} |
| 271 |
< |
|
| 272 |
< |
if (packages.empty()) { |
| 273 |
< |
cout << "Error: You have no installed packages!\n"; |
| 274 |
< |
return; |
| 275 |
< |
} |
| 276 |
< |
|
| 277 |
< |
//listInstalledPackages(packages); |
| 278 |
< |
|
| 279 |
< |
} |
| 280 |
< |
void uninstallPackages() { |
| 281 |
< |
; |
| 282 |
< |
} |
| 283 |
< |
|
| 284 |
< |
void getInstalledPackages() { |
| 285 |
< |
; |
| 286 |
< |
} |
| 205 |
> |
} |
| 206 |
> |
} |
| 207 |
> |
|
| 208 |
> |
} |
| 209 |
> |
package.doOutput(); |
| 210 |
> |
return package; |
| 211 |
> |
} |
| 212 |
> |
|
| 213 |
> |
int mainMenu(void) { |
| 214 |
> |
int choice = '0'; |
| 215 |
> |
bool ok = FALSE; |
| 216 |
> |
cout << "1. Install new packages\n"; |
| 217 |
> |
cout << "2. Uninstall packages\n"; |
| 218 |
> |
cout << "3. See what is installed\n"; |
| 219 |
> |
cout << "4. About AE\n"; |
| 220 |
> |
cout << "5. Quit\n\n"; |
| 221 |
> |
|
| 222 |
> |
do { |
| 223 |
> |
ok = TRUE; |
| 224 |
> |
choice = cin.get(); |
| 225 |
> |
cin.ignore(1); |
| 226 |
> |
switch(choice) { |
| 227 |
> |
case '1': |
| 228 |
> |
installPackages(); |
| 229 |
> |
break; |
| 230 |
> |
case '2': |
| 231 |
> |
uninstallPackages(); |
| 232 |
> |
break; |
| 233 |
> |
case '3': |
| 234 |
> |
//listInstalledPackages(); |
| 235 |
> |
break; |
| 236 |
> |
case '5': |
| 237 |
> |
return 0; |
| 238 |
> |
default: |
| 239 |
> |
ok = FALSE; |
| 240 |
> |
} |
| 241 |
> |
} while(ok == FALSE); |
| 242 |
> |
return 0; |
| 243 |
> |
} |
| 244 |
> |
|
| 245 |
> |
|
| 246 |
> |
void installPackages() { |
| 247 |
> |
ModPackage package; |
| 248 |
> |
vector<string> installed_packages; |
| 249 |
> |
vector<ModPackage> packages; // = getPackages() |
| 250 |
> |
vector<ModPackage>::iterator iter; |
| 251 |
> |
iter = packages.begin(); |
| 252 |
> |
|
| 253 |
> |
getPackages(); |
| 254 |
> |
|
| 255 |
> |
if (packages.empty()) { |
| 256 |
> |
cout << "Error: You have no packages!\n"; |
| 257 |
> |
return; |
| 258 |
> |
} |
| 259 |
> |
|
| 260 |
> |
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"; |
| 276 |
> |
return; |
| 277 |
> |
} |
| 278 |
> |
|
| 279 |
> |
//listInstalledPackages(packages); |
| 280 |
> |
|
| 281 |
> |
} |
| 282 |
> |
void uninstallPackages() { |
| 283 |
> |
; |
| 284 |
> |
} |
| 285 |
> |
|
| 286 |
> |
void getInstalledPackages() { |
| 287 |
> |
; |
| 288 |
> |
} |