mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 14:29:03 +02:00
Delete install directory right before installing and keep a copy of config.json
This commit is contained in:
parent
7b3fa22d0c
commit
6a7b9c0202
4 changed files with 48 additions and 65 deletions
|
@ -174,19 +174,11 @@ void CLauncherDlg::startProcess() {
|
||||||
theApp._manager.addToLog(_T("Starting Process Setup"));
|
theApp._manager.addToLog(_T("Starting Process Setup"));
|
||||||
setDrawDialog(DrawStep::DrawProcessSetup);
|
setDrawDialog(DrawStep::DrawProcessSetup);
|
||||||
}
|
}
|
||||||
theApp._manager.addToLog(_T("Deleting directories before install"));
|
theApp._manager.addToLog(_T("Deleting download directory"));
|
||||||
|
|
||||||
CString installDir;
|
|
||||||
theApp._manager.getAndCreatePaths(LauncherManager::PathType::Interface_Directory, installDir);
|
|
||||||
CString downloadDir;
|
CString downloadDir;
|
||||||
theApp._manager.getAndCreatePaths(LauncherManager::PathType::Download_Directory, downloadDir);
|
theApp._manager.getAndCreatePaths(LauncherManager::PathType::Download_Directory, downloadDir);
|
||||||
|
LauncherUtils::deleteDirectoryOnThread(downloadDir, [&](bool error) {
|
||||||
LauncherUtils::deleteDirectoriesOnThread(installDir, downloadDir, [&](int error) {
|
if (!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."));
|
|
||||||
if (!theApp._manager.isLoggedIn()) {
|
if (!theApp._manager.isLoggedIn()) {
|
||||||
theApp._manager.addToLog(_T("Downloading Content"));
|
theApp._manager.addToLog(_T("Downloading Content"));
|
||||||
theApp._manager.downloadContent();
|
theApp._manager.downloadContent();
|
||||||
|
@ -194,23 +186,12 @@ void CLauncherDlg::startProcess() {
|
||||||
theApp._manager.addToLog(_T("Downloading App"));
|
theApp._manager.addToLog(_T("Downloading App"));
|
||||||
theApp._manager.downloadApplication();
|
theApp._manager.downloadApplication();
|
||||||
}
|
}
|
||||||
break;
|
} else {
|
||||||
case LauncherUtils::DeleteDirError::ErrorDeletingBothDirs:
|
theApp._manager.addToLog(_T("Error deleting download directory."));
|
||||||
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) {
|
|
||||||
theApp._manager.setFailed(true);
|
theApp._manager.setFailed(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL CLauncherDlg::getHQInfo(const CString& orgname) {
|
BOOL CLauncherDlg::getHQInfo(const CString& orgname) {
|
||||||
|
|
|
@ -38,6 +38,9 @@ void LauncherManager::init() {
|
||||||
addToLog(_T("New build found. Updating"));
|
addToLog(_T("New build found. Updating"));
|
||||||
_shouldUpdate = TRUE;
|
_shouldUpdate = TRUE;
|
||||||
}
|
}
|
||||||
|
} else if (_loggedIn) {
|
||||||
|
addToLog(_T("Interface not found but logged in. Reinstalling"));
|
||||||
|
_shouldUpdate = TRUE;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
_hasFailed = true;
|
_hasFailed = true;
|
||||||
|
@ -189,9 +192,9 @@ BOOL LauncherManager::isApplicationInstalled(CString& version, CString& domain,
|
||||||
CString applicationPath = applicationDir + "interface\\interface.exe";
|
CString applicationPath = applicationDir + "interface\\interface.exe";
|
||||||
BOOL isApplicationInstalled = PathFileExistsW(applicationPath);
|
BOOL isApplicationInstalled = PathFileExistsW(applicationPath);
|
||||||
BOOL configFileExist = PathFileExistsW(applicationDir + _T("interface\\config.json"));
|
BOOL configFileExist = PathFileExistsW(applicationDir + _T("interface\\config.json"));
|
||||||
if (isApplicationInstalled && configFileExist) {
|
if (configFileExist) {
|
||||||
LauncherUtils::ResponseError status = readConfigJSON(version, domain, content, loggedIn);
|
LauncherUtils::ResponseError status = readConfigJSON(version, domain, content, loggedIn);
|
||||||
return status == LauncherUtils::ResponseError::NoError;
|
return isApplicationInstalled && status == LauncherUtils::ResponseError::NoError;
|
||||||
}
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
@ -441,10 +444,6 @@ void LauncherManager::onZipExtracted(ZipType type, int size) {
|
||||||
downloadApplication();
|
downloadApplication();
|
||||||
} else if (type == ZipType::ZipApplication) {
|
} else if (type == ZipType::ZipApplication) {
|
||||||
createShortcuts();
|
createShortcuts();
|
||||||
CString versionPath;
|
|
||||||
getAndCreatePaths(LauncherManager::PathType::Launcher_Directory, versionPath);
|
|
||||||
addToLog(_T("Creating config.json"));
|
|
||||||
createConfigJSON();
|
|
||||||
addToLog(_T("Launching application."));
|
addToLog(_T("Launching application."));
|
||||||
_shouldLaunch = TRUE;
|
_shouldLaunch = TRUE;
|
||||||
if (!_shouldUpdate) {
|
if (!_shouldUpdate) {
|
||||||
|
@ -458,6 +457,8 @@ void LauncherManager::onZipExtracted(ZipType type, int size) {
|
||||||
BOOL LauncherManager::extractApplication() {
|
BOOL LauncherManager::extractApplication() {
|
||||||
CString installPath;
|
CString installPath;
|
||||||
getAndCreatePaths(LauncherManager::PathType::Interface_Directory, installPath);
|
getAndCreatePaths(LauncherManager::PathType::Interface_Directory, installPath);
|
||||||
|
addToLog(_T("Creating config.json"));
|
||||||
|
createConfigJSON();
|
||||||
BOOL success = LauncherUtils::unzipFileOnThread(ZipType::ZipApplication, LauncherUtils::cStringToStd(_applicationZipPath),
|
BOOL success = LauncherUtils::unzipFileOnThread(ZipType::ZipApplication, LauncherUtils::cStringToStd(_applicationZipPath),
|
||||||
LauncherUtils::cStringToStd(installPath), [&](int type, int size) {
|
LauncherUtils::cStringToStd(installPath), [&](int type, int size) {
|
||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
|
@ -477,11 +478,31 @@ BOOL LauncherManager::extractApplication() {
|
||||||
|
|
||||||
void LauncherManager::onFileDownloaded(DownloadType type) {
|
void LauncherManager::onFileDownloaded(DownloadType type) {
|
||||||
if (type == DownloadType::DownloadContent) {
|
if (type == DownloadType::DownloadContent) {
|
||||||
addToLog(_T("Installing content."));
|
addToLog(_T("Deleting content directory before install"));
|
||||||
installContent();
|
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) {
|
} else if (type == DownloadType::DownloadApplication) {
|
||||||
addToLog(_T("Installing application."));
|
addToLog(_T("Deleting application directory before install"));
|
||||||
extractApplication();
|
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);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -480,16 +480,10 @@ DWORD WINAPI LauncherUtils::downloadThread(LPVOID lpParameter) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
DWORD WINAPI LauncherUtils::deleteDirectoriesThread(LPVOID lpParameter) {
|
DWORD WINAPI LauncherUtils::deleteDirectoryThread(LPVOID lpParameter) {
|
||||||
DeleteThreadData& data = *((DeleteThreadData*)lpParameter);
|
DeleteThreadData& data = *((DeleteThreadData*)lpParameter);
|
||||||
DeleteDirError error = DeleteDirError::NoErrorDeleting;
|
BOOL success = LauncherUtils::deleteFileOrDirectory(data._dirPath);
|
||||||
if (!LauncherUtils::deleteFileOrDirectory(data._applicationDir)) {
|
data.callback(!success);
|
||||||
error = DeleteDirError::ErrorDeletingApplicationDir;
|
|
||||||
}
|
|
||||||
if (!LauncherUtils::deleteFileOrDirectory(data._downloadsDir)) {
|
|
||||||
error = error == NoError ? DeleteDirError::ErrorDeletingDownloadsDir : DeleteDirError::ErrorDeletingBothDirs;
|
|
||||||
}
|
|
||||||
data.callback(error);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -523,15 +517,12 @@ BOOL LauncherUtils::downloadFileOnThread(int type, const CString& url, const CSt
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL LauncherUtils::deleteDirectoriesOnThread(const CString& applicationDir,
|
BOOL LauncherUtils::deleteDirectoryOnThread(const CString& dirPath, std::function<void(bool)> callback) {
|
||||||
const CString& downloadsDir,
|
|
||||||
std::function<void(int)> callback) {
|
|
||||||
DWORD myThreadID;
|
DWORD myThreadID;
|
||||||
DeleteThreadData* deleteThreadData = new DeleteThreadData();
|
DeleteThreadData* deleteThreadData = new DeleteThreadData();
|
||||||
deleteThreadData->_applicationDir = applicationDir;
|
deleteThreadData->_dirPath = dirPath;
|
||||||
deleteThreadData->_downloadsDir = downloadsDir;
|
|
||||||
deleteThreadData->setCallback(callback);
|
deleteThreadData->setCallback(callback);
|
||||||
HANDLE myHandle = CreateThread(0, 0, deleteDirectoriesThread, deleteThreadData, 0, &myThreadID);
|
HANDLE myHandle = CreateThread(0, 0, deleteDirectoryThread, deleteThreadData, 0, &myThreadID);
|
||||||
if (myHandle) {
|
if (myHandle) {
|
||||||
CloseHandle(myHandle);
|
CloseHandle(myHandle);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
|
@ -30,13 +30,6 @@ public:
|
||||||
NoError
|
NoError
|
||||||
};
|
};
|
||||||
|
|
||||||
enum DeleteDirError {
|
|
||||||
NoErrorDeleting = 0,
|
|
||||||
ErrorDeletingApplicationDir,
|
|
||||||
ErrorDeletingDownloadsDir,
|
|
||||||
ErrorDeletingBothDirs
|
|
||||||
};
|
|
||||||
|
|
||||||
struct DownloadThreadData {
|
struct DownloadThreadData {
|
||||||
int _type;
|
int _type;
|
||||||
CString _url;
|
CString _url;
|
||||||
|
@ -60,10 +53,9 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DeleteThreadData {
|
struct DeleteThreadData {
|
||||||
CString _applicationDir;
|
CString _dirPath;
|
||||||
CString _downloadsDir;
|
std::function<void(bool)> callback;
|
||||||
std::function<void(int)> callback;
|
void setCallback(std::function<void(bool)> fn) { callback = std::bind(fn, std::placeholders::_1); }
|
||||||
void setCallback(std::function<void(int)> fn) { callback = std::bind(fn, std::placeholders::_1); }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ProcessData {
|
struct ProcessData {
|
||||||
|
@ -91,9 +83,7 @@ public:
|
||||||
static BOOL deleteRegistryKey(const CString& registryPath);
|
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 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 downloadFileOnThread(int type, const CString& url, const CString& file, std::function<void(int, bool)> callback);
|
||||||
static BOOL deleteDirectoriesOnThread(const CString& applicationDir,
|
static BOOL deleteDirectoryOnThread(const CString& dirPath, std::function<void(bool)> callback);
|
||||||
const CString& downloadsDir,
|
|
||||||
std::function<void(int)> callback);
|
|
||||||
static CString urlEncodeString(const CString& url);
|
static CString urlEncodeString(const CString& url);
|
||||||
static HWND executeOnForeground(const CString& path, const CString& params);
|
static HWND executeOnForeground(const CString& path, const CString& params);
|
||||||
|
|
||||||
|
@ -101,5 +91,5 @@ private:
|
||||||
// Threads
|
// Threads
|
||||||
static DWORD WINAPI unzipThread(LPVOID lpParameter);
|
static DWORD WINAPI unzipThread(LPVOID lpParameter);
|
||||||
static DWORD WINAPI downloadThread(LPVOID lpParameter);
|
static DWORD WINAPI downloadThread(LPVOID lpParameter);
|
||||||
static DWORD WINAPI deleteDirectoriesThread(LPVOID lpParameter);
|
static DWORD WINAPI deleteDirectoryThread(LPVOID lpParameter);
|
||||||
};
|
};
|
Loading…
Reference in a new issue