From fb754b0d4350ec9e7804dff967159909466e5dfe Mon Sep 17 00:00:00 2001 From: mjk Date: Fri, 5 Mar 2021 22:50:36 +0000 Subject: [PATCH] generalize GetShortcutPath into GetEnv --- plugins/windows-notification/api/include/win32.hpp | 2 +- plugins/windows-notification/api/src/shortcutcreator.cpp | 3 +-- plugins/windows-notification/api/src/win32.cpp | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/plugins/windows-notification/api/include/win32.hpp b/plugins/windows-notification/api/include/win32.hpp index eba2e0e7..34b9874c 100644 --- a/plugins/windows-notification/api/include/win32.hpp +++ b/plugins/windows-notification/api/include/win32.hpp @@ -31,7 +31,7 @@ private: }; std::wstring GetExePath(); -std::wstring GetShortcutPath(); +std::wstring GetEnv(const wchar_t *variable_name); #define EXTERN extern "C" #define NOEXCEPT noexcept diff --git a/plugins/windows-notification/api/src/shortcutcreator.cpp b/plugins/windows-notification/api/src/shortcutcreator.cpp index f62c8267..0042d45d 100644 --- a/plugins/windows-notification/api/src/shortcutcreator.cpp +++ b/plugins/windows-notification/api/src/shortcutcreator.cpp @@ -134,9 +134,8 @@ bool ImplEnsureAumiddedShortcutExists(const char *const aumid) } 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)) { return SUCCEEDED(InstallShortcut(exePath, waumid, path)); diff --git a/plugins/windows-notification/api/src/win32.cpp b/plugins/windows-notification/api/src/win32.cpp index 02285fe1..91d3ad8e 100644 --- a/plugins/windows-notification/api/src/win32.cpp +++ b/plugins/windows-notification/api/src/win32.cpp @@ -21,10 +21,10 @@ std::wstring GetExePath() throw win32_error{}; } -std::wstring GetShortcutPath() +std::wstring GetEnv(const wchar_t *const variable_name) { 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) { shortcutPath.resize(charWritten);