comparison src/core/filesystem.cpp @ 45:4b05bc7668eb

filesystem: split config path into dotpath and config, add anime db path EVENTUALLY I'll get around to saving the anime db and list...
author Paper <mrpapersonic@gmail.com>
date Fri, 22 Sep 2023 15:21:55 -0400
parents 619cbd6e69f9
children 327e9a5c72f1
comparison
equal deleted inserted replaced
44:619cbd6e69f9 45:4b05bc7668eb
58 size_t pos = 0; 58 size_t pos = 0;
59 pos = path.find_last_of(DELIM); 59 pos = path.find_last_of(DELIM);
60 return path.substr(0, pos); 60 return path.substr(0, pos);
61 } 61 }
62 62
63 std::string GetConfigPath(void) { 63 std::string GetDotPath(void) {
64 std::string ret = ""; 64 std::string ret = "";
65 #ifdef WIN32 65 #ifdef WIN32
66 char buf[PATH_MAX + 1]; 66 char buf[PATH_MAX + 1];
67 if (SHGetFolderPathAndSubDir(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, CONFIG_DIR, buf) == S_OK) { 67 if (SHGetFolderPathAndSubDir(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, CONFIG_DIR, buf) == S_OK) {
68 ret += buf; 68 ret += buf;
69 ret += DELIM CONFIG_NAME;
70 } 69 }
71 #elif defined(MACOSX) 70 #elif defined(MACOSX)
72 /* pass all of our problems to objc++ code */
73 ret += osx::GetApplicationSupportDirectory(); 71 ret += osx::GetApplicationSupportDirectory();
74 ret += DELIM CONFIG_DIR DELIM CONFIG_NAME; 72 ret += DELIM CONFIG_DIR;
75 #else // just assume POSIX 73 #else // just assume POSIX
76 if (getenv("HOME") != NULL) 74 if (getenv("HOME") != NULL)
77 ret += getenv("HOME"); 75 ret += getenv("HOME");
78 # ifdef __linux__ 76 # ifdef __linux__
79 else 77 else
80 ret += getpwuid(getuid())->pw_dir; 78 ret += getpwuid(getuid())->pw_dir;
81 # endif // __linux__ 79 # endif // __linux__
82 if (!ret.empty()) 80 if (!ret.empty())
83 ret += DELIM ".config" DELIM CONFIG_DIR DELIM CONFIG_NAME; 81 ret += DELIM ".config" DELIM CONFIG_DIR;
84 #endif // !WIN32 && !MACOSX 82 #endif // !WIN32 && !MACOSX
85 return ret; 83 return ret;
86 } 84 }
87 85
86 std::string GetConfigPath(void) {
87 std::string ret = "";
88 ret += GetDotPath();
89 if (!ret.empty())
90 ret += DELIM CONFIG_NAME;
91 return ret;
92 }
93
94 std::string GetAnimeDBPath(void) {
95 std::string ret = "";
96 ret += GetDotPath();
97 if (!ret.empty())
98 ret += DELIM "anime" DELIM "db.json";
99 return ret;
100 }
101
88 } // namespace Filesystem 102 } // namespace Filesystem