diff options
author | Alex Zolotarev <deathbaba@gmail.com> | 2011-10-31 00:14:52 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 01:27:10 +0300 |
commit | eea66458919753af7edc32b9210adfa1a1f36751 (patch) | |
tree | 4545e07fbda279938b77b45069c7973c2437a857 /platform/platform_linux.cpp | |
parent | 29f6e38b349ca9620ed36a637c692fbccb12eb32 (diff) |
Completed platform refactoring and fixed paths for resources/writable dirs
Diffstat (limited to 'platform/platform_linux.cpp')
-rw-r--r-- | platform/platform_linux.cpp | 55 |
1 files changed, 39 insertions, 16 deletions
diff --git a/platform/platform_linux.cpp b/platform/platform_linux.cpp index 748fd50dcd..be9b580cf4 100644 --- a/platform/platform_linux.cpp +++ b/platform/platform_linux.cpp @@ -4,33 +4,56 @@ #include <unistd.h> #include <sys/stat.h> -#define LOCALAPPDATA_DIR "MapsWithMe" +//static bool GetUserWritableDir(string & outDir) +//{ +// char * path = ::getenv("HOME"); +// if (path) +// { +// outDir = path; +// outDir += "/.MapsWithMe/"; +// ::mkdir(outDir.c_str(), 0755); +// return true; +// } +// return false; +//} -bool GetUserWritableDir(string & outDir) -{ - char * path = ::getenv("HOME"); - if (path) - { - outDir = path; - outDir += "." LOCALAPPDATA_DIR "/"; - ::mkdir(outDir.c_str(), 0755); - return true; - } - return false; -} - -/// @return full path including binary itself -bool GetPathToBinary(string & outPath) +/// @return directory where binary resides, including slash at the end +static bool GetBinaryFolder(string & outPath) { char path[4096] = {0}; if (0 < ::readlink("/proc/self/exe", path, ARRAY_SIZE(path))) { outPath = path; + outPath.erase(outPath.find_last_of('/') + 1); return true; } return false; } +Platform::Platform() +{ + // init directories + string path; + CHECK(GetBinaryFolder(path), ("Can't retrieve path to executable")); + + // @TODO implement correct resources and writable directories for public releases + m_resourcesDir = path + "../../../data"; + m_writableDir = m_resourcesDir; + + LOG(LDEBUG, ("Resources directory:", m_resourcesDir)); + LOG(LDEBUG, ("Writable directory:", m_writableDir)); +} + +Platform::~Platform() +{ +} + +bool Platform::IsFileExists(string const & file) const +{ + struct stat s; + return stat(file.c_str(), &s) == 0; +} + int Platform::CpuCores() const { long numCPU = sysconf(_SC_NPROCESSORS_ONLN); |