--- AE/Installer/trunk/source/installer.cpp 2010/03/27 14:17:32 505 +++ AE/Installer/trunk/source/installer.cpp 2010/05/22 22:07:58 526 @@ -27,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) { @@ -231,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" ); } @@ -245,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" @@ -306,7 +309,7 @@ int globalizeData(void) /* 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/ (Oni wants the folder that *contains* the GDF) + string fullAEpath = escapePath(system_complete(".").parent_path().parent_path().string()); // get full path for Edition/ (Oni wants folder that *contains* the GDF) //bad Iritscen, bad! fixed buffers can cause crashes. /*char prefsCommand[300] = "[ -f ~/Library/Preferences/com.godgames.oni.plist ] && defaults write com.godgames.oni RetailInstallationPath -string '"; strcat(prefsCommand, fullAEpath.c_str()); @@ -374,16 +377,7 @@ vector getPackages(string pa } ModPackage fileToModPackage(fstream &file, string modName) -{ - /* - 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; const string AEInstallVersion = "AEInstallVersion"; // used for comparing to the current token... @@ -575,7 +569,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++; @@ -631,7 +626,8 @@ void recompileAll(vector install importCommand += " ../GameDataFolder/" + dir_itr->path().filename() + ".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 " + + dir_itr->path().filename() + " "); system(importCommand.c_str()); j++; } @@ -708,7 +704,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; @@ -739,8 +735,10 @@ void copyBSL(string copypath, vectorpath(), "../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" ; + } } } } @@ -816,6 +814,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) { @@ -930,7 +929,7 @@ int GetUpdateStatus(Install_info_cfg *cu } newUpdateLog << "Installer was updated to:\n"; newUpdateLog << newUpdateLine.c_str(); - *installerJustUpdated = true; // this value is indirectly returned to AEInstallerAp::OnInit() + *installerJustUpdated = true; // this value is indirectly returned to AEInstallerApp::OnInit() doneReadingFile = true; newUpdateLog.close(); newUpdateLog.clear(); @@ -969,53 +968,51 @@ int GetUpdateStatus(Install_info_cfg *cu return UPDATE_SIMP_AVAIL; } } - try { - directory_iterator end; - if(exists("../updates")){ - for ( directory_iterator install_iter( "../updates" ); - install_iter != end; - ++install_iter ) + try { - - 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()) - { - ModPackage updatePackage = fileToModPackage(file, install_iter->path().filename()); - } - else - { - file.close(); - continue; - } - if(!exists("packages" + install_iter->path().filename() + "/Mod_Info.cfg")); - file.close(); - file.open( ("packages" + install_iter->path().filename() + "/Mod_Info.cfg").c_str()); - if (!file.fail()) - { - ModPackage installedPackage = fileToModPackage(file, install_iter->path().filename()); - } - else + directory_iterator end; + if (exists("../updates")) + { + for (directory_iterator install_iter("../updates"); install_iter != end; ++install_iter) { - file.close(); - return UPDATE_THIRD_PARTY; - } - file.close(); - if(updatePackage.modStringVersion > installedPackage.modStringVersion) { - return UPDATE_THIRD_PARTY; + 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; + } + } } - - } } - - } } catch (exception & ex) { // setStatusArea("Warning, handled exception: " + (string)ex.what()); } - return UPDATE_NO_UPD_AVAIL; } @@ -1030,7 +1027,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 = "->"; @@ -1242,7 +1239,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... @@ -1272,76 +1268,6 @@ bool ProcessInstallerUpdate(Install_info #endif return true; // returning 'true' tells the Installer to quit itself ASAP so it can be replaced by the process that is now running } -//strPathToEUFNPackages - -void CrawlPackages(string pathToUpdate, string strPathToPackages) { - try{ - directory_iterator end; - for ( directory_iterator update_iter( pathToUpdate ); - update_iter != end; - ++update_iter ) - { - - ModPackage installedPackage, updatePackage; - string updateStr = update_iter->path().string() + "/Mod_Info.cfg"; - if ( !boost::iequals(update_iter->path().filename(),"Edition") - && !boost::iequals(update_iter->path().filename(),"Edition-patch") - && is_directory( update_iter->path() ) - && exists( update_iter->path().string() + "/Mod_Info.cfg" ) ) - { - bool update = 0; - fstream file; - file.open( (update_iter->path().string() + "/Mod_Info.cfg").c_str()); - if (!file.fail()) - { - updatePackage = fileToModPackage(file, update_iter->path().filename()); - } - else - { - file.close(); - continue; - } - if(!exists(strPathToPackages + "/" + update_iter->path().filename() + "/Mod_Info.cfg")); - file.close(); - file.clear(); - file.open((strPathToPackages + "/" + update_iter->path().filename() + "/Mod_Info.cfg").c_str()); - if (!file.fail()) - { - installedPackage = fileToModPackage(file, update_iter->path().filename()); - file.close(); - if(updatePackage.modStringVersion > installedPackage.modStringVersion) { - remove_all((path)(strPathToPackages + "/" + installedPackage.modStringName)); - update = 1; - } - } - else - { - file.close(); - update = 1; - } - file.close(); - - if(update) { - rename((path)(pathToUpdate + "/" + updatePackage.modStringName), (path)(strPathToPackages + "/" + updatePackage.modStringName)); - - } - } - } - } - catch (exception & ex) { - // ex.what(); - setStatusArea("Warning, handled exception: " + (string)ex.what()); - } -} - - -bool ProcessThirdPartyUpdates() { -CrawlPackages( "../updates", "./packages"); -return true; - // globalPackages = getPackages(); -// refreshMods(globalInstalledMods); -} - bool ProcessAEUpdate(Install_info_cfg *currentAE, Install_info_cfg *updateAE, bool *installerJustUpdated) { @@ -1368,9 +1294,8 @@ bool ProcessAEUpdate(Install_info_cfg *c bool needNewTrashDir = false; bool readingVerAndDate = false; - // TODO: Fill in Windows equivalent of code below #ifdef WIN32 - string strTrashDir = "Trash\\"; + string strTrashDir = "Trash\\"; // string unused in Windows because files are simply deleted #else FILE *fUserName = NULL; char chrUserName[32]; @@ -1507,7 +1432,7 @@ bool ProcessAEUpdate(Install_info_cfg *c } } - CrawlPackages( strPathToEUFNPackages, strPathToPackages); + ProcessPackageUpdates(strPathToEUFNPackages, strPathToPackages); // 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 @@ -1564,11 +1489,97 @@ 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; } +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 \ | update's Globalize folder and changes its path, originally relative to the Installer, to be | | relative to the structure of the Globalize folder; this makes it easier to have the Installer |