Updater: Preserve non-standard exe names on update

This commit is contained in:
TellowKrinkle 2022-12-05 23:51:16 -06:00 committed by refractionpcsx2
parent 05a9a71f4a
commit a4b598aa15
1 changed files with 16 additions and 13 deletions

View File

@ -453,7 +453,7 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLi
const int parent_process_id = StringUtil::FromChars<int>(StringUtil::WideStringToUTF8String(argv[1])).value_or(0);
const std::string destination_directory = StringUtil::WideStringToUTF8String(argv[2]);
const std::string zip_path = StringUtil::WideStringToUTF8String(argv[3]);
std::wstring program_to_launch(argv[4]);
const std::wstring program_to_launch(argv[4]);
argv.reset();
if (parent_process_id <= 0 || destination_directory.empty() || zip_path.empty() || program_to_launch.empty())
@ -493,7 +493,6 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLi
return 1;
}
DeleteFileW(program_to_launch.c_str()); // In case the new exe has a different name, delete the old one to prevent confusion
if (!updater.CommitUpdate())
{
progress.ModalError(
@ -504,22 +503,26 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLi
updater.CleanupStagingDirectory();
updater.RemoveUpdateZip();
progress.ModalInformation("Update complete.");
if (GetFileAttributesW(program_to_launch.c_str()) == INVALID_FILE_ATTRIBUTES)
// Rename the new executable to match the existing one
if (std::string actual_exe = updater.FindPCSX2Exe(); !actual_exe.empty())
{
// New executable doesn't match old, try to find the real one...
if (std::string actual_exe = updater.FindPCSX2Exe(); !actual_exe.empty())
const std::string full_path = destination_directory + FS_OSPATH_SEPARATOR_STR + actual_exe;
progress.DisplayFormattedInformation("Moving '%s' to '%S'", full_path.c_str(), program_to_launch.c_str());
const bool ok = MoveFileExW(StringUtil::UTF8StringToWideString(full_path).c_str(),
program_to_launch.c_str(), MOVEFILE_REPLACE_EXISTING);
if (!ok)
{
std::string full_path = destination_directory + FS_OSPATH_SEPARATOR_STR + actual_exe;
program_to_launch = StringUtil::UTF8StringToWideString(full_path);
}
else
{
progress.ModalError("Couldn't find PCSX2 in update package, please re-download a fresh version from GitHub.");
progress.DisplayFormattedModalError("Failed to rename '%s' to %S", full_path.c_str(), program_to_launch.c_str());
return 1;
}
}
else
{
progress.ModalError("Couldn't find PCSX2 in update package, please re-download a fresh version from GitHub.");
return 1;
}
progress.ModalInformation("Update complete.");
progress.DisplayFormattedInformation("Launching '%s'...",
StringUtil::WideStringToUTF8String(program_to_launch).c_str());