--- AE/Installer/trunk/source/main_window.cpp 2009/06/14 23:28:58 353 +++ AE/Installer/trunk/source/main_window.cpp 2010/03/24 07:12:25 503 @@ -1,888 +1,23 @@ -/* - AE/Mod Installer - by Gumby and Iritscen - */ - -// To-do: - Disable Install button when nothing (new) is selected -// - Institute lots of checks into file-handling -// - Clear mod info fields when mod is de-selected - -#define DEBUG -#include -//#include -//#include -#include -#include -#include -#include -#include -#include -#include - -#include "boost/filesystem.hpp" // includes all needed Boost.Filesystem declarations - -#include "installer.h" - -#ifdef WIN32 -#include -#else // assume we're on Mac -#include -#include -#endif - -const string strInstallerVersion = "1.0"; -const bool SPLIT = 1; -const bool NOT_SPLIT = 0; -bool splitInstances = SPLIT; +/***************************************************************************\ +| Project: AE Installer | +| By: Gumby & Iritscen | +| File: Main_Window.cpp | +| Function: Handles the GUI. | +| Created: 07/05/2009 20:38:25 | +\***************************************************************************/ -#ifdef WIN32 -const string strOniSplit = "Onisplit.exe"; -string strImportOption = "-import:nosep"; -const char* strClsCmd = "cls"; -const char* strPauseCmd = "PAUSE"; -#else // set up Mac equivalents since we're in Mac OS -const string strOniSplit = "mono Onisplit.exe"; -string strImportOption = "-import:sep"; -const char* strClsCmd = "clear"; -const char* strPauseCmd = "read -n 1 -p \"Press any key to continue\""; -void Sleep(int ms) { sleep( ms / 1000 ); } +#ifndef NTDDI_VERSION +#define NTDDI_VERSION NTDDI_WIN7 #endif - -using namespace boost::filesystem; -using namespace std; - - -/* - int main(void) - { - if ( exists( "../../GameDataFolder/level0_Final.sep" ) ) splitInstances = NOT_SPLIT; - else splitInstances = NOT_SPLIT; - // SetConsoleTitle("AE Installer"); windows junk, convert to SDL - #ifdef WIN32 - system("color 0A"); - #endif - cout << "\nWelcome to the AE installer!\n"; - cout << "\nWhat would you like to do?\n"; - - return mainMenu(); - } - */ - - - -int mainMenu(void) -{ - char choice = '0'; - bool exit = false; - int err = 0; - do - { - if( exists( "../GameDataFolder" ) ) { - cout << "\n1. Add new packages\n"; - cout << "2. Remove packages\n"; - cout << "3. See what is installed\n"; - cout << "4. Globalize data\n"; - cout << "5. About AE\n"; - cout << "6. Quit\n\n"; - - choice = cin.get(); - cin.ignore(128, '\n'); - switch(choice) - { - case '1': - err = installPackages(); - break; - case '2': - err = uninstallPackages(); - break; - case '3': - err = listInstalledPackages(); - break; - case '4': - err = globalizeData(); - break; - case '5': - err = printInstallerInfo(); - break; - case '6': - exit = true; - break; - default: - cout << "Please choose one of the above numbers, and press Enter.\n\n"; - } - if (err) // if something fatal happened - exit = true; - } - else { - cout << "\n1. Globalize data\n"; - cout << "2. About AE\n"; - cout << "3. Quit\n\n"; - - choice = cin.get(); - cin.ignore(128, '\n'); - switch(choice) - { - case '1': - err = globalizeData(); - break; - case '2': - err = printInstallerInfo(); - break; - case '3': - exit = true; - break; - default: - cout << "Please choose one of the above numbers, and press Enter.\n\n"; - } - if (err) // if something fatal happened - exit = true; - } - } while(!exit); - - return err; -} - -int globalizeData(void) -{ - int err = 0; - - try { - int levels[15] = {0, 1, 2, 3, 4, 6, 8, 9, 10, 11, 12, 13, 14, 18, 19}; // the levels Oni has - char choice = 0; - - //SetCurrentDirectory("C:/Program Files/Oni/edition/install"); - char levelnum[3]; - path Characters = "../GameDataFolder/level0_Characters"; - path Particles = "../GameDataFolder/level0_Particles"; - path Archive = "../GameDataFolder/Archive"; - path Textures = "../GameDataFolder/level0_Textures"; - path Sounds = "../GameDataFolder/level0_Sounds"; - path Animations = "../GameDataFolder/level0_Animations"; - path TRAC = Animations / "level0_TRAC"; - path TRAM = Animations / "level0_TRAM"; - /* - if (exists("../GameDataFolder/")) - { - //cout << "\nIt looks like you've already globalized Oni's data.\nDo you want to re-globalize?\n(This will erase existing mods installed to the AE's game data.)" - // << "\n1. Re-globalize" - // << "\n2. Return to main menu\n"; - //choice = cin.get(); - cin.ignore(128, '\n'); - if (choice == '1') - remove_all("../GameDataFolder"); // remove AE GDF - if (choice == '2') - return 0; - } - */ - create_directory( "../GameDataFolder/" ); - create_directory( "packages" ); - if (exists("packages/VanillaDats")) remove_all("packages/VanillaDats"); - create_directory( "packages/VanillaDats" ); - - create_directory( "packages/VanillaDats/level0_Final/" ); - create_directory( Characters ); - create_directory( Particles ); - create_directory( Archive ); - create_directory( Textures ); - create_directory( Sounds ); - create_directory( Animations ); - create_directory( TRAC ); - create_directory( TRAM ); - - for(int i = 0; i < 15; i++) - { - sprintf(levelnum,"%d",levels[i]); // int to char array - exists("../../GameDataFolder/level" + (string)levelnum + "_Final"); - system((strOniSplit + " -export ../GameDataFolder/level" + (string)levelnum + "_Final ../../GameDataFolder/level" + (string)levelnum + "_Final.dat").c_str()); - - create_directory( "packages/VanillaDats/level" + (string)levelnum + "_Final" ); //remember to cast your arrays as strings :) - create_directory( "packages/VanillaDats/level" + (string)levelnum + "_Final/level" + (string)levelnum + "_Final" ); - - directory_iterator end_iter; - for ( directory_iterator dir_itr( "../GameDataFolder/level" + (string)levelnum + "_Final" ); dir_itr != end_iter; ++dir_itr ) - { - //cout << dir_itr->path().filename(); - if ( is_regular_file( dir_itr->status() ) ) - { - - if ( dir_itr->path().filename().substr(0,8) == "TXMPfail" || - dir_itr->path().filename().substr(0,9) == "TXMPlevel" || - ( dir_itr->path().filename().substr(0,4) == "TXMP" && dir_itr->path().filename().find("intro")!=string::npos) || - dir_itr->path().filename().substr(0,4) == "TXMB" || - dir_itr->path().filename() == "M3GMpowerup_lsi.oni" || - dir_itr->path().filename() == "TXMPlsi_icon.oni" || - ( dir_itr->path().filename().substr(0,4) == "TXMB" && dir_itr->path().filename().find("splash_screen.oni")!=string::npos) ) - { - cout <path().filename() << "\n"; - create_directory( dir_itr->path().parent_path() / "NoGlobal"); - if(!exists( dir_itr->path().parent_path() / "NoGlobal" / dir_itr->filename())) rename(dir_itr->path(), dir_itr->path().parent_path() / "NoGlobal" / - dir_itr->filename()); - else remove(dir_itr->path()); - } - else if (dir_itr->path().filename().substr(0,4) == "TRAC") { - cout <path().filename() << "\n"; - if(!exists( TRAC / dir_itr->filename())) rename(dir_itr->path(), TRAC / dir_itr->filename()); - else remove(dir_itr->path()); - } - else if (dir_itr->path().filename().substr(0,4) == "TRAM") { - cout <path().filename() << "\n"; - if(!exists( TRAM / dir_itr->filename())) rename(dir_itr->path(), TRAM / dir_itr->filename()); - else remove(dir_itr->path()); - } - else if (dir_itr->path().filename().substr(0,4) == "ONSK" || - dir_itr->path().filename().substr(0,4) == "TXMP") { - cout <path().filename() << "\n";\ - create_directory( dir_itr->path().parent_path() / "TexFix"); - if(!exists( Textures / dir_itr->filename())) rename(dir_itr->path(), Textures / dir_itr->filename()); - //rename(dir_itr->path(), dir_itr->path().parent_path() / "TexFix" / dir_itr->filename()); - } - else if (dir_itr->path().filename().substr(0,4) == "ONCC" - || dir_itr->path().filename().substr(0,4) == "TRBS" - || dir_itr->path().filename().substr(0,4) == "TRMA" - || dir_itr->path().filename().substr(0,4) == "TRSC" - || dir_itr->path().filename().substr(0,4) == "TRAS") { - cout <path().filename() << "\n"; - if(!exists( Characters / dir_itr->filename())) rename(dir_itr->path(), Characters / dir_itr->filename()); - else remove(dir_itr->path()); - } - else if (dir_itr->path().filename().substr(0,4) == "OSBD" - || dir_itr->path().filename().substr(0,4) == "SNDD") { - cout << dir_itr->path().filename() << "\n"; - if(!exists( Sounds / dir_itr->filename())) rename(dir_itr->path(), Sounds / dir_itr->filename()); - else remove(dir_itr->path()); - } - else if (dir_itr->path().filename().substr(0,5) == "BINA3" - || dir_itr->path().filename().substr(0,10) == "M3GMdebris" - || dir_itr->path().filename() == "M3GMtoxic_bubble.oni" - || dir_itr->path().filename().substr(0,8) == "M3GMelec" - || dir_itr->path().filename().substr(0,7) == "M3GMrat" - || dir_itr->path().filename().substr(0,7) == "M3GMjet" - || dir_itr->path().filename().substr(0,9) == "M3GMbomb_" - || dir_itr->path().filename() == "M3GMbarab_swave.oni" - || dir_itr->path().filename() == "M3GMbloodyfoot.oni" - ){ - cout <path().filename() << "\n"; - if(!exists( Particles / dir_itr->filename())) rename(dir_itr->path(), Particles / dir_itr->filename()); - else remove(dir_itr->path()); - } - else if (dir_itr->path().filename().substr(0,4) == "AGDB" - || dir_itr->path().filename().substr(0,4) == "TRCM") { - cout <path().filename() << "\n"; - - if(!exists( Archive / dir_itr->filename())) rename(dir_itr->path(), Archive / dir_itr->filename()); - else remove(dir_itr->path()); - } - } - - - } - system( (strOniSplit + " -move:delete " + Textures.string() + " ../GameDataFolder/level" + (string)levelnum + "_Final/TXMP*.oni").c_str()); - - } - - for (int i = 0; i < 15; i++) - { - sprintf(levelnum,"%d",levels[i]); - system( (strOniSplit + " " + strImportOption + " ../GameDataFolder/level" + levelnum + "_Final packages/VanillaDats/level" + levelnum + "_Final/level" - + levelnum + "_Final/level" + levelnum + "_Final.oni").c_str()); - } - path VanillaCharacters = "packages/VanillaDats/level0_Final/level0_Characters/level0_Characters.oni"; - path VanillaParticles = "packages/VanillaDats/level0_Final/level0_Particles/level0_Particles.oni"; - path VanillaTextures = "packages/VanillaDats/level0_Final/level0_Textures/level0_Textures.oni"; - path VanillaSounds = "packages/VanillaDats/level0_Final/level0_Sounds/level0_Sounds.oni"; - path VanillaAnimations = "packages/VanillaDats/level0_Final/level0_Animations/level0_Animations.oni"; - path VanillaTRAC = "packages/VanillaDats/level0_Final/level0_Animations/level0_TRAC.oni"; - path VanillaTRAM = "packages/VanillaDats/level0_Final/level0_Animations/level0_TRAM.oni"; - create_directory( VanillaCharacters.parent_path() ); - create_directory( VanillaParticles.parent_path() ); - create_directory( VanillaTextures.parent_path() ); - create_directory( VanillaSounds.parent_path() ); - create_directory( VanillaAnimations.remove_filename() ); - system((strOniSplit + " " + strImportOption + " " + Characters.string() + " " + VanillaCharacters.string()).c_str()); - system((strOniSplit + " " + strImportOption + " " + Particles.string() + " " + VanillaParticles.string()).c_str()); - system((strOniSplit + " " + strImportOption + " " + Textures.string() + " " + VanillaTextures.string()).c_str()); - //system((strOniSplit + " " + strImportOption + (string)" " + Animations.string() + (string)" " + VanillaAnimations.string()).c_str()); - system((strOniSplit + " " + strImportOption + " " + TRAC.string() + " " + VanillaTRAC.string()).c_str()); - system((strOniSplit + " " + strImportOption + " " + Sounds.string() + " " + VanillaSounds.string()).c_str()); - system((strOniSplit + " " + strImportOption + " " + TRAM.string() + " " + VanillaTRAM.string()).c_str()); - - create_directory("../GameDataFolder/IGMD"); - copy((path)"packages/VanillaBSL/IGMD", (path)"../GameDataFolder"); - } - catch (exception ex) { - cout << ex.what(); - } - return err; -} - -int installPackages(void) -{ - bool installed_something = 0; - int err = 0; - ModPackage package; - vector installed_packages; - vector packages; - vector::iterator iter; - vector installString; - - iter = packages.begin(); - packages = getPackages(); - vector installedMods = getInstallString(); - - if (packages.empty()) - { - cout << "Error: You have no packages!\n"; - return 0; - } - - cout << "Detecting installed packages...\n"; - - int index = 1; - char choice = '0'; - - for (vector::iterator package_iter = packages.begin(); package_iter != packages.end(); ++package_iter) - { - if (!binary_search(installedMods.begin(), installedMods.end(), package_iter->modStringName)) - { //package_iter->isInstalled :< I forgot about this... - //cout << index << " "; - system(strClsCmd); - cout << (*package_iter).name << "\n"; - for (int character = 1; character <= (*package_iter).name.length() - 1; character++) cout << '-'; - cout << "\n" - << (*package_iter).readme << "\n\n" - << "Please enter a number choice\n" - << " 1. Add\n" - << " 2. Don't Add\n" - << ""; - index++; - choice = 0; - - do - { - choice = cin.get(); - cin.ignore(1280, '\n'); - } while(choice == 0); - - if (choice == '1') - { - cout << "\nInstalling...\n\n"; - if (package_iter->hasOnis || (package_iter->hasDeltas /*(*package_iter).isUnpacked */ )) - { - installed_something = 1; - installedMods.push_back(package_iter->modStringName); - system(strPauseCmd); - } - } - } - } - if (index == 1) - { - cout << "Warning: All packages are already installed\n"; - //would you like to recombine your data? - return 0; - } - if (installed_something == 0) - { - cout << "Warning: You didn't add anything!\n"; - //would you like to recombine your data? - return 0; - } - - sort(installedMods.begin(), installedMods.end()); - //system(Onisplit.c_str()); - recompileAll(installedMods); - system(strPauseCmd); - - return err; -} - -int uninstallPackages(void) -{ - int err = 0; - ModPackage package; - vector installed_packages; - vector packages; - vector::iterator iter; - vector installString; - - iter = packages.begin(); - packages = getPackages(); - - - cout << "Detecting installed packages...\n"; - - vector installedMods = getInstallString(); - - if (packages.empty()) - { - cout << "Error: You have no packages!\n"; - return 0; - } - - int index = 0; - int uninstalled_something = 0; - char choice = '0'; - - for (vector::iterator package_iter = packages.begin(); package_iter != packages.end(); ++package_iter) - { - if (binary_search(installedMods.begin(), installedMods.end(), package_iter->modStringName)) - { //package_iter->isInstalled :< I forgot about this... - //cout << index << " "; - system(strClsCmd); - cout << (*package_iter).name << "\n"; - for (int character = 1; character <= (*package_iter).name.length() - 1; character++) cout << '-'; - cout << "\n" - << (*package_iter).readme << "\n\n" - << "Please enter a number choice\n" - << " 1. Remove\n" - << " 2. Don't Remove\n" - << ""; - - choice = 0; - - do - { - choice = cin.get(); - cin.ignore(1280, '\n'); - } while(choice == 0); - - if (choice == '1') - { - cout << "\nUninstalling...\n\n"; - installedMods.erase( installedMods.begin() + (index) ); - system(strPauseCmd); - uninstalled_something = 1; - - } - else { - index++; - } - } - } - if ( uninstalled_something == 0 ) - { - if (index == 0) //bad practice, I need to implement a second vector or something. Meh. - { - cout << "\nWarning: You have no installed packages!"; - } - else - { - cout << "\nWarning: You didn't remove anything!"; - } - //would you like to recombine your data? - return 0; - - } - sort(installedMods.begin(), installedMods.end()); - //system(Onisplit.c_str()); - recompileAll(installedMods); - system(strPauseCmd); - - return err; -} - -int listInstalledPackages(void) -{ - cout << "\nThis feature not yet implemented.\n\n"; - - return 0; -} - -int printInstallerInfo(void) -{ - cout << "\nAE/Mod Installer\n"; - cout << "version " << strInstallerVersion << "\n"; - cout << "by Gumby & Iritscen\n"; - cout << "see http://oni.bungie.org/community/forums for more info\n\n"; - - return 0; -} - -vector getPackages(void) -{ - vector packages; - packages.reserve(65536); // come on, we shouldn't need this much space...right?! - fstream file; - string filename = "\0"; - string MODINFO_CFG = "Mod_Info.cfg"; - - try - { - directory_iterator end_iter; - for (directory_iterator dir_itr("./packages"); dir_itr != end_iter; ++dir_itr) - { - file.open((dir_itr->path().string() + "/" + MODINFO_CFG).c_str()); - //cout << filename << "\n"; - - if(!file.fail()) - { - //cout << dir_itr->path().string() + MODINFO_CFG; - //would prefer to push a pointer to a package, but this will do for now - packages.push_back(fileToModPackage(file)); - } - file.close(); - file.clear(); - } - } - catch (const std::exception & ex) - { - cout << "Warning, something odd happened!\n"; - } - - return packages; -} - -ModPackage fileToModPackage(fstream &file) -{ - /* - This converts a file to a ModPackage struct. - - A few notes... - "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. - 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. - */ - ModPackage package; - string line; - static string NameOfMod = "NameOfMod"; //used for comparing to the current token... - //I could have done it in reverse (*iter).compare("ModString") or - static string ARROW = "->"; //did something like "ModString".compare(*iter), and it would have been - static string ModString = "ModString"; //functionably the same. - static string HasOnis = "HasOnis"; - static string HasDeltas = "HasDeltas"; - static string HasBSL = "HasBSL"; - static string HasDats = "HasDats"; - static string IsEngine = "IsEngine"; - static string Readme = "Readme"; - static string GlobalNeeded = "GlobalNeeded"; - static string Category = "Category"; - static string Creator = "Creator"; - while (! file.eof() ) - { - getline (file,line); - vector tokens; - vector::iterator iter; - tokenize(line, tokens); //string to vector of "words" - if (tokens.capacity() >= 2) { //make sure they are using enough stuff - iter = tokens.begin(); //what word we are on, starts at first word - /* - if (!AEInstallVersion.compare(*iter)) - If mod is too old, skip this mod. - */ - /*else*/if (!NameOfMod.compare(*iter)) { //if it contains the name - for ( ; iter !=tokens.end() && SLASHSLASH.compare(*iter); iter++) { //interates through the words, ends if it reaches the end of the line or a "//" comment - if (ARROW.compare(*iter) && NameOfMod.compare(*iter)) { //ignores "->" and "NameOfMod" - //cout << *iter; - //cout << " "; - package.name += *iter + " "; - } - } - - } - else if (!ModString.compare(*iter)) { - iter++; iter++; - package.modStringName = *iter; - iter++; - package.modStringVersion = atoi((*iter).c_str()); - } - else if (!HasOnis.compare(*iter)) { - iter++; iter++; - 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 - else if (!HasBSL.compare(*iter)) { // string comparer...I know my implementation here sucks. I need to change it to check each character one by one. At the moment, - iter++; iter++;} // using "YFR" would probably set it off. :< - - if (toupper((*iter)[0]) + toupper((*iter)[1]) + toupper((*iter)[2]) == 'Y' + 'E' + 'S') package.hasBSL = 1; - } - else if (!HasDeltas.compare(*iter)) { - iter++; iter++; - if (toupper((*iter)[0]) + toupper((*iter)[1]) + toupper((*iter)[2]) == 'Y' + 'E' + 'S') package.hasDeltas = 1; - } - else if (!HasDats.compare(*iter)) { - iter++; iter++; - if (toupper((*iter)[0]) + toupper((*iter)[1]) + toupper((*iter)[2]) == 'Y' + 'E' + 'S') package.hasDats = 1; - } - else if (!IsEngine.compare(*iter)) { - iter++; iter++; - if (toupper((*iter)[0]) + toupper((*iter)[1]) + toupper((*iter)[2]) == 'Y' + 'E' + 'S') package.isEngine = 1; - } - else if (!GlobalNeeded.compare(*iter)) { - iter++; iter++; - if (toupper((*iter)[0]) + toupper((*iter)[1]) + toupper((*iter)[2]) == 'Y' + 'E' + 'S') package.globalNeeded = 1; - else if (toupper((*iter)[0]) + toupper((*iter)[1]) == 'N' + 'O') package.globalNeeded = 1; //Really the only place where checking for "No" is important atm. - } - else if (!Category.compare(*iter)) { - for ( ; iter !=tokens.end() && SLASHSLASH.compare(*iter); iter++) { //interates through the words, ends if it reaches the end of the line or a "//" comment - if (ARROW.compare(*iter) && Category.compare(*iter)) { //ignores "->" and "Category" - //cout << *iter; - //cout << " "; - package.category += *iter + " "; - } - } - } - else if (!Creator.compare(*iter)) { //if it contains the name - for ( ; iter !=tokens.end() && SLASHSLASH.compare(*iter); iter++) { //interates through the words, ends if it reaches the end of the line or a "//" comment - if (ARROW.compare(*iter) && Creator.compare(*iter)) { //ignores "->" and "Category" - //cout << *iter; - //cout << " "; - package.creator += *iter + " "; - } - } - } - else if (!Readme.compare(*iter)) { //if it contains the name - for ( ; iter !=tokens.end() && SLASHSLASH.compare(*iter); iter++) { //interates through the words, ends if it reaches the end of the line or a "//" comment - if (ARROW.compare(*iter) && Readme.compare(*iter)) { //ignores "->" and "Category" - if(!(*iter).compare("\\n")) package.readme += '\n'; - else package.readme += *iter + " "; - } - } - } - } - - } - package.doOutput(); - return package; -} - -void recompileAll(vector installedMods) -{ #ifdef WIN32 - RedirectIOToConsole(); - HWND hWnd = GetConsoleWindow(); - ShowWindow( hWnd, SW_HIDE ); +#include +#include +HWND Handle; +ITaskbarList *pTaskbarList; +ITaskbarList3 *pTaskbarList3; #endif - setStatusArea("Importing levels..."); - //setStatusArea("Recompiling Data..."); - path vanilla_dir = "./packages/VanillaDats/"; - string importCommand = ""; - char statusString[128]; - int numberOfDats = 0; - int j = 1; - string datString; - std::stringstream out; - - - clearOldDats(); - remove("Onisplit.log"); - if(splitInstances == SPLIT){ - recursive_directory_iterator end_iter; - - for ( recursive_directory_iterator dir_itr( vanilla_dir ); - dir_itr != end_iter; - ++dir_itr ) - { - try{ - if ( is_directory( dir_itr->status() ) && dir_itr.level() == 1) - { - numberOfDats++; - } - } - catch(exception ex) { - - } - } - - //recursive_directory_iterator end_iter; - - - out << numberOfDats; - datString = out.str(); - try { - for ( recursive_directory_iterator dir_itr( vanilla_dir ); - dir_itr != end_iter; - ++dir_itr ) - { - try - { - if ( is_directory( dir_itr->status() ) && dir_itr.level() == 1) - { - importCommand = strOniSplit + " " + strImportOption + " " + dir_itr->path().parent_path().string() + '/' + dir_itr->path().filename(); - for (int i = 0; i < installedMods.size(); ++i) { - if (exists("packages/" + installedMods[i] + "/oni/" + dir_itr->path().parent_path().filename() + '/' + dir_itr->path().filename() )) - importCommand += " packages/" + installedMods[i] + "/oni/" + dir_itr->path().parent_path().filename() + '/' + dir_itr->path().filename(); - - //else cout << " packages/VanillaDats/" + installedMods[i] + "/oni/"; - } - importCommand += " ../GameDataFolder/" + dir_itr->path().filename() + ".dat >> Onisplit.log"; - - sprintf(statusString,"%d/%i\0",j,numberOfDats); - setProgressBar( (int)(1000 * (float)(j-1) / (float)numberOfDats) ); //100% * dat we're on / total dats - setStatusArea("Importing " + dir_itr->path().filename() + " " + statusString); - - system(importCommand.c_str()); - //Sleep(1000); - //cout << importCommand << "\n"; - j++; - - } - } - catch ( const std::exception & ex ) - { - cout << "Warning, exception " << ex.what() << "!"; - } - } - - } - catch( const std::exception & ex ) { - cout << "Warning, exception " << ex.what() << "!\n" - << "You probably need to re-globalize."; - //create_directory( "./packages/VanillaDats" ); - } - - } - else if(splitInstances == NOT_SPLIT){ - directory_iterator end_iter; - - for ( directory_iterator dir_itr( vanilla_dir ); - dir_itr != end_iter; - ++dir_itr ) - { - - if ( is_directory( dir_itr->status() ) ) - { - numberOfDats++; - } - - - } - - out << numberOfDats; - datString = out.str(); - - for ( directory_iterator dir_itr( vanilla_dir ); - dir_itr != end_iter; - ++dir_itr ) - { - try - { - if ( is_directory( dir_itr->status() ) ) - { - importCommand = strOniSplit + " " + strImportOption + " " + vanilla_dir.string() + dir_itr->path().filename() + " " + "../GameDataFolder/" + dir_itr->path().filename() - + ".dat"; - for (int i = 0; i < installedMods.size(); ++i) { - if (exists("packages/" + installedMods[i] + "/oni/" + dir_itr->path().filename() )) - importCommand += " packages/" + installedMods[i] + "/oni/" + dir_itr->path().filename(); - } - importCommand += " ../GameDataFolder/" + dir_itr->path().filename() + ".dat"; - - sprintf(statusString,"%d/%i\0",j,numberOfDats); - setProgressBar( (int)(1000 * (float)(j-1) / (float)numberOfDats) ); //100% * dat we're on / total dats - setStatusArea("Importing " + dir_itr->path().filename() + " " + statusString); - - system(importCommand.c_str()); - - j++; - } - } - catch ( const std::exception & ex ) - { - cout << "Warning, something odd happened!\n"; - } - } - } - writeInstalledMods(installedMods); - setProgressBar(1000); - setStatusArea("Done!"); - Sleep(1000); - setProgressBar(0); -} - -void writeInstalledMods(vector installedMods) -{ - - if ( exists( strInstallCfg ) ) - { - remove( strInstallCfg ); - } - - ofstream file(strInstallCfg.c_str()); - - vectorlist = installedMods; - vector::iterator begin_iter = list.begin(); - vector::iterator end_iter = list.end(); - - sort( list.begin(), list.end() ); - - for( ; begin_iter != end_iter; ++begin_iter) { - file << *begin_iter << " "; - } - - file.close(); - file.clear(); - -} - -vector getInstallString(string Cfg) -{ - //system(strPauseCmd); - vector returnval; - - string line; - fstream file; - - if (exists( Cfg )) - { - file.open(Cfg.c_str()); - getline(file, line); - tokenize(line, returnval); - file.close(); - file.clear(); - sort(returnval.begin(), returnval.end()); - } - else cout << "fail"; - - return returnval; -} - -//stolen token function... -void tokenize(const string& str, vector& tokens, const string& delimiters) -{ - // Skip delimiters at beginning. - string::size_type lastPos = str.find_first_not_of(delimiters, 0); - // Find first "non-delimiter". - string::size_type pos = str.find_first_of(delimiters, lastPos); - - while (string::npos != pos || string::npos != lastPos) - { - // Found a token, add it to the vector. - tokens.push_back(str.substr(lastPos, pos - lastPos)); - // Skip delimiters. Note the "not_of" - lastPos = str.find_first_not_of(delimiters, pos); - // Find next "non-delimiter" - pos = str.find_first_of(delimiters, lastPos); - } -} -void clearOldDats(void) { - directory_iterator end_iter_gdf; - for ( directory_iterator dir_itr_gdf( "../GameDataFolder" ); - dir_itr_gdf != end_iter_gdf; - ++dir_itr_gdf ) - { - //cout << dir_itr_gdf->path().extension() << "\n"; - if ( dir_itr_gdf->path().extension() == ".dat" || dir_itr_gdf->path().extension() == ".raw" || dir_itr_gdf->path().extension() == ".sep" ) { - remove( dir_itr_gdf->path() ); - } - - } - -} - -vector globalInstalledMods; -vector globalPackages; -#include "boost/thread.hpp" #include - -///////////////////////////////////////////////////////////////////////////// -// Name: main_window.cpp -// Purpose: -// Author: -// Modified by: -// Created: 07/05/2009 20:38:25 -// RCS-ID: -// Copyright: -// Licence: -///////////////////////////////////////////////////////////////////////////// - // For compilers that support precompilation, includes "wx/wx.h". #include "wx/wxprec.h" @@ -895,31 +30,45 @@ vector globalPackages; #endif ////@begin includes -#include "about_window.h" -////@end includes - +#include "about.h" #include "main_window.h" +#include "installer.h" +////@end includes ////@begin XPM images -#include "redo.xpm" +#include "aelogosmall.xpm" +#include "undo.xpm" #include "fileopen.xpm" #include "filesaveas.xpm" #include "quit.xpm" ////@end XPM images -//#define wxDebug 1; -//#define wxUSE_UNICODE 1; +bool busy = false; +int updateStatus; +bool installerJustUpdated = false; +vector globalInstalledMods; +vector globalPackages; +// Variable declarations +#ifdef WIN32 +bool splitInstances = true; +string strImportOption = "-import:nosep"; +string strOniSplit = "Onisplit.exe"; +#else +bool splitInstances = false; +string strImportOption = "-import:sep"; +string strOniSplit = "mono Onisplit.exe"; +#endif /* - * MainWindow type definition - */ +* MainWindow type definition +*/ IMPLEMENT_CLASS( MainWindow, wxFrame ) /* - * MainWindow event table definition - */ +* MainWindow event table definition +*/ BEGIN_EVENT_TABLE( MainWindow, wxFrame ) @@ -939,7 +88,7 @@ BEGIN_EVENT_TABLE( MainWindow, wxFrame ) EVT_RADIOBUTTON( NoSep_RadioButton, MainWindow::OnNoSepRadioButtonSelected ) - EVT_RADIOBUTTON( Separated_RadioButton, MainWindow::OnSeparatedRadioButtonSelected ) + EVT_RADIOBUTTON( Seperated_RadioButton, MainWindow::OnSeperatedRadioButtonSelected ) EVT_RADIOBUTTON( Complete_RadioButton, MainWindow::OnCompleteRadioButtonSelected ) @@ -955,62 +104,61 @@ BEGIN_EVENT_TABLE( MainWindow, wxFrame ) EVT_MENU( wxID_ABOUT, MainWindow::OnAboutClick ) + EVT_BUTTON( Dir_Button, MainWindow::OnDirButtonClick ) ////@end MainWindow event table entries END_EVENT_TABLE() /* - * MainWindow constructors - */ +* MainWindow constructors +*/ MainWindow::MainWindow() -{ - Init(); +{ + Init(); } MainWindow::MainWindow( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style ) { - Init(); - Create( parent, id, caption, pos, size, style ); + Init(); + Create( parent, id, caption, pos, size, style ); } /* - * MainWindow creator - */ +* MainWindow creator +*/ bool MainWindow::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style ) { -////@begin MainWindow creation + ////@begin MainWindow creation wxFrame::Create( parent, id, caption, pos, size, style ); CreateControls(); - SetIcon(GetIconResource(wxT("oni_special.ico"))); + SetIcon(GetIconResource(wxT("aelogosmall.png"))); Centre(); -////@end MainWindow creation - return true; + ////@end MainWindow creation + return true; } - /* - * MainWindow destructor - */ +* MainWindow destructor +*/ MainWindow::~MainWindow() { -////@begin MainWindow destruction -////@end MainWindow destruction + ////@begin MainWindow destruction + ////@end MainWindow destruction } - /* - * Member initialisation - */ +* Member initialisation +*/ void MainWindow::Init() { -////@begin MainWindow member initialisation + ////@begin MainWindow member initialisation MainSplitter = NULL; SelectAll = NULL; RefreshButton = NULL; @@ -1024,25 +172,23 @@ void MainWindow::Init() OptionsPanel = NULL; SepRadio = NULL; NoSepRadio = NULL; - SeparatedRadio = NULL; + SeperatedRadio = NULL; CompleteRadio = NULL; ReglobalizeButton = NULL; -////@end MainWindow member initialisation + ChangeDirectoryButton = NULL; + ////@end MainWindow member initialisation } - /* - * Control creation for MainWindow - */ +* Control creation for MainWindow +*/ wxStatusBar **TheStatusBar; wxButton* TheInstallButton; wxGauge* TheProgressBar; void MainWindow::CreateControls() { -////@begin MainWindow content construction - // Generated by DialogBlocks, 31/05/2009 19:03:55 (unregistered) - + ////@begin MainWindow content construction MainWindow* itemFrame1 = this; wxMenuBar* menuBar = new wxMenuBar; @@ -1070,17 +216,20 @@ void MainWindow::CreateControls() wxMenu* itemMenu42 = new wxMenu; itemMenu42->Append(wxID_OPTIONS, _("Show Advanced Options..."), wxEmptyString, wxITEM_CHECK); menuBar->Append(itemMenu42, _("Options")); - wxMenu* itemMenu44 = new wxMenu; - itemMenu44->Append(wxID_HELP, _("Help"), wxEmptyString, wxITEM_NORMAL); - itemMenu44->Append(wxID_ABOUT, _("About"), wxEmptyString, wxITEM_NORMAL); - menuBar->Append(itemMenu44, _("Help")); +//#ifdef WIN32 +// itemMenu44->Append(wxID_ABOUT, _("About"), wxEmptyString, wxITEM_NORMAL); +// menuBar->Append(itemMenu44, _("Help")); +//#else + itemMenu37->Append(wxID_ABOUT, _("About"), wxEmptyString, wxITEM_NORMAL); +//#endif + itemFrame1->SetMenuBar(menuBar); wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL); itemFrame1->SetSizer(itemBoxSizer2); MainSplitter = new wxSplitterWindow( itemFrame1, ID_SPLITTERWINDOW, wxDefaultPosition, wxSize(100, 100), wxSP_LIVE_UPDATE|wxNO_BORDER ); - MainSplitter->SetMinimumPaneSize(150); + MainSplitter->SetMinimumPaneSize(1); MainSplitter->SetName(_T("MainSplitter")); wxPanel* itemPanel4 = new wxPanel( MainSplitter, ID_PANEL, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER|wxTAB_TRAVERSAL ); @@ -1094,7 +243,7 @@ void MainWindow::CreateControls() SelectAll->SetName(_T("SelectAll_Checkbox")); itemBoxSizer6->Add(SelectAll, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); - RefreshButton = new wxBitmapButton( itemPanel4, Refresh_Button, itemFrame1->GetBitmapResource(wxT("redo.xpm")), wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW ); + RefreshButton = new wxBitmapButton( itemPanel4, Refresh_Button, itemFrame1->GetBitmapResource(wxT("undo.xpm")), wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW ); RefreshButton->SetName(_T("RefreshButton")); itemBoxSizer6->Add(RefreshButton, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxTOP|wxBOTTOM, 5); @@ -1128,28 +277,29 @@ void MainWindow::CreateControls() itemStaticLine17->Show(false); itemBoxSizer11->Add(itemStaticLine17, 0, wxGROW|wxALL, 5); - descriptionText = new wxTextCtrl( itemPanel10, Description_Text, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_READONLY|wxTE_RICH|wxTE_AUTO_URL ); + descriptionText = new wxTextCtrl( itemPanel10, Description_Text, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_READONLY|wxTE_RICH|wxTE_RICH2 ); descriptionText->SetName(_T("DescriptionName")); descriptionText->SetBackgroundColour(wxColour(240, 240, 240)); itemBoxSizer11->Add(descriptionText, 1, wxGROW|wxLEFT|wxRIGHT, 5); - MainSplitter->SplitVertically(itemPanel4, itemPanel10, 150); + MainSplitter->SplitVertically(itemPanel4, itemPanel10, 200); itemBoxSizer2->Add(MainSplitter, 1, wxGROW|wxALL, 0); StatusArea = new wxStatusBar( itemFrame1, ID_STATUSBAR, 0 ); StatusArea->SetName(_T("StatusArea")); StatusArea->SetFieldsCount(1); - StatusArea->SetStatusText(_("Status Area"), 0); + string versionText = "AE Installer v" + (string)INSTALLER_VERSION; + StatusArea->SetStatusText(versionText.c_str(), 0); itemBoxSizer2->Add(StatusArea, 0, wxGROW|wxALL, 0); wxBoxSizer* itemBoxSizer20 = new wxBoxSizer(wxHORIZONTAL); itemBoxSizer2->Add(itemBoxSizer20, 0, wxGROW|wxALL, 0); - ProgressBar = new wxGauge( itemFrame1, ProgressBar_Gauge, 1000, wxDefaultPosition, wxSize(-1, 30), wxGA_SMOOTH ); + ProgressBar = new wxGauge( itemFrame1, ProgressBar_Gauge, 1000, wxDefaultPosition, wxDefaultSize, wxGA_SMOOTH ); ProgressBar->SetValue(0); itemBoxSizer20->Add(ProgressBar, 1, wxGROW|wxALL, 0); - InstallButton = new wxButton( itemFrame1, Install_Button, _("Install!"), wxDefaultPosition, wxSize(-1, 30), 0 ); + InstallButton = new wxButton( itemFrame1, Install_Button, _("Install!"), wxDefaultPosition, wxDefaultSize, 0 ); itemBoxSizer20->Add(InstallButton, 0, wxGROW|wxALL, 0); wxBoxSizer* itemBoxSizer23 = new wxBoxSizer(wxVERTICAL); @@ -1182,10 +332,10 @@ void MainWindow::CreateControls() wxBoxSizer* itemBoxSizer30 = new wxBoxSizer(wxVERTICAL); itemBoxSizer25->Add(itemBoxSizer30, 0, wxGROW|wxALL, 5); - SeparatedRadio = new wxRadioButton( OptionsPanel, Separated_RadioButton, _("Separated Level0"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP ); - SeparatedRadio->SetValue(false); - SeparatedRadio->SetName(_T("Separated_RadioButton")); - itemBoxSizer30->Add(SeparatedRadio, 0, wxALIGN_LEFT|wxALL, 5); + SeperatedRadio = new wxRadioButton( OptionsPanel, Seperated_RadioButton, _("Separated Level0"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP ); + SeperatedRadio->SetValue(false); + SeperatedRadio->SetName(_T("Seperated_RadioButton")); + itemBoxSizer30->Add(SeperatedRadio, 0, wxALIGN_LEFT|wxALL, 5); CompleteRadio = new wxRadioButton( OptionsPanel, Complete_RadioButton, _("Complete Level0"), wxDefaultPosition, wxDefaultSize, 0 ); CompleteRadio->SetValue(false); @@ -1202,98 +352,98 @@ void MainWindow::CreateControls() ReglobalizeButton->SetName(_T("Reglobalize_Button")); itemBoxSizer34->Add(ReglobalizeButton, 0, wxGROW|wxALL, 5); - // Connect events and objects + wxStaticLine* itemStaticLine100 = new wxStaticLine( OptionsPanel, wxID_STATIC, wxDefaultPosition, wxDefaultSize, wxLI_VERTICAL ); + itemBoxSizer25->Add(itemStaticLine100, 0, wxGROW|wxALL, 5); + + ChangeDirectoryButton = new wxButton( OptionsPanel, Dir_Button, _("Change Dir"), wxDefaultPosition, wxDefaultSize, 0 ); + ChangeDirectoryButton->SetName(_T("Dir_Button")); + itemBoxSizer34->Add(ChangeDirectoryButton, 0, wxGROW|wxALL, 5); + + // Connect events and objects Mods_CheckboxList->Connect(Mods_CheckboxList1, wxEVT_CREATE, wxWindowCreateEventHandler(MainWindow::ModList_OnCreate), NULL, this); -////@end MainWindow content construction - - if ( exists( "../../GameDataFolder/level0_Final.sep" ) ) { - static_cast("-import:sep"); - splitInstances = NOT_SPLIT; - } - else { - static_cast("-import:nosep"); - splitInstances = SPLIT; - } + ////@end MainWindow content construction +#ifdef WIN32 + Handle = (HWND)GetHWND(); + ::CoCreateInstance(CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER, IID_ITaskbarList, (void **)&pTaskbarList); +#endif + updateStatus = GetUpdateStatus(¤tAE, &updateAE, &installerJustUpdated); + globalPackages = getPackages(); globalInstalledMods = getInstallString(); - for (int i = 0; i < globalPackages.size(); i++) { - Mods_CheckboxList->Append(globalPackages[i].name.c_str()); - if( binary_search(globalInstalledMods.begin(), globalInstalledMods.end(), globalPackages[i].modStringName ) ) Mods_CheckboxList->Check(i); + for (unsigned int i = 0; i < globalPackages.size(); i++) + { + Mods_CheckboxList->Append(globalPackages[i].name.c_str()); + if (binary_search(globalInstalledMods.begin(), globalInstalledMods.end(), globalPackages[i].modStringName)) Mods_CheckboxList->Check(i); } - TheStatusBar = &StatusArea; - TheInstallButton = InstallButton; - TheProgressBar = ProgressBar; - OptionsPanel->Hide(); - if(splitInstances == SPLIT) SeparatedRadio->SetValue(true); - else CompleteRadio->SetValue(true); - - - - if(strImportOption == "-import:nosep") NoSepRadio->SetValue(true); - else SepRadio->SetValue(true); - //MainWindow::SetSize(MainWindow::GetRect().GetWidth(), MainWindow::GetRect().GetHeight()-OptionsPanel->GetRect().GetHeight() ); + TheStatusBar = &StatusArea; + TheInstallButton = InstallButton; + TheProgressBar = ProgressBar; + OptionsPanel->Hide(); + + if(splitInstances) SeperatedRadio->SetValue(true); + else CompleteRadio->SetValue(true); + if(strImportOption == "-import:nosep") NoSepRadio->SetValue(true); + else SepRadio->SetValue(true); + +#ifdef WIN32 + RedirectIOToConsole(); + HWND hWnd = GetConsoleWindow(); + ShowWindow( hWnd, SW_HIDE ); +#endif } - /* - * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for SelectAll_Checkbox - */ +* wxEVT_COMMAND_CHECKBOX_CLICKED event handler for SelectAll_Checkbox +*/ void MainWindow::OnSelectAllCheckboxClick( wxCommandEvent& event ) { - switch(SelectAll->Get3StateValue()) { + switch(SelectAll->Get3StateValue()) { case wxCHK_UNCHECKED: - for(int i = 0; i < globalPackages.size(); i++) Mods_CheckboxList->Check(i, false); - //SelectAll->Set3StateValue(wxCHK_CHECKED); + for(unsigned int i = 0; i < globalPackages.size(); i++) Mods_CheckboxList->Check(i, false); break; case wxCHK_CHECKED: - for(int i = 0; i < globalPackages.size(); i++) Mods_CheckboxList->Check(i, true); - //SelectAll->Set3StateValue(wxCHK_UNCHECKED); + for(unsigned int i = 0; i < globalPackages.size(); i++) Mods_CheckboxList->Check(i, true); break; case wxCHK_UNDETERMINED: - for(int i = 0; i < globalPackages.size(); i++) Mods_CheckboxList->Check(i, false); - //SelectAll->Set3StateValue(wxCHK_CHECKED); + for(unsigned int i = 0; i < globalPackages.size(); i++) Mods_CheckboxList->Check(i, false); break; - } - } - /* - * wxEVT_CREATE event handler for Mods_CheckboxList - */ +* wxEVT_CREATE event handler for Mods_CheckboxList +*/ void MainWindow::ModList_OnCreate( wxWindowCreateEvent& event ) { - } /* - * Should we show tooltips? - */ +* Should we show tooltips? +*/ bool MainWindow::ShowToolTips() { - return true; + return true; } /* - * Get bitmap resources - */ +* Get bitmap resources +*/ wxBitmap MainWindow::GetBitmapResource( const wxString& name ) { - // Bitmap retrieval -////@begin MainWindow bitmap retrieval + // Bitmap retrieval + ////@begin MainWindow bitmap retrieval wxUnusedVar(name); - if (name == _T("redo.xpm")) + if (name == _T("undo.xpm")) { - wxBitmap bitmap(redo_xpm); + wxBitmap bitmap( undo_xpm); return bitmap; } else if (name == _T("fileopen.xpm")) @@ -1312,349 +462,339 @@ wxBitmap MainWindow::GetBitmapResource( return bitmap; } return wxNullBitmap; -////@end MainWindow bitmap retrieval + ////@end MainWindow bitmap retrieval } /* - * Get icon resources - */ +* Get icon resources +*/ wxIcon MainWindow::GetIconResource( const wxString& name ) { - // Icon retrieval -////@begin MainWindow icon retrieval + // Icon retrieval + ////@begin MainWindow icon retrieval wxUnusedVar(name); - if (name == _T("oni_special.ico")) + if (name == _T("aelogosmall.png")) { - wxIcon icon(_T("oni_special.ico"), wxBITMAP_TYPE_ICO); + wxIcon icon(aelogosmall_xpm); return icon; } return wxNullIcon; -////@end MainWindow icon retrieval + ////@end MainWindow icon retrieval } - /* - * wxEVT_COMMAND_LISTBOX_SELECTED event handler for Mods_CheckboxList1 - */ +* wxEVT_COMMAND_LISTBOX_SELECTED event handler for Mods_CheckboxList1 +*/ void MainWindow::OnModsCheckboxList1Selected( wxCommandEvent& event ) { - //event.GetSelection titleText->SetValue(globalPackages[event.GetSelection()].name.c_str()); creatorText->SetValue(globalPackages[event.GetSelection()].creator.c_str()); descriptionText->SetValue(globalPackages[event.GetSelection()].readme.c_str()); - - //creatorText->Refresh(); } - /* - * wxEVT_COMMAND_CHECKLISTBOX_TOGGLED event handler for Mods_CheckboxList1 - */ +* wxEVT_COMMAND_CHECKLISTBOX_TOGGLED event handler for Mods_CheckboxList1 +*/ void MainWindow::OnModsCheckboxList1Toggled( wxCommandEvent& event ) { SelectAll->Set3StateValue(wxCHK_UNDETERMINED); if(event.GetInt()) { - /* + /* switch(SelectAll->Get3StateValue()) { - case wxCHK_UNCHECKED: + case wxCHK_UNCHECKED: break; - case wxCHK_CHECKED: + case wxCHK_CHECKED: break; - case wxCHK_UNDETERMINED : + case wxCHK_UNDETERMINED : break; - } - */ + } + */ } } /* - * wxEVT_COMMAND_MENU_SELECTED event handler for wxID_OPTIONS - */ +* wxEVT_COMMAND_MENU_SELECTED event handler for wxID_OPTIONS +*/ void MainWindow::OnOptionsClick( wxCommandEvent& event ) { - if (!event.GetInt() ) { OptionsPanel->Hide(); - MainWindow::SetSize(MainWindow::GetRect().GetWidth(), MainWindow::GetRect().GetHeight()-OptionsPanel->GetRect().GetHeight());} + + this->SetSize(this->GetRect().GetWidth(), this->GetRect().GetHeight()-OptionsPanel->GetRect().GetHeight());} else { + wxMessageDialog* YesNoDialog = new wxMessageDialog(this, "WARNING: These options are for advanced users only, use with caution.", + "AE Installer Alert", wxOK | wxICON_EXCLAMATION , wxDefaultPosition); + YesNoDialog->ShowModal(); OptionsPanel->Show(); - MainWindow::SetSize(MainWindow::GetRect().GetWidth(), MainWindow::GetRect().GetHeight()+OptionsPanel->GetRect().GetHeight()); + this->SetSize(this->GetRect().GetWidth(), this->GetRect().GetHeight()+OptionsPanel->GetRect().GetHeight()+1); + this->SetSize(this->GetRect().GetWidth(), this->GetRect().GetHeight()-1); } } - /* - * wxEVT_COMMAND_MENU_SELECTED event handler for wxID_EXIT - */ +* wxEVT_COMMAND_MENU_SELECTED event handler for wxID_EXIT +*/ void MainWindow::OnExitClick( wxCommandEvent& event ) { -exit(0); + exit(0); } - /* - * wxEVT_COMMAND_BUTTON_CLICKED event handler for Install_Button - */ - +* wxEVT_COMMAND_BUTTON_CLICKED event handler for Install_Button +*/ struct recompile { - recompile(vector localPackages) : thePackages(localPackages) { } - void operator()() - { + recompile(vector localPackages) : thePackages(localPackages) { } + void operator()() + { TheInstallButton->Disable(); - recompileAll(thePackages); - TheInstallButton->Enable(); - } - - vector thePackages; + recompileAll(thePackages); + TheInstallButton->Enable(); + + } + vector thePackages; }; +void globalize2(void) { + TheInstallButton->Disable(); + globalizeData(); + TheInstallButton->Enable(); +} + void MainWindow::OnInstallButtonClick( wxCommandEvent& event ) { - vector localPackages; - localPackages.push_back("Globalize"); - for(int i = 0; i < globalPackages.size(); i++) if(Mods_CheckboxList->IsChecked(i)) localPackages.push_back( globalPackages[i].modStringName ); + localPackages.push_back("00000Globalize"); + for(unsigned int i = 0; i < globalPackages.size(); i++) if(Mods_CheckboxList->IsChecked(i)) localPackages.push_back( globalPackages[i].modStringName ); if ( !localPackages.empty() ) { - - //MainWindow::MainWindow().Hide(); - // boost::thread thrd2(recompileAll(localPackages) ); - //MainWindow::MainWindow().Show(); + sort(localPackages.begin(), localPackages.end()); + localPackages[0] = "Globalize"; + this->InstallButton->Disable(); + this->ReglobalizeButton->Disable(); #ifdef WIN32 recompile packages(localPackages); boost::thread thrd(packages); #else - this->Disable(); recompileAll(localPackages); - this->Enable(); #endif - + this->InstallButton->Enable(); + this->ReglobalizeButton->Enable(); } - - } -/*void setStatusArea( string s ) { - //TheStatusBar = MainWindow::StatusArea; - (**TheStatusBar).SetStatusText(_(s.c_str()), 0); - - //MainWindow::MainWindow().SetSize(MainWindow::MainWindow().GetRect().GetWidth(), MainWindow::MainWindow().GetRect().GetHeight()+1); - - //MainWindow::StatusBar->SetLabel("Importing Files..."); - //StatusBar->SetLabel(s); -//->SetLabel(s); - -}*/ - -void setProgressBar( int i ) { -//TheProgressBar->SetValue( - +void setProgressBar( int i ) +{ +#ifdef WIN32 +if (SUCCEEDED(pTaskbarList->QueryInterface(IID_ITaskbarList3, (void **)&pTaskbarList3))) +{ + pTaskbarList3->SetProgressValue(Handle,i, 1000); + if ( i == 0 ) + { + pTaskbarList3->SetProgressState(Handle,TBPF_NOPROGRESS); + } +} +#endif TheProgressBar->SetValue(i); - } - /* - * wxEVT_UPDATE_UI event handler for ID_STATUSBAR - */ +* wxEVT_UPDATE_UI event handler for ID_STATUSBAR +*/ void MainWindow::OnStatusbarUpdate( wxUpdateUIEvent& event ) { -////@begin wxEVT_UPDATE_UI event handler for ID_STATUSBAR in MainWindow. + ////@begin wxEVT_UPDATE_UI event handler for ID_STATUSBAR in MainWindow. // Before editing this code, remove the block markers. event.Skip(); -////@end wxEVT_UPDATE_UI event handler for ID_STATUSBAR in MainWindow. + ////@end wxEVT_UPDATE_UI event handler for ID_STATUSBAR in MainWindow. } - /* - * wxEVT_COMMAND_MENU_SELECTED event handler for wxID_ABOUT - */ +* wxEVT_COMMAND_MENU_SELECTED event handler for wxID_ABOUT +*/ void MainWindow::OnAboutClick( wxCommandEvent& event ) { -////@begin wxEVT_COMMAND_MENU_SELECTED event handler for wxID_ABOUT in MainWindow. + ////@begin wxEVT_COMMAND_MENU_SELECTED event handler for wxID_ABOUT in MainWindow. // Before editing this code, remove the block markers. + // TODO: Make About window work again! About* window = new About(this); - int returnValue = window->ShowModal(); + window->ShowModal(); window->Destroy(); -////@end wxEVT_COMMAND_MENU_SELECTED event handler for wxID_ABOUT in MainWindow. + ////@end wxEVT_COMMAND_MENU_SELECTED event handler for wxID_ABOUT in MainWindow. } - /* - * wxEVT_COMMAND_RADIOBUTTON_SELECTED event handler for NoSep_RadioButton - */ - +* wxEVT_COMMAND_RADIOBUTTON_SELECTED event handler for NoSep_RadioButton +*/ + void MainWindow::OnNoSepRadioButtonSelected( wxCommandEvent& event ) { static_cast("-import:nosep"); } - /* - * wxEVT_COMMAND_RADIOBUTTON_SELECTED event handler for Sep_RadioButton - */ +* wxEVT_COMMAND_RADIOBUTTON_SELECTED event handler for Sep_RadioButton +*/ void MainWindow::OnSepRadioButtonSelected( wxCommandEvent& event ) { static_cast("-import:sep"); } - /* - * wxEVT_COMMAND_RADIOBUTTON_SELECTED event handler for Separated_RadioButton - */ - -void MainWindow::OnSeparatedRadioButtonSelected( wxCommandEvent& event ) -{ -splitInstances = SPLIT; - -} - +* wxEVT_COMMAND_RADIOBUTTON_SELECTED event handler for Separated_RadioButton +*/ /* - * wxEVT_COMMAND_RADIOBUTTON_SELECTED event handler for Complete_RadioButton - */ +* wxEVT_COMMAND_RADIOBUTTON_SELECTED event handler for Complete_RadioButton +*/ void MainWindow::OnCompleteRadioButtonSelected( wxCommandEvent& event ) { -splitInstances = NOT_SPLIT; - + splitInstances = false; } - /* - * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BITMAPBUTTON - */ +* wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BITMAPBUTTON +*/ void MainWindow::OnRefreshButtonClick( wxCommandEvent& event ) { + globalPackages = getPackages(); refreshMods(globalInstalledMods); } - /* - * wxEVT_COMMAND_MENU_SELECTED event handler for wxID_LOAD - */ - +* wxEVT_COMMAND_MENU_SELECTED event handler for wxID_LOAD +*/ - - -void MainWindow::refreshMods (vector s) { - +// TODO: Make refreshMods actually refresh the list in the window of available mods so we can see any new package info and deleted mods are removed from the list +void MainWindow::refreshMods (vector s) +{ Mods_CheckboxList->Clear(); - //globalInstalledMods = getPackages(); - for (int i = 0; i < globalPackages.size(); i++) { - Mods_CheckboxList->Append(globalPackages[i].name.c_str()); - if( binary_search(s.begin(), s.end(), globalPackages[i].modStringName ) ) Mods_CheckboxList->Check(i); - //else Mods_CheckboxList->Check(i,0); - - } + for (unsigned int i = 0; i < globalPackages.size(); i++) { + Mods_CheckboxList->Append(globalPackages[i].name.c_str()); + if( binary_search(s.begin(), s.end(), globalPackages[i].modStringName ) ) + Mods_CheckboxList->Check(i); + } } void MainWindow::OnLoadClick( wxCommandEvent& event ) { + if (busy == 1) return; static const wxChar *FILETYPES = _T( "Mod Loadouts (*.cfg)|*.cfg|" "All files (*.*)|*.*" - ); - + ); + wxFileDialog* openFileDialog = new wxFileDialog( this, _("Open Mod Loadout"), "", "", FILETYPES, - wxOPEN, wxDefaultPosition); - + wxOPEN, wxDefaultPosition); + if ( openFileDialog->ShowModal() == wxID_OK ) { refreshMods(getInstallString( string(openFileDialog->GetPath()) )); } - - } - /* - * wxEVT_COMMAND_MENU_SELECTED event handler for wxID_SAVE - */ +* wxEVT_COMMAND_MENU_SELECTED event handler for wxID_SAVE +*/ void MainWindow::OnSaveClick( wxCommandEvent& event ) { + if (busy == 1) return; static const wxChar *FILETYPES = _T( "Mod Loadouts (*.cfg)|*.cfg|" "All files (*.*)|*.*" - ); + ); - wxFileDialog* openFileDialog = + wxFileDialog* openFileDialog = new wxFileDialog( this, _("Open file"), "", "", FILETYPES, wxSAVE, wxDefaultPosition); if ( openFileDialog->ShowModal() == wxID_OK ) { - - - //Mods_CheckboxList-> - - - - // - if ( exists( openFileDialog->GetPath().c_str() ) ) - { - remove( openFileDialog->GetPath().c_str() ); - } + { + remove( openFileDialog->GetPath().c_str() ); + } - ofstream file(openFileDialog->GetPath().c_str()); - - vectorlist; - for(int i = 0; i < globalPackages.size(); i++) if(Mods_CheckboxList->IsChecked(i)) list.push_back( globalPackages[i].modStringName ); - vector::iterator begin_iter = list.begin(); - vector::iterator end_iter = list.end(); + ofstream file(openFileDialog->GetPath().c_str()); - sort( list.begin(), list.end() ); + vectorlist; + for(unsigned int i = 0; i < globalPackages.size(); i++) if(Mods_CheckboxList->IsChecked(i)) list.push_back( globalPackages[i].modStringName ); + vector::iterator begin_iter = list.begin(); + vector::iterator end_iter = list.end(); - for( ; begin_iter != end_iter; ++begin_iter) { - file << *begin_iter << " "; - } - - file.close(); - file.clear(); + sort( list.begin(), list.end() ); + + for( ; begin_iter != end_iter; ++begin_iter) { + file << *begin_iter << " "; + } - //SetCurrentFilename(openFileDialog->GetFilename()); - //theText->LoadFile(openFileDialog->GetFilename()); - //SetStatusText(GetCurrentFilename(), 0); - //SetStatusText(openFileDialog->GetDirectory(),1); + file.close(); + file.clear(); } } - /* - * wxEVT_COMMAND_BUTTON_CLICKED event handler for ReGlobalize_Button - */ +* wxEVT_COMMAND_BUTTON_CLICKED event handler for ReGlobalize_Button +*/ void MainWindow::OnReGlobalizeButtonClick( wxCommandEvent& event ) { -globalizeData(); - setProgressBar(1000); - setStatusArea("Done!"); -} + string YesNoMsg = "WARNING: This will DELETE the Edition's GameDataFolder and recreate it from the vanilla Oni game data.\n"; + YesNoMsg = YesNoMsg + "Are you SURE you want to do this?"; + wxMessageDialog* YesNoDialog = new wxMessageDialog(this, YesNoMsg.c_str(), "AE Installer Alert", wxYES_NO | wxICON_EXCLAMATION , wxDefaultPosition); + if (YesNoDialog->ShowModal() == wxID_NO) + { + //if the user said no... + } + else + { + this->InstallButton->Disable(); + this->ReglobalizeButton->Disable(); +#ifdef WIN32 + boost::thread thrd2(globalizeData); + //globalizeData(); + //boost::thread::create_thread(&globalizeData); + // boost::thread_group Tg; + // Tg.create_thread( &globalizeData(), this ); +#else + globalizeData(); +#endif + this->InstallButton->Enable(); + this->ReglobalizeButton->Enable(); + } +} +/* +* wxEVT_COMMAND_RADIOBUTTON_SELECTED event handler for Separated_RadioButton +*/ /* - * wxEVT_COMMAND_RADIOBUTTON_SELECTED event handler for Separated_RadioButton + * wxEVT_COMMAND_RADIOBUTTON_SELECTED event handler for Seperated_RadioButton */ -/*void MainWindow::OnSeparatedRadioButtonSelected( wxCommandEvent& event ) +void MainWindow::OnSeperatedRadioButtonSelected( wxCommandEvent& event ) { -////@begin wxEVT_COMMAND_RADIOBUTTON_SELECTED event handler for Separated_RadioButton in MainWindow. - // Before editing this code, remove the block markers. - event.Skip(); -////@end wxEVT_COMMAND_RADIOBUTTON_SELECTED event handler for Separated_RadioButton in MainWindow. -}*/ + splitInstances = true; +} +void MainWindow::OnDirButtonClick( wxCommandEvent& event ) +{ + wxDirDialog* newDir = new wxDirDialog(this, "Set current directory", "", wxDD_DEFAULT_STYLE, + wxDefaultPosition, wxDefaultSize, "wxDirCtrl"); + newDir->ShowModal(); + if(newDir->GetPath()[0]) current_path( (path)newDir->GetPath() ); + OnRefreshButtonClick(event); +} \ No newline at end of file