11#pragma comment(lib, "userenv.lib")
16class WindowsPaths :
public Paths
19 std::filesystem::path getDataDir()
const override
21 wchar_t path[MAX_PATH];
22 if (SUCCEEDED(SHGetFolderPathW(
nullptr, CSIDL_APPDATA,
nullptr, 0, path)))
24 return std::filesystem::path(path) /
"GameLauncher";
26 return getHomeDir() /
"AppData" /
"Roaming" /
"GameLauncher";
29 std::filesystem::path getCacheDir()
const override
31 wchar_t path[MAX_PATH];
32 if (SUCCEEDED(SHGetFolderPathW(
nullptr, CSIDL_LOCAL_APPDATA,
nullptr, 0, path)))
34 return std::filesystem::path(path) /
"GameLauncher" /
"cache";
36 return getHomeDir() /
"AppData" /
"Local" /
"GameLauncher" /
"cache";
39 std::filesystem::path getLogDir()
const override
41 return getDataDir() /
"logs";
44 std::filesystem::path
getHomeDir()
const override
47 wchar_t path[MAX_PATH];
48 DWORD size = MAX_PATH;
49 if (GetEnvironmentVariableW(L
"USERPROFILE", path, size) > 0)
51 return std::filesystem::path(path);
55 if (SUCCEEDED(SHGetFolderPathW(
nullptr, CSIDL_PROFILE,
nullptr, 0, path)))
57 return std::filesystem::path(path);
61 wchar_t drive[MAX_PATH], homePath[MAX_PATH];
62 if (GetEnvironmentVariableW(L
"HOMEDRIVE", drive, MAX_PATH) > 0 &&
63 GetEnvironmentVariableW(L
"HOMEPATH", homePath, MAX_PATH) > 0)
65 return std::filesystem::path(drive) / homePath;
69 return "C:\\Users\\Default";
72 std::filesystem::path getDocumentsDir()
const override
74 wchar_t path[MAX_PATH];
75 if (SUCCEEDED(SHGetFolderPathW(
nullptr, CSIDL_PERSONAL,
nullptr, 0, path)))
77 return std::filesystem::path(path);
82 std::filesystem::path expandPath(
const std::string& path)
const override
86 return std::filesystem::path();
90 int wideLen = MultiByteToWideChar(CP_UTF8, 0, path.c_str(), -1,
nullptr, 0);
91 std::wstring widePath(wideLen, L
'\0');
92 MultiByteToWideChar(CP_UTF8, 0, path.c_str(), -1, widePath.data(), wideLen);
95 wchar_t expanded[MAX_PATH * 2];
96 DWORD result = ExpandEnvironmentStringsW(widePath.c_str(), expanded, MAX_PATH * 2);
98 if (result > 0 && result < MAX_PATH * 2)
100 return std::filesystem::path(expanded);
103 return std::filesystem::path(path);
110 return std::make_unique<WindowsPaths>();
std::filesystem::path getHomeDir()