From dcaae5dea7a22183576ee6ce3045cacab085a56c Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 10 Jan 2022 18:12:15 +0300 Subject: PU::IsMirandaFolderWritable - core function to detect if need to draw a shield on buttons that require escalation --- plugins/PluginUpdater/src/DlgListNew.cpp | 17 ++--------------- plugins/PluginUpdater/src/DlgUpdate.cpp | 18 ++---------------- 2 files changed, 4 insertions(+), 31 deletions(-) (limited to 'plugins/PluginUpdater') diff --git a/plugins/PluginUpdater/src/DlgListNew.cpp b/plugins/PluginUpdater/src/DlgListNew.cpp index 8dcbc35592..bcc050163f 100644 --- a/plugins/PluginUpdater/src/DlgListNew.cpp +++ b/plugins/PluginUpdater/src/DlgListNew.cpp @@ -129,21 +129,8 @@ public: ImageList_AddIconFromIconLib(hIml, IDI_INFO); m_list.SetImageList(hIml, LVSIL_SMALL); - if (IsWinVer7Plus()) { - TFileName szPath; - GetModuleFileNameW(nullptr, szPath, _countof(szPath)); - wchar_t *ext = wcsrchr(szPath, '.'); - if (ext != nullptr) - *ext = '\0'; - wcscat(szPath, L".test"); - HANDLE hFile = CreateFileW(szPath, GENERIC_WRITE, FILE_SHARE_READ, nullptr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); - if (hFile == INVALID_HANDLE_VALUE) - Button_SetElevationRequiredState(GetDlgItem(m_hwnd, IDOK), !PU::IsProcessElevated()); - else { - CloseHandle(hFile); - DeleteFile(szPath); - } - } + if (!PU::IsMirandaFolderWritable()) + Button_SetElevationRequiredState(GetDlgItem(m_hwnd, IDOK), !PU::IsProcessElevated()); ////////////////////////////////////////////////////////////////////////////////////// LVCOLUMN lvc = { 0 }; diff --git a/plugins/PluginUpdater/src/DlgUpdate.cpp b/plugins/PluginUpdater/src/DlgUpdate.cpp index baa2d0e90d..90a5a3be48 100644 --- a/plugins/PluginUpdater/src/DlgUpdate.cpp +++ b/plugins/PluginUpdater/src/DlgUpdate.cpp @@ -203,22 +203,8 @@ public: Window_SetIcon_IcoLib(m_hwnd, g_plugin.getIconHandle(IDI_MENU)); - if (IsWinVerVistaPlus()) { - TFileName wszPath; - GetModuleFileName(nullptr, wszPath, _countof(wszPath)); - wchar_t *ext = wcsrchr(wszPath, '.'); - if (ext != nullptr) - *ext = '\0'; - wcscat(wszPath, L".test"); - HANDLE hFile = CreateFileW(wszPath, GENERIC_WRITE, FILE_SHARE_READ, nullptr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); - if (hFile == INVALID_HANDLE_VALUE) - // Running Windows Vista or later (major version >= 6). - Button_SetElevationRequiredState(btnOk.GetHwnd(), !PU::IsProcessElevated()); - else { - CloseHandle(hFile); - DeleteFileW(wszPath); - } - } + if (!PU::IsMirandaFolderWritable()) + Button_SetElevationRequiredState(btnOk.GetHwnd(), !PU::IsProcessElevated()); // Initialize the LVCOLUMN structure. // The mask specifies that the format, width, text, and -- cgit v1.2.3