Mercurial > minori
comparison src/core/filesystem.cpp @ 15:cde8f67a7c7d
*: update, megacommit :)
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Tue, 19 Sep 2023 22:36:08 -0400 |
parents | fc1bf97c528b |
children | 28d8f4c0ae12 |
comparison
equal
deleted
inserted
replaced
14:a29c9402faf0 | 15:cde8f67a7c7d |
---|---|
1 #ifdef WIN32 | 1 #ifdef WIN32 |
2 #include <shlobj.h> | 2 # include <shlobj.h> |
3 #elif defined(MACOSX) | 3 #elif defined(MACOSX) |
4 #include "sys/osx/filesystem.h" | 4 # include "sys/osx/filesystem.h" |
5 #elif defined(__linux__) | 5 #elif defined(__linux__) |
6 #include <pwd.h> | 6 # include <pwd.h> |
7 #include <sys/types.h> | 7 # include <sys/types.h> |
8 #endif | 8 #endif |
9 | 9 |
10 #ifdef WIN32 | 10 #ifdef WIN32 |
11 #define DELIM "\\" | 11 # define DELIM "\\" |
12 #else | 12 #else |
13 #define DELIM "/" | 13 # define DELIM "/" |
14 #include <unistd.h> | 14 # include <errno.h> |
15 #include <errno.h> | 15 # include <unistd.h> |
16 #endif | 16 #endif |
17 | 17 |
18 #include "core/config.h" | |
18 #include "core/filesystem.h" | 19 #include "core/filesystem.h" |
19 #include "core/config.h" | |
20 #include <limits.h> | 20 #include <limits.h> |
21 | 21 |
22 namespace Filesystem { | 22 namespace Filesystem { |
23 | 23 |
24 bool CreateDirectories(std::string path) { | 24 bool CreateDirectories(std::string path) { |
25 std::string temp = ""; | 25 std::string temp = ""; |
26 size_t start; | 26 size_t start; |
27 size_t end = 0; | 27 size_t end = 0; |
28 | 28 |
29 while ((start = path.find_first_not_of(DELIM, end)) != std::string::npos) | 29 while ((start = path.find_first_not_of(DELIM, end)) != std::string::npos) { |
30 { | |
31 end = path.find(DELIM, start); | 30 end = path.find(DELIM, start); |
32 temp.append(path.substr(start, end - start)); | 31 temp.append(path.substr(start, end - start)); |
33 #ifdef WIN32 | 32 #ifdef WIN32 |
34 if (!CreateDirectoryA(temp.c_str(), NULL) && GetLastError() == ERROR_PATH_NOT_FOUND) | 33 if (!CreateDirectoryA(temp.c_str(), NULL) && GetLastError() == ERROR_PATH_NOT_FOUND) |
35 /* ERROR_PATH_NOT_FOUND should NOT happen here */ | 34 /* ERROR_PATH_NOT_FOUND should NOT happen here */ |
71 ret += osx::GetApplicationSupportDirectory(); | 70 ret += osx::GetApplicationSupportDirectory(); |
72 ret += DELIM CONFIG_DIR DELIM CONFIG_NAME; | 71 ret += DELIM CONFIG_DIR DELIM CONFIG_NAME; |
73 #else // just assume POSIX | 72 #else // just assume POSIX |
74 if (getenv("HOME") != NULL) | 73 if (getenv("HOME") != NULL) |
75 ret += getenv("HOME"); | 74 ret += getenv("HOME"); |
76 #ifdef __linux__ | 75 # ifdef __linux__ |
77 else | 76 else |
78 ret += getpwuid(getuid())->pw_dir; | 77 ret += getpwuid(getuid())->pw_dir; |
79 #endif // __linux__ | 78 # endif // __linux__ |
80 if (!ret.empty()) | 79 if (!ret.empty()) |
81 ret += DELIM ".config" DELIM CONFIG_DIR DELIM CONFIG_NAME; | 80 ret += DELIM ".config" DELIM CONFIG_DIR DELIM CONFIG_NAME; |
82 #endif // !WIN32 && !MACOSX | 81 #endif // !WIN32 && !MACOSX |
83 return ret; | 82 return ret; |
84 } | 83 } |
85 | 84 |
86 } | 85 } // namespace Filesystem |