[feat] save log and cache files into user folder

This commit is contained in:
dijunkun
2025-07-22 18:55:12 +08:00
parent 3bf68a396f
commit e8d7ec8daf
11 changed files with 146 additions and 65 deletions

View File

@@ -16,7 +16,7 @@ std::filesystem::path PathManager::GetConfigPath() {
std::filesystem::path PathManager::GetCachePath() {
#ifdef _WIN32
return GetKnownFolder(FOLDERID_LocalAppData) / app_name_ / "Cache";
return GetKnownFolder(FOLDERID_LocalAppData) / app_name_ / "cache";
#elif __APPLE__
return GetEnvOrDefault("XDG_CACHE_HOME", GetHome() + "/.cache") / app_name_;
#else
@@ -26,7 +26,7 @@ std::filesystem::path PathManager::GetCachePath() {
std::filesystem::path PathManager::GetLogPath() {
#ifdef _WIN32
return GetKnownFolder(FOLDERID_LocalAppData) / app_name_ / "Logs";
return GetKnownFolder(FOLDERID_LocalAppData) / app_name_ / "logs";
#elif __APPLE__
return GetHome() + "/Library/Logs/" + app_name_;
#else
@@ -34,6 +34,20 @@ std::filesystem::path PathManager::GetLogPath() {
#endif
}
std::filesystem::path PathManager::GetCertPath() {
#ifdef _WIN32
// %APPDATA%\AppName\Certs
return GetKnownFolder(FOLDERID_RoamingAppData) / app_name_ / "certs";
#elif __APPLE__
// $HOME/Library/Application Support/AppName/certs
return GetHome() + "/Library/Application Support/" + app_name_ + "/certs";
#else
// $XDG_CONFIG_HOME/AppName/certs
return GetEnvOrDefault("XDG_CONFIG_HOME", GetHome() + "/.config") /
app_name_ / "certs";
#endif
}
bool PathManager::CreateDirectories(const std::filesystem::path& p) {
std::error_code ec;
bool created = std::filesystem::create_directories(p, ec);

View File

@@ -24,6 +24,8 @@ class PathManager {
std::filesystem::path GetLogPath();
std::filesystem::path GetCertPath();
bool CreateDirectories(const std::filesystem::path& p);
private: