juk3n/fluffypublic Fork
⑂ 27755dd
Commits
⬇ Clone ▾
git clone https://git.rickub.com/juk3n/fluffy.git
git clone ssh://git@rickub.com/juk3n/fluffy.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

Merge pull request #18 from Juk3n/17-fix-path-issue-when-running-app-from-pathUnverified

17 fix path issue when running app from path
Adrian Duraj committed 2024-07-03T14:27:02+02:00 Browse files
27755dd parents: 66a711a aef1911
modified app/src/main.cpp +9 -1
@@ -13,6 +13,8 @@
1313 #include <sqlite3.h>
1414 #include <string>
1515 #include <vector>
16+#include <unistd.h>
17+#include <limits.h>
1618
1719 #include <game.hpp>
1820
@@ -168,8 +170,14 @@ auto runConsoleApp(sqlite3* database) -> void {
168170
169171 }
170172
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+
171179 auto main(int argc, char const *argv[]) -> int {
172- auto appPath{ std::filesystem::path(argv[0])};
180+ std::filesystem::path appPath{ getExecutablePath() };
173181 auto databasePath{ std::filesystem::path(appPath.parent_path().string() + "/data.db")};
174182 bool newCreation = not std::filesystem::exists(databasePath.string());
175183 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;