dolphin/Source/Core/WinUpdater/Main.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

67 lines
1.6 KiB
C++
Raw Normal View History

// Copyright 2018 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <windows.h>
2018-04-25 22:38:10 +02:00
#include <ShlObj.h>
#include <shellapi.h>
#include <optional>
#include <string>
#include <vector>
#include "Common/CommonFuncs.h"
#include "Common/StringUtil.h"
#include "UpdaterCommon/UI.h"
#include "UpdaterCommon/UpdaterCommon.h"
2018-03-28 00:28:40 +02:00
// Refer to docs/autoupdate_overview.md for a detailed overview of the autoupdate process
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
{
if (lstrlenW(pCmdLine) == 0)
{
MessageBoxW(nullptr,
L"This updater is not meant to be launched directly. Configure Auto-Update in "
"Dolphin's settings instead.",
L"Error", MB_ICONERROR);
return 1;
}
// Test for write permissions
2018-04-25 22:38:10 +02:00
bool need_admin = false;
auto path = GetModuleName(hInstance);
if (!path)
{
UI::Error("Failed to get updater filename.");
return 1;
}
FILE* test_fh =
_wfopen((std::filesystem::path(*path).parent_path() / "Updater.log").c_str(), L"w");
if (test_fh == nullptr)
need_admin = true;
else
fclose(test_fh);
2018-04-25 22:38:10 +02:00
if (need_admin)
{
if (IsUserAnAdmin())
{
MessageBox(nullptr, L"Failed to write to directory despite administrator priviliges.",
L"Error", MB_ICONERROR);
2018-04-25 22:38:10 +02:00
return 1;
}
// Relaunch the updater as administrator
ShellExecuteW(nullptr, L"runas", path->c_str(), pCmdLine, NULL, SW_SHOW);
2018-04-25 22:38:10 +02:00
return 0;
}
2018-03-28 00:28:40 +02:00
std::vector<std::string> args = CommandLineToUtf8Argv(pCmdLine);
2018-03-28 00:28:40 +02:00
return RunUpdater(args) ? 0 : 1;
}