--- AE/Installer/trunk/source/installer.cpp 2009/12/30 01:51:38 487 +++ AE/Installer/trunk/source/installer.cpp 2010/03/03 02:09:02 499 @@ -9,8 +9,11 @@ // TODO: Load credits from text resource file // TODO: Clear mod info fields when mod is de-selected -#define DEBUG - +//#define DEBUG +#ifdef WIN32 +//#include +#define popen _popen +#endif #include "boost/date_time/gregorian/gregorian.hpp" #include "boost/date_time/date_parsing.hpp" #include "boost/date_time/posix_time/posix_time.hpp" @@ -936,6 +939,7 @@ bool ReadInstallInfoCfg(fstream *fileHan while (getline(*fileHandler, line)) { + StripNewlines(&line); tokenize(line, tokens); iter = tokens.begin(); @@ -1139,6 +1143,7 @@ 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... // ...so we actually get the current user's shortname and manually construct the path to home @@ -1160,8 +1165,11 @@ bool ProcessInstallerUpdate(Install_info #endif file.close(); file.clear(); +#ifdef WIN32 + system(popenCommand.c_str()); +#else popen(popenCommand.c_str(), "r"); - +#endif return true; // returning 'true' tells the Installer to quit itself ASAP so it can be replaced by the process that is now running } @@ -1192,7 +1200,7 @@ bool ProcessAEUpdate(Install_info_cfg *c // TODO: Fill in Windows equivalent of code below #ifdef WIN32 - string strTrashDir = "%RECYCLE%"; + string strTrashDir = "Trash\\"; #else FILE *fUserName = NULL; char chrUserName[32]; @@ -1237,7 +1245,7 @@ bool ProcessAEUpdate(Install_info_cfg *c needNewTrashDir = true; } } - +#ifndef WIN32 if (!*installerJustUpdated || needNewTrashDir) // prepare a new directory for deleted files to go to { tm tmStartTime = to_tm(startTime); @@ -1245,6 +1253,7 @@ bool ProcessAEUpdate(Install_info_cfg *c boost::lexical_cast(tmStartTime.tm_min) + "-" + boost::lexical_cast(tmStartTime.tm_sec) + "/"; create_directory(strTrashDir); } +#endif file.close(); file.clear(); @@ -1279,9 +1288,9 @@ bool ProcessAEUpdate(Install_info_cfg *c if (exists(strPathToEUFNInstall + strWinGUI)) { if (exists((path)strWinGUI)) - rename((path)strWinGUI, (path)strcat(strTrashDir, strWinGUI)); + rename((path)strWinGUI, (path)(strTrashDir + strWinGUI)); if (exists(strWinGUILang)) - rename((path)strWinGUILang, (path)strcat(strTrashDir, strWinGUILang)); + rename((path)strWinGUILang, (path)(strTrashDir + strWinGUILang)); rename((path)(strPathToEUFNInstall + strWinGUI), (path)strWinGUI); rename((path)(strPathToEUFNInstall + strWinGUILang), (path)strWinGUILang); } @@ -1320,7 +1329,11 @@ bool ProcessAEUpdate(Install_info_cfg *c curPos = thePath.find("/", lastPos); aParentPath = aParentPath + "/"; } +#ifndef WIN32 rename((path)("../" + thePath), (path)(strTrashDir + thePath)); +#else + remove((path)("../" + thePath)); +#endif } } @@ -1343,7 +1356,11 @@ bool ProcessAEUpdate(Install_info_cfg *c matchFound = true; if (iter1->modStringVersion > iter2->modStringVersion) { +#ifndef WIN32 rename((path)(strPathToPackages + iter2->modStringName), (path)(strTrashDir + iter2->modStringName)); +#else + remove((path)(strPathToPackages + iter2->modStringName)); +#endif rename((path)(strPathToEUFNPackages + iter1->modStringName), (path)(strPathToPackages + iter1->modStringName)); } } @@ -1454,6 +1471,17 @@ void tokenize(const string& str, vector< } } +/* StripNewlines() gets rids of any linebreaks that come from text returned by getline(); \ +| getline() should be stripping those out, but Windows CR/LF files seem to be sneaking | +\ some extra return characters into strings in the ReadInstallInfoCfg() function. */ +void StripNewlines(string *theLine) +{ + int deleteFromHere = 0; + deleteFromHere = theLine->find("\r"); + if (deleteFromHere > 0) + theLine->erase(deleteFromHere, theLine->size()); +} + void clearOldDats(void) { directory_iterator end_iter_gdf; for ( directory_iterator dir_itr_gdf( "../GameDataFolder" ); @@ -1579,12 +1607,12 @@ ModPackage::ModPackage() readme = ""; globalNeeded = true; } - +#ifndef WIN32 void Sleep(int ms) { sleep(ms / 1000); } - +#endif #ifdef WIN32 void RedirectIOToConsole()