mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 02:06:36 +02:00
* Merge and conflict resolution * Messages good, backup/restore algo better. * Start of "GetExportVerion" * fixed spelling * New backup/restore mode working. * Rename a project * Removed test project * Switch to text.json * Renamed BackupAndSync to BackupAndRestore * Added IgnoredPTRunSettings and full merge * Restored "fixed" settings that change for no reason * Various UI updates. * speling * Some cleanup and zip support. * Merge and clean * code clean up * code clean up * code clean up * Smarter settings compare and merge. * config based file include/exclude * Removed some "words" * Code clean up * cleanup * cleanup * cleanup * cleanup * fixed spelling. * Fixed clean up 1 * more clean up * Trying to add ptb as an OK word * Some UI updates. * UI tweaks and PR review items. * UI tweaks * Merge conflicts resolved. * Added CurrentSettingMatchText * PR review updates. * Removed weird file. * Review updates and fixes * More UI tweaks. * UI tweaks * Set default backup location to "%USERPROFILE%\\Documents\\PowerToys\\Backup" * settings ui tweaks * Added ExpanderContentSettingStyle * fix missing config file * fix missing config file, part 2 * update ui, cleanup cope * update ui, cleanup code - Part2 * update method comments * code cleanup and adjust Backup message time * fix changing backup location on empty Regsitry * fix select location - part 2 * location input box min-width * remove lastRestoreDate from ViewModel * Code or backup timing, and error handling. * Should fix file/folder name crash. * Progress to instance class for backup/restore * Persist backup status state, added refresh button. * Better auto check for settings status * Some UI/text updates. * Clean up * Added prefix for "General_Settings" to resources * Code review updates. * Code review changes. * Changed to FolderPicker per review * Fixed issue with early delete of cleanup. * Testing issues with FolderPicker * Removed WinForm req and fixed win10 issue. * Review update. * Review changes. Co-authored-by: htcfreek <61519853+htcfreek@users.noreply.github.com>
64 lines
1.7 KiB
C++
64 lines
1.7 KiB
C++
#include "pch.h"
|
|
#include "restart_elevated.h"
|
|
|
|
#include <common/utils/elevation.h>
|
|
|
|
enum State
|
|
{
|
|
None,
|
|
RestartAsElevated,
|
|
RestartAsElevatedOpenSettings,
|
|
RestartAsNonElevated,
|
|
RestartAsNonElevatedOpenSettings
|
|
};
|
|
static State state = None;
|
|
|
|
void schedule_restart_as_elevated(bool openSettings)
|
|
{
|
|
state = openSettings ? RestartAsElevatedOpenSettings : RestartAsElevated;
|
|
}
|
|
|
|
void schedule_restart_as_non_elevated()
|
|
{
|
|
state = RestartAsNonElevated;
|
|
}
|
|
|
|
void schedule_restart_as_non_elevated(bool openSettings)
|
|
{
|
|
state = openSettings ? RestartAsNonElevatedOpenSettings : RestartAsNonElevated;
|
|
}
|
|
|
|
bool is_restart_scheduled()
|
|
{
|
|
return state != None;
|
|
}
|
|
|
|
bool restart_if_scheduled()
|
|
{
|
|
// Make sure we have enough room, even for the long (\\?\) paths
|
|
constexpr DWORD exe_path_size = 0xFFFF;
|
|
auto exe_path = std::make_unique<wchar_t[]>(exe_path_size);
|
|
GetModuleFileNameW(nullptr, exe_path.get(), exe_path_size);
|
|
switch (state)
|
|
{
|
|
case RestartAsElevated:
|
|
return run_elevated(exe_path.get(), {});
|
|
case RestartAsElevatedOpenSettings:
|
|
return run_elevated(exe_path.get(), L"--open-settings");
|
|
case RestartAsNonElevatedOpenSettings:
|
|
return run_non_elevated(exe_path.get(), L"--open-settings", NULL);
|
|
case RestartAsNonElevated:
|
|
return run_non_elevated(exe_path.get(), L"", NULL);
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
|
|
bool restart_same_elevation()
|
|
{
|
|
constexpr DWORD exe_path_size = 0xFFFF;
|
|
auto exe_path = std::make_unique<wchar_t[]>(exe_path_size);
|
|
GetModuleFileNameW(nullptr, exe_path.get(), exe_path_size);
|
|
return run_same_elevation(exe_path.get(), L"", nullptr);
|
|
}
|