mirror of
https://github.com/glest/glest-source.git
synced 2025-08-12 03:14:00 +02:00
Lots of changes to make glest binary more portable on linux.
This commit is contained in:
@@ -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;
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user