From 7ab521f740bc46419158ae4f02f8f4b52c5aa56c Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Thu, 6 Aug 2020 22:37:40 +1000 Subject: [PATCH] Updater: Handle UTF-8 paths when launching at end --- src/updater/updater.cpp | 5 +++-- src/updater/win32_main.cpp | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/updater/updater.cpp b/src/updater/updater.cpp index 993bd3b0a..177e841c8 100644 --- a/src/updater/updater.cpp +++ b/src/updater/updater.cpp @@ -162,7 +162,8 @@ bool Updater::PrepareStagingDirectory() if (FileSystem::DirectoryExists(m_staging_directory.c_str())) { m_progress->DisplayFormattedWarning("Update staging directory already exists, removing"); - if (!RecursiveDeleteDirectory(m_staging_directory.c_str()) || FileSystem::DirectoryExists(m_staging_directory.c_str())) + if (!RecursiveDeleteDirectory(m_staging_directory.c_str()) || + FileSystem::DirectoryExists(m_staging_directory.c_str())) { m_progress->ModalError("Failed to remove old staging directory"); return false; @@ -284,7 +285,7 @@ bool Updater::CommitUpdate() "%s%c%s", m_staging_directory.c_str(), FS_OSPATH_SEPERATOR_CHARACTER, ftu.destination_filename.c_str()); const std::string dest_file_name = StringUtil::StdStringFromFormat( "%s%c%s", m_destination_directory.c_str(), FS_OSPATH_SEPERATOR_CHARACTER, ftu.destination_filename.c_str()); - m_progress->DisplayFormattedDebugMessage("Moving '%s' to '%s'", staging_file_name.c_str(), dest_file_name.c_str()); + m_progress->DisplayFormattedInformation("Moving '%s' to '%s'", staging_file_name.c_str(), dest_file_name.c_str()); #ifdef WIN32 const bool result = MoveFileExW(StringUtil::UTF8StringToWideString(staging_file_name).c_str(), diff --git a/src/updater/win32_main.cpp b/src/updater/win32_main.cpp index d7b50d69a..6bdea1dea 100644 --- a/src/updater/win32_main.cpp +++ b/src/updater/win32_main.cpp @@ -37,7 +37,7 @@ int wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int const int parent_process_id = StringUtil::FromChars(StringUtil::WideStringToUTF8String(argv[0])).value_or(0); const std::string destination_directory = StringUtil::WideStringToUTF8String(argv[1]); const std::string zip_path = StringUtil::WideStringToUTF8String(argv[2]); - const std::string program_to_launch = StringUtil::WideStringToUTF8String(argv[3]); + const std::wstring program_to_launch(argv[3]); LocalFree(argv); if (parent_process_id <= 0 || destination_directory.empty() || zip_path.empty() || program_to_launch.empty()) @@ -85,7 +85,8 @@ int wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int progress.ModalInformation("Update complete."); - progress.DisplayFormattedInformation("Launching '%s'...", program_to_launch.c_str()); - ShellExecuteA(nullptr, "open", program_to_launch.c_str(), nullptr, nullptr, SW_SHOWNORMAL); + progress.DisplayFormattedInformation("Launching '%s'...", + StringUtil::WideStringToUTF8String(program_to_launch).c_str()); + ShellExecuteW(nullptr, L"open", program_to_launch.c_str(), nullptr, nullptr, SW_SHOWNORMAL); return 0; }