Platformer
Platformer
FilePaths.hpp
1 #ifndef FILE_PATHS_HPP
2 #define FILE_PATHS_HPP
3 
4 #include <string>
5 
6 #if defined(MINGW)
7 // Do nothing
8 #elif defined(__linux__)
9 #include <limits.h>
10 #include <unistd.h>
11 #else
12 #include <limits.h>
13 #include <mach-o/dyld.h>
14 #endif
15 
16 #define ASSETS_PATH "../Assets/"
17 #define CONFIG_PATH "../Config/"
18 
19 inline std::string FullPath() {
20  std::string path;
21 #if defined(MINGW)
22 // Do nothing for now
23 #elif defined(__linux__)
24  char buf[PATH_MAX];
25  ssize_t len = readlink("/proc/self/exe", buf, sizeof(buf) - 1);
26  if (len != -1) {
27  buf[len] = '\0';
28  path = std::string(buf);
29  } else {
30  path = "";
31  }
32 #else
33  char buf[PATH_MAX];
34  uint32_t bufsize = PATH_MAX;
35  if (!_NSGetExecutablePath(buf, &bufsize)) {
36  path = std::string(buf);
37  } else {
38  path = "";
39  }
40 #endif
41 
42  size_t lastSlash = path.find_last_of('/');
43  if (lastSlash == std::string::npos) {
44  return "";
45  }
46  return path.substr(0, lastSlash + 1);
47 }
48 
50 inline std::string FullAssetsPath() { return FullPath() + ASSETS_PATH; }
51 
53 inline std::string FullConfigPath() { return FullPath() + CONFIG_PATH; }
54 
55 #endif