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

View file

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

View file

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

View file

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