Merge pull request #15997 from luiscuenca/WLAutoInstallerFix

DEV-243: WL Fix auto-installer bugs
This commit is contained in:
Andy Howell 2019-07-30 16:19:10 -07:00 committed by GitHub
commit 2e8bb5f90a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 91 additions and 43 deletions

View file

@ -42,8 +42,7 @@ BOOL CLauncherApp::InitInstance() {
bool uninstalling = false;
bool restarting = false;
bool noUpdate = false;
bool continueUpdating = false;
bool skipSplash = false;
LauncherManager::ContinueActionOnStart continueAction = LauncherManager::ContinueActionOnStart::ContinueNone;
if (iNumOfArgs > 1) {
for (int i = 1; i < iNumOfArgs; i++) {
CString curArg = CString(pArgs[i]);
@ -53,10 +52,10 @@ BOOL CLauncherApp::InitInstance() {
restarting = true;
} else if (curArg.Compare(_T("--noUpdate")) == 0) {
noUpdate = true;
} else if (curArg.Compare(_T("--continueUpdating")) == 0) {
continueUpdating = true;
} else if (curArg.Compare(_T("--skipSplash")) == 0) {
skipSplash = true;
} else if (curArg.Compare(_T("--continueAction")) == 0) {
if (i + 1 < iNumOfArgs) {
continueAction = LauncherManager::getContinueActionFromParam(pArgs[i + 1]);
}
}
}
}
@ -71,7 +70,7 @@ BOOL CLauncherApp::InitInstance() {
if (uninstalling) {
_manager.uninstall();
} else {
_manager.init(!noUpdate, continueUpdating, skipSplash);
_manager.init(!noUpdate, continueAction);
}
if (!_manager.hasFailed() && !_manager.installLauncher()) {
return FALSE;

View file

@ -357,7 +357,7 @@ void CLauncherDlg::drawVoxel(CHwndRenderTarget* pRenderTarget) {
}
void CLauncherDlg::drawProgress(CHwndRenderTarget* pRenderTarget, float progress, const D2D1::ColorF& color) {
auto size = pRenderTarget->GetPixelSize();
auto size = pRenderTarget->GetSize();
if (progress == 0.0f) {
return;
} else {
@ -693,22 +693,26 @@ void CLauncherDlg::OnTimer(UINT_PTR nIDEvent) {
}
}
}
LauncherManager::ContinueActionOnStart continueAction = theApp._manager.getContinueAction();
if (_showSplash) {
if (_splashStep == 0) {
if (theApp._manager.needsUninstall()) {
theApp._manager.addToLog(_T("Waiting to uninstall"));
setDrawDialog(DrawStep::DrawProcessUninstall);
} else if (theApp._manager.shouldContinueUpdating()) {
_splashStep = SPLASH_DURATION;
} else if (continueAction == LauncherManager::ContinueActionOnStart::ContinueUpdate) {
setDrawDialog(DrawStep::DrawProcessUpdate);
theApp._manager.updateProgress(LauncherManager::ProcessType::Uninstall, 0.0f);
} else if (continueAction == LauncherManager::ContinueActionOnStart::ContinueLogIn) {
_splashStep = SPLASH_DURATION;
} else if (continueAction == LauncherManager::ContinueActionOnStart::ContinueFinish) {
theApp._manager.updateProgress(LauncherManager::ProcessType::Uninstall, 1.0f);
setDrawDialog(DrawStep::DrawProcessFinishUpdate);
_splashStep = SPLASH_DURATION;
_showSplash = false;
} else {
if (theApp._manager.shouldSkipSplashScreen()) {
_splashStep = SPLASH_DURATION;
} else {
theApp._manager.addToLog(_T("Start splash screen"));
setDrawDialog(DrawStep::DrawLogo);
}
theApp._manager.addToLog(_T("Start splash screen"));
setDrawDialog(DrawStep::DrawLogo);
}
} else if (_splashStep > SPLASH_DURATION && !theApp._manager.needsToWait()) {
_showSplash = false;

View file

@ -16,27 +16,55 @@
LauncherManager::LauncherManager() {
int tokenPos = 0;
_launcherVersion = CString(LAUNCHER_BUILD_VERSION).Tokenize(_T("-"), tokenPos);
}
LauncherManager::~LauncherManager() {
}
void LauncherManager::init(BOOL allowUpdate, BOOL continueUpdating, BOOL skipSplashScreen) {
void LauncherManager::init(BOOL allowUpdate, ContinueActionOnStart continueAction) {
initLog();
int tokenPos = 0;
_updateLauncherAllowed = allowUpdate;
_continueUpdating = continueUpdating;
_skipSplashScreen = skipSplashScreen;
_shouldWait = !skipSplashScreen;
if (_continueUpdating) {
_continueAction = continueAction;
CString msg;
msg.Format(_T("Start Screen: %s"), getContinueActionParam(continueAction));
addToLog(msg);
_shouldWait = _continueAction == ContinueActionOnStart::ContinueNone;
if (_continueAction == ContinueActionOnStart::ContinueUpdate) {
_progressOffset = CONTINUE_UPDATING_GLOBAL_OFFSET;
}
_launcherVersion = CString(LAUNCHER_BUILD_VERSION).Tokenize(_T("-"), tokenPos);
addToLog(_T("Launcher is running version: " + _launcherVersion));
addToLog(_T("Getting most recent builds"));
getMostRecentBuilds(_latestLauncherURL, _latestLauncherVersion, _latestApplicationURL, _latestVersion);
}
CString LauncherManager::getContinueActionParam(LauncherManager::ContinueActionOnStart continueAction) {
switch (continueAction) {
case LauncherManager::ContinueActionOnStart::ContinueNone:
return _T("");
case LauncherManager::ContinueActionOnStart::ContinueLogIn:
return _T("LogIn");
case LauncherManager::ContinueActionOnStart::ContinueUpdate:
return _T("Update");
case LauncherManager::ContinueActionOnStart::ContinueFinish:
return _T("Finish");
default:
return _T("");
}
}
LauncherManager::ContinueActionOnStart LauncherManager::getContinueActionFromParam(const CString& param) {
if (param.Compare(_T("LogIn")) == 0) {
return ContinueActionOnStart::ContinueLogIn;
} else if (param.Compare(_T("Update")) == 0) {
return ContinueActionOnStart::ContinueUpdate;
} else if (param.Compare(_T("Finish")) == 0) {
return ContinueActionOnStart::ContinueFinish;
} else {
return ContinueActionOnStart::ContinueNone;
}
}
BOOL LauncherManager::initLog() {
CString logPath;
auto result = getAndCreatePaths(PathType::Launcher_Directory, logPath);
@ -432,7 +460,8 @@ void LauncherManager::onMostRecentBuildsReceived(const CString& response, Launch
addToLog(updatingMsg);
_shouldUpdateLauncher = TRUE;
_shouldDownloadLauncher = TRUE;
_willContinueUpdating = isInstalled && newInterfaceVersion;
_keepLoggingIn = !isInstalled;
_keepUpdating = isInstalled && newInterfaceVersion;
} else {
if (_updateLauncherAllowed) {
addToLog(_T("Already running most recent build. Launching interface.exe"));
@ -612,11 +641,15 @@ void LauncherManager::onFileDownloaded(ProcessType type) {
void LauncherManager::restartNewLauncher() {
closeLog();
if (_willContinueUpdating) {
LauncherUtils::launchApplication(_tempLauncherPath, _T(" --restart --noUpdate --continueUpdating"));
} else {
LauncherUtils::launchApplication(_tempLauncherPath, _T(" --restart --noUpdate --skipSplash"));
ContinueActionOnStart continueAction = ContinueActionOnStart::ContinueFinish;
if (_keepUpdating) {
continueAction = ContinueActionOnStart::ContinueUpdate;
} else if (_keepLoggingIn) {
continueAction = ContinueActionOnStart::ContinueLogIn;
}
CStringW params;
params.Format(_T(" --restart --noUpdate --continueAction %s"), getContinueActionParam(continueAction));
LauncherUtils::launchApplication(_tempLauncherPath, params.GetBuffer());
Sleep(500);
}

View file

@ -11,6 +11,7 @@
#pragma once
#include "LauncherUtils.h"
#include "LauncherDlg.h"
const CString DIRECTORY_NAME_APP = _T("HQ");
const CString DIRECTORY_NAME_DOWNLOADS = _T("downloads");
@ -27,8 +28,7 @@ const float DOWNLOAD_APPLICATION_UPDATE_WEIGHT = 0.75f;
const float EXTRACT_APPLICATION_UPDATE_WEIGHT = 0.25f;
const float CONTINUE_UPDATING_GLOBAL_OFFSET = 0.2f;
class LauncherManager
{
class LauncherManager {
public:
enum PathType {
Running_Path = 0,
@ -57,22 +57,33 @@ public:
UnzipApplication,
Uninstall
};
enum ContinueActionOnStart {
ContinueNone = 0,
ContinueLogIn,
ContinueUpdate,
ContinueFinish
};
LauncherManager();
~LauncherManager();
void init(BOOL allowUpdate, BOOL continueUpdating, BOOL skipSplashScreen);
void init(BOOL allowUpdate, ContinueActionOnStart continueAction);
static CString getContinueActionParam(ContinueActionOnStart continueAction);
static ContinueActionOnStart getContinueActionFromParam(const CString& param);
BOOL initLog();
BOOL addToLog(const CString& line);
void closeLog();
void saveErrorLog();
BOOL getAndCreatePaths(PathType type, CString& outPath);
BOOL getInstalledVersion(const CString& path, CString& version);
BOOL isApplicationInstalled(CString& version, CString& domain,
BOOL isApplicationInstalled(CString& version, CString& domain,
CString& content, bool& loggedIn);
LauncherUtils::ResponseError getAccessTokenForCredentials(const CString& username, const CString& password);
void getMostRecentBuilds(CString& launcherUrlOut, CString& launcherVersionOut,
CString& interfaceUrlOut, CString& interfaceVersionOut);
void getMostRecentBuilds(CString& launcherUrlOut,
CString& launcherVersionOut,
CString& interfaceUrlOut,
CString& interfaceVersionOut);
LauncherUtils::ResponseError readOrganizationJSON(const CString& hash);
LauncherUtils::ResponseError readConfigJSON(CString& version, CString& domain,
LauncherUtils::ResponseError readConfigJSON(CString& version, CString& domain,
CString& content, bool& loggedIn);
BOOL createConfigJSON();
BOOL createApplicationRegistryKeys(int size);
@ -90,7 +101,6 @@ public:
const CString& getVersion() const { return _version; }
BOOL shouldShutDown() const { return _shouldShutdown; }
BOOL shouldLaunch() const { return _shouldLaunch; }
BOOL shouldSkipSplashScreen() const { return _skipSplashScreen; }
BOOL needsUpdate() const { return _shouldUpdate; }
BOOL needsSelfUpdate() const { return _shouldUpdateLauncher; }
BOOL needsSelfDownload() const { return _shouldDownloadLauncher; }
@ -98,14 +108,17 @@ public:
BOOL needsInstall() const { return _shouldInstall; }
BOOL needsToWait() const { return _shouldWait; }
BOOL needsRestartNewLauncher() const { return _shouldRestartNewLauncher; }
BOOL shouldContinueUpdating() const { return _continueUpdating; }
BOOL willContinueUpdating() const { return _willContinueUpdating; }
BOOL willContinueUpdating() const { return _keepUpdating; }
ContinueActionOnStart getContinueAction() { return _continueAction; }
void setDisplayName(const CString& displayName) { _displayName = displayName; }
bool isLoggedIn() const { return _loggedIn; }
bool hasFailed() const { return _hasFailed; }
void setFailed(bool hasFailed) { _hasFailed = hasFailed; }
const CString& getLatestInterfaceURL() const { return _latestApplicationURL; }
void uninstall() { _shouldUninstall = true; _shouldWait = false; };
void uninstall() {
_shouldUninstall = true;
_shouldWait = false;
};
BOOL downloadFile(ProcessType type, const CString& url, CString& localPath);
BOOL downloadContent();
@ -149,11 +162,10 @@ private:
BOOL _shouldDownloadLauncher { FALSE };
BOOL _updateLauncherAllowed { TRUE };
BOOL _shouldRestartNewLauncher { FALSE };
BOOL _continueUpdating { FALSE };
BOOL _willContinueUpdating { FALSE };
BOOL _skipSplashScreen { FALSE };
BOOL _keepLoggingIn { FALSE };
BOOL _keepUpdating { FALSE };
ContinueActionOnStart _continueAction;
float _progressOffset { 0.0f };
float _progress { 0.0f };
CStdioFile _logFile;
};