Skip to content

Commit a87582d

Browse files
committed
Skip gitlab barrier when looking for launcher pre-releases (for now at least... could decide to add support for it to the gitlab).
Updater: Terminate the previous launcher process earlier, since leaving it alive is no longer useful. Delete legacy update exe if found.
1 parent bfbe339 commit a87582d

4 files changed

Lines changed: 33 additions & 29 deletions

File tree

include/shared/launcher_update_checker.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,17 @@ namespace Shared {
4242
public:
4343
/* Check if an update of the launcher is available.
4444
*
45-
* allowDrafts indicates if a prerelease is considered a valid update.
45+
* allowPreRelease indicates if a prerelease is considered a valid update.
4646
* force causes the function to pick the first available release,
47-
* regardless of allowDrafts and regardless of whether said release is
47+
* regardless of allowPreRelease and regardless of whether said release is
4848
* new than the current one.
4949
* version receives the name of new available version, if any.
5050
* url receives the url to download the newest available version, if any.
5151
*
5252
* Return true if an update is available, false otherwise. false is
5353
* also returned on error.
5454
*/
55-
bool IsSelfUpdateAvailable(bool allowDrafts, bool force,
55+
bool IsSelfUpdateAvailable(bool allowPreRelease, bool force,
5656
std::string& version, std::string& url, curl::DownloadStringResult& fetchReleaseResult, SteamLauncherUpdateStatus& steamUpdateStatus);
5757

5858
/* Select the target release for a self update.
@@ -61,17 +61,17 @@ namespace Shared {
6161
* the releases and pick the first valid one depending on whether it is
6262
* a prerelease or not, and whether it is newer than the currently
6363
* installed release. This can be controlled through the two
64-
* parameters allowDrafts and force.
64+
* parameters allowPreRelease and force.
6565
*
66-
* allowDrafts indicates if a prerelease is considered a valid update.
66+
* allowPreRelease indicates if a prerelease is considered a valid update.
6767
* force causes the function to pick the first available release,
68-
* regardless of allowDrafts and regardless of wheter said release
68+
* regardless of allowPreRelease and regardless of wheter said release
6969
* if newer than the current one.
7070
*
7171
* The function returns an extended error code that can designate
7272
* multiple points of failure in the entire process.
7373
*/
74-
SelfUpdateErrorCode SelectReleaseTarget(bool allowDrafts, bool force);
74+
SelfUpdateErrorCode SelectReleaseTarget(bool allowPreRelease, bool force);
7575

7676
private:
7777
rapidjson::Document _releasesInfo;

self_updater/self_updater.cpp

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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) {
276277
Updater::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.

shared/launcher_update_checker.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ namespace Shared {
4343
return true;
4444
}
4545

46-
bool SelectTargetRelease(rapidjson::Document const& releases, bool allowPre,
46+
bool SelectTargetRelease(rapidjson::Document const& releases, bool allowPreRelease,
4747
bool force, std::string& version, std::string& url);
4848

49-
bool LauncherUpdateChecker::IsSelfUpdateAvailable(bool allowDrafts, bool force,
49+
bool LauncherUpdateChecker::IsSelfUpdateAvailable(bool allowPreRelease, bool force,
5050
std::string& version, std::string& url, curl::DownloadStringResult& fetchReleasesResult, SteamLauncherUpdateStatus& steamUpdateStatus) {
5151

5252
steamUpdateStatus = STEAM_LAUNCHER_UPDATE_NOT_USED;
5353

5454
//GitLab Barrier
55-
if (!force && !ShouldDoTimeBasedGitLabSkip()) {
55+
if (!force && !allowPreRelease && !ShouldDoTimeBasedGitLabSkip()) {
5656
if (RemoteGitLabVersionMatches("versionlauncher", Launcher::LAUNCHER_VERSION)) {
5757
fetchReleasesResult = curl::DownloadStringResult::DOWNLOAD_STRING_OK; //I would call this up a level so I dont have to do this hacky, but here is more convenient because I have some things already pre-chewed
5858
return false;
@@ -97,10 +97,10 @@ namespace Shared {
9797
}
9898

9999
_hasRelease = true;
100-
return SelectTargetRelease(_releasesInfo, allowDrafts, force, version, url) && strcmp(::Launcher::LAUNCHER_VERSION, version.c_str());
100+
return SelectTargetRelease(_releasesInfo, allowPreRelease, force, version, url) && strcmp(::Launcher::LAUNCHER_VERSION, version.c_str());
101101
}
102102

103-
bool SelectTargetRelease(rapidjson::Document const& releases, bool allowPre,
103+
bool SelectTargetRelease(rapidjson::Document const& releases, bool allowPreRelease,
104104
bool, std::string& version, std::string& url) {
105105
if (!releases.IsArray()) {
106106
rapidjson::StringBuffer buffer;
@@ -112,7 +112,7 @@ namespace Shared {
112112

113113
auto releaseArray = releases.GetArray();
114114
for (auto const& release : releaseArray) {
115-
if (!release["prerelease"].IsTrue() || allowPre) {
115+
if (!release["prerelease"].IsTrue() || allowPreRelease) {
116116
version = release["name"].GetString();
117117
url = release["url"].GetString();
118118
return true;

src/app.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ bool Launcher::App::OnInit() {
148148

149149
if (sCLI->CheckSelfUpdate()) {
150150
Logger::Info("Self-update startup check requested...\n");
151-
HandleSelfUpdate(_mainFrame, sCLI->UnstableLauncher(), false);
151+
HandleSelfUpdate(_mainFrame, sCLI->UnstableLauncher(), true);
152152
}
153153

154154
LauncherConfigurationInitialize initializationResult;

0 commit comments

Comments
 (0)