| 9 |
|
// TODO: Load credits from text resource file |
| 10 |
|
// TODO: Clear mod info fields when mod is de-selected |
| 11 |
|
|
| 12 |
< |
#define DEBUG |
| 13 |
< |
|
| 12 |
> |
//#define DEBUG |
| 13 |
> |
#ifdef WIN32 |
| 14 |
> |
//#include <windows.h> |
| 15 |
> |
#define popen _popen |
| 16 |
> |
#endif |
| 17 |
|
#include "boost/date_time/gregorian/gregorian.hpp" |
| 18 |
|
#include "boost/date_time/date_parsing.hpp" |
| 19 |
|
#include "boost/date_time/posix_time/posix_time.hpp" |
| 20 |
+ |
#include <boost/algorithm/string.hpp> |
| 21 |
|
#include "installer.h" |
| 22 |
|
#include "aeinstallerapp.h" |
| 23 |
|
|
| 270 |
|
setStatusArea("Step " + lexical_cast<std::string>(parts_done + 1) + "/" + lexical_cast<std::string>(total_steps) + ": moving level0_Characters" ); |
| 271 |
|
copy((path)"../GameDataFolder/level0_Characters", (path)("VanillaDats/level0_Final")); |
| 272 |
|
GDFPaths.push_back( Characters ); |
| 273 |
+ |
//concactates level0.... |
| 274 |
|
for(int i = 0; i < GDFPaths.size(); i++) |
| 275 |
|
{ |
| 276 |
|
directory_iterator end_iter; |
| 285 |
|
} |
| 286 |
|
} |
| 287 |
|
} |
| 288 |
+ |
//?: syntax is fun. |
| 289 |
+ |
//condition ? value_if_true : value_if_false |
| 290 |
+ |
(is_empty(Characters) ? remove( Characters ) : 1); |
| 291 |
+ |
(is_empty(Particles) ? remove( Particles ) : 1); |
| 292 |
+ |
(is_empty(Textures) ? remove( Textures ) : 1); |
| 293 |
+ |
(is_empty(Sounds) ? remove( Sounds ) : 1); |
| 294 |
+ |
(is_empty(TRAC) ? remove( TRAC ) : 1); |
| 295 |
+ |
(is_empty(TRAM) ? remove( TRAM ) : 1); |
| 296 |
+ |
(is_empty(Animations) ? remove( Animations ) : 1); |
| 297 |
|
|
| 298 |
|
create_directory((path)"../GameDataFolder/IGMD"); |
| 299 |
|
copy((path)"packages/VanillaBSL/IGMD", (path)"../GameDataFolder"); |
| 300 |
|
setProgressBar( 1000 ); |
| 301 |
< |
|
| 302 |
< |
if(exists("../../persist.dat")) |
| 303 |
< |
if(!exists("../persist.dat")) |
| 304 |
< |
|
| 291 |
< |
//TODO: Concatenate level0 Dirs. |
| 292 |
< |
|
| 293 |
< |
copy("../../persist.dat",".."); |
| 294 |
< |
if(exists("../../key_config.txt")) |
| 295 |
< |
if(!exists("../key_config.txt")) |
| 296 |
< |
copy("../../key_config.txt",".."); |
| 297 |
< |
|
| 301 |
> |
|
| 302 |
> |
if(exists("../../persist.dat") && !exists("../persist.dat")) copy("../../persist.dat",".."); |
| 303 |
> |
if(exists("../../key_config.txt")&& !exists("../key_config.txt")) copy("../../key_config.txt",".."); |
| 304 |
> |
|
| 305 |
|
#ifndef WIN32 |
| 306 |
|
/* 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). |
| 307 |
|
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 |
| 308 |
|
run Oni before :-p */ |
| 309 |
< |
string fullAEpath = escapePath(system_complete(".").parent_path().parent_path().string()); // get full path for edition/ |
| 310 |
< |
char prefsCommand[300] = "[ -f ~/Library/Preferences/com.godgames.oni.plist ] && defaults write com.godgames.oni RetailInstallationPath -string '"; |
| 311 |
< |
strcat(prefsCommand, fullAEpath.c_str()); // get path of Edition/ folder (Oni wants the folder that *contains* the GDF) |
| 309 |
> |
string fullAEpath = escapePath(system_complete(".").parent_path().parent_path().string()); // get full path for Edition/ (Oni wants the folder that *contains* the GDF) |
| 310 |
> |
//bad Iritscen, bad! fixed buffers can cause crashes. |
| 311 |
> |
/*char prefsCommand[300] = "[ -f ~/Library/Preferences/com.godgames.oni.plist ] && defaults write com.godgames.oni RetailInstallationPath -string '"; |
| 312 |
> |
strcat(prefsCommand, fullAEpath.c_str()); |
| 313 |
|
strcat(prefsCommand, "'"); // path string is enclosed in single quotes to avoid the need to escape UNIX-unfriendly characters |
| 314 |
< |
system(prefsCommand); |
| 314 |
> |
*/ |
| 315 |
> |
string prefsCommand = "[ -f ~/Library/Preferences/com.godgames.oni.plist ] && defaults write com.godgames.oni RetailInstallationPath -string '" |
| 316 |
> |
+ fullAEpath + "'"; |
| 317 |
> |
system(prefsCommand.c_str()); |
| 318 |
> |
|
| 319 |
|
#endif |
| 320 |
|
|
| 321 |
|
setStatusArea((string)"Done! Now select your mod packages and click install."); |
| 335 |
|
vector<ModPackage> getPackages(string packageDir) |
| 336 |
|
{ |
| 337 |
|
vector<ModPackage> packages; |
| 338 |
+ |
ModPackage package; |
| 339 |
|
packages.reserve(256); |
| 340 |
|
fstream file; |
| 341 |
|
string filename = "\0"; |
| 347 |
|
{ |
| 348 |
|
file.open((dir_itr->path().string() + "/" + MODINFO_CFG).c_str()); |
| 349 |
|
|
| 350 |
< |
if(!file.fail()) |
| 350 |
> |
if (!file.fail()) |
| 351 |
|
{ |
| 352 |
< |
//would prefer to push a pointer to a package, but this will do for now |
| 353 |
< |
packages.push_back(fileToModPackage(file)); |
| 352 |
> |
package = fileToModPackage(file, dir_itr->path().filename()); |
| 353 |
> |
if (package.installerVersion.compare(INSTALLER_VERSION) < 1) // if mod requires newer version of the Installer, we won't add it to the list |
| 354 |
> |
{ |
| 355 |
> |
#ifdef WIN32 |
| 356 |
> |
if (!package.platform.compare("Windows") || !package.platform.compare("Both")) // don't show package if it's not for the right OS |
| 357 |
> |
#else |
| 358 |
> |
if (!package.platform.compare("Macintosh") || !package.platform.compare("Both")) |
| 359 |
> |
#endif |
| 360 |
> |
packages.push_back(package); |
| 361 |
> |
} |
| 362 |
|
} |
| 363 |
|
file.close(); |
| 364 |
|
file.clear(); |
| 373 |
|
return packages; |
| 374 |
|
} |
| 375 |
|
|
| 376 |
< |
ModPackage fileToModPackage(fstream &file) |
| 376 |
> |
ModPackage fileToModPackage(fstream &file, string modName) |
| 377 |
|
{ |
| 378 |
|
/* |
| 379 |
|
This converts a file to a ModPackage struct. |
| 383 |
|
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 |
| 384 |
|
slower than reading a variable. |
| 385 |
|
*/ |
| 386 |
+ |
|
| 387 |
|
ModPackage package; |
| 388 |
|
string line; |
| 389 |
< |
static string NameOfMod = "NameOfMod"; //used for comparing to the current token... |
| 390 |
< |
//I could have done it in reverse (*iter).compare("ModString") or |
| 391 |
< |
static string ARROW = "->"; //did something like "ModString".compare(*iter), and it would have been |
| 392 |
< |
static string ModString = "ModString"; //functionably the same. |
| 393 |
< |
static string HasOnis = "HasOnis"; |
| 394 |
< |
static string HasDeltas = "HasDeltas"; |
| 395 |
< |
static string HasBSL = "HasBSL"; |
| 396 |
< |
static string HasDats = "HasDats"; |
| 397 |
< |
static string IsEngine = "IsEngine"; |
| 398 |
< |
static string Readme = "Readme"; |
| 399 |
< |
static string GlobalNeeded = "GlobalNeeded"; |
| 400 |
< |
static string Category = "Category"; |
| 401 |
< |
static string Creator = "Creator"; |
| 402 |
< |
while (! file.eof() ) |
| 389 |
> |
const string AEInstallVersion = "AEInstallVersion"; // used for comparing to the current token... |
| 390 |
> |
const string NameOfMod = "NameOfMod"; |
| 391 |
> |
const string ARROW = "->"; |
| 392 |
> |
const string ModString = "ModString"; |
| 393 |
> |
const string ModVersion = "ModVersion"; |
| 394 |
> |
const string Platform = "Platform"; |
| 395 |
> |
const string HasOnis = "HasOnis"; |
| 396 |
> |
const string HasDeltas = "HasDeltas"; |
| 397 |
> |
const string HasBSL = "HasBSL"; |
| 398 |
> |
const string HasDats = "HasDats"; |
| 399 |
> |
const string IsEngine = "IsEngine"; |
| 400 |
> |
const string Readme = "Readme"; |
| 401 |
> |
const string GlobalNeeded = "GlobalNeeded"; |
| 402 |
> |
const string Category = "Category"; |
| 403 |
> |
const string Creator = "Creator"; |
| 404 |
> |
package.modStringName = modName; |
| 405 |
> |
while (!file.eof()) |
| 406 |
|
{ |
| 407 |
< |
getline (file,line); |
| 407 |
> |
getline(file,line); |
| 408 |
|
vector<string> tokens; |
| 409 |
|
vector<string>::iterator iter; |
| 410 |
< |
tokenize(line, tokens); //string to vector of "words" |
| 411 |
< |
if (tokens.capacity() >= 3) { //make sure they are using enough stuff |
| 412 |
< |
iter = tokens.begin(); //what word we are on, starts at first word |
| 413 |
< |
/* TODO: Get this "required Installer version" code working |
| 414 |
< |
if (!AEInstallVersion.compare(*iter)) |
| 415 |
< |
If mod is too old, skip this mod. |
| 416 |
< |
*/ |
| 417 |
< |
/*else*/if (!NameOfMod.compare(*iter)) { //if it contains the name |
| 418 |
< |
for ( ; iter !=tokens.end() && SLASHSLASH.compare(*iter); iter++) { // iterates through the words, ends if it reaches the end of the line or a "//" comment |
| 419 |
< |
if (ARROW.compare(*iter) && NameOfMod.compare(*iter)) { // ignores "->" and "NameOfMod" |
| 410 |
> |
tokenize(line, tokens); |
| 411 |
> |
if (tokens.capacity() >= 3) |
| 412 |
> |
{ |
| 413 |
> |
iter = tokens.begin(); |
| 414 |
> |
|
| 415 |
> |
if (!AEInstallVersion.compare(*iter)) |
| 416 |
> |
{ |
| 417 |
> |
iter++; iter++; |
| 418 |
> |
package.installerVersion = *iter; |
| 419 |
> |
} |
| 420 |
> |
else if (!NameOfMod.compare(*iter)) |
| 421 |
> |
{ |
| 422 |
> |
for ( ; iter !=tokens.end() && SLASHSLASH.compare(*iter); iter++) // iterates through the words, ends if it reaches the end of the line or a "//" comment |
| 423 |
> |
{ |
| 424 |
> |
if (ARROW.compare(*iter) && NameOfMod.compare(*iter)) // ignores "->" and "NameOfMod" |
| 425 |
|
package.name += *iter + " "; |
| 396 |
– |
} |
| 426 |
|
} |
| 398 |
– |
|
| 427 |
|
} |
| 428 |
< |
else if (!ModString.compare(*iter)) { |
| 428 |
> |
else if (!ModString.compare(*iter)) |
| 429 |
> |
{ |
| 430 |
|
iter++; iter++; |
| 431 |
< |
package.modStringName = *iter; |
| 431 |
> |
//package.modStringName = *iter; |
| 432 |
|
iter++; |
| 433 |
< |
package.modStringVersion = atoi((*iter).c_str()); |
| 433 |
> |
package.modStringVersion = atof((*iter).c_str()); |
| 434 |
> |
} |
| 435 |
> |
else if (!ModString.compare(*iter)) |
| 436 |
> |
{ |
| 437 |
> |
iter++; iter++; |
| 438 |
> |
package.modStringVersion = atof((*iter).c_str()); |
| 439 |
|
} |
| 440 |
< |
else if (!HasOnis.compare(*iter)) { |
| 440 |
> |
else if (!Platform.compare(*iter)) |
| 441 |
> |
{ |
| 442 |
> |
iter++; iter++; |
| 443 |
> |
package.platform = *iter; |
| 444 |
> |
} |
| 445 |
> |
else if (!HasOnis.compare(*iter)) |
| 446 |
> |
{ |
| 447 |
|
iter++; iter++; |
| 448 |
< |
if ( boost::iequals(*iter, "Yes")) package.hasOnis = 1; |
| 448 |
> |
if (boost::iequals(*iter, "Yes")) package.hasOnis = 1; |
| 449 |
|
} |
| 450 |
< |
else if (!HasBSL.compare(*iter)) { |
| 451 |
< |
if(toupper((*iter)[0]) == 'Y' && toupper((*iter)[1]) == 'E' && toupper((*iter)[2]) == 'S') package.hasBSL = true; |
| 452 |
< |
else if ( boost::iequals(*iter, "Addon")) package.hasAddon = true; |
| 450 |
> |
else if (!HasBSL.compare(*iter)) |
| 451 |
> |
{ |
| 452 |
> |
iter++; iter++; |
| 453 |
> |
if (boost::iequals(*iter, "Yes")) package.hasBSL = true; |
| 454 |
> |
else if (boost::iequals(*iter, "Addon")) package.hasAddon = true; |
| 455 |
|
} |
| 456 |
< |
else if (!HasDeltas.compare(*iter)) { |
| 456 |
> |
else if (!HasDeltas.compare(*iter)) |
| 457 |
> |
{ |
| 458 |
|
iter++; iter++; |
| 459 |
< |
if (toupper((*iter)[0]) + toupper((*iter)[1]) + toupper((*iter)[2]) == 'Y' + 'E' + 'S') package.hasDeltas = 1; |
| 459 |
> |
if (toupper((*iter)[0]) == 'Y' && toupper((*iter)[1]) == 'E' && toupper((*iter)[2]) == 'S') package.hasDeltas = 1; |
| 460 |
|
} |
| 461 |
< |
else if (!HasDats.compare(*iter)) { |
| 461 |
> |
else if (!HasDats.compare(*iter)) |
| 462 |
> |
{ |
| 463 |
|
iter++; iter++; |
| 464 |
< |
if (toupper((*iter)[0]) + toupper((*iter)[1]) + toupper((*iter)[2]) == 'Y' + 'E' + 'S') package.hasDats = 1; |
| 464 |
> |
if (toupper((*iter)[0]) == 'Y' && toupper((*iter)[1]) == 'E' && toupper((*iter)[2]) == 'S') package.hasDats = 1; |
| 465 |
|
} |
| 466 |
< |
else if (!IsEngine.compare(*iter)) { |
| 466 |
> |
else if (!IsEngine.compare(*iter)) |
| 467 |
> |
{ |
| 468 |
|
iter++; iter++; |
| 469 |
< |
if (toupper((*iter)[0]) + toupper((*iter)[1]) + toupper((*iter)[2]) == 'Y' + 'E' + 'S') package.isEngine = 1; |
| 469 |
> |
if (toupper((*iter)[0]) == 'Y' && toupper((*iter)[1]) == 'E' && toupper((*iter)[2]) == 'S') package.isEngine = 1; |
| 470 |
|
} |
| 471 |
< |
else if (!GlobalNeeded.compare(*iter)) { |
| 471 |
> |
else if (!GlobalNeeded.compare(*iter)) |
| 472 |
> |
{ |
| 473 |
|
iter++; iter++; |
| 474 |
< |
if (toupper((*iter)[0]) + toupper((*iter)[1]) + toupper((*iter)[2]) == 'Y' + 'E' + 'S') package.globalNeeded = 1; |
| 475 |
< |
else if (toupper((*iter)[0]) + toupper((*iter)[1]) == 'N' + 'O') package.globalNeeded = 1; // only place where checking for "No" is important atm. |
| 474 |
> |
if (toupper((*iter)[0]) == 'Y' && toupper((*iter)[1]) == 'E' && toupper((*iter)[2]) == 'S') package.globalNeeded = 1; |
| 475 |
> |
else if (toupper((*iter)[0]) == 'N' && toupper((*iter)[1]) == 'O') package.globalNeeded = 1; // only place where checking for "No" is important atm |
| 476 |
|
} |
| 477 |
< |
else if (!Category.compare(*iter)) { |
| 478 |
< |
for ( ; iter !=tokens.end() && SLASHSLASH.compare(*iter); iter++) { // iterates through the words, ends if it reaches end of line or a "//" comment |
| 479 |
< |
if (ARROW.compare(*iter) && Category.compare(*iter)) { // ignores "->" and "Category" |
| 477 |
> |
else if (!Category.compare(*iter)) |
| 478 |
> |
{ |
| 479 |
> |
for ( ; iter !=tokens.end() && SLASHSLASH.compare(*iter); iter++) |
| 480 |
> |
{ |
| 481 |
> |
if (ARROW.compare(*iter) && Category.compare(*iter)) // ignores "->" and "Category" |
| 482 |
|
package.category += *iter + " "; |
| 435 |
– |
} |
| 483 |
|
} |
| 484 |
|
} |
| 485 |
< |
else if (!Creator.compare(*iter)) { //if it contains the name |
| 486 |
< |
for ( ; iter !=tokens.end() && SLASHSLASH.compare(*iter); iter++) { // iterates through the words, ends if it reaches end of line or a "//" comment |
| 487 |
< |
if (ARROW.compare(*iter) && Creator.compare(*iter)) { // ignores "->" and "Creator" |
| 485 |
> |
else if (!Creator.compare(*iter)) |
| 486 |
> |
{ |
| 487 |
> |
for ( ; iter !=tokens.end() && SLASHSLASH.compare(*iter); iter++) |
| 488 |
> |
{ |
| 489 |
> |
if (ARROW.compare(*iter) && Creator.compare(*iter)) // ignores "->" and "Creator" |
| 490 |
|
package.creator += *iter + " "; |
| 442 |
– |
} |
| 491 |
|
} |
| 492 |
|
} |
| 493 |
< |
else if (!Readme.compare(*iter)) { //if it contains the name |
| 494 |
< |
for ( ; iter !=tokens.end() && SLASHSLASH.compare(*iter); iter++) { // iterates through the words, ends if it reaches end of line or a "//" comment |
| 495 |
< |
if (ARROW.compare(*iter) && Readme.compare(*iter)) { // ignores "->" and "Readme" |
| 496 |
< |
if(!(*iter).compare("\\n")) package.readme += '\n'; |
| 493 |
> |
else if (!Readme.compare(*iter)) |
| 494 |
> |
{ |
| 495 |
> |
for ( ; iter !=tokens.end() && SLASHSLASH.compare(*iter); iter++) |
| 496 |
> |
{ |
| 497 |
> |
if (ARROW.compare(*iter) && Readme.compare(*iter)) // ignores "->" and "Readme" |
| 498 |
> |
{ |
| 499 |
> |
if (!(*iter).compare("\\n")) package.readme += '\n'; |
| 500 |
|
else package.readme += *iter + " "; |
| 501 |
|
} |
| 502 |
|
} |
| 503 |
|
} |
| 504 |
|
} |
| 454 |
– |
|
| 505 |
|
} |
| 506 |
|
|
| 507 |
|
return package; |
| 844 |
|
else |
| 845 |
|
return UPDATE_LOG_READ_ERR; |
| 846 |
|
} |
| 847 |
< |
|
| 847 |
> |
|
| 848 |
|
// Is there an update folder, and is it a monthly release or a patch? |
| 849 |
< |
if (!exists("../updates/Edition")) |
| 849 |
> |
bool firstParty = 0; |
| 850 |
> |
if (exists("../updates/Edition")) |
| 851 |
|
{ |
| 852 |
+ |
firstParty = 1; |
| 853 |
+ |
} |
| 854 |
+ |
else { |
| 855 |
|
strEUFN = "Edition-patch"; |
| 856 |
< |
if (!exists("../updates/Edition-patch")) |
| 857 |
< |
return UPDATE_NO_UPD_AVAIL; |
| 856 |
> |
if (exists("../updates/Edition-patch")) { |
| 857 |
> |
firstParty = 1; |
| 858 |
> |
} |
| 859 |
> |
|
| 860 |
|
} |
| 861 |
< |
|
| 862 |
< |
// Unlike the current AE's version info, we *need* to find the update's version info or we won't continue |
| 863 |
< |
string updateCfgPath = ("../updates/" + strEUFN + "/install/packages/Globalize/Install_Info.cfg"); |
| 864 |
< |
updateAECfg.open(updateCfgPath.c_str()); |
| 865 |
< |
if (!updateAECfg.fail()) |
| 866 |
< |
{ |
| 867 |
< |
if (!ReadInstallInfoCfg(&updateAECfg, updateAE)) |
| 861 |
> |
|
| 862 |
> |
if(firstParty) { |
| 863 |
> |
// Unlike the current AE's version info, we *need* to find the update's version info or we won't continue |
| 864 |
> |
string updateCfgPath = ("../updates/" + strEUFN + "/install/packages/Globalize/Install_Info.cfg"); |
| 865 |
> |
updateAECfg.open(updateCfgPath.c_str()); |
| 866 |
> |
if (!updateAECfg.fail()) |
| 867 |
> |
{ |
| 868 |
> |
if (!ReadInstallInfoCfg(&updateAECfg, updateAE)) |
| 869 |
> |
return UPDATE_LOG_READ_ERR; |
| 870 |
> |
|
| 871 |
> |
updateAECfg.close(); |
| 872 |
> |
updateAECfg.clear(); |
| 873 |
> |
} |
| 874 |
> |
else |
| 875 |
|
return UPDATE_LOG_READ_ERR; |
| 813 |
– |
|
| 814 |
– |
updateAECfg.close(); |
| 815 |
– |
updateAECfg.clear(); |
| 816 |
– |
} |
| 817 |
– |
else |
| 818 |
– |
return UPDATE_LOG_READ_ERR; |
| 876 |
|
|
| 877 |
< |
// Now we check for an Installer update in progress |
| 878 |
< |
if (exists("Update.log")) |
| 879 |
< |
{ |
| 880 |
< |
updateLog.open("Update.log"); |
| 881 |
< |
if (!updateLog.fail()) |
| 825 |
< |
{ |
| 826 |
< |
vector<string> lines; |
| 827 |
< |
string line; |
| 828 |
< |
int num_lines = 0; |
| 829 |
< |
bool readingInstallerVersion = false, doneReadingFile = false; |
| 830 |
< |
|
| 831 |
< |
while (!updateLog.eof() && !doneReadingFile) |
| 877 |
> |
// Now we check for an Installer update in progress |
| 878 |
> |
if (exists("Update.log")) |
| 879 |
> |
{ |
| 880 |
> |
updateLog.open("Update.log"); |
| 881 |
> |
if (!updateLog.fail()) |
| 882 |
|
{ |
| 883 |
< |
getline(updateLog, line); |
| 884 |
< |
lines.push_back(line); |
| 885 |
< |
num_lines++; |
| 886 |
< |
vector<string> tokens; |
| 887 |
< |
vector<string>::iterator iter; |
| 888 |
< |
tokenize(line, tokens); |
| 839 |
< |
iter = tokens.begin(); |
| 840 |
< |
if (!readingInstallerVersion && tokens.capacity() >= 4) |
| 883 |
> |
vector<string> lines; |
| 884 |
> |
string line; |
| 885 |
> |
int num_lines = 0; |
| 886 |
> |
bool readingInstallerVersion = false, doneReadingFile = false; |
| 887 |
> |
|
| 888 |
> |
while (!updateLog.eof() && !doneReadingFile) |
| 889 |
|
{ |
| 890 |
< |
if (!strInstaller.compare(*iter)) |
| 890 |
> |
getline(updateLog, line); |
| 891 |
> |
lines.push_back(line); |
| 892 |
> |
num_lines++; |
| 893 |
> |
vector<string> tokens; |
| 894 |
> |
vector<string>::iterator iter; |
| 895 |
> |
tokenize(line, tokens); |
| 896 |
> |
iter = tokens.begin(); |
| 897 |
> |
if (!readingInstallerVersion && tokens.capacity() >= 4) |
| 898 |
|
{ |
| 899 |
< |
if (!strBeing.compare(*++iter)) |
| 900 |
< |
readingInstallerVersion = true; |
| 901 |
< |
else if (!strWas.compare(*iter)) |
| 902 |
< |
*installerJustUpdated = true; // our third indirect return value after currentAE and updateAE |
| 899 |
> |
if (!strInstaller.compare(*iter)) |
| 900 |
> |
{ |
| 901 |
> |
if (!strBeing.compare(*++iter)) |
| 902 |
> |
readingInstallerVersion = true; |
| 903 |
> |
else if (!strWas.compare(*iter)) |
| 904 |
> |
*installerJustUpdated = true; // our third indirect return value after currentAE and updateAE |
| 905 |
> |
} |
| 906 |
|
} |
| 907 |
< |
} |
| 850 |
< |
else if (readingInstallerVersion && tokens.capacity() >= 3) |
| 851 |
< |
{ |
| 852 |
< |
readingInstallerVersion = false; |
| 853 |
< |
string installerVersion = INSTALLER_VERSION; |
| 854 |
< |
if (installerVersion.compare(*iter)) // then the shell script-powered replacement failed |
| 855 |
< |
return UPDATE_INST_REPL_ERR; |
| 856 |
< |
else |
| 907 |
> |
else if (readingInstallerVersion && tokens.capacity() >= 3) |
| 908 |
|
{ |
| 909 |
< |
updateLog.close(); |
| 910 |
< |
updateLog.clear(); |
| 911 |
< |
Sleep(1000); |
| 912 |
< |
remove("Update.log"); |
| 913 |
< |
ofstream newUpdateLog("Update.log"); |
| 863 |
< |
if (!newUpdateLog.fail()) |
| 909 |
> |
readingInstallerVersion = false; |
| 910 |
> |
string installerVersion = INSTALLER_VERSION; |
| 911 |
> |
if (installerVersion.compare(*iter)) // then the shell script-powered replacement failed |
| 912 |
> |
return UPDATE_INST_REPL_ERR; |
| 913 |
> |
else |
| 914 |
|
{ |
| 915 |
< |
// Write over old log with updated information |
| 916 |
< |
ptime startTime(second_clock::local_time()); |
| 917 |
< |
string strStartTime = to_simple_string(startTime); |
| 918 |
< |
string newUpdateLine = installerVersion + " on " + strStartTime; |
| 919 |
< |
for (int a = 0; a < lines.capacity() - 2; a++) // if there were even lines in the log before this at all |
| 915 |
> |
updateLog.close(); |
| 916 |
> |
updateLog.clear(); |
| 917 |
> |
Sleep(1000); |
| 918 |
> |
remove("Update.log"); |
| 919 |
> |
ofstream newUpdateLog("Update.log"); |
| 920 |
> |
if (!newUpdateLog.fail()) |
| 921 |
|
{ |
| 922 |
< |
newUpdateLog << lines[a].c_str(); |
| 923 |
< |
newUpdateLog << "\n"; |
| 922 |
> |
// Write over old log with updated information |
| 923 |
> |
ptime startTime(second_clock::local_time()); |
| 924 |
> |
string strStartTime = to_simple_string(startTime); |
| 925 |
> |
string newUpdateLine = installerVersion + " on " + strStartTime; |
| 926 |
> |
for (int a = 0; a < lines.capacity() - 2; a++) // if there were even lines in the log before this at all |
| 927 |
> |
{ |
| 928 |
> |
newUpdateLog << lines[a].c_str(); |
| 929 |
> |
newUpdateLog << "\n"; |
| 930 |
> |
} |
| 931 |
> |
newUpdateLog << "Installer was updated to:\n"; |
| 932 |
> |
newUpdateLog << newUpdateLine.c_str(); |
| 933 |
> |
*installerJustUpdated = true; // this value is indirectly returned to AEInstallerAp::OnInit() |
| 934 |
> |
doneReadingFile = true; |
| 935 |
> |
newUpdateLog.close(); |
| 936 |
> |
newUpdateLog.clear(); |
| 937 |
> |
//return UPDATE_CONT_UPD; // as noted above, we are not using this return value; in fact, we want... |
| 938 |
> |
// ...the code to continue running down through the Edition version check |
| 939 |
|
} |
| 940 |
< |
newUpdateLog << "Installer was updated to:\n"; |
| 941 |
< |
newUpdateLog << newUpdateLine.c_str(); |
| 876 |
< |
*installerJustUpdated = true; // this value is indirectly returned to AEInstallerAp::OnInit() |
| 877 |
< |
doneReadingFile = true; |
| 878 |
< |
newUpdateLog.close(); |
| 879 |
< |
newUpdateLog.clear(); |
| 880 |
< |
//return UPDATE_CONT_UPD; // as noted above, we are not using this return value; in fact, we want... |
| 881 |
< |
// ...the code to continue running down through the Edition version check |
| 940 |
> |
else |
| 941 |
> |
return UPDATE_LOG_READ_ERR; |
| 942 |
|
} |
| 883 |
– |
else |
| 884 |
– |
return UPDATE_LOG_READ_ERR; |
| 943 |
|
} |
| 944 |
|
} |
| 945 |
+ |
updateLog.close(); |
| 946 |
+ |
updateLog.clear(); |
| 947 |
|
} |
| 948 |
< |
updateLog.close(); |
| 949 |
< |
updateLog.clear(); |
| 948 |
> |
else |
| 949 |
> |
return UPDATE_LOG_READ_ERR; |
| 950 |
> |
} |
| 951 |
> |
|
| 952 |
> |
if (updateAE->AEVersion.compare(currentAE->AEVersion) >= 1) // is the release update newer than what's installed? |
| 953 |
> |
{ |
| 954 |
> |
if (!strEUFN.compare("Edition-patch")) // if update is a patch... |
| 955 |
> |
{ |
| 956 |
> |
if (currentAE->AEVersion.compare(updateAE->AEVersion.substr(0, updateAE->AEVersion.length() - 1))) // ...is it for a different month? |
| 957 |
> |
return UPDATE_MNTH_REQD_ERR; |
| 958 |
> |
} |
| 959 |
> |
string strNewInstallerPath = "../updates/" + strEUFN + "/install/" + strInstallerName; |
| 960 |
> |
string installerVersion = INSTALLER_VERSION; |
| 961 |
> |
if (updateAE->InstallerVersion.compare(installerVersion) >= 1) |
| 962 |
> |
{ |
| 963 |
> |
if (exists(strNewInstallerPath)) |
| 964 |
> |
return UPDATE_INST_AVAIL; |
| 965 |
> |
} |
| 966 |
> |
else if (updateAE->globalizationRequired) |
| 967 |
> |
return UPDATE_GLOB_AVAIL; |
| 968 |
> |
else |
| 969 |
> |
return UPDATE_SIMP_AVAIL; |
| 970 |
|
} |
| 891 |
– |
else |
| 892 |
– |
return UPDATE_LOG_READ_ERR; |
| 971 |
|
} |
| 972 |
< |
|
| 973 |
< |
if (updateAE->AEVersion.compare(currentAE->AEVersion) >= 1) // is the release update newer than what's installed? |
| 972 |
> |
try { |
| 973 |
> |
directory_iterator end; |
| 974 |
> |
if(exists("../updates")){ |
| 975 |
> |
for ( directory_iterator install_iter( "../updates" ); |
| 976 |
> |
install_iter != end; |
| 977 |
> |
++install_iter ) |
| 978 |
|
{ |
| 979 |
< |
if (!strEUFN.compare("Edition-patch")) // if update is a patch... |
| 980 |
< |
{ |
| 981 |
< |
if (currentAE->AEVersion.compare(updateAE->AEVersion.substr(0, updateAE->AEVersion.length() - 1))) // ...is it for a different month? |
| 982 |
< |
return UPDATE_MNTH_REQD_ERR; |
| 979 |
> |
|
| 980 |
> |
ModPackage installedPackage, updatePackage; |
| 981 |
> |
if ( is_directory( install_iter->path() ) && exists( install_iter->path().string() + "/Mod_Info.cfg" ) ) { |
| 982 |
> |
fstream file; |
| 983 |
> |
file.open( (install_iter->path().string() + "/Mod_Info.cfg").c_str()); |
| 984 |
> |
if (!file.fail()) |
| 985 |
> |
{ |
| 986 |
> |
ModPackage updatePackage = fileToModPackage(file, install_iter->path().filename()); |
| 987 |
> |
} |
| 988 |
> |
else |
| 989 |
> |
{ |
| 990 |
> |
file.close(); |
| 991 |
> |
continue; |
| 992 |
> |
} |
| 993 |
> |
if(!exists("packages" + install_iter->path().filename() + "/Mod_Info.cfg")); |
| 994 |
> |
file.close(); |
| 995 |
> |
file.open( ("packages" + install_iter->path().filename() + "/Mod_Info.cfg").c_str()); |
| 996 |
> |
if (!file.fail()) |
| 997 |
> |
{ |
| 998 |
> |
ModPackage installedPackage = fileToModPackage(file, install_iter->path().filename()); |
| 999 |
> |
} |
| 1000 |
> |
else |
| 1001 |
> |
{ |
| 1002 |
> |
file.close(); |
| 1003 |
> |
return UPDATE_THIRD_PARTY; |
| 1004 |
> |
} |
| 1005 |
> |
file.close(); |
| 1006 |
> |
if(updatePackage.modStringVersion > installedPackage.modStringVersion) { |
| 1007 |
> |
return UPDATE_THIRD_PARTY; |
| 1008 |
> |
} |
| 1009 |
> |
|
| 1010 |
|
} |
| 902 |
– |
string strNewInstallerPath = "../updates/" + strEUFN + "/install/" + strInstallerName; |
| 903 |
– |
string installerVersion = INSTALLER_VERSION; |
| 904 |
– |
if (updateAE->InstallerVersion.compare(installerVersion) >= 1) |
| 905 |
– |
{ |
| 906 |
– |
if (exists(strNewInstallerPath)) |
| 907 |
– |
return UPDATE_INST_AVAIL; |
| 1011 |
|
} |
| 1012 |
< |
else if (updateAE->globalizationRequired) |
| 1013 |
< |
return UPDATE_GLOB_AVAIL; |
| 1014 |
< |
else |
| 1015 |
< |
return UPDATE_SIMP_AVAIL; |
| 1012 |
> |
|
| 1013 |
> |
} |
| 1014 |
> |
} |
| 1015 |
> |
catch (exception & ex) { |
| 1016 |
> |
// setStatusArea("Warning, handled exception: " + (string)ex.what()); |
| 1017 |
|
} |
| 914 |
– |
else |
| 915 |
– |
return UPDATE_NO_UPD_AVAIL; |
| 1018 |
|
|
| 1019 |
+ |
|
| 1020 |
|
return UPDATE_NO_UPD_AVAIL; |
| 1021 |
|
} |
| 1022 |
|
|
| 1039 |
|
|
| 1040 |
|
while (getline(*fileHandler, line)) |
| 1041 |
|
{ |
| 1042 |
+ |
StripNewlines(&line); |
| 1043 |
|
tokenize(line, tokens); |
| 1044 |
|
iter = tokens.begin(); |
| 1045 |
|
|
| 1243 |
|
string popenCommand = "../updates/" + strEUFN + "/install/"; |
| 1244 |
|
#ifdef WIN32 |
| 1245 |
|
// TODO: Fill in Windows equivalent of code below :-3 |
| 1246 |
+ |
popenCommand = "replace_installer.bat"; |
| 1247 |
|
#else |
| 1248 |
|
// We can't just use '~' to mean "the home directory" because we need to check the path in C... |
| 1249 |
|
// ...so we actually get the current user's shortname and manually construct the path to home |
| 1265 |
|
#endif |
| 1266 |
|
file.close(); |
| 1267 |
|
file.clear(); |
| 1268 |
+ |
#ifdef WIN32 |
| 1269 |
+ |
system(popenCommand.c_str()); |
| 1270 |
+ |
#else |
| 1271 |
|
popen(popenCommand.c_str(), "r"); |
| 1272 |
< |
|
| 1272 |
> |
#endif |
| 1273 |
|
return true; // returning 'true' tells the Installer to quit itself ASAP so it can be replaced by the process that is now running |
| 1274 |
|
} |
| 1275 |
+ |
//strPathToEUFNPackages |
| 1276 |
+ |
|
| 1277 |
+ |
void CrawlPackages(string pathToUpdate, string strPathToPackages) { |
| 1278 |
+ |
try{ |
| 1279 |
+ |
directory_iterator end; |
| 1280 |
+ |
for ( directory_iterator update_iter( pathToUpdate ); |
| 1281 |
+ |
update_iter != end; |
| 1282 |
+ |
++update_iter ) |
| 1283 |
+ |
{ |
| 1284 |
+ |
|
| 1285 |
+ |
ModPackage installedPackage, updatePackage; |
| 1286 |
+ |
string updateStr = update_iter->path().string() + "/Mod_Info.cfg"; |
| 1287 |
+ |
if ( !boost::iequals(update_iter->path().filename(),"Edition") |
| 1288 |
+ |
&& !boost::iequals(update_iter->path().filename(),"Edition-patch") |
| 1289 |
+ |
&& is_directory( update_iter->path() ) |
| 1290 |
+ |
&& exists( update_iter->path().string() + "/Mod_Info.cfg" ) ) |
| 1291 |
+ |
{ |
| 1292 |
+ |
bool update = 0; |
| 1293 |
+ |
fstream file; |
| 1294 |
+ |
file.open( (update_iter->path().string() + "/Mod_Info.cfg").c_str()); |
| 1295 |
+ |
if (!file.fail()) |
| 1296 |
+ |
{ |
| 1297 |
+ |
updatePackage = fileToModPackage(file, update_iter->path().filename()); |
| 1298 |
+ |
} |
| 1299 |
+ |
else |
| 1300 |
+ |
{ |
| 1301 |
+ |
file.close(); |
| 1302 |
+ |
continue; |
| 1303 |
+ |
} |
| 1304 |
+ |
if(!exists(strPathToPackages + "/" + update_iter->path().filename() + "/Mod_Info.cfg")); |
| 1305 |
+ |
file.close(); |
| 1306 |
+ |
file.clear(); |
| 1307 |
+ |
file.open((strPathToPackages + "/" + update_iter->path().filename() + "/Mod_Info.cfg").c_str()); |
| 1308 |
+ |
if (!file.fail()) |
| 1309 |
+ |
{ |
| 1310 |
+ |
installedPackage = fileToModPackage(file, update_iter->path().filename()); |
| 1311 |
+ |
file.close(); |
| 1312 |
+ |
if(updatePackage.modStringVersion > installedPackage.modStringVersion) { |
| 1313 |
+ |
remove_all((path)(strPathToPackages + "/" + installedPackage.modStringName)); |
| 1314 |
+ |
update = 1; |
| 1315 |
+ |
} |
| 1316 |
+ |
} |
| 1317 |
+ |
else |
| 1318 |
+ |
{ |
| 1319 |
+ |
file.close(); |
| 1320 |
+ |
update = 1; |
| 1321 |
+ |
} |
| 1322 |
+ |
file.close(); |
| 1323 |
+ |
|
| 1324 |
+ |
if(update) { |
| 1325 |
+ |
rename((path)(pathToUpdate + "/" + updatePackage.modStringName), (path)(strPathToPackages + "/" + updatePackage.modStringName)); |
| 1326 |
+ |
|
| 1327 |
+ |
} |
| 1328 |
+ |
} |
| 1329 |
+ |
} |
| 1330 |
+ |
} |
| 1331 |
+ |
catch (exception & ex) { |
| 1332 |
+ |
// ex.what(); |
| 1333 |
+ |
setStatusArea("Warning, handled exception: " + (string)ex.what()); |
| 1334 |
+ |
} |
| 1335 |
+ |
} |
| 1336 |
+ |
|
| 1337 |
+ |
|
| 1338 |
+ |
bool ProcessThirdPartyUpdates() { |
| 1339 |
+ |
CrawlPackages( "../updates", "./packages"); |
| 1340 |
+ |
return true; |
| 1341 |
+ |
// globalPackages = getPackages(); |
| 1342 |
+ |
// refreshMods(globalInstalledMods); |
| 1343 |
+ |
} |
| 1344 |
+ |
|
| 1345 |
|
|
| 1346 |
|
bool ProcessAEUpdate(Install_info_cfg *currentAE, Install_info_cfg *updateAE, bool *installerJustUpdated) |
| 1347 |
|
{ |
| 1370 |
|
|
| 1371 |
|
// TODO: Fill in Windows equivalent of code below |
| 1372 |
|
#ifdef WIN32 |
| 1373 |
< |
string strTrashDir = "%RECYCLE%"; |
| 1373 |
> |
string strTrashDir = "Trash\\"; |
| 1374 |
|
#else |
| 1375 |
|
FILE *fUserName = NULL; |
| 1376 |
|
char chrUserName[32]; |
| 1415 |
|
needNewTrashDir = true; |
| 1416 |
|
} |
| 1417 |
|
} |
| 1418 |
< |
|
| 1418 |
> |
#ifndef WIN32 |
| 1419 |
|
if (!*installerJustUpdated || needNewTrashDir) // prepare a new directory for deleted files to go to |
| 1420 |
|
{ |
| 1421 |
|
tm tmStartTime = to_tm(startTime); |
| 1423 |
|
boost::lexical_cast<string>(tmStartTime.tm_min) + "-" + boost::lexical_cast<string>(tmStartTime.tm_sec) + "/"; |
| 1424 |
|
create_directory(strTrashDir); |
| 1425 |
|
} |
| 1426 |
+ |
#endif |
| 1427 |
|
file.close(); |
| 1428 |
|
file.clear(); |
| 1429 |
|
|
| 1458 |
|
if (exists(strPathToEUFNInstall + strWinGUI)) |
| 1459 |
|
{ |
| 1460 |
|
if (exists((path)strWinGUI)) |
| 1461 |
< |
rename((path)strWinGUI, (path)strcat(strTrashDir, strWinGUI)); |
| 1461 |
> |
rename((path)strWinGUI, (path)(strTrashDir + strWinGUI)); |
| 1462 |
|
if (exists(strWinGUILang)) |
| 1463 |
< |
rename((path)strWinGUILang, (path)strcat(strTrashDir, strWinGUILang)); |
| 1463 |
> |
rename((path)strWinGUILang, (path)(strTrashDir + strWinGUILang)); |
| 1464 |
|
rename((path)(strPathToEUFNInstall + strWinGUI), (path)strWinGUI); |
| 1465 |
|
rename((path)(strPathToEUFNInstall + strWinGUILang), (path)strWinGUILang); |
| 1466 |
|
} |
| 1499 |
|
curPos = thePath.find("/", lastPos); |
| 1500 |
|
aParentPath = aParentPath + "/"; |
| 1501 |
|
} |
| 1502 |
+ |
#ifndef WIN32 |
| 1503 |
|
rename((path)("../" + thePath), (path)(strTrashDir + thePath)); |
| 1504 |
+ |
#else |
| 1505 |
+ |
remove((path)("../" + thePath)); |
| 1506 |
+ |
#endif |
| 1507 |
|
} |
| 1508 |
|
} |
| 1509 |
|
|
| 1510 |
< |
// Now we crawl the update's package folders for newer versions and move them over, trashing ones that are already present |
| 1328 |
< |
vector<ModPackage> updatePackages, currentPackages; |
| 1329 |
< |
bool matchFound; |
| 1330 |
< |
updatePackages.reserve(256); |
| 1331 |
< |
currentPackages.reserve(256); |
| 1332 |
< |
|
| 1333 |
< |
currentPackages = getPackages(); |
| 1334 |
< |
updatePackages = getPackages(strPathToEUFNPackages); |
| 1335 |
< |
|
| 1336 |
< |
for (vector<ModPackage>::iterator iter1 = updatePackages.begin(); iter1 != updatePackages.end(); iter1++) |
| 1337 |
< |
{ |
| 1338 |
< |
matchFound = false; |
| 1339 |
< |
for (vector<ModPackage>::iterator iter2 = currentPackages.begin(); iter2 != currentPackages.end(); iter2++) |
| 1340 |
< |
{ |
| 1341 |
< |
if (!iter1->modStringName.compare(iter2->modStringName)) |
| 1342 |
< |
{ |
| 1343 |
< |
matchFound = true; |
| 1344 |
< |
if (iter1->modStringVersion > iter2->modStringVersion) |
| 1345 |
< |
{ |
| 1346 |
< |
rename((path)(strPathToPackages + iter2->modStringName), (path)(strTrashDir + iter2->modStringName)); |
| 1347 |
< |
rename((path)(strPathToEUFNPackages + iter1->modStringName), (path)(strPathToPackages + iter1->modStringName)); |
| 1348 |
< |
} |
| 1349 |
< |
} |
| 1350 |
< |
} |
| 1351 |
< |
if (!matchFound) // then there's no old package in the way, so just move in the one from the update |
| 1352 |
< |
rename((path)(strPathToEUFNPackages + iter1->modStringName), (path)(strPathToPackages + iter1->modStringName)); |
| 1353 |
< |
} |
| 1510 |
> |
CrawlPackages( strPathToEUFNPackages, strPathToPackages); |
| 1511 |
|
|
| 1512 |
|
// 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... |
| 1513 |
|
// ...and folders which do not exist in the current AE will be created there |
| 1564 |
|
CheckForGlobalization(true); // the 'true' value forces re-globalization |
| 1565 |
|
|
| 1566 |
|
globalPackages = getPackages(); // refresh the list in memory |
| 1410 |
– |
|
| 1567 |
|
// TODO: Refresh the packages list in the window |
| 1568 |
|
|
| 1569 |
|
return true; |
| 1610 |
|
} |
| 1611 |
|
} |
| 1612 |
|
|
| 1613 |
+ |
/* StripNewlines() gets rids of any linebreaks that come from text returned by getline(); \ |
| 1614 |
+ |
| getline() should be stripping those out, but Windows CR/LF files seem to be sneaking | |
| 1615 |
+ |
\ some extra return characters into strings in the ReadInstallInfoCfg() function. */ |
| 1616 |
+ |
void StripNewlines(string *theLine) |
| 1617 |
+ |
{ |
| 1618 |
+ |
int deleteFromHere = 0; |
| 1619 |
+ |
deleteFromHere = theLine->find("\r"); |
| 1620 |
+ |
if (deleteFromHere > 0) |
| 1621 |
+ |
theLine->erase(deleteFromHere, theLine->size()); |
| 1622 |
+ |
} |
| 1623 |
+ |
|
| 1624 |
|
void clearOldDats(void) { |
| 1625 |
|
directory_iterator end_iter_gdf; |
| 1626 |
|
for ( directory_iterator dir_itr_gdf( "../GameDataFolder" ); |
| 1735 |
|
name = ""; |
| 1736 |
|
modStringName = ""; |
| 1737 |
|
modStringVersion = 0; |
| 1738 |
+ |
platform = "Both"; |
| 1739 |
|
hasOnis = false; |
| 1740 |
|
hasDeltas = false; |
| 1741 |
|
hasBSL = false; |
| 1747 |
|
readme = ""; |
| 1748 |
|
globalNeeded = true; |
| 1749 |
|
} |
| 1750 |
< |
|
| 1750 |
> |
#ifndef WIN32 |
| 1751 |
|
void Sleep(int ms) |
| 1752 |
|
{ |
| 1753 |
|
sleep(ms / 1000); |
| 1754 |
|
} |
| 1755 |
< |
|
| 1755 |
> |
#endif |
| 1756 |
|
#ifdef WIN32 |
| 1757 |
|
|
| 1758 |
|
void RedirectIOToConsole() |