summaryrefslogtreecommitdiff
path: root/Source/Core/WinUpdater/Main.cpp
diff options
context:
space:
mode:
authorAdmiral H. Curtiss <pikachu025@gmail.com>2022-11-22 23:50:13 +0100
committerGitHub <noreply@github.com>2022-11-22 23:50:13 +0100
commit5e442f6ffa7664dbc696e18693c1a4dd872fae8d (patch)
treeeaad2633703fd5321626a39dbc562b45898eea69 /Source/Core/WinUpdater/Main.cpp
parent19b6251a3c6de6de431a395fec9ce6bb6d0f6f82 (diff)
parent5ebb894685a97570c3d12eb00956c32d56557629 (diff)
Merge pull request #11281 from AdmiralCurtiss/updater-admin-check
Updater: Check for write permissions in directory of Updater.exe.
Diffstat (limited to 'Source/Core/WinUpdater/Main.cpp')
-rw-r--r--Source/Core/WinUpdater/Main.cpp23
1 files changed, 13 insertions, 10 deletions
diff --git a/Source/Core/WinUpdater/Main.cpp b/Source/Core/WinUpdater/Main.cpp
index caa9f40958..6b7fd801ef 100644
--- a/Source/Core/WinUpdater/Main.cpp
+++ b/Source/Core/WinUpdater/Main.cpp
@@ -31,12 +31,22 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine
// Test for write permissions
bool need_admin = false;
- FILE* test_fh = fopen("Updater.log", "w");
+ auto path = GetModuleName(hInstance);
+ if (!path)
+ {
+ UI::Error("Failed to get updater filename.");
+ return 1;
+ }
+
+ const auto test_fh = ::CreateFileW(
+ (std::filesystem::path(*path).parent_path() / "directory_writable_check.tmp").c_str(),
+ GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS,
+ FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE, nullptr);
- if (test_fh == nullptr)
+ if (test_fh == INVALID_HANDLE_VALUE)
need_admin = true;
else
- fclose(test_fh);
+ CloseHandle(test_fh);
if (need_admin)
{
@@ -47,13 +57,6 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine
return 1;
}
- auto path = GetModuleName(hInstance);
- if (!path)
- {
- MessageBox(nullptr, L"Failed to get updater filename.", L"Error", MB_ICONERROR);
- return 1;
- }
-
// Relaunch the updater as administrator
ShellExecuteW(nullptr, L"runas", path->c_str(), pCmdLine, NULL, SW_SHOW);
return 0;