@@ -35,6 +35,7 @@ namespace Updater {
3535 // The old renamed exe will be deleted the next time the updater runs.
3636 static const char * UpdaterExeFilename = " REPENTOGONLauncher.exe" ;
3737 static const char * RenamedUpdaterExeFilename = " REPENTOGONLauncher.exe.bak" ;
38+ static const char * LegacyUpdaterExeFilename = " REPENTOGONLauncherUpdater.exe" ;
3839
3940 static const char * LauncherDataFolder = " launcher-data" ;
4041 static const char * LauncherDataBackupFolder = " launcher-data.old" ;
@@ -276,8 +277,6 @@ void Updater::ProgressBarThread(POINT windowPos) {
276277Updater::UpdateLauncherResult Updater::TryUpdateLauncher (int argc, char ** argv, HWND mainWindow) {
277278 Logger::Info (" TryUpdateLauncher started.\n " );
278279
279- // Open a handle for the active launcher process, if provided by the launcher itself.
280- HANDLE launcherHandle = TryOpenLauncherProcessHandle (argc, argv);
281280 // Validate that no other instance of the updater is running.
282281 HANDLE lockFile = NULL ;
283282
@@ -311,6 +310,12 @@ Updater::UpdateLauncherResult Updater::TryUpdateLauncher(int argc, char** argv,
311310
312311 SetCurrentUpdaterState (UPDATER_CHECKING_FOR_UPDATE);
313312
313+ // Delete the legacy updater exe, if it exists.
314+ if (std::filesystem::exists (LegacyUpdaterExeFilename)) {
315+ Logger::Info (" Deleting legacy updater exe...\n " );
316+ std::filesystem::remove (LegacyUpdaterExeFilename);
317+ }
318+
314319 // If the version backup folder exists, and an unfinished/broken update is detected, attempt to roll back.
315320 if (std::filesystem::exists (LauncherDataBackupFolder) && (std::filesystem::exists (UnfinishedUpdateMarker) || !std::filesystem::exists (LauncherDllPath))) {
316321 Logger::Error (" Detected failed update!\n " );
@@ -443,19 +448,6 @@ Updater::UpdateLauncherResult Updater::TryUpdateLauncher(int argc, char** argv,
443448
444449 SetCurrentUpdaterState (UPDATER_DOWNLOADING_UPDATE);
445450
446- // If we opened a launcher process handle, terminate it now.
447- if (launcherHandle != INVALID_HANDLE_VALUE) {
448- Logger::Info (" Terminating launcher...\n " );
449- if (TerminateProcess (launcherHandle, 0 )) {
450- WaitForSingleObject (launcherHandle, INFINITE);
451- }
452- else {
453- // We continue on after this error since we'll notice if the launcher exe is locked and prompt the user about it then.
454- Logger::Error (" Failed to terminate launcher process (%d)\n " , GetLastError ());
455- }
456- CloseHandle (launcherHandle);
457- }
458-
459451 Logger::Info (" Starting update download from %s\n " , url.c_str ());
460452
461453 std::string updateZipFilename;
@@ -623,6 +615,18 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR cli, int) {
623615 int argc = 0 ;
624616 char ** argv = Updater::Utils::CommandLineToArgvA (cli, &argc);
625617
618+ // Open a handle for the prior launcher process, if provided, and kill it.
619+ if (HANDLE launcherHandle = Updater::TryOpenLauncherProcessHandle (argc, argv); launcherHandle != INVALID_HANDLE_VALUE) {
620+ Logger::Info (" Restart detected. Terminating previous launcher instance...\n " );
621+ if (TerminateProcess (launcherHandle, 0 )) {
622+ WaitForSingleObject (launcherHandle, INFINITE);
623+ } else {
624+ // We can continue on after this and hope for the best.
625+ Logger::Error (" Failed to terminate launcher process (%d)\n " , GetLastError ());
626+ }
627+ CloseHandle (launcherHandle);
628+ }
629+
626630 sGithubExecutor ->Start ();
627631
628632 // Create a dummy window to use as a parent for popups.
0 commit comments