From ae97a1306c1f4575933b83e665c44b4d2d06e596 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Thu, 10 Mar 2011 19:19:14 +0000 Subject: [PATCH] - added another special variable (application path) that can be used for variable substituion in ini file values --- source/g3d_viewer/main.cpp | 1 + source/glest_game/main/main.cpp | 2 ++ source/shared_lib/include/util/properties.h | 4 ++++ source/shared_lib/sources/util/properties.cpp | 5 +++++ 4 files changed, 12 insertions(+) diff --git a/source/g3d_viewer/main.cpp b/source/g3d_viewer/main.cpp index ec3bc31d..bdd4527a 100644 --- a/source/g3d_viewer/main.cpp +++ b/source/g3d_viewer/main.cpp @@ -210,6 +210,7 @@ MainWindow::MainWindow( std::pair > unitToLoad, wxSize(Renderer::windowW, Renderer::windowH)), model(NULL), glCanvas(NULL), renderer(NULL), initTextureManager(true), timer(NULL) { this->appPath = appPath; + Properties::setApplicationPath(extractDirectoryPathFromFile(appPath)); Config &config = Config::getInstance(); //getGlPlatformExtensions(); diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index 5dbcc67d..2f67dbb5 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -1508,6 +1508,8 @@ int glestMain(int argc, char** argv) { return -1; } + Properties::setApplicationPath(extractDirectoryPathFromFile(argv[0])); + ServerSocket::setMaxPlayerCount(GameConstants::maxPlayers); SystemFlags::VERBOSE_MODE_ENABLED = false; if(hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_VERBOSE_MODE]) == true) { diff --git a/source/shared_lib/include/util/properties.h b/source/shared_lib/include/util/properties.h index abf169e0..946dd453 100644 --- a/source/shared_lib/include/util/properties.h +++ b/source/shared_lib/include/util/properties.h @@ -43,9 +43,13 @@ private: PropertyVector propertyVector; PropertyMap propertyMap; string path; + static string applicationPath; bool applyTagsToValue(string &value); public: + static void setApplicationPath(string value) { applicationPath=value; } + static string getApplicationPath() { return applicationPath; } + void clear(); void load(const string &path); void save(const string &path); diff --git a/source/shared_lib/sources/util/properties.cpp b/source/shared_lib/sources/util/properties.cpp index 706c0523..d3c88494 100644 --- a/source/shared_lib/sources/util/properties.cpp +++ b/source/shared_lib/sources/util/properties.cpp @@ -25,6 +25,8 @@ using namespace Shared::PlatformCommon; namespace Shared{ namespace Util{ +string Properties::applicationPath = ""; + // ===================================================== // class Properties // ===================================================== @@ -101,6 +103,9 @@ bool Properties::applyTagsToValue(string &value) { replaceAll(value, "$USERNAME", (username != NULL ? username : "")); replaceAll(value, "%%USERNAME%%", (username != NULL ? username : "")); + replaceAll(value, "$APPLICATIONPATH", Properties::applicationPath); + replaceAll(value, "%%APPLICATIONPATH%%", Properties::applicationPath); + return (originalValue != value); }