--- AE/Installer/trunk/source/installer.cpp 2010/03/03 02:09:02 499 +++ AE/Installer/trunk/source/installer.cpp 2010/05/30 17:28:34 562 @@ -17,6 +17,7 @@ #include "boost/date_time/gregorian/gregorian.hpp" #include "boost/date_time/date_parsing.hpp" #include "boost/date_time/posix_time/posix_time.hpp" +#include #include "installer.h" #include "aeinstallerapp.h" @@ -26,6 +27,7 @@ using namespace boost::posix_time; // externs declared in installer.h string strInstallCfg = "../GameDataFolder/Add.cfg"; string strEUFN = "Edition"; // GetUpdateStatus() may set this to "Edition-patch" later, but this is the assumed name of the new Edition folder in Updates/ +extern MainWindow* TheWindow; int globalizeData(void) { @@ -230,7 +232,8 @@ int globalizeData(void) if ( strcmp(levels[i].c_str(), "0") ){ - system((strOniSplit + " -move:overwrite ../GameDataFolder/level" + levels[i] + "_Final ../GameDataFolder/level" + levels[i] + "_Final/AKEV/AKEV*.oni").c_str()); + system((strOniSplit + " -move:overwrite ../GameDataFolder/level" + levels[i] + "_Final ../GameDataFolder/level" + levels[i] + + "_Final/AKEV/AKEV*.oni").c_str()); remove( "../GameDataFolder/level" + levels[i] + "_Final/AKEV" ); } @@ -244,7 +247,8 @@ int globalizeData(void) for (int i = 0; i < 15; i++) { logfile << "\tReimporting level" << levels[i] << "_Final.oni\n"; - setStatusArea("Step " + lexical_cast(parts_done + 1) + "/" + lexical_cast(total_steps) + " reimporting level" + levels[i]+"_Final.oni"); + setStatusArea("Step " + lexical_cast(parts_done + 1) + "/" + lexical_cast(total_steps) + " reimporting level" + + levels[i] + "_Final.oni"); logfile << (strOniSplit + " " + strImportOption + " ../GameDataFolder/level" + levels[i] + "_Final VanillaDats/level" + levels[i] + "_Final/level" + levels[i] + "_Final/level" + levels[i] + "_Final.oni >> Globalize.log").c_str() << '\n'; string sys_str = (strOniSplit + " " + strImportOption + " ../GameDataFolder/level" + levels[i] + "_Final VanillaDats/level" + levels[i] + "_Final/level" @@ -269,6 +273,7 @@ int globalizeData(void) setStatusArea("Step " + lexical_cast(parts_done + 1) + "/" + lexical_cast(total_steps) + ": moving level0_Characters" ); copy((path)"../GameDataFolder/level0_Characters", (path)("VanillaDats/level0_Final")); GDFPaths.push_back( Characters ); + //concactates level0.... for(int i = 0; i < GDFPaths.size(); i++) { directory_iterator end_iter; @@ -283,30 +288,32 @@ int globalizeData(void) } } } + //?: syntax is fun. + //condition ? value_if_true : value_if_false + (is_empty(Characters) ? remove( Characters ) : 1); + (is_empty(Particles) ? remove( Particles ) : 1); + (is_empty(Textures) ? remove( Textures ) : 1); + (is_empty(Sounds) ? remove( Sounds ) : 1); + (is_empty(TRAC) ? remove( TRAC ) : 1); + (is_empty(TRAM) ? remove( TRAM ) : 1); + (is_empty(Animations) ? remove( Animations ) : 1); create_directory((path)"../GameDataFolder/IGMD"); copy((path)"packages/VanillaBSL/IGMD", (path)"../GameDataFolder"); setProgressBar( 1000 ); - - if(exists("../../persist.dat")) - if(!exists("../persist.dat")) - - //TODO: Concatenate level0 Dirs. - - copy("../../persist.dat",".."); - if(exists("../../key_config.txt")) - if(!exists("../key_config.txt")) - copy("../../key_config.txt",".."); - + + if(exists("../../persist.dat") && !exists("../persist.dat")) copy("../../persist.dat",".."); + if(exists("../../key_config.txt")&& !exists("../key_config.txt")) copy("../../key_config.txt",".."); + #ifndef WIN32 /* On Mac only, set the current GDF to the AE GDF by writing to Oni's global preferences file (thankfully a standard OS X ".plist" XML file). Tests for presence of prefs with [ -f ] before doing anything so it doesn't create a partial prefs file -- just in case user has never run Oni before :-p */ - string fullAEpath = escapePath(system_complete(".").parent_path().parent_path().string()); // get full path for edition/ - char prefsCommand[300] = "[ -f ~/Library/Preferences/com.godgames.oni.plist ] && defaults write com.godgames.oni RetailInstallationPath -string '"; - strcat(prefsCommand, fullAEpath.c_str()); // get path of Edition/ folder (Oni wants the folder that *contains* the GDF) - strcat(prefsCommand, "'"); // path string is enclosed in single quotes to avoid the need to escape UNIX-unfriendly characters - system(prefsCommand); + string fullAEpath = escapePath(system_complete(".").parent_path().parent_path().string()); // get full path for Edition/ (Oni wants folder that *contains* the GDF) + string prefsCommand = "[ -f ~/Library/Preferences/com.godgames.oni.plist ] && defaults write com.godgames.oni RetailInstallationPath -string '" + + fullAEpath + "'"; + system(prefsCommand.c_str()); + #endif setStatusArea((string)"Done! Now select your mod packages and click install."); @@ -326,6 +333,7 @@ int globalizeData(void) vector getPackages(string packageDir) { vector packages; + ModPackage package; packages.reserve(256); fstream file; string filename = "\0"; @@ -337,10 +345,18 @@ vector getPackages(string pa { file.open((dir_itr->path().string() + "/" + MODINFO_CFG).c_str()); - if(!file.fail()) + if (!file.fail()) { - //would prefer to push a pointer to a package, but this will do for now - packages.push_back(fileToModPackage(file)); + package = fileToModPackage(file, dir_itr->path().filename()); + if (package.installerVersion.compare(INSTALLER_VERSION) < 1) // if mod requires newer version of the Installer, we won't add it to the list + { +#ifdef WIN32 + if (!package.platform.compare("Windows") || !package.platform.compare("Both")) // don't show package if it's not for the right OS +#else + if (!package.platform.compare("Macintosh") || !package.platform.compare("Both")) +#endif + packages.push_back(package); + } } file.close(); file.clear(); @@ -355,108 +371,127 @@ vector getPackages(string pa 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 fileToModPackage(fstream &file, string modName) +{ 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() ) + const string AEInstallVersion = "AEInstallVersion"; // used for comparing to the current token... + const string NameOfMod = "NameOfMod"; + const string ARROW = "->"; + const string ModString = "ModString"; + const string ModVersion = "ModVersion"; + const string Platform = "Platform"; + const string HasOnis = "HasOnis"; + const string HasDeltas = "HasDeltas"; + const string HasBSL = "HasBSL"; + const string HasDats = "HasDats"; + const string IsEngine = "IsEngine"; + const string Readme = "Readme"; + const string GlobalNeeded = "GlobalNeeded"; + const string Category = "Category"; + const string Creator = "Creator"; + while (!file.eof()) { - getline (file,line); + getline(file,line); vector tokens; vector::iterator iter; - tokenize(line, tokens); //string to vector of "words" - if (tokens.capacity() >= 3) { //make sure they are using enough stuff - iter = tokens.begin(); //what word we are on, starts at first word - /* TODO: Get this "required Installer version" code working - 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++) { // iterates 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" + tokenize(line, tokens); + if (tokens.capacity() >= 3) + { + iter = tokens.begin(); + + if (!AEInstallVersion.compare(*iter)) + { + iter++; iter++; + package.installerVersion = *iter; + } + else if (!NameOfMod.compare(*iter)) + { + for ( ; iter !=tokens.end() && SLASHSLASH.compare(*iter); iter++) // iterates 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" package.name += *iter + " "; - } } - } - else if (!ModString.compare(*iter)) { + else if (!ModString.compare(*iter)) + { iter++; iter++; - package.modStringName = *iter; + //package.modStringName = *iter; iter++; - package.modStringVersion = atoi((*iter).c_str()); + package.modStringVersion = atof((*iter).c_str()); + } + else if (!ModVersion.compare(*iter)) + { + iter++; iter++; + package.modStringVersion = atof((*iter).c_str()); + } + else if (!Platform.compare(*iter)) + { + iter++; iter++; + package.platform = *iter; } - else if (!HasOnis.compare(*iter)) { + else if (!HasOnis.compare(*iter)) + { iter++; iter++; - if ( boost::iequals(*iter, "Yes")) package.hasOnis = 1; + if (boost::iequals(*iter, "Yes")) package.hasOnis = 1; } - else if (!HasBSL.compare(*iter)) { - if(toupper((*iter)[0]) == 'Y' && toupper((*iter)[1]) == 'E' && toupper((*iter)[2]) == 'S') package.hasBSL = true; - else if ( boost::iequals(*iter, "Addon")) package.hasAddon = true; + else if (!HasBSL.compare(*iter)) + { + iter++; iter++; + if (boost::iequals(*iter, "Yes")) package.hasBSL = true; + else if (boost::iequals(*iter, "Addon")) package.hasAddon = true; } - else if (!HasDeltas.compare(*iter)) { + else if (!HasDeltas.compare(*iter)) + { iter++; iter++; - if (toupper((*iter)[0]) + toupper((*iter)[1]) + toupper((*iter)[2]) == 'Y' + 'E' + 'S') package.hasDeltas = 1; + if (toupper((*iter)[0]) == 'Y' && toupper((*iter)[1]) == 'E' && toupper((*iter)[2]) == 'S') package.hasDeltas = 1; } - else if (!HasDats.compare(*iter)) { + else if (!HasDats.compare(*iter)) + { iter++; iter++; - if (toupper((*iter)[0]) + toupper((*iter)[1]) + toupper((*iter)[2]) == 'Y' + 'E' + 'S') package.hasDats = 1; + if (toupper((*iter)[0]) == 'Y' && toupper((*iter)[1]) == 'E' && toupper((*iter)[2]) == 'S') package.hasDats = 1; } - else if (!IsEngine.compare(*iter)) { + else if (!IsEngine.compare(*iter)) + { iter++; iter++; - if (toupper((*iter)[0]) + toupper((*iter)[1]) + toupper((*iter)[2]) == 'Y' + 'E' + 'S') package.isEngine = 1; + if (toupper((*iter)[0]) == 'Y' && toupper((*iter)[1]) == 'E' && toupper((*iter)[2]) == 'S') package.isEngine = 1; } - else if (!GlobalNeeded.compare(*iter)) { + 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; // only place where checking for "No" is important atm. + if (toupper((*iter)[0]) == 'Y' && toupper((*iter)[1]) == 'E' && toupper((*iter)[2]) == 'S') package.globalNeeded = 1; + else if (toupper((*iter)[0]) == 'N' && toupper((*iter)[1]) == 'O') package.globalNeeded = 1; // only place where checking for "No" is important atm } - else if (!Category.compare(*iter)) { - for ( ; iter !=tokens.end() && SLASHSLASH.compare(*iter); iter++) { // iterates through the words, ends if it reaches end of line or a "//" comment - if (ARROW.compare(*iter) && Category.compare(*iter)) { // ignores "->" and "Category" + else if (!Category.compare(*iter)) + { + for ( ; iter !=tokens.end() && SLASHSLASH.compare(*iter); iter++) + { + if (ARROW.compare(*iter) && Category.compare(*iter)) // ignores "->" and "Category" package.category += *iter + " "; - } } } - else if (!Creator.compare(*iter)) { //if it contains the name - for ( ; iter !=tokens.end() && SLASHSLASH.compare(*iter); iter++) { // iterates through the words, ends if it reaches end of line or a "//" comment - if (ARROW.compare(*iter) && Creator.compare(*iter)) { // ignores "->" and "Creator" + else if (!Creator.compare(*iter)) + { + for ( ; iter !=tokens.end() && SLASHSLASH.compare(*iter); iter++) + { + if (ARROW.compare(*iter) && Creator.compare(*iter)) // ignores "->" and "Creator" package.creator += *iter + " "; - } } } - else if (!Readme.compare(*iter)) { //if it contains the name - for ( ; iter !=tokens.end() && SLASHSLASH.compare(*iter); iter++) { // iterates through the words, ends if it reaches end of line or a "//" comment - if (ARROW.compare(*iter) && Readme.compare(*iter)) { // ignores "->" and "Readme" - if(!(*iter).compare("\\n")) package.readme += '\n'; + else if (!Readme.compare(*iter)) + { + for ( ; iter !=tokens.end() && SLASHSLASH.compare(*iter); iter++) + { + if (ARROW.compare(*iter) && Readme.compare(*iter)) // ignores "->" and "Readme" + { + if (!(*iter).compare("\\n")) package.readme += '\n'; else package.readme += *iter + " "; } } } } - } - + package.modStringName = modName; return package; } @@ -528,7 +563,8 @@ void recompileAll(vector install setProgressBar( (int)(1000 * (float)(j-1) / (float)numberOfDats) ); //100% * dat we're on / total dats - setStatusArea("Step " + lexical_cast(j) + '/' + lexical_cast(numberOfDats)+ ": Importing " + dir_itr->path().filename() + " "); + setStatusArea("Step " + lexical_cast(j) + '/' + lexical_cast(numberOfDats)+ ": Importing " + + dir_itr->path().filename() + " "); system(importCommand.c_str()); j++; @@ -555,36 +591,53 @@ void recompileAll(vector install else if(splitInstances == false){ directory_iterator end_iter; - for ( directory_iterator dir_itr( vanilla_dir ); - dir_itr != end_iter; - ++dir_itr ) - { - if ( is_directory( dir_itr->status() ) ) - { - numberOfDats++; + + char levelnums[256] = {0}; + + + + for(int k = 0; k < 256; k++) { + if( exists( (path)("./VanillaDats/level" + lexical_cast(k) + "_final/") ) ) { + levelnums[k] = 1; + } } - + + for (int i = installedMods.size() - 1; i >= 0; i--) { //Iterates through the installed mods (backwards :P) + for (unsigned int j = 0; j < globalPackages.size(); ++j) { //looking in the global packages + if (globalPackages[j].modStringName == installedMods[i]) { //for a mod that has BSL in it + for(int k = 0; k < 256; k++) { + if( globalPackages[j].hasOnis && + exists( (path)("packages/" + globalPackages[j].modStringName + "/oni/level" + lexical_cast(k) + "_final/") ) ) { + levelnums[k] = 1; + + } + } + } + } + } + for (int levelnum = 0; levelnum < 256; levelnum++) + if (levelnums[levelnum]) + numberOfDats++; + out << numberOfDats; datString = out.str(); - - for ( directory_iterator dir_itr( vanilla_dir ); - dir_itr != end_iter; - ++dir_itr ) - { + + for(int levelnum = 0; levelnum < 256; levelnum++) { try { - if ( is_directory( dir_itr->status() ) ) + if ( levelnums[levelnum] ) { - importCommand = strOniSplit + " " + strImportOption + " " + vanilla_dir.string() + dir_itr->path().filename() + " "; + importCommand = strOniSplit + " " + strImportOption + " " + vanilla_dir.string() + "level" + lexical_cast(levelnum) + "_Final "; for (unsigned 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(); + if (exists((path)("packages/" + installedMods[i] + "/oni/level" + lexical_cast(levelnum) + "_final") )) + importCommand += " packages/" + installedMods[i] + "/oni/level" + lexical_cast(levelnum) + "_Final"; } - importCommand += " ../GameDataFolder/" + dir_itr->path().filename() + ".dat >> Install.log"; + importCommand += " ../GameDataFolder/level" + lexical_cast(levelnum) + "_Final.dat >> Install.log"; setProgressBar( (int)(1000 * (float)(j-1) / (float)numberOfDats) ); //100% * dat we're on / total dats - setStatusArea("Step " + lexical_cast(j) + '/' + lexical_cast(numberOfDats)+ ": Importing " + dir_itr->path().filename() + " "); + setStatusArea("Step " + lexical_cast(j) + '/' + lexical_cast(numberOfDats)+ ": Importing " + + "level" + lexical_cast(levelnum) + "_Final"+ " "); system(importCommand.c_str()); j++; } @@ -604,6 +657,11 @@ void recompileAll(vector install vector skippedfolders; ofstream BSLlog("BSL.log"); + if(!exists("../GameDataFolder/BSLBackup/")) { + create_directory("../GameDataFolder/BSLBackup/"); + copy("../GameDataFolder/IGMD/", "../GameDataFolder/BSLBackup/"); + } + for ( directory_iterator dir_itr( "../GameDataFolder/IGMD/" ), end_itr; dir_itr != end_itr; ++dir_itr ) { @@ -616,7 +674,7 @@ void recompileAll(vector install for (int i = installedMods.size() - 1; i >= 0; i--) { //Iterates through the installed mods (backwards :P) for (unsigned int j = 0; j < globalPackages.size(); ++j) { //looking in the global packages if (globalPackages[j].modStringName == installedMods[i]) { //for a mod that has BSL in it - if(!(globalPackages[j].hasAddon || globalPackages[j].hasBSL)) break; //skip non-BSL + if(globalPackages[j].hasBSL) break; //skip non-BSL if( exists( "packages/" + globalPackages[j].modStringName + "/BSL/" ) ) { copyBSL("packages/" + globalPackages[j].modStringName + "/BSL", BSLfolders, globalPackages[j] ); BSLlog << "Copied " << globalPackages[j].modStringName << "!\n"; @@ -625,12 +683,26 @@ void recompileAll(vector install } } + + ModPackage emptyPackage; emptyPackage.modStringName = "VanillaBSL"; emptyPackage.hasBSL = 1; copyBSL("packages/VanillaBSL/IGMD", BSLfolders, emptyPackage); BSLlog.close(); - + + for (int i = installedMods.size() - 1; i >= 0; i--) { //Iterates through the installed mods (backwards :P) + for (unsigned int j = 0; j < globalPackages.size(); ++j) { //looking in the global packages + if (globalPackages[j].modStringName == installedMods[i]) { //for a mod that has BSL in it + if(!globalPackages[j].hasAddon) break; //skip non-BSL + if( exists( "packages/" + globalPackages[j].modStringName + "/BSL/" ) ) { + copyBSL("packages/" + globalPackages[j].modStringName + "/BSL", BSLfolders, globalPackages[j] ); + BSLlog << "Copied " << globalPackages[j].modStringName << "!\n"; + } + } + } + } + logfile << "Writing config file"; writeInstalledMods(installedMods); setProgressBar(1000); @@ -661,7 +733,7 @@ void recompileAll(vector install void copyBSL(string copypath, vector& BSLfolders, ModPackage pkg) { - ofstream BSLlog("BSL2.log", ios::app ); + ofstream BSLlog("BSL.log", ios::app ); try { for ( directory_iterator dir_itr( copypath ), end_itr; @@ -671,17 +743,18 @@ void copyBSL(string copypath, vectorpath() ) && dir_itr->path().string() != ".svn" ) { BSLlog << "Testing " << dir_itr->path().string() << " HasBSL: " << pkg.hasBSL << " HasAddon: " << pkg.hasAddon << "\n"; int skip_folder = 0; - - for(unsigned int k = 0; k < BSLfolders.size(); k++) {//iterate through already found BSL folders - BSLlog << "testing " << dir_itr->path().filename() << " vs " << BSLfolders[k] << "\n"; - if(dir_itr->path().filename() == BSLfolders[k]) { - skip_folder = 1; - BSLlog << "skipping " << BSLfolders[k] << " in " << pkg.modStringName << "\n"; - break; + if(!pkg.hasAddon) { + for(unsigned int k = 0; k < BSLfolders.size(); k++) {//iterate through already found BSL folders + BSLlog << "testing " << dir_itr->path().filename() << " vs " << BSLfolders[k] << "\n"; + if(dir_itr->path().filename() == BSLfolders[k]) { + skip_folder = 1; + BSLlog << "skipping " << BSLfolders[k] << " in " << pkg.modStringName << "\n"; + break; + } } } if (!skip_folder && !exists("../GameDataFolder/IGMD/" + dir_itr->path().filename() + "/ignore.txt")) { - remove_all( "../GameDataFolder/IGMD/" + dir_itr->path().filename() ); + if(!pkg.hasAddon) remove_all( "../GameDataFolder/IGMD/" + dir_itr->path().filename() ); Sleep(100); create_directory( "../GameDataFolder/IGMD/" + dir_itr->path().filename()); BSLlog << "Copied " << dir_itr->path().string() << " in " << pkg.modStringName << "!\n"; @@ -689,11 +762,15 @@ void copyBSL(string copypath, vectorpath().extension() == ".bsl" ) { + if(exists("../GameDataFolder/IGMD/" + dir_itr->path().filename() + "/" + bsl_itr->path().filename())) + remove("../GameDataFolder/IGMD/" + dir_itr->path().filename() + "/" + bsl_itr->path().filename()); copy_file(bsl_itr->path(), "../GameDataFolder/IGMD/" + dir_itr->path().filename() + "/" + bsl_itr->path().filename()); } } - BSLfolders.push_back( dir_itr->path().filename() ); //add back check for addon - BSLlog << "Pushing " << dir_itr->path().filename() << "\n" ; + if( !pkg.hasAddon ) { + BSLfolders.push_back( dir_itr->path().filename() ); //add back check for addon + BSLlog << "Pushing " << dir_itr->path().filename() << "\n" ; + } } } } @@ -769,6 +846,7 @@ vector getInstallString(string C | Installer to be replaced (when the new Installer | | launches, this function will be called again but will | | return UPDATE_SIMP_AVAIL or UPDATE_GLOB_AVAIL) | +| UPDATE_PKG_AVAIL -- A newer version of individual package(s) is available | \* UPDATE_CONT_UPD -- Currently unused */ int GetUpdateStatus(Install_info_cfg *currentAE, Install_info_cfg *updateAE, bool *installerJustUpdated) { @@ -797,126 +875,177 @@ int GetUpdateStatus(Install_info_cfg *cu else return UPDATE_LOG_READ_ERR; } - - // Is there an update folder, and is it a monthly release or a patch? - if (!exists("../updates/Edition")) + + // Is there an update in the updates/ folder, and is it a monthly release or a patch? + bool firstParty = 0; + // First create the folder if it's missing, so users are never left wondering where updates are supposed to be put + if (!exists("../updates")) + create_directory("../updates"); + if (exists("../updates/Edition")) { + firstParty = 1; + } + else { strEUFN = "Edition-patch"; - if (!exists("../updates/Edition-patch")) - return UPDATE_NO_UPD_AVAIL; + if (exists("../updates/Edition-patch")) { + firstParty = 1; + } + } - - // Unlike the current AE's version info, we *need* to find the update's version info or we won't continue - string updateCfgPath = ("../updates/" + strEUFN + "/install/packages/Globalize/Install_Info.cfg"); - updateAECfg.open(updateCfgPath.c_str()); - if (!updateAECfg.fail()) - { - if (!ReadInstallInfoCfg(&updateAECfg, updateAE)) + + if(firstParty) { + // Unlike the current AE's version info, we *need* to find the update's version info or we won't continue + string updateCfgPath = ("../updates/" + strEUFN + "/install/packages/Globalize/Install_Info.cfg"); + updateAECfg.open(updateCfgPath.c_str()); + if (!updateAECfg.fail()) + { + if (!ReadInstallInfoCfg(&updateAECfg, updateAE)) + return UPDATE_LOG_READ_ERR; + + updateAECfg.close(); + updateAECfg.clear(); + } + else return UPDATE_LOG_READ_ERR; - - updateAECfg.close(); - updateAECfg.clear(); - } - else - return UPDATE_LOG_READ_ERR; - // Now we check for an Installer update in progress - if (exists("Update.log")) - { - updateLog.open("Update.log"); - if (!updateLog.fail()) - { - vector lines; - string line; - int num_lines = 0; - bool readingInstallerVersion = false, doneReadingFile = false; - - while (!updateLog.eof() && !doneReadingFile) + // Now we check for an Installer update in progress + if (exists("Update.log")) + { + updateLog.open("Update.log"); + if (!updateLog.fail()) { - getline(updateLog, line); - lines.push_back(line); - num_lines++; - vector tokens; - vector::iterator iter; - tokenize(line, tokens); - iter = tokens.begin(); - if (!readingInstallerVersion && tokens.capacity() >= 4) + vector lines; + string line; + int num_lines = 0; + bool readingInstallerVersion = false, doneReadingFile = false; + + while (!updateLog.eof() && !doneReadingFile) { - if (!strInstaller.compare(*iter)) + getline(updateLog, line); + lines.push_back(line); + num_lines++; + vector tokens; + vector::iterator iter; + tokenize(line, tokens); + iter = tokens.begin(); + if (!readingInstallerVersion && tokens.capacity() >= 4) { - if (!strBeing.compare(*++iter)) - readingInstallerVersion = true; - else if (!strWas.compare(*iter)) - *installerJustUpdated = true; // our third indirect return value after currentAE and updateAE + if (!strInstaller.compare(*iter)) + { + if (!strBeing.compare(*++iter)) + readingInstallerVersion = true; + else if (!strWas.compare(*iter)) + *installerJustUpdated = true; // our third indirect return value after currentAE and updateAE + } } - } - else if (readingInstallerVersion && tokens.capacity() >= 3) - { - readingInstallerVersion = false; - string installerVersion = INSTALLER_VERSION; - if (installerVersion.compare(*iter)) // then the shell script-powered replacement failed - return UPDATE_INST_REPL_ERR; - else + else if (readingInstallerVersion && tokens.capacity() >= 3) { - updateLog.close(); - updateLog.clear(); - Sleep(1000); - remove("Update.log"); - ofstream newUpdateLog("Update.log"); - if (!newUpdateLog.fail()) + readingInstallerVersion = false; + string installerVersion = INSTALLER_VERSION; + if (installerVersion.compare(*iter)) // then the shell script-powered replacement failed + return UPDATE_INST_REPL_ERR; + else { - // Write over old log with updated information - ptime startTime(second_clock::local_time()); - string strStartTime = to_simple_string(startTime); - string newUpdateLine = installerVersion + " on " + strStartTime; - for (int a = 0; a < lines.capacity() - 2; a++) // if there were even lines in the log before this at all + updateLog.close(); + updateLog.clear(); + Sleep(1000); + remove("Update.log"); + ofstream newUpdateLog("Update.log"); + if (!newUpdateLog.fail()) { - newUpdateLog << lines[a].c_str(); - newUpdateLog << "\n"; + // Write over old log with updated information + ptime startTime(second_clock::local_time()); + string strStartTime = to_simple_string(startTime); + string newUpdateLine = installerVersion + " on " + strStartTime; + for (int a = 0; a < lines.capacity() - 2; a++) // if there were even lines in the log before this at all + { + newUpdateLog << lines[a].c_str(); + newUpdateLog << "\n"; + } + newUpdateLog << "Installer was updated to:\n"; + newUpdateLog << newUpdateLine.c_str(); + *installerJustUpdated = true; // this value is indirectly returned to AEInstallerApp::OnInit() + doneReadingFile = true; + newUpdateLog.close(); + newUpdateLog.clear(); + //return UPDATE_CONT_UPD; // as noted above, we are not using this return value; in fact, we want... + // ...the code to continue running down through the Edition version check } - newUpdateLog << "Installer was updated to:\n"; - newUpdateLog << newUpdateLine.c_str(); - *installerJustUpdated = true; // this value is indirectly returned to AEInstallerAp::OnInit() - doneReadingFile = true; - newUpdateLog.close(); - newUpdateLog.clear(); - //return UPDATE_CONT_UPD; // as noted above, we are not using this return value; in fact, we want... - // ...the code to continue running down through the Edition version check + else + return UPDATE_LOG_READ_ERR; } - else - return UPDATE_LOG_READ_ERR; } } + updateLog.close(); + updateLog.clear(); } - updateLog.close(); - updateLog.clear(); + else + return UPDATE_LOG_READ_ERR; + } + + if (updateAE->AEVersion.compare(currentAE->AEVersion) > 0) // is the release update newer than what's installed? + { + string strNewInstallerPath = "../updates/" + strEUFN + "/install/" + strInstallerName; + string installerVersion = INSTALLER_VERSION; + if (updateAE->InstallerVersion.compare(installerVersion) >= 1) + { + if (exists(strNewInstallerPath)) + return UPDATE_INST_AVAIL; + } + else if (updateAE->globalizationRequired) + return UPDATE_GLOB_AVAIL; + else + return UPDATE_SIMP_AVAIL; } else - return UPDATE_LOG_READ_ERR; + return UPDATE_MNTH_REQD_ERR; } - - if (updateAE->AEVersion.compare(currentAE->AEVersion) >= 1) // is the release update newer than what's installed? + try { - if (!strEUFN.compare("Edition-patch")) // if update is a patch... - { - if (currentAE->AEVersion.compare(updateAE->AEVersion.substr(0, updateAE->AEVersion.length() - 1))) // ...is it for a different month? - return UPDATE_MNTH_REQD_ERR; - } - string strNewInstallerPath = "../updates/" + strEUFN + "/install/" + strInstallerName; - string installerVersion = INSTALLER_VERSION; - if (updateAE->InstallerVersion.compare(installerVersion) >= 1) + directory_iterator end; + if (exists("../updates")) { - if (exists(strNewInstallerPath)) - return UPDATE_INST_AVAIL; + for (directory_iterator install_iter("../updates"); install_iter != end; ++install_iter) + { + ModPackage installedPackage, updatePackage; + if (is_directory(install_iter->path()) && exists(install_iter->path().string() + "/Mod_Info.cfg")) + { + fstream file; + file.open((install_iter->path().string() + "/Mod_Info.cfg").c_str()); + if (!file.fail()) + updatePackage = fileToModPackage(file, install_iter->path().filename()); + else + { + file.close(); + continue; + } + if (exists("packages/" + install_iter->path().filename() + "/Mod_Info.cfg")) + { + file.close(); + file.clear(); + file.open(("packages/" + install_iter->path().filename() + "/Mod_Info.cfg").c_str()); + if (!file.fail()) + installedPackage = fileToModPackage(file, install_iter->path().filename()); + file.close(); + if (updatePackage.modStringVersion > installedPackage.modStringVersion) + { + if (updatePackage.installerVersion <= INSTALLER_VERSION) + return UPDATE_PKG_AVAIL; + } + } + else + { + file.close(); + return UPDATE_PKG_AVAIL; + } + } + } } - else if (updateAE->globalizationRequired) - return UPDATE_GLOB_AVAIL; - else - return UPDATE_SIMP_AVAIL; } - else - return UPDATE_NO_UPD_AVAIL; - + catch (exception & ex) { + // setStatusArea("Warning, handled exception: " + (string)ex.what()); + } + return UPDATE_NO_UPD_AVAIL; } @@ -930,7 +1059,7 @@ bool ReadInstallInfoCfg(fstream *fileHan string strDaodanVersion = "Daodan_Version"; string strOniSplitVersion = "OniSplit_Version"; string strGUIWinVersion = "GUI_Win_Version"; - string strGUIMacVersion = "GUI_Mac_Version"; + string strGUIMacVersion = "GUI_Mac_Version"; string strReglobalize = "Reglobalize"; string strDeleteList = "Delete_List"; string strArrow = "->"; @@ -1142,7 +1271,6 @@ bool ProcessInstallerUpdate(Install_info string popenCommand = "../updates/" + strEUFN + "/install/"; #ifdef WIN32 - // TODO: Fill in Windows equivalent of code below :-3 popenCommand = "replace_installer.bat"; #else // We can't just use '~' to mean "the home directory" because we need to check the path in C... @@ -1175,6 +1303,7 @@ bool ProcessInstallerUpdate(Install_info bool ProcessAEUpdate(Install_info_cfg *currentAE, Install_info_cfg *updateAE, bool *installerJustUpdated) { + try { fstream file; string line; vector tokens, updateStarted; @@ -1194,13 +1323,18 @@ bool ProcessAEUpdate(Install_info_cfg *c string strOniApp = "Oni.exe"; #else string strOniApp = "Oni.app"; -#endif bool needNewTrashDir = false; +#endif + bool readingVerAndDate = false; - // TODO: Fill in Windows equivalent of code below #ifdef WIN32 - string strTrashDir = "Trash\\"; + //remove readonly attrib from files. + setStatusArea("Removing readonly attribute..."); + system("attrib -r ./* /s"); + system("attrib -r ../Oni.exe /s"); + system("attrib -r ../binkw32.dll /s"); + #else FILE *fUserName = NULL; char chrUserName[32]; @@ -1235,6 +1369,7 @@ bool ProcessAEUpdate(Install_info_cfg *c if (readingVerAndDate && tokens.capacity() >= 3) tokenize(tokens[2], updateStarted, "-"); } +#ifndef WIN32 if (updateStarted.capacity() < 3) needNewTrashDir = true; else @@ -1244,6 +1379,7 @@ bool ProcessAEUpdate(Install_info_cfg *c if (!exists(strTrashDir)) needNewTrashDir = true; } +#endif } #ifndef WIN32 if (!*installerJustUpdated || needNewTrashDir) // prepare a new directory for deleted files to go to @@ -1260,16 +1396,24 @@ bool ProcessAEUpdate(Install_info_cfg *c // Special code to replace our special files -- the Oni app, OniSplit, the Daodan DLL, and the GUI for OniSplit if (exists(strPathToEUFN + strOniApp)) { - if (exists(strOniApp)) - rename((path)strOniApp, (path)(strTrashDir + strOniApp)); - rename((path)(strPathToEUFN + strOniApp), (path)strOniApp); + if (exists("../" + strOniApp)) +#ifdef WIN32 + remove((path)("../" + strOniApp)); +#else + rename((path)("../" + strOniApp), (path)(strTrashDir + strOniApp)); +#endif + rename((path)(strPathToEUFN + strOniApp), (path)("../" + strOniApp)); } if (updateAE->OniSplitVersion.compare(currentAE->OniSplitVersion) >= 1) { if (exists(strPathToEUFNInstall + strOniSplit)) { if (exists(strOniSplit)) +#ifdef WIN32 + remove((path)strOniSplit); +#else rename((path)strOniSplit, (path)(strTrashDir + strOniSplit)); +#endif rename((path)(strPathToEUFNInstall + strOniSplit), (path)strOniSplit); } } @@ -1279,7 +1423,7 @@ bool ProcessAEUpdate(Install_info_cfg *c if (exists(strPathToEUFN + strDaodan)) { if (exists(("../" + strDaodan))) - rename((path)("../" + strDaodan), (path)(strTrashDir + strDaodan)); + remove((path)("../" + strDaodan)); rename((path)(strPathToEUFN + strDaodan), (path)("../" + strDaodan)); } } @@ -1288,9 +1432,9 @@ bool ProcessAEUpdate(Install_info_cfg *c if (exists(strPathToEUFNInstall + strWinGUI)) { if (exists((path)strWinGUI)) - rename((path)strWinGUI, (path)(strTrashDir + strWinGUI)); + remove((path)strWinGUI); if (exists(strWinGUILang)) - rename((path)strWinGUILang, (path)(strTrashDir + strWinGUILang)); + remove((path)strWinGUILang); rename((path)(strPathToEUFNInstall + strWinGUI), (path)strWinGUI); rename((path)(strPathToEUFNInstall + strWinGUILang), (path)strWinGUILang); } @@ -1323,8 +1467,10 @@ bool ProcessAEUpdate(Install_info_cfg *c while (curPos != string::npos && curPos < thePath.size()) { aParentPath = aParentPath + thePath.substr(lastPos, curPos - lastPos); +#ifndef WIN32 if (!exists(strTrashDir + aParentPath)) create_directory(strTrashDir + aParentPath); +#endif lastPos = curPos + 1; curPos = thePath.find("/", lastPos); aParentPath = aParentPath + "/"; @@ -1332,81 +1478,55 @@ bool ProcessAEUpdate(Install_info_cfg *c #ifndef WIN32 rename((path)("../" + thePath), (path)(strTrashDir + thePath)); #else - remove((path)("../" + thePath)); + remove_all((path)("../" + thePath)); #endif } } - // Now we crawl the update's package folders for newer versions and move them over, trashing ones that are already present - vector updatePackages, currentPackages; - bool matchFound; - updatePackages.reserve(256); - currentPackages.reserve(256); + ProcessPackageUpdates(strPathToEUFNPackages, strPathToPackages); - currentPackages = getPackages(); - updatePackages = getPackages(strPathToEUFNPackages); - - for (vector::iterator iter1 = updatePackages.begin(); iter1 != updatePackages.end(); iter1++) + // Next, move over files in the update's Globalize folder; subfolders which do not exist in the current AE will be created by Boost's... + // ...create_directories() function + string strPath; + path thePath; + for (recursive_directory_iterator dir_itr(strPathToEUFNPackages + strGlobalize), end_itr; dir_itr != end_itr; ++dir_itr) { - matchFound = false; - for (vector::iterator iter2 = currentPackages.begin(); iter2 != currentPackages.end(); iter2++) + strPath = dir_itr->path().string(); + MakePathLocalToGlobalize(&strPath); + thePath = (path)strPath; + if (is_regular_file(dir_itr->status())) { - if (!iter1->modStringName.compare(iter2->modStringName)) + if (thePath.filename().at(0) != '.') // skip over dot-files, which are invisible in Unix { - matchFound = true; - if (iter1->modStringVersion > iter2->modStringVersion) + if (exists(strPathToPackages + strGlobalize + strPath)) { -#ifndef WIN32 - rename((path)(strPathToPackages + iter2->modStringName), (path)(strTrashDir + iter2->modStringName)); +#ifdef WIN32 + remove((path)(strPathToPackages + strGlobalize + strPath)); #else - remove((path)(strPathToPackages + iter2->modStringName)); + create_directories((path)(strTrashDir + thePath.parent_path().string())); + rename((path)(strPathToPackages + strGlobalize + strPath), (path)(strTrashDir + strPath)); #endif - rename((path)(strPathToEUFNPackages + iter1->modStringName), (path)(strPathToPackages + iter1->modStringName)); + rename((path)(strPathToEUFNPackages + strGlobalize + strPath), (path)(strPathToPackages + strGlobalize + strPath)); + } + else + { + int slashLoc = 0; + slashLoc = strPath.find("/", 0); + if (slashLoc != string::npos) // then path contains slashes, so we need to make sure its parents' paths exist before moving it + create_directories((path)(strPathToPackages + strGlobalize + thePath.parent_path().string())); + rename((path)(strPathToEUFNPackages + strGlobalize + strPath), (path)(strPathToPackages + strGlobalize + strPath)); } } } - if (!matchFound) // then there's no old package in the way, so just move in the one from the update - rename((path)(strPathToEUFNPackages + iter1->modStringName), (path)(strPathToPackages + iter1->modStringName)); - } - - // Next, we get a list of which files and folders in the update's Globalize folder to move over; all files not starting with '.' will be moved... - // ...and folders which do not exist in the current AE will be created there - vector foldersToMake, filesToMove; - string thePath; - for (recursive_directory_iterator dir_itr(strPathToEUFNPackages + strGlobalize), end_itr; dir_itr != end_itr; ++dir_itr) - { - thePath = dir_itr->path().string(); - MakePathLocalToGlobalize(&thePath); - if (is_regular_file(dir_itr->status())) - { - if (dir_itr->filename().at(0) != '.') // skip over dot-files, which are invisible in Unix - filesToMove.push_back(thePath); - } - else if (is_directory(dir_itr->status())) - { - if (!exists(strPathToPackages + strGlobalize + thePath)) - foldersToMake.push_back(thePath); - } - } - // Sort the foldersToMake strings by length, which is a fast solution to the problem of "How do we make sure we create folder 'parent/'... - // ...before folder 'parent/child/'"? - sort(foldersToMake.begin(), foldersToMake.end(), SortBySize); // SortBySize is a custom comparison function found later in this source file - // First make the folders that don't exist in the current AE, so all the files have a place to go - for (vector::iterator iter = foldersToMake.begin(); iter != foldersToMake.end(); iter++) - { - create_directory(strPathToPackages + strGlobalize + *iter); - } - for (vector::iterator iter = filesToMove.begin(); iter != filesToMove.end(); iter++) - { - if (exists(strPathToPackages + strGlobalize + *iter)) - rename((path)(strPathToPackages + strGlobalize + *iter), (path)(strTrashDir + *iter)); - rename((path)(strPathToEUFNPackages + strGlobalize + *iter), (path)(strPathToPackages + strGlobalize + *iter)); } // Clean up after ourselves, trashing any packages or programs in the update package that are not newer than the current AE +#ifdef WIN32 + remove_all((path)strPathToEUFN); +#else create_directory(strTrashDir + "Unneeded update files"); rename((path)strPathToEUFN, (path)(strTrashDir + "Unneeded update files/" + strEUFN)); - +#endif // Write to log that we are finished with update ptime end_time(second_clock::local_time()); string progressMsg2 = "Edition was updated to:\n" + @@ -1424,10 +1544,106 @@ bool ProcessAEUpdate(Install_info_cfg *c CheckForGlobalization(true); // the 'true' value forces re-globalization globalPackages = getPackages(); // refresh the list in memory - - // TODO: Refresh the packages list in the window - + wxCommandEvent e; + TheWindow->OnRefreshButtonClick( e ); return true; + } + catch (exception & ex) + { + wxMessageDialog* DotNetDialogOfDeath = + new wxMessageDialog(TheWindow, ex.what(), "AE Installer Alert", + wxICON_EXCLAMATION , wxDefaultPosition); + + DotNetDialogOfDeath->ShowModal(); + setStatusArea("Warning, handled exception: " + (string)ex.what()); + return false; + } +} + +void ProcessPackageUpdates(string pathToUpdate, string strPathToPackages) +{ + ptime startTime(second_clock::local_time()); +#ifdef WIN32 + string strTrashDir = "Trash\\"; // string unused in Windows because files are simply deleted +#else + FILE *fUserName = NULL; + char chrUserName[32]; + fUserName = popen("whoami", "r"); + fgets(chrUserName, sizeof(chrUserName), fUserName); + pclose(fUserName); + string strUserName = (string)chrUserName; // stringsblaaarrrgggghhhh + int endOfName = strUserName.find("\n", 0); + string strTrashDir = "/Users/" + strUserName.substr(0, endOfName) + "/.Trash/"; + bool needNewTrashDir = true; + tm tmStartTime = to_tm(startTime); +#endif + + try + { + directory_iterator end; + for (directory_iterator update_iter(pathToUpdate); update_iter != end; ++update_iter) + { + ModPackage installedPackage, updatePackage; + string updtPath = update_iter->path().string(); + string updtFolder = update_iter->path().filename(); + string updtModInfo = updtPath + "/Mod_Info.cfg"; + string instModInfo = strPathToPackages + "/" + updtFolder + "/Mod_Info.cfg"; + if (!boost::iequals(updtFolder, "Edition") + && !boost::iequals(updtFolder, "Edition-patch") + && is_directory(update_iter->path()) + && exists(updtModInfo)) + { + fstream file; + file.open((updtModInfo).c_str()); + if (!file.fail()) + updatePackage = fileToModPackage(file, updtFolder); + else + { + file.close(); + continue; + } + if (exists(instModInfo)) + { + file.close(); + file.clear(); + file.open(instModInfo.c_str()); + if (!file.fail()) + { + installedPackage = fileToModPackage(file, updtFolder); + } + file.close(); + } + file.close(); + if (updatePackage.modStringVersion > installedPackage.modStringVersion) + { + if (updatePackage.installerVersion <= INSTALLER_VERSION) + { + if(exists(strPathToPackages + "/" + updatePackage.modStringName)) { +#ifdef WIN32 + remove_all((path)(strPathToPackages + "/" + updatePackage.modStringName)); +#else + if (needNewTrashDir) + { + strTrashDir = strTrashDir + "Old_packages_" + boost::lexical_cast(tmStartTime.tm_hour) + "-" + + boost::lexical_cast(tmStartTime.tm_min) + "-" + boost::lexical_cast(tmStartTime.tm_sec) + "/"; + create_directory(strTrashDir); + needNewTrashDir = false; + } + rename((path)(strPathToPackages + "/" + updatePackage.modStringName), (path)(strTrashDir + updatePackage.modStringName)); +#endif + } + rename((path)(pathToUpdate + "/" + updatePackage.modStringName), (path)(strPathToPackages + "/" + updatePackage.modStringName)); + } + } + } + } + } + catch (exception & ex) + { + setStatusArea("Warning, handled exception: " + (string)ex.what()); + } + wxCommandEvent e; + TheWindow->OnRefreshButtonClick( e ); } /* MakePathLocalToGlobalize is a function used once by ProcessAEUpdate() that takes a file in an \ @@ -1526,23 +1742,23 @@ void copy( const path & from_ph, } else if(from_ph.filename() != ".svn") - { - path destination; - if(!exists(to_ph)) - { - destination=to_ph; - } - else - { - destination=to_ph/from_ph.filename(); - } + { + path destination; + if(!exists(to_ph)) + { + destination=to_ph; + } + else + { + destination=to_ph/from_ph.filename(); + } - for(directory_iterator i(from_ph); i!=directory_iterator(); ++i) + for(directory_iterator i(from_ph); i!=directory_iterator(); ++i) { //the idiot who coded this in the first place (not me) //forgot to make a new directory. Exception city. x_x - create_directory(destination); - copy(*i,destination/i->filename()); + create_directory(destination); + copy(*i, destination/i->filename()); } } } @@ -1596,6 +1812,7 @@ ModPackage::ModPackage() name = ""; modStringName = ""; modStringVersion = 0; + platform = "Both"; hasOnis = false; hasDeltas = false; hasBSL = false;