modified app/src/main.cpp +9 -1
| @@ -13,6 +13,8 @@ |
| 13 | 13 | #include <sqlite3.h> |
| 14 | 14 | #include <string> |
| 15 | 15 | #include <vector> |
| 16 | +#include <unistd.h> |
| 17 | +#include <limits.h> |
| 16 | 18 | |
| 17 | 19 | #include <game.hpp> |
| 18 | 20 | |
| @@ -168,8 +170,14 @@ auto runConsoleApp(sqlite3* database) -> void { |
| 168 | 170 | |
| 169 | 171 | } |
| 170 | 172 | |
| 173 | +std::string getExecutablePath() { |
| 174 | + char result[PATH_MAX]; |
| 175 | + ssize_t count = readlink("/proc/self/exe", result, PATH_MAX); |
| 176 | + return std::string(result, (count > 0) ? count : 0); |
| 177 | +} |
| 178 | + |
| 171 | 179 | auto main(int argc, char const *argv[]) -> int { |
| 172 | | - auto appPath{ std::filesystem::path(argv[0])}; |
| 180 | + std::filesystem::path appPath{ getExecutablePath() }; |
| 173 | 181 | auto databasePath{ std::filesystem::path(appPath.parent_path().string() + "/data.db")}; |
| 174 | 182 | bool newCreation = not std::filesystem::exists(databasePath.string()); |
| 175 | 183 | char *messageError; |
| @@ -13,6 +13,8 @@ |
| 13 | #include <sqlite3.h> | 13 | #include <sqlite3.h> |
| 14 | #include <string> | 14 | #include <string> |
| 15 | #include <vector> | 15 | #include <vector> |
| | 16 | +#include <unistd.h> |
| | 17 | +#include <limits.h> |
| 16 | | 18 | |
| 17 | #include <game.hpp> | 19 | #include <game.hpp> |
| 18 | | 20 | |
| @@ -168,8 +170,14 @@ auto runConsoleApp(sqlite3* database) -> void { |
| 168 | | 170 | |
| 169 | } | 171 | } |
| 170 | | 172 | |
| | 173 | +std::string getExecutablePath() { |
| | 174 | + char result[PATH_MAX]; |
| | 175 | + ssize_t count = readlink("/proc/self/exe", result, PATH_MAX); |
| | 176 | + return std::string(result, (count > 0) ? count : 0); |
| | 177 | +} |
| | 178 | + |
| 171 | auto main(int argc, char const *argv[]) -> int { | 179 | auto main(int argc, char const *argv[]) -> int { |
| 172 | - auto appPath{ std::filesystem::path(argv[0])}; | 180 | + std::filesystem::path appPath{ getExecutablePath() }; |
| 173 | auto databasePath{ std::filesystem::path(appPath.parent_path().string() + "/data.db")}; | 181 | auto databasePath{ std::filesystem::path(appPath.parent_path().string() + "/data.db")}; |
| 174 | bool newCreation = not std::filesystem::exists(databasePath.string()); | 182 | bool newCreation = not std::filesystem::exists(databasePath.string()); |
| 175 | char *messageError; | 183 | char *messageError; |