From 36cb12acb8c0d46ddec43719a7e9b009ced97ada Mon Sep 17 00:00:00 2001 From: tildearrow Date: Tue, 18 Jun 2024 18:00:22 -0500 Subject: [PATCH] find exe path --- src/main.cpp | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 68d40355f..3e066f7fb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -116,7 +116,8 @@ char localeDir[4096]; const char* localeDirs[]={ "locale", - "../po/locale", + ".." DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR "locale", + ".." DIR_SEPARATOR_STR "po" DIR_SEPARATOR_STR "locale", #ifdef LOCALE_DIR LOCALE_DIR, #endif @@ -124,6 +125,15 @@ const char* localeDirs[]={ }; #endif +bool getExePath(char* argv0, char* exePath, size_t maxSize) { + if (argv0==NULL) return false; + if (realpath(argv0,exePath)==NULL) return false; + char* lastChar=strrchr(exePath,DIR_SEPARATOR); + if (lastChar==NULL) return false; + *lastChar=0; + return true; +} + TAParamResult pHelp(String) { printf("usage: furnace [params] [filename]\n" "you may specify the following parameters:\n"); @@ -566,9 +576,22 @@ int main(int argc, char** argv) { } #endif + char exePath[4096]; +#ifdef ANDROID + memset(exePath,0,4096); +#else + if (!getExePath(argv[0],exePath,4096)) memset(exePath,0,4096); +#endif + bool textDomainBound=false; for (int i=0; localeDirs[i]; i++) { - strncpy(localeDir,localeDirs[i],4095); + if (exePath[0]!=0 && localeDirs[i][0]!=DIR_SEPARATOR) { + strncpy(localeDir,exePath,4095); + strncat(localeDir,DIR_SEPARATOR_STR,4095); + strncat(localeDir,localeDirs[i],4095); + } else { + strncpy(localeDir,localeDirs[i],4095); + } logV("bind text domain: %s",localeDir); if (!dirExists(localeDir)) continue; if ((localeRet=TA_BINDTEXTDOMAIN("furnace",localeDir))==NULL) {