/* AE\Mod Installer. Needs getPackages() now! */ #include #include #include "methods.h" #include #include #include "Include\dirent.h" #include #include using namespace std; bool FALSE = 0; bool TRUE = 0; int main(void) { // SetConsoleTitle("AE Installer"); windows junk, convert to SDL // system("color 0A"); cout << "\nWelcome to the AE installer!\n"; cout << "\nWhat would you like to do?\n"; return mainMenu(); } vector getPackages(void) { vector packages; packages.reserve(256); //thats 63 or 64 pointers to packages...i think. :P Reserving this improves performance when we add new pointers #ifdef WIN32 string path = "K:\\Oni\\edition\\install\\packages"; //only for my build. :P #else string path = "K:\\Oni\\edition\\install\\packages"; //change this, 'scen. #endif string filename = "\0"; string MODINFO_CFG = "\\Mod_Info.cfg"; DIR *pdir; struct dirent *pent; pdir = opendir( path.c_str() ); //"." refers to the current dir if (!pdir){ printf ("opendir() failure; terminating"); exit(1); } errno=0; while ((pent=readdir(pdir))){ filename = path + '\\' + pent->d_name + MODINFO_CFG; //cout << filename << "\n"; if (FILE * file = fopen( filename.c_str(), "r")) { //do stuff like adding to vector :P cout << pent->d_name << "\n"; //would prefer to push a pointer to a package, but this will do for now //packages.push_back(modelfileToModPackage(file *)) fclose(file); } } if (errno){ printf ("readdir() failure; terminating"); exit(1); } closedir(pdir); return packages; } int mainMenu(void) { int choice = '0'; bool ok = FALSE; cout << "1. Install new packages\n"; cout << "2. Uninstall packages\n"; cout << "3. See what is installed\n"; cout << "4. About AE\n"; cout << "5. Quit\n\n"; do { ok = TRUE; choice = cin.get(); cin.ignore(1); switch(choice) { case '1': installPackages(); break; case '2': uninstallPackages(); break; case '3': //listInstalledPackages(); break; case '5': return 0; default: ok = FALSE; } } while(ok == FALSE); return 0; } void installPackages() { ModPackage package; vector installed_packages; vector packages; // = getPackages() vector::iterator iter; iter = packages.begin(); getPackages(); if (packages.empty()) { cout << "Error: You have no packages!\n"; return; } cout << "Detecting installed packages...\n"; for(int i = 0; i < packages.size();) { package = *iter; if(!package.isInstalled){ packages.erase(iter); } else { i++; iter++; } } if (packages.empty()) { cout << "Error: You have no installed packages!\n"; return; } //listInstalledPackages(packages); } void uninstallPackages() { ; } void getInstalledPackages() { ; }