--- AE/Installer/trunk/source/installer.cpp 2010/05/26 23:28:22 550 +++ AE/Installer/trunk/source/installer.cpp 2010/07/21 22:44:28 570 @@ -24,7 +24,6 @@ using namespace boost::gregorian; 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; @@ -310,11 +309,6 @@ int globalizeData(void) 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 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()); - strcat(prefsCommand, "'"); // path string is enclosed in single quotes to avoid the need to escape UNIX-unfriendly characters - */ string prefsCommand = "[ -f ~/Library/Preferences/com.godgames.oni.plist ] && defaults write com.godgames.oni RetailInstallationPath -string '" + fullAEpath + "'"; system(prefsCommand.c_str()); @@ -353,7 +347,8 @@ vector getPackages(string pa if (!file.fail()) { 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 + + if (package.installerVersion.compare(gInstallerVersion) < 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 @@ -379,7 +374,6 @@ vector getPackages(string pa ModPackage fileToModPackage(fstream &file, string modName) { ModPackage package; - string line; const string AEInstallVersion = "AEInstallVersion"; // used for comparing to the current token... const string NameOfMod = "NameOfMod"; const string ARROW = "->"; @@ -395,17 +389,19 @@ ModPackage fileToModPackage(fstream &fil const string GlobalNeeded = "GlobalNeeded"; const string Category = "Category"; const string Creator = "Creator"; - package.modStringName = modName; while (!file.eof()) { - getline(file,line); - vector tokens; + string line; + getline(file, line); + vector tokens; vector::iterator iter; tokenize(line, tokens); if (tokens.capacity() >= 3) { + for (int a = 0; a < tokens.size(); a++) + StripNewlines(&tokens.at(a)); iter = tokens.begin(); - + if (!AEInstallVersion.compare(*iter)) { iter++; iter++; @@ -426,7 +422,7 @@ ModPackage fileToModPackage(fstream &fil iter++; package.modStringVersion = atof((*iter).c_str()); } - else if (!ModString.compare(*iter)) + else if (!ModVersion.compare(*iter)) { iter++; iter++; package.modStringVersion = atof((*iter).c_str()); @@ -497,7 +493,7 @@ ModPackage fileToModPackage(fstream &fil } } } - + package.modStringName = modName; return package; } @@ -597,37 +593,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() + " "); + "level" + lexical_cast(levelnum) + "_Final"+ " "); system(importCommand.c_str()); j++; } @@ -647,13 +659,11 @@ void recompileAll(vector install vector skippedfolders; ofstream BSLlog("BSL.log"); - if(exists("../GameDataFolder/BSLBackup/")) { - remove_all("../GameDataFolder/BSLBackup/"); - } - else { + if(!exists("../GameDataFolder/BSLBackup/")) { create_directory("../GameDataFolder/BSLBackup/"); + copy("../GameDataFolder/IGMD/", "../GameDataFolder/BSLBackup/"); } - copy("../GameDataFolder/IGMD/", "../GameDataFolder/BSLBackup/"); + for ( directory_iterator dir_itr( "../GameDataFolder/IGMD/" ), end_itr; dir_itr != end_itr; ++dir_itr ) { @@ -666,7 +676,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].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"; @@ -746,7 +756,7 @@ void copyBSL(string copypath, vectorpath().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"; @@ -754,6 +764,8 @@ 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()); } } @@ -931,8 +943,7 @@ int GetUpdateStatus(Install_info_cfg *cu else if (readingInstallerVersion && tokens.capacity() >= 3) { readingInstallerVersion = false; - string installerVersion = INSTALLER_VERSION; - if (installerVersion.compare(*iter)) // then the shell script-powered replacement failed + if (gInstallerVersion.compare(*iter)) // then the shell script-powered replacement failed return UPDATE_INST_REPL_ERR; else { @@ -946,7 +957,7 @@ int GetUpdateStatus(Install_info_cfg *cu // Write over old log with updated information ptime startTime(second_clock::local_time()); string strStartTime = to_simple_string(startTime); - string newUpdateLine = installerVersion + " on " + strStartTime; + string newUpdateLine = gInstallerVersion + " 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(); @@ -973,16 +984,10 @@ int GetUpdateStatus(Install_info_cfg *cu return UPDATE_LOG_READ_ERR; } - if (updateAE->AEVersion.compare(currentAE->AEVersion) >= 1) // is the release update newer than what's installed? + if (updateAE->AEVersion.compare(currentAE->AEVersion) > 0) // is the release update newer than what's installed? { - 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) + if (updateAE->InstallerVersion.compare(gInstallerVersion) >= 1) { if (exists(strNewInstallerPath)) return UPDATE_INST_AVAIL; @@ -992,6 +997,8 @@ int GetUpdateStatus(Install_info_cfg *cu else return UPDATE_SIMP_AVAIL; } + else + return UPDATE_MNTH_REQD_ERR; } try { @@ -1022,7 +1029,7 @@ int GetUpdateStatus(Install_info_cfg *cu file.close(); if (updatePackage.modStringVersion > installedPackage.modStringVersion) { - if (updatePackage.installerVersion <= INSTALLER_VERSION) + if (updatePackage.installerVersion.compare(gInstallerVersion) < 1) return UPDATE_PKG_AVAIL; } } @@ -1322,7 +1329,12 @@ bool ProcessAEUpdate(Install_info_cfg *c bool readingVerAndDate = false; #ifdef WIN32 - //string strTrashDir = "Trash\\"; // string unused in Windows because files are simply deleted + //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]; @@ -1466,49 +1478,46 @@ bool ProcessAEUpdate(Install_info_cfg *c #ifndef WIN32 rename((path)("../" + thePath), (path)(strTrashDir + thePath)); #else - remove((path)("../" + thePath)); + remove_all((path)("../" + thePath)); #endif } } 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 - vector foldersToMake, filesToMove; - string thePath; + // 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) { - thePath = dir_itr->path().string(); - MakePathLocalToGlobalize(&thePath); + strPath = dir_itr->path().string(); + MakePathLocalToGlobalize(&strPath); + thePath = (path)strPath; 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)) + if (thePath.filename().at(0) != '.') // skip over dot-files, which are invisible in Unix + { + if (exists(strPathToPackages + strGlobalize + strPath)) + { #ifdef WIN32 - remove((path)(strPathToPackages + strGlobalize + *iter)); + remove((path)(strPathToPackages + strGlobalize + strPath)); #else - rename((path)(strPathToPackages + strGlobalize + *iter), (path)(strTrashDir + *iter)); + create_directories((path)(strTrashDir + thePath.parent_path().string())); + rename((path)(strPathToPackages + strGlobalize + strPath), (path)(strTrashDir + strPath)); #endif - rename((path)(strPathToEUFNPackages + strGlobalize + *iter), (path)(strPathToPackages + strGlobalize + *iter)); + 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)); + } + } + } } // Clean up after ourselves, trashing any packages or programs in the update package that are not newer than the current AE @@ -1541,10 +1550,14 @@ bool ProcessAEUpdate(Install_info_cfg *c } 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) @@ -1603,7 +1616,7 @@ void ProcessPackageUpdates(string pathTo file.close(); if (updatePackage.modStringVersion > installedPackage.modStringVersion) { - if (updatePackage.installerVersion <= INSTALLER_VERSION) + if (updatePackage.installerVersion.compare(gInstallerVersion) < 1) { if(exists(strPathToPackages + "/" + updatePackage.modStringName)) { #ifdef WIN32 @@ -1676,7 +1689,7 @@ 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. */ +\ some extra return characters into strings. */ void StripNewlines(string *theLine) { int deleteFromHere = 0; @@ -1729,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()); } } }