Fix runner warnings (#8211)

This commit is contained in:
Mykhailo Pylyp
2020-11-30 16:16:49 +02:00
committed by GitHub
parent 7c9888300b
commit f0553c370a
17 changed files with 101 additions and 139 deletions

View File

@@ -46,7 +46,6 @@ namespace
const wchar_t POWER_TOYS_MODULE_LOAD_FAIL[] = L"Failed to load "; // Module name will be appended on this message and it is not localized.
}
std::shared_ptr<Logger> logger;
void chdir_current_executable()
{
// Change current directory to the path of the executable.
@@ -77,7 +76,11 @@ void open_menu_from_another_instance()
int runner(bool isProcessElevated)
{
logger->info("Runner is starting. Elevated={}", isProcessElevated);
std::filesystem::path logFilePath(PTSettingsHelper::get_root_save_folder_location());
logFilePath.append(LogSettings::runnerLogPath);
Logger::init(LogSettings::runnerLoggerName, logFilePath.wstring(), PTSettingsHelper::get_log_settings_file_location());
Logger::info("Runner is starting. Elevated={}", isProcessElevated);
DPIAware::EnableDPIAwarenessForThisProcess();
#if _DEBUG && _WIN64
@@ -296,10 +299,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
return 0;
}
std::filesystem::path logFilePath(PTSettingsHelper::get_root_save_folder_location());
logFilePath = logFilePath.append(LogSettings::runnerLogPath);
logger = std::make_shared<Logger>(LogSettings::runnerLoggerName, logFilePath.wstring(), PTSettingsHelper::get_log_settings_file_location());
int n_cmd_args = 0;
LPWSTR* cmd_arg_list = CommandLineToArgvW(GetCommandLineW(), &n_cmd_args);
switch (should_run_in_special_mode(n_cmd_args, cmd_arg_list))

View File

@@ -19,6 +19,7 @@
#include <common/os-detect.h>
#include <common/version.h>
#include <common/VersionHelper.h>
#include <common/logger/logger.h>
#define BUFSIZE 1024
@@ -276,9 +277,18 @@ void run_settings_window()
std::wstring powertoys_pipe_name(L"\\\\.\\pipe\\powertoys_runner_");
std::wstring settings_pipe_name(L"\\\\.\\pipe\\powertoys_settings_");
UUID temp_uuid;
UuidCreate(&temp_uuid);
wchar_t* uuid_chars;
UuidToString(&temp_uuid, (RPC_WSTR*)&uuid_chars);
wchar_t* uuid_chars = nullptr;
if (UuidCreate(&temp_uuid) == RPC_S_UUID_NO_ADDRESS)
{
auto val = get_last_error_message(GetLastError());
Logger::warn(L"UuidCreate can not create guid. {}", val.has_value() ? val.value() : L"");
}
else if (UuidToString(&temp_uuid, (RPC_WSTR*)&uuid_chars) != RPC_S_OK)
{
auto val = get_last_error_message(GetLastError());
Logger::warn(L"UuidToString can not convert to string. {}", val.has_value() ? val.value() : L"");
}
if (uuid_chars != nullptr)
{
powertoys_pipe_name += std::wstring(uuid_chars);
@@ -386,10 +396,18 @@ void run_settings_window()
current_settings_ipc->start(hToken);
g_settings_process_id = process_info.dwProcessId;
WaitForSingleObject(process_info.hProcess, INFINITE);
if (WaitForSingleObject(process_info.hProcess, INFINITE) != WAIT_OBJECT_0)
if (process_info.hProcess)
{
show_last_error_message(L"Couldn't wait on the Settings Window to close.", GetLastError(), L"PowerToys - runner");
WaitForSingleObject(process_info.hProcess, INFINITE);
if (WaitForSingleObject(process_info.hProcess, INFINITE) != WAIT_OBJECT_0)
{
show_last_error_message(L"Couldn't wait on the Settings Window to close.", GetLastError(), L"PowerToys - runner");
}
}
else
{
auto val = get_last_error_message(GetLastError());
Logger::error(L"Process handle is empty. {}", val.has_value() ? val.value() : L"");
}
LExit: