Lots of changes to make glest binary more portable on linux.

This commit is contained in:
Jammyjamjamman
2019-04-12 21:28:19 +01:00
parent 629229a6bf
commit 35b08573f8
9 changed files with 107 additions and 61 deletions

View File

@@ -53,12 +53,10 @@ namespace Shared {
namespace Util {
string Properties::applicationPath = "";
#ifdef SNAPCRAFT
string Properties::applicationDataPath = std::getenv("SNAP") + formatPath(TOSTRING(DATADIR));
#elif FLATPAK
string Properties::applicationDataPath = formatPath(TOSTRING(DATADIR));
#if defined(DATADIR) && defined(BINDIR)
string Properties::applicationDataPath = getDatPath();
#else
string Properties::applicationDataPath = "";
string Properties::applicationDataPath = "";
#endif
string Properties::techtreePath = "";
string Properties::scenarioPath = "";
@@ -245,7 +243,7 @@ namespace Shared {
//char pMBBuffer[MAX_PATH + 1]="";
//wcstombs_s(&size, &pMBBuffer[0], (size_t)size, wBuf, (size_t)size);// Convert to char* from TCHAR[]
//string appPath="";
//appPath.assign(&pMBBuffer[0]); // Now assign the char* to the string, and there you have it!!! :)
//appPath.assign(&pMBBuffer[0]); // Now assign the char* to the string, and there you have it!!! :)
std::string appPath = utf8_encode(szPath);
replaceAll(appPath, "\\", "/");
@@ -266,8 +264,7 @@ namespace Shared {
mapTagReplacementValues["$APPLICATIONPATH"] = Properties::applicationPath;
mapTagReplacementValues["%%APPLICATIONPATH%%"] = Properties::applicationPath;
mapTagReplacementValues["{APPLICATIONPATH}"] = Properties::applicationPath;
mapTagReplacementValues["$APPLICATIONDATAPATH"] = Properties::applicationDataPath;
mapTagReplacementValues["$APPLICATIONDATAPATH"] = Properties::applicationPath;
mapTagReplacementValues["%%APPLICATIONDATAPATH%%"] = Properties::applicationDataPath;
mapTagReplacementValues["{APPLICATIONDATAPATH}"] = Properties::applicationDataPath;
@@ -372,7 +369,7 @@ namespace Shared {
//char pMBBuffer[MAX_PATH + 1]="";
//wcstombs_s(&size, &pMBBuffer[0], (size_t)size, wBuf, (size_t)size);// Convert to char* from TCHAR[]
//string appPath="";
//appPath.assign(&pMBBuffer[0]); // Now assign the char* to the string, and there you have it!!! :)
//appPath.assign(&pMBBuffer[0]); // Now assign the char* to the string, and there you have it!!! :)
std::string appPath = utf8_encode(szPath);
//string appPath = szPath;

View File

@@ -32,6 +32,7 @@
#include <io.h> // for open()
#else
#include <unistd.h>
#include <limits.h>
#endif
#include <sys/stat.h> // for open()
@@ -874,5 +875,45 @@ namespace Shared {
return 0;
}
}
#ifdef __linux__
std::string getExecPath() {
char buff[PATH_MAX];
ssize_t len = ::readlink("/proc/self/exe", buff, sizeof(buff)-1);
if (len != -1) {
buff[len] = '\0';
return std::string(buff);
}
/* handle error condition */
return std::string("");
}
#endif // __linux__
void eraseSubStr(std::string & mainStr, const std::string & toErase)
{
// Search for the substring in string
size_t pos = mainStr.find(toErase);
if (pos != std::string::npos)
{
// If found then erase it from string
mainStr.erase(pos, toErase.length());
}
}
#if defined(DATADIR) && defined(BINDIR)
string getDatPath() {
string curPath = getExecPath();
printf("\n binary Path: %s", curPath.c_str());
const string subBinPath = endPathWithSlash(formatPath(TOSTRING(BINDIR))) + "glest";
printf("\n binary Path: %s", subBinPath.c_str());
eraseSubStr(curPath, subBinPath);
printf("\n path now: %s", curPath.c_str());
string datPath = curPath + endPathWithSlash(TOSTRING(DATADIR));
printf("\n what is this???: %s", TOSTRING(DATADIR));
printf("\n data path: %s", datPath.c_str());
return datPath;
}
#endif
}
} //end namespace