diff --git a/mk/linux/glest.ini b/mk/linux/glest.ini index 3c01f928..112deb06 100644 --- a/mk/linux/glest.ini +++ b/mk/linux/glest.ini @@ -19,6 +19,7 @@ ColorBits=32 ConsoleMaxLines=7 ConsoleMaxLinesStored=20 ConsoleTimeout=20 +DataPath=$APPLICATIONPATH/ DayTime=1000 DebugLogFile=debug.log DebugMode=false diff --git a/source/g3d_viewer/main.cpp b/source/g3d_viewer/main.cpp index 8f5c05f9..463ec8fe 100644 --- a/source/g3d_viewer/main.cpp +++ b/source/g3d_viewer/main.cpp @@ -215,7 +215,7 @@ MainWindow::MainWindow( std::pair > unitToLoad, startupSettingsInited(false) { this->appPath = appPath; - Properties::setApplicationPath(extractDirectoryPathFromFile(appPath)); + Properties::setApplicationPath(executable_path(appPath)); Config &config = Config::getInstance(); //getGlPlatformExtensions(); diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index 981edb2b..dce0617b 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -86,7 +86,7 @@ namespace Glest{ namespace Game{ bool disableBacktrace = false; bool gameInitialized = false; -static char *application_binary=NULL; +static string application_binary=""; static string mg_app_name = ""; static string mailStringSupport = ""; static bool sdl_quitCalled = false; @@ -296,7 +296,7 @@ public: // prepare command to be executed // our program need to be passed after the -e parameter //sprintf (buf, "/usr/bin/addr2line -C -e ./a.out -f -i %lx", addr); - sprintf (buf, "addr2line -C -e %s -f -i %p",application_binary,address); + sprintf (buf, "addr2line -C -e %s -f -i %p",application_binary.c_str(),address); FILE* f = popen (buf, "r"); @@ -1982,7 +1982,7 @@ int glestMain(int argc, char** argv) { bool foundInvalidArgs = false; preCacheThread=NULL; - Properties::setApplicationPath(extractDirectoryPathFromFile(argv[0])); + Properties::setApplicationPath(executable_path(argv[0])); ServerSocket::setMaxPlayerCount(GameConstants::maxPlayers); SystemFlags::VERBOSE_MODE_ENABLED = false; @@ -2724,7 +2724,8 @@ int glestMainWrapper(int argc, char** argv) { #ifdef WIN32_STACK_TRACE __try { #endif - application_binary=argv[0]; + application_binary= executable_path(argv[0]); + //printf("\n\nargv0 [%s] application_binary [%s]\n\n",argv[0],application_binary.c_str()); #if defined(__GNUC__) && !defined(__MINGW32__) && !defined(__FreeBSD__) && !defined(BSD) signal(SIGSEGV, handleSIGSEGV); diff --git a/source/glest_game/world/unit_updater.cpp b/source/glest_game/world/unit_updater.cpp index 3d7ceab9..8a14b808 100644 --- a/source/glest_game/world/unit_updater.cpp +++ b/source/glest_game/world/unit_updater.cpp @@ -701,7 +701,7 @@ void UnitUpdater::updateBuild(Unit *unit, int frameIndex) { builtUnit->create(); if(builtUnitType->hasSkillClass(scBeBuilt) == false) { - throw runtime_error("Unit " + builtUnitType->getName() + "has no be_built skill"); + throw runtime_error("Unit [" + builtUnitType->getName() + "] has no be_built skill."); } builtUnit->setCurrSkill(scBeBuilt); diff --git a/source/glest_map_editor/main.cpp b/source/glest_map_editor/main.cpp index 92f731a4..a087284e 100644 --- a/source/glest_map_editor/main.cpp +++ b/source/glest_map_editor/main.cpp @@ -78,7 +78,7 @@ MainWindow::MainWindow(string appPath) , program(NULL), boxsizer(NULL), startupSettingsInited(false) { this->appPath = appPath; - Properties::setApplicationPath(extractDirectoryPathFromFile(appPath)); + Properties::setApplicationPath(executable_path(appPath)); this->panel = new wxPanel(this, wxID_ANY); diff --git a/source/shared_lib/include/platform/common/platform_common.h b/source/shared_lib/include/platform/common/platform_common.h index 2ed0917c..c8d0f819 100644 --- a/source/shared_lib/include/platform/common/platform_common.h +++ b/source/shared_lib/include/platform/common/platform_common.h @@ -209,6 +209,7 @@ inline string trim (const string & s, const string & t = SPACES) { string getFullFileArchiveExtractCommand(string fileArchiveExtractCommand, string fileArchiveExtractCommandParameters, string outputpath, string archivename); bool executeShellCommand(string cmd,int expectedResult=IGNORE_CMD_RESULT_VALUE); +string executable_path(string exeName); class ValueCheckerVault { diff --git a/source/shared_lib/sources/platform/common/platform_common.cpp b/source/shared_lib/sources/platform/common/platform_common.cpp index e6e4cdcf..3059b149 100644 --- a/source/shared_lib/sources/platform/common/platform_common.cpp +++ b/source/shared_lib/sources/platform/common/platform_common.cpp @@ -1678,6 +1678,53 @@ off_t getFileSize(string filename) { return 0; } +string executable_path(string exeName) { + string value = ""; +#ifdef _WIN32 + char path[MAX_PATH]=""; + if( GetModuleFileName(NULL,path,MAX_PATH) == 0 ) { + value = extractDirectoryPathFromFile(exeName); + } + else { + value = extractDirectoryPathFromFile(path); + } +#elif __APPLE__ + char path[MAXPATHLEN+1]=""; + uint32_t path_len = MAXPATHLEN; + if ( _NSGetExecutablePath(path, &path_len) ) { + value = extractDirectoryPathFromFile(exeName); + } + else { + value = extractDirectoryPathFromFile(path); + } +#else + char exe_link_path[200]=""; + int length = readlink("/proc/self/exe", exe_link_path, sizeof(exe_link_path)); + if(length < 0 || length >= 200 ) { + char *argv0_path = realpath(exeName.c_str(),NULL); + if(argv0_path != NULL) { + value = extractDirectoryPathFromFile(argv0_path); + free(argv0_path); + argv0_path = NULL; + } + else { + const char *shell_path = getenv("_"); + if(shell_path != NULL) { + value = extractDirectoryPathFromFile(shell_path); + } + else { + value = extractDirectoryPathFromFile(exeName); + } + } + } + else { + exe_link_path[length] = '\0'; + value = extractDirectoryPathFromFile(exe_link_path); + } +#endif + return value; +} + // ===================================== // ModeInfo // ===================================== diff --git a/source/tools/convert_faction_xml2html/convert_faction_xml2html.pl b/source/tools/convert_faction_xml2html/convert_faction_xml2html.pl index 8f715bdb..4c4f4906 100755 --- a/source/tools/convert_faction_xml2html/convert_faction_xml2html.pl +++ b/source/tools/convert_faction_xml2html/convert_faction_xml2html.pl @@ -118,6 +118,7 @@ use Cwd; use File::Glob ':glob'; #use Image::Resize; use Image::Magick; + BEGIN { $ENV{APP_ROOT} = Cwd::realpath(File::Spec->rel2abs($FindBin::Bin)) ; } diff --git a/source/tools/convert_faction_xml2html/mg.ini b/source/tools/convert_faction_xml2html/mg.ini index 489fef94..0fd646cd 100644 --- a/source/tools/convert_faction_xml2html/mg.ini +++ b/source/tools/convert_faction_xml2html/mg.ini @@ -14,7 +14,7 @@ export_graph=as_svg;as_png;as_canon;as_text;as_cmapx # combine png and cmapx to clickable map build_clickable_map=1 -version=Megapack of Megaglest 3.4.0 +version=Megapack of Megaglest 3.5.1 # should links to units go the single pages for each unit (vs. the techtree-page if set to 0) link_to_single_units=1 @@ -32,7 +32,7 @@ level_armor=1.5 [files] -g3dviewer_path=../../../mk/linux/glest_g3dviewer +g3dviewer_path=../../../mk/linux/megaglest_g3dviewer factions_path=../../../data/glest_game/techs/megapack/factions resources_path=../../../data/glest_game/techs/megapack/resources