generalize GetShortcutPath into GetEnv

This commit is contained in:
mjk 2021-03-05 22:50:36 +00:00 committed by LAGonauta
parent 2eb1eea06e
commit fb754b0d43
3 changed files with 4 additions and 5 deletions

View file

@ -31,7 +31,7 @@ private:
}; };
std::wstring GetExePath(); std::wstring GetExePath();
std::wstring GetShortcutPath(); std::wstring GetEnv(const wchar_t *variable_name);
#define EXTERN extern "C" #define EXTERN extern "C"
#define NOEXCEPT noexcept #define NOEXCEPT noexcept

View file

@ -134,9 +134,8 @@ bool ImplEnsureAumiddedShortcutExists(const char *const aumid)
} }
auto exePath = GetExePath(); auto exePath = GetExePath();
auto shortcutPath = GetShortcutPath();
auto path = shortcutPath + LR"(\Microsoft\Windows\Start Menu\Programs\Dino.lnk)"; auto path = GetEnv(L"APPDATA") + LR"(\Microsoft\Windows\Start Menu\Programs\Dino.lnk)";
if (!std::filesystem::exists(path)) if (!std::filesystem::exists(path))
{ {
return SUCCEEDED(InstallShortcut(exePath, waumid, path)); return SUCCEEDED(InstallShortcut(exePath, waumid, path));

View file

@ -21,10 +21,10 @@ std::wstring GetExePath()
throw win32_error{}; throw win32_error{};
} }
std::wstring GetShortcutPath() std::wstring GetEnv(const wchar_t *const variable_name)
{ {
std::wstring shortcutPath(MAX_PATH, 0); std::wstring shortcutPath(MAX_PATH, 0);
auto charWritten = GetEnvironmentVariable(L"APPDATA", shortcutPath.data(), shortcutPath.size()); auto charWritten = GetEnvironmentVariable(variable_name, shortcutPath.data(), shortcutPath.size());
if (charWritten > 0) if (charWritten > 0)
{ {
shortcutPath.resize(charWritten); shortcutPath.resize(charWritten);