| 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 |
#include "Include\dirent.h" |
| 15 |
#include <stdio.h> |
| 16 |
#include <stdlib.h> |
| 17 |
|
| 18 |
|
| 19 |
using namespace std; |
| 20 |
bool FALSE = 0; |
| 21 |
bool TRUE = 0; |
| 22 |
|
| 23 |
|
| 24 |
int main(void) |
| 25 |
{ |
| 26 |
|
| 27 |
// SetConsoleTitle("AE Installer"); windows junk, convert to SDL |
| 28 |
// system("color 0A"); |
| 29 |
|
| 30 |
cout << "\nWelcome to the AE installer!\n"; |
| 31 |
|
| 32 |
cout << "\nWhat would you like to do?\n"; |
| 33 |
|
| 34 |
return mainMenu(); |
| 35 |
} |
| 36 |
|
| 37 |
vector<ModPackage> getPackages(void) { |
| 38 |
vector<ModPackage> packages; |
| 39 |
packages.reserve(256); //thats 63 or 64 pointers to packages...i think. :P Reserving this improves performance when we add new pointers |
| 40 |
|
| 41 |
fstream file; |
| 42 |
|
| 43 |
#ifdef WIN32 |
| 44 |
string path = "K:\\Oni\\edition\\install\\packages"; //only for my build. :P |
| 45 |
#else |
| 46 |
string path = "K:\\Oni\\edition\\install\\packages"; //change this, 'scen. |
| 47 |
#endif |
| 48 |
|
| 49 |
string filename = "\0"; |
| 50 |
string MODINFO_CFG = "\\Mod_Info.cfg"; |
| 51 |
|
| 52 |
string line; |
| 53 |
|
| 54 |
DIR *pdir; |
| 55 |
struct dirent *pent; |
| 56 |
|
| 57 |
pdir = opendir( path.c_str() ); //"." refers to the current dir |
| 58 |
if (!pdir){ |
| 59 |
printf ("opendir() failure; terminating"); |
| 60 |
exit(1); |
| 61 |
} |
| 62 |
errno=0; |
| 63 |
|
| 64 |
while (( pent = readdir(pdir) )){ |
| 65 |
|
| 66 |
filename = path + '\\' + pent->d_name + MODINFO_CFG; |
| 67 |
file.open(filename.c_str()); |
| 68 |
|
| 69 |
//cout << filename << "\n"; |
| 70 |
|
| 71 |
if(!file.fail() ) |
| 72 |
{ |
| 73 |
//file.open(filename.c_str(), fstream::out); |
| 74 |
|
| 75 |
//do stuff like adding to vector :P |
| 76 |
cout << pent->d_name << "\n"; |
| 77 |
while (! file.eof() ) |
| 78 |
{ |
| 79 |
getline (file,line); |
| 80 |
cout << line << endl; |
| 81 |
} |
| 82 |
//would prefer to push a pointer to a package, but this will do for now |
| 83 |
//packages.push_back( fileToModPackage(file) ); |
| 84 |
|
| 85 |
} |
| 86 |
file.close(); |
| 87 |
file.clear(); |
| 88 |
|
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
if (errno){ |
| 93 |
printf ("readdir() failure; terminating"); |
| 94 |
exit(1); |
| 95 |
} |
| 96 |
closedir(pdir); |
| 97 |
|
| 98 |
|
| 99 |
return packages; |
| 100 |
} |
| 101 |
|
| 102 |
ModPackage fileToModPackage(fstream file) { |
| 103 |
ModPackage package; |
| 104 |
cout << file; |
| 105 |
return package; |
| 106 |
} |
| 107 |
|
| 108 |
int mainMenu(void) { |
| 109 |
int choice = '0'; |
| 110 |
bool ok = FALSE; |
| 111 |
cout << "1. Install new packages\n"; |
| 112 |
cout << "2. Uninstall packages\n"; |
| 113 |
cout << "3. See what is installed\n"; |
| 114 |
cout << "4. About AE\n"; |
| 115 |
cout << "5. Quit\n\n"; |
| 116 |
|
| 117 |
do { |
| 118 |
ok = TRUE; |
| 119 |
choice = cin.get(); |
| 120 |
cin.ignore(1); |
| 121 |
switch(choice) { |
| 122 |
case '1': |
| 123 |
installPackages(); |
| 124 |
break; |
| 125 |
case '2': |
| 126 |
uninstallPackages(); |
| 127 |
break; |
| 128 |
case '3': |
| 129 |
//listInstalledPackages(); |
| 130 |
break; |
| 131 |
case '5': |
| 132 |
return 0; |
| 133 |
default: |
| 134 |
ok = FALSE; |
| 135 |
} |
| 136 |
} while(ok == FALSE); |
| 137 |
return 0; |
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
void installPackages() { |
| 142 |
ModPackage package; |
| 143 |
vector<string> installed_packages; |
| 144 |
vector<ModPackage> packages; // = getPackages() |
| 145 |
vector<ModPackage>::iterator iter; |
| 146 |
iter = packages.begin(); |
| 147 |
|
| 148 |
getPackages(); |
| 149 |
|
| 150 |
if (packages.empty()) { |
| 151 |
cout << "Error: You have no packages!\n"; |
| 152 |
return; |
| 153 |
} |
| 154 |
|
| 155 |
cout << "Detecting installed packages...\n"; |
| 156 |
|
| 157 |
for(int i = 0; i < packages.size();) { |
| 158 |
package = *iter; |
| 159 |
if(!package.isInstalled){ |
| 160 |
packages.erase(iter); |
| 161 |
} |
| 162 |
else { |
| 163 |
i++; |
| 164 |
iter++; |
| 165 |
} |
| 166 |
|
| 167 |
} |
| 168 |
|
| 169 |
if (packages.empty()) { |
| 170 |
cout << "Error: You have no installed packages!\n"; |
| 171 |
return; |
| 172 |
} |
| 173 |
|
| 174 |
//listInstalledPackages(packages); |
| 175 |
|
| 176 |
} |
| 177 |
void uninstallPackages() { |
| 178 |
; |
| 179 |
} |
| 180 |
|
| 181 |
void getInstalledPackages() { |
| 182 |
; |
| 183 |
} |