Merge pull request #15893 from luiscuenca/WLKeepConfigWhenESC

BUGZ-768: Keep config.json when updating to avoid relogin.
This commit is contained in:
Shannon Romano 2019-07-08 15:26:02 -07:00 committed by GitHub
commit 9474ca29f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 48 additions and 65 deletions

View file

@ -208,19 +208,11 @@ void CLauncherDlg::startProcess() {
theApp._manager.addToLog(_T("Starting Process Setup"));
setDrawDialog(DrawStep::DrawProcessSetup);
}
theApp._manager.addToLog(_T("Deleting directories before install"));
CString installDir;
theApp._manager.getAndCreatePaths(LauncherManager::PathType::Interface_Directory, installDir);
theApp._manager.addToLog(_T("Deleting download directory"));
CString downloadDir;
theApp._manager.getAndCreatePaths(LauncherManager::PathType::Download_Directory, downloadDir);
LauncherUtils::deleteDirectoriesOnThread(installDir, downloadDir, [&](int error) {
LauncherUtils::DeleteDirError deleteError = (LauncherUtils::DeleteDirError)error;
switch(error) {
case LauncherUtils::DeleteDirError::NoErrorDeleting:
theApp._manager.addToLog(_T("Install directory deleted."));
theApp._manager.addToLog(_T("Downloads directory deleted."));
LauncherUtils::deleteDirectoryOnThread(downloadDir, [&](bool error) {
if (!error) {
if (!theApp._manager.isLoggedIn()) {
theApp._manager.addToLog(_T("Downloading Content"));
theApp._manager.downloadContent();
@ -228,23 +220,12 @@ void CLauncherDlg::startProcess() {
theApp._manager.addToLog(_T("Downloading App"));
theApp._manager.downloadApplication();
}
break;
case LauncherUtils::DeleteDirError::ErrorDeletingBothDirs:
theApp._manager.addToLog(_T("Error deleting directories."));
break;
case LauncherUtils::DeleteDirError::ErrorDeletingApplicationDir:
theApp._manager.addToLog(_T("Error deleting application directory."));
break;
case LauncherUtils::DeleteDirError::ErrorDeletingDownloadsDir:
theApp._manager.addToLog(_T("Error deleting downloads directory."));
break;
default:
break;
}
if (error != LauncherUtils::DeleteDirError::NoErrorDeleting) {
} else {
theApp._manager.addToLog(_T("Error deleting download directory."));
theApp._manager.setFailed(true);
}
});
}
BOOL CLauncherDlg::getHQInfo(const CString& orgname) {

View file

@ -38,6 +38,9 @@ void LauncherManager::init() {
addToLog(_T("New build found. Updating"));
_shouldUpdate = TRUE;
}
} else if (_loggedIn) {
addToLog(_T("Interface not found but logged in. Reinstalling"));
_shouldUpdate = TRUE;
}
} else {
_hasFailed = true;
@ -189,9 +192,9 @@ BOOL LauncherManager::isApplicationInstalled(CString& version, CString& domain,
CString applicationPath = applicationDir + "interface\\interface.exe";
BOOL isApplicationInstalled = PathFileExistsW(applicationPath);
BOOL configFileExist = PathFileExistsW(applicationDir + _T("interface\\config.json"));
if (isApplicationInstalled && configFileExist) {
if (configFileExist) {
LauncherUtils::ResponseError status = readConfigJSON(version, domain, content, loggedIn);
return status == LauncherUtils::ResponseError::NoError;
return isApplicationInstalled && status == LauncherUtils::ResponseError::NoError;
}
return FALSE;
}
@ -441,10 +444,6 @@ void LauncherManager::onZipExtracted(ZipType type, int size) {
downloadApplication();
} else if (type == ZipType::ZipApplication) {
createShortcuts();
CString versionPath;
getAndCreatePaths(LauncherManager::PathType::Launcher_Directory, versionPath);
addToLog(_T("Creating config.json"));
createConfigJSON();
addToLog(_T("Launching application."));
_shouldLaunch = TRUE;
if (!_shouldUpdate) {
@ -458,6 +457,8 @@ void LauncherManager::onZipExtracted(ZipType type, int size) {
BOOL LauncherManager::extractApplication() {
CString installPath;
getAndCreatePaths(LauncherManager::PathType::Interface_Directory, installPath);
addToLog(_T("Creating config.json"));
createConfigJSON();
BOOL success = LauncherUtils::unzipFileOnThread(ZipType::ZipApplication, LauncherUtils::cStringToStd(_applicationZipPath),
LauncherUtils::cStringToStd(installPath), [&](int type, int size) {
if (size > 0) {
@ -477,11 +478,31 @@ BOOL LauncherManager::extractApplication() {
void LauncherManager::onFileDownloaded(DownloadType type) {
if (type == DownloadType::DownloadContent) {
addToLog(_T("Installing content."));
installContent();
addToLog(_T("Deleting content directory before install"));
CString contentDir;
getAndCreatePaths(PathType::Content_Directory, contentDir);
LauncherUtils::deleteDirectoryOnThread(contentDir, [&](bool error) {
if (!error) {
addToLog(_T("Installing content."));
installContent();
} else {
addToLog(_T("Error deleting content directory."));
setFailed(true);
}
});
} else if (type == DownloadType::DownloadApplication) {
addToLog(_T("Installing application."));
extractApplication();
addToLog(_T("Deleting application directory before install"));
CString applicationDir;
getAndCreatePaths(PathType::Interface_Directory, applicationDir);
LauncherUtils::deleteDirectoryOnThread(applicationDir, [&](bool error) {
if (!error) {
addToLog(_T("Installing application."));
extractApplication();
} else {
addToLog(_T("Error deleting install directory."));
setFailed(true);
}
});
}
}

View file

@ -480,16 +480,10 @@ DWORD WINAPI LauncherUtils::downloadThread(LPVOID lpParameter) {
return 0;
}
DWORD WINAPI LauncherUtils::deleteDirectoriesThread(LPVOID lpParameter) {
DWORD WINAPI LauncherUtils::deleteDirectoryThread(LPVOID lpParameter) {
DeleteThreadData& data = *((DeleteThreadData*)lpParameter);
DeleteDirError error = DeleteDirError::NoErrorDeleting;
if (!LauncherUtils::deleteFileOrDirectory(data._applicationDir)) {
error = DeleteDirError::ErrorDeletingApplicationDir;
}
if (!LauncherUtils::deleteFileOrDirectory(data._downloadsDir)) {
error = error == NoError ? DeleteDirError::ErrorDeletingDownloadsDir : DeleteDirError::ErrorDeletingBothDirs;
}
data.callback(error);
BOOL success = LauncherUtils::deleteFileOrDirectory(data._dirPath);
data.callback(!success);
return 0;
}
@ -523,15 +517,12 @@ BOOL LauncherUtils::downloadFileOnThread(int type, const CString& url, const CSt
return FALSE;
}
BOOL LauncherUtils::deleteDirectoriesOnThread(const CString& applicationDir,
const CString& downloadsDir,
std::function<void(int)> callback) {
BOOL LauncherUtils::deleteDirectoryOnThread(const CString& dirPath, std::function<void(bool)> callback) {
DWORD myThreadID;
DeleteThreadData* deleteThreadData = new DeleteThreadData();
deleteThreadData->_applicationDir = applicationDir;
deleteThreadData->_downloadsDir = downloadsDir;
deleteThreadData->_dirPath = dirPath;
deleteThreadData->setCallback(callback);
HANDLE myHandle = CreateThread(0, 0, deleteDirectoriesThread, deleteThreadData, 0, &myThreadID);
HANDLE myHandle = CreateThread(0, 0, deleteDirectoryThread, deleteThreadData, 0, &myThreadID);
if (myHandle) {
CloseHandle(myHandle);
return TRUE;

View file

@ -30,13 +30,6 @@ public:
NoError
};
enum DeleteDirError {
NoErrorDeleting = 0,
ErrorDeletingApplicationDir,
ErrorDeletingDownloadsDir,
ErrorDeletingBothDirs
};
struct DownloadThreadData {
int _type;
CString _url;
@ -60,10 +53,9 @@ public:
};
struct DeleteThreadData {
CString _applicationDir;
CString _downloadsDir;
std::function<void(int)> callback;
void setCallback(std::function<void(int)> fn) { callback = std::bind(fn, std::placeholders::_1); }
CString _dirPath;
std::function<void(bool)> callback;
void setCallback(std::function<void(bool)> fn) { callback = std::bind(fn, std::placeholders::_1); }
};
struct ProcessData {
@ -91,9 +83,7 @@ public:
static BOOL deleteRegistryKey(const CString& registryPath);
static BOOL unzipFileOnThread(int type, const std::string& zipFile, const std::string& path, std::function<void(int, int)> callback);
static BOOL downloadFileOnThread(int type, const CString& url, const CString& file, std::function<void(int, bool)> callback);
static BOOL deleteDirectoriesOnThread(const CString& applicationDir,
const CString& downloadsDir,
std::function<void(int)> callback);
static BOOL deleteDirectoryOnThread(const CString& dirPath, std::function<void(bool)> callback);
static CString urlEncodeString(const CString& url);
static HWND executeOnForeground(const CString& path, const CString& params);
@ -101,5 +91,5 @@ private:
// Threads
static DWORD WINAPI unzipThread(LPVOID lpParameter);
static DWORD WINAPI downloadThread(LPVOID lpParameter);
static DWORD WINAPI deleteDirectoriesThread(LPVOID lpParameter);
static DWORD WINAPI deleteDirectoryThread(LPVOID lpParameter);
};