| 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 |
|
| 13 |
#include <errno.h> |
| 14 |
#ifdef WIN32 |
| 15 |
#include "Include\dirent.h" |
| 16 |
#else |
| 17 |
#include <dirent.h> //??? is this included for Macs? |
| 18 |
#endif |
| 19 |
#include <stdio.h> |
| 20 |
#include <stdlib.h> |
| 21 |
|
| 22 |
|
| 23 |
using namespace std; |
| 24 |
bool FALSE = 0; |
| 25 |
bool TRUE = 0; |
| 26 |
|
| 27 |
|
| 28 |
int main(void) |
| 29 |
{ |
| 30 |
|
| 31 |
// SetConsoleTitle("AE Installer"); windows junk, convert to SDL |
| 32 |
// system("color 0A"); |
| 33 |
|
| 34 |
cout << "\nWelcome to the AE installer!\n"; |
| 35 |
|
| 36 |
cout << "\nWhat would you like to do?\n"; |
| 37 |
|
| 38 |
return mainMenu(); |
| 39 |
} |
| 40 |
|
| 41 |
vector<ModPackage> getPackages(void) { |
| 42 |
vector<ModPackage> packages; |
| 43 |
packages.reserve(256); //thats 63 or 64 pointers to packages...i think. :P Reserving this improves performance when we add new pointers |
| 44 |
|
| 45 |
fstream file; |
| 46 |
|
| 47 |
#ifdef WIN32 |
| 48 |
string path = "K:\\Oni\\edition\\install\\packages"; //only for my build. :P |
| 49 |
#else |
| 50 |
string path = "K:\\Oni\\edition\\install\\packages"; //change this, 'scen. |
| 51 |
#endif |
| 52 |
|
| 53 |
string filename = "\0"; |
| 54 |
string MODINFO_CFG = "\\Mod_Info.cfg"; |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
DIR *pdir; |
| 59 |
struct dirent *pent; |
| 60 |
|
| 61 |
pdir = opendir( path.c_str() ); //"." refers to the current dir |
| 62 |
if (!pdir){ |
| 63 |
printf ("opendir() failure; terminating"); |
| 64 |
exit(1); |
| 65 |
} |
| 66 |
errno=0; |
| 67 |
|
| 68 |
while (( pent = readdir(pdir) )){ |
| 69 |
|
| 70 |
filename = path + '\\' + pent->d_name + MODINFO_CFG; |
| 71 |
file.open(filename.c_str()); |
| 72 |
|
| 73 |
//cout << filename << "\n"; |
| 74 |
|
| 75 |
if(!file.fail() ) |
| 76 |
{ |
| 77 |
//file.open(filename.c_str(), fstream::out); |
| 78 |
|
| 79 |
//do stuff like adding to vector :P |
| 80 |
|
| 81 |
//would prefer to push a pointer to a package, but this will do for now |
| 82 |
packages.push_back( fileToModPackage(file) ); |
| 83 |
|
| 84 |
} |
| 85 |
file.close(); |
| 86 |
file.clear(); |
| 87 |
|
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
if (errno){ |
| 92 |
printf ("readdir() failure; terminating"); |
| 93 |
exit(1); |
| 94 |
} |
| 95 |
closedir(pdir); |
| 96 |
|
| 97 |
|
| 98 |
return packages; |
| 99 |
} |
| 100 |
|
| 101 |
ModPackage fileToModPackage(fstream &file) { |
| 102 |
ModPackage package = {0, ""}; |
| 103 |
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 |
|
| 146 |
return package; |
| 147 |
} |
| 148 |
|
| 149 |
int mainMenu(void) { |
| 150 |
int choice = '0'; |
| 151 |
bool ok = FALSE; |
| 152 |
cout << "1. Install new packages\n"; |
| 153 |
cout << "2. Uninstall packages\n"; |
| 154 |
cout << "3. See what is installed\n"; |
| 155 |
cout << "4. About AE\n"; |
| 156 |
cout << "5. Quit\n\n"; |
| 157 |
|
| 158 |
do { |
| 159 |
ok = TRUE; |
| 160 |
choice = cin.get(); |
| 161 |
cin.ignore(1); |
| 162 |
switch(choice) { |
| 163 |
case '1': |
| 164 |
installPackages(); |
| 165 |
break; |
| 166 |
case '2': |
| 167 |
uninstallPackages(); |
| 168 |
break; |
| 169 |
case '3': |
| 170 |
//listInstalledPackages(); |
| 171 |
break; |
| 172 |
case '5': |
| 173 |
return 0; |
| 174 |
default: |
| 175 |
ok = FALSE; |
| 176 |
} |
| 177 |
} while(ok == FALSE); |
| 178 |
return 0; |
| 179 |
} |
| 180 |
|
| 181 |
|
| 182 |
void installPackages() { |
| 183 |
ModPackage package; |
| 184 |
vector<string> installed_packages; |
| 185 |
vector<ModPackage> packages; // = getPackages() |
| 186 |
vector<ModPackage>::iterator iter; |
| 187 |
iter = packages.begin(); |
| 188 |
|
| 189 |
getPackages(); |
| 190 |
|
| 191 |
if (packages.empty()) { |
| 192 |
cout << "Error: You have no packages!\n"; |
| 193 |
return; |
| 194 |
} |
| 195 |
|
| 196 |
cout << "Detecting installed packages...\n"; |
| 197 |
|
| 198 |
for(int i = 0; i < packages.size();) { |
| 199 |
package = *iter; |
| 200 |
if(!package.isInstalled){ |
| 201 |
packages.erase(iter); |
| 202 |
} |
| 203 |
else { |
| 204 |
i++; |
| 205 |
iter++; |
| 206 |
} |
| 207 |
|
| 208 |
} |
| 209 |
|
| 210 |
if (packages.empty()) { |
| 211 |
cout << "Error: You have no installed packages!\n"; |
| 212 |
return; |
| 213 |
} |
| 214 |
|
| 215 |
//listInstalledPackages(packages); |
| 216 |
|
| 217 |
} |
| 218 |
void uninstallPackages() { |
| 219 |
; |
| 220 |
} |
| 221 |
|
| 222 |
void getInstalledPackages() { |
| 223 |
; |
| 224 |
} |