--- AE/Installer/trunk/source/installer.cpp 2010/02/22 00:00:55 496 +++ AE/Installer/trunk/source/installer.cpp 2010/03/22 16:51:50 502 @@ -302,9 +302,9 @@ 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/ + string fullAEpath = escapePath(system_complete(".").parent_path().parent_path().string()); // get full path for Edition/ (Oni wants the folder that *contains* the GDF) 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, fullAEpath.c_str()); strcat(prefsCommand, "'"); // path string is enclosed in single quotes to avoid the need to escape UNIX-unfriendly characters system(prefsCommand); #endif @@ -326,6 +326,7 @@ int globalizeData(void) vector getPackages(string packageDir) { vector packages; + ModPackage package; packages.reserve(256); fstream file; string filename = "\0"; @@ -337,10 +338,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); + 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(); @@ -367,10 +376,11 @@ ModPackage fileToModPackage(fstream &fil */ 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 AEInstallVersion = "AEInstallVersion"; // used for comparing to the current token... + static string NameOfMod = "NameOfMod"; + static string ARROW = "->"; + static string ModString = "ModString"; + static string Platform = "Platform"; static string HasOnis = "HasOnis"; static string HasDeltas = "HasDeltas"; static string HasBSL = "HasBSL"; @@ -380,81 +390,101 @@ ModPackage fileToModPackage(fstream &fil static string GlobalNeeded = "GlobalNeeded"; static string Category = "Category"; static string Creator = "Creator"; - while (! file.eof() ) + 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; iter++; package.modStringVersion = atoi((*iter).c_str()); } - else if (!HasOnis.compare(*iter)) { + else if (!Platform.compare(*iter)) + { + iter++; iter++; + package.platform = *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 (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 (!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 + " "; } } } } - } return package; @@ -939,6 +969,7 @@ bool ReadInstallInfoCfg(fstream *fileHan while (getline(*fileHandler, line)) { + StripNewlines(&line); tokenize(line, tokens); iter = tokens.begin(); @@ -1470,6 +1501,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" ); @@ -1584,6 +1626,7 @@ ModPackage::ModPackage() name = ""; modStringName = ""; modStringVersion = 0; + platform = "Both"; hasOnis = false; hasDeltas = false; hasBSL = false;