mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 21:43:03 +02:00
Password case insensitive and encoded. Proper uninstall
This commit is contained in:
parent
9835f16821
commit
e572057d7c
6 changed files with 219 additions and 60 deletions
|
@ -46,6 +46,10 @@ CLauncherDlg::CLauncherDlg(CWnd* pParent)
|
||||||
EnableD2DSupport();
|
EnableD2DSupport();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CLauncherDlg::~CLauncherDlg() {
|
||||||
|
theApp._manager.closeLog();
|
||||||
|
}
|
||||||
|
|
||||||
void CLauncherDlg::DoDataExchange(CDataExchange* pDX)
|
void CLauncherDlg::DoDataExchange(CDataExchange* pDX)
|
||||||
{
|
{
|
||||||
DDX_Control(pDX, IDC_BUTTON_NEXT, m_btnNext);
|
DDX_Control(pDX, IDC_BUTTON_NEXT, m_btnNext);
|
||||||
|
@ -154,25 +158,50 @@ HCURSOR CLauncherDlg::OnQueryDragIcon()
|
||||||
}
|
}
|
||||||
|
|
||||||
void CLauncherDlg::startProcess() {
|
void CLauncherDlg::startProcess() {
|
||||||
if (theApp._manager.needsUpdate()) {
|
if (theApp._manager.needsUpdate()) {
|
||||||
setDrawDialog(DrawStep::DrawProcessUpdate);
|
theApp._manager.addToLog(_T("Starting Process Update"));
|
||||||
} else {
|
setDrawDialog(DrawStep::DrawProcessUpdate);
|
||||||
setDrawDialog(DrawStep::DrawProcessSetup);
|
} else {
|
||||||
}
|
theApp._manager.addToLog(_T("Starting Process Setup"));
|
||||||
|
setDrawDialog(DrawStep::DrawProcessSetup);
|
||||||
CString installDir;
|
}
|
||||||
theApp._manager.getAndCreatePaths(LauncherManager::PathType::Interface_Directory, installDir);
|
theApp._manager.addToLog(_T("Deleting directories before install"));
|
||||||
CString interfaceExe = installDir += "\\interface.exe";
|
|
||||||
if (!theApp._manager.isLoggedIn()) {
|
CString installDir;
|
||||||
theApp._manager.downloadContent();
|
theApp._manager.getAndCreatePaths(LauncherManager::PathType::Interface_Directory, installDir);
|
||||||
} else {
|
CString downloadDir;
|
||||||
theApp._manager.downloadApplication();
|
theApp._manager.getAndCreatePaths(LauncherManager::PathType::Download_Directory, downloadDir);
|
||||||
}
|
|
||||||
|
LauncherUtils::deleteDirectoriesOnThread(installDir, downloadDir, [&](int error) {
|
||||||
|
LauncherUtils::DeleteDirError deleteError = (LauncherUtils::DeleteDirError)error;
|
||||||
|
if (error == LauncherUtils::DeleteDirError::NoErrorDeleting) {
|
||||||
|
theApp._manager.addToLog(_T("Install directory deleted."));
|
||||||
|
theApp._manager.addToLog(_T("Downloads directory deleted."));
|
||||||
|
// CString interfaceExe = installPath += "\\interface.exe";
|
||||||
|
if (!theApp._manager.isLoggedIn()) {
|
||||||
|
theApp._manager.addToLog(_T("Downloading Content"));
|
||||||
|
theApp._manager.downloadContent();
|
||||||
|
} else {
|
||||||
|
theApp._manager.addToLog(_T("Downloading App"));
|
||||||
|
theApp._manager.downloadApplication();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (error == LauncherUtils::DeleteDirError::ErrorDeletingPath1 ||
|
||||||
|
error == LauncherUtils::DeleteDirError::ErrorDeletingPaths) {
|
||||||
|
theApp._manager.addToLog(_T("Error deleting install directory."));
|
||||||
|
}
|
||||||
|
if (error == LauncherUtils::DeleteDirError::ErrorDeletingPath2 ||
|
||||||
|
error == LauncherUtils::DeleteDirError::ErrorDeletingPaths) {
|
||||||
|
theApp._manager.addToLog(_T("Error deleting downloads directory."));
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL CLauncherDlg::getHQInfo(const CString& orgname) {
|
BOOL CLauncherDlg::getHQInfo(const CString& orgname) {
|
||||||
CString hash;
|
CString hash;
|
||||||
LauncherUtils::hMac256(orgname, LAUNCHER_HMAC_SECRET, hash);
|
CString lowerOrgName = orgname;
|
||||||
|
lowerOrgName.MakeLower();
|
||||||
|
LauncherUtils::hMac256(lowerOrgName, LAUNCHER_HMAC_SECRET, hash);
|
||||||
return theApp._manager.readOrganizationJSON(hash) == LauncherUtils::ResponseError::NoError;
|
return theApp._manager.readOrganizationJSON(hash) == LauncherUtils::ResponseError::NoError;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,33 +210,44 @@ afx_msg void CLauncherDlg::OnTroubleClicked() {
|
||||||
}
|
}
|
||||||
|
|
||||||
afx_msg void CLauncherDlg::OnNextClicked() {
|
afx_msg void CLauncherDlg::OnNextClicked() {
|
||||||
if (_drawStep != DrawStep::DrawChoose) {
|
if (_drawStep != DrawStep::DrawChoose) {
|
||||||
CString token;
|
CString token;
|
||||||
CString username, password, orgname;
|
CString username, password, orgname;
|
||||||
m_orgname.GetWindowTextW(orgname);
|
m_orgname.GetWindowTextW(orgname);
|
||||||
m_username.GetWindowTextW(username);
|
m_username.GetWindowTextW(username);
|
||||||
m_password.GetWindowTextW(password);
|
m_password.GetWindowTextW(password);
|
||||||
LauncherUtils::ResponseError error;
|
|
||||||
if (orgname.GetLength() > 0 && username.GetLength() > 0 && password.GetLength() > 0) {
|
username = LauncherUtils::urlEncodeString(username);
|
||||||
if (getHQInfo(orgname)) {
|
password = LauncherUtils::urlEncodeString(password);
|
||||||
error = theApp._manager.getAccessTokenForCredentials(username, password);
|
LauncherUtils::ResponseError error;
|
||||||
if (error == LauncherUtils::ResponseError::NoError) {
|
if (orgname.GetLength() > 0 && username.GetLength() > 0 && password.GetLength() > 0) {
|
||||||
setDrawDialog(DrawStep::DrawChoose);
|
theApp._manager.addToLog(_T("Trying to get organization data"));
|
||||||
} else if (error == LauncherUtils::ResponseError::BadCredentials) {
|
if (getHQInfo(orgname)) {
|
||||||
setDrawDialog(DrawStep::DrawLoginErrorCred);
|
theApp._manager.addToLog(_T("Organization data received."));
|
||||||
} else {
|
theApp._manager.addToLog(_T("Trying to log in with credentials"));
|
||||||
MessageBox(L"Error Reading or retreaving response.", L"Network Error", MB_OK | MB_ICONERROR);
|
error = theApp._manager.getAccessTokenForCredentials(username, password);
|
||||||
}
|
if (error == LauncherUtils::ResponseError::NoError) {
|
||||||
} else {
|
theApp._manager.addToLog(_T("Logged in correctly."));
|
||||||
setDrawDialog(DrawStep::DrawLoginErrorOrg);
|
setDrawDialog(DrawStep::DrawChoose);
|
||||||
}
|
} else if (error == LauncherUtils::ResponseError::BadCredentials) {
|
||||||
}
|
theApp._manager.addToLog(_T("Bad credentials. Try again"));
|
||||||
} else {
|
setDrawDialog(DrawStep::DrawLoginErrorCred);
|
||||||
CString displayName;
|
} else {
|
||||||
m_username.GetWindowTextW(displayName);
|
theApp._manager.addToLog(_T("Error Reading or retreaving response."));
|
||||||
theApp._manager.setDisplayName(displayName);
|
MessageBox(L"Error Reading or retreaving response.", L"Network Error", MB_OK | MB_ICONERROR);
|
||||||
startProcess();
|
}
|
||||||
}
|
} else {
|
||||||
|
theApp._manager.addToLog(_T("Organization name does not exist."));
|
||||||
|
setDrawDialog(DrawStep::DrawLoginErrorOrg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
CString displayName;
|
||||||
|
m_username.GetWindowTextW(displayName);
|
||||||
|
theApp._manager.setDisplayName(displayName);
|
||||||
|
theApp._manager.addToLog(_T("Setting display name: " + displayName));
|
||||||
|
startProcess();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CLauncherDlg::drawBackground(CHwndRenderTarget* pRenderTarget) {
|
void CLauncherDlg::drawBackground(CHwndRenderTarget* pRenderTarget) {
|
||||||
|
@ -534,11 +574,13 @@ void CLauncherDlg::OnTimer(UINT_PTR nIDEvent) {
|
||||||
}
|
}
|
||||||
if (_showSplash) {
|
if (_showSplash) {
|
||||||
if (_splashStep == 0){
|
if (_splashStep == 0){
|
||||||
if (theApp._manager.needsUninstall()) {
|
if (theApp._manager.needsUninstall()) {
|
||||||
setDrawDialog(DrawStep::DrawProcessUninstall);
|
theApp._manager.addToLog(_T("Waiting to unistall"));
|
||||||
} else {
|
setDrawDialog(DrawStep::DrawProcessUninstall);
|
||||||
setDrawDialog(DrawStep::DrawLogo);
|
} else {
|
||||||
}
|
theApp._manager.addToLog(_T("Start splash screen"));
|
||||||
|
setDrawDialog(DrawStep::DrawLogo);
|
||||||
|
}
|
||||||
} else if (_splashStep > 100) {
|
} else if (_splashStep > 100) {
|
||||||
_showSplash = false;
|
_showSplash = false;
|
||||||
if (theApp._manager.shouldShutDown()) {
|
if (theApp._manager.shouldShutDown()) {
|
||||||
|
@ -551,6 +593,7 @@ void CLauncherDlg::OnTimer(UINT_PTR nIDEvent) {
|
||||||
theApp._manager.uninstallApplication();
|
theApp._manager.uninstallApplication();
|
||||||
exit(0);
|
exit(0);
|
||||||
} else {
|
} else {
|
||||||
|
theApp._manager.addToLog(_T("Starting login"));
|
||||||
setDrawDialog(DrawStep::DrawLoginLogin);
|
setDrawDialog(DrawStep::DrawLoginLogin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
CLauncherDlg(CWnd* pParent = nullptr);
|
CLauncherDlg(CWnd* pParent = nullptr);
|
||||||
|
~CLauncherDlg();
|
||||||
virtual BOOL PreTranslateMessage(MSG* pMsg);
|
virtual BOOL PreTranslateMessage(MSG* pMsg);
|
||||||
|
|
||||||
void setDrawDialog(DrawStep step, BOOL isUpdate = FALSE);
|
void setDrawDialog(DrawStep step, BOOL isUpdate = FALSE);
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
|
#include <time.h>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
#include "LauncherManager.h"
|
#include "LauncherManager.h"
|
||||||
|
@ -24,19 +25,57 @@ LauncherManager::~LauncherManager()
|
||||||
}
|
}
|
||||||
|
|
||||||
void LauncherManager::init() {
|
void LauncherManager::init() {
|
||||||
getMostRecentBuild(_latestApplicationURL, _latestVersion);
|
initLog();
|
||||||
CString currentVersion;
|
addToLog(_T("Getting most recent build"));
|
||||||
if (isApplicationInstalled(currentVersion, _domainURL, _contentURL, _loggedIn) && _loggedIn) {
|
getMostRecentBuild(_latestApplicationURL, _latestVersion);
|
||||||
if (_latestVersion.Compare(currentVersion) == 0) {
|
addToLog(_T("Latest version: ") + _latestVersion);
|
||||||
launchApplication();
|
CString currentVersion;
|
||||||
_shouldShutdown = TRUE;
|
if (isApplicationInstalled(currentVersion, _domainURL, _contentURL, _loggedIn) && _loggedIn) {
|
||||||
} else {
|
addToLog(_T("Installed version: ") + currentVersion);
|
||||||
_shouldUpdate = TRUE;
|
if (_latestVersion.Compare(currentVersion) == 0) {
|
||||||
}
|
addToLog(_T("Already running most recent build. Launching interface.exe"));
|
||||||
}
|
launchApplication();
|
||||||
|
_shouldShutdown = TRUE;
|
||||||
|
} else {
|
||||||
|
addToLog(_T("New build found. Updating"));
|
||||||
|
_shouldUpdate = TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL LauncherManager::initLog() {
|
||||||
|
CString logPath;
|
||||||
|
auto result = getAndCreatePaths(PathType::Launcher_Directory, logPath);
|
||||||
|
if (result) {
|
||||||
|
logPath += _T("log.txt");
|
||||||
|
return result = _logFile.Open(logPath, CFile::modeCreate | CFile::modeReadWrite);
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL LauncherManager::addToLog(const CString& line) {
|
||||||
|
if (_logFile.m_hFile != CStdioFile::hFileNull) {
|
||||||
|
char buff[100];
|
||||||
|
time_t now = time(0);
|
||||||
|
tm ltm;
|
||||||
|
localtime_s(<m, &now);
|
||||||
|
|
||||||
|
strftime(buff, 100, "%Y-%m-%d %H:%M:%S", <m);
|
||||||
|
CString timeStr = CString(buff);
|
||||||
|
_logFile.WriteString(timeStr + _T(" ") + line + _T("\n"));
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LauncherManager::closeLog() {
|
||||||
|
if (_logFile.m_hFile != CStdioFile::hFileNull) {
|
||||||
|
_logFile.Close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL LauncherManager::installLauncher() {
|
BOOL LauncherManager::installLauncher() {
|
||||||
|
addToLog(_T("Installing Launcher."));
|
||||||
CString appPath;
|
CString appPath;
|
||||||
BOOL result = getAndCreatePaths(PathType::Running_Path, appPath);
|
BOOL result = getAndCreatePaths(PathType::Running_Path, appPath);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
|
@ -60,6 +99,7 @@ BOOL LauncherManager::installLauncher() {
|
||||||
CopyFile(appPath, instalationPath, FALSE);
|
CopyFile(appPath, instalationPath, FALSE);
|
||||||
}
|
}
|
||||||
} else if (_shouldUninstall) {
|
} else if (_shouldUninstall) {
|
||||||
|
addToLog(_T("Launching uninstall mode."));
|
||||||
CString tempPath;
|
CString tempPath;
|
||||||
if (getAndCreatePaths(PathType::Temp_Directory, tempPath)) {
|
if (getAndCreatePaths(PathType::Temp_Directory, tempPath)) {
|
||||||
tempPath += _T("\\HQ_uninstaller_tmp.exe");
|
tempPath += _T("\\HQ_uninstaller_tmp.exe");
|
||||||
|
@ -73,6 +113,7 @@ BOOL LauncherManager::installLauncher() {
|
||||||
|
|
||||||
BOOL LauncherManager::createShortcuts() {
|
BOOL LauncherManager::createShortcuts() {
|
||||||
CString desktopLnkPath;
|
CString desktopLnkPath;
|
||||||
|
addToLog(_T("Creating shortcuts."));
|
||||||
getAndCreatePaths(PathType::Desktop_Directory, desktopLnkPath);
|
getAndCreatePaths(PathType::Desktop_Directory, desktopLnkPath);
|
||||||
desktopLnkPath += _T("\\HQ Launcher.lnk");
|
desktopLnkPath += _T("\\HQ Launcher.lnk");
|
||||||
CString installDir;
|
CString installDir;
|
||||||
|
@ -100,6 +141,7 @@ BOOL LauncherManager::createShortcuts() {
|
||||||
|
|
||||||
BOOL LauncherManager::deleteShortcuts() {
|
BOOL LauncherManager::deleteShortcuts() {
|
||||||
CString desktopLnkPath;
|
CString desktopLnkPath;
|
||||||
|
addToLog(_T("Deleting shortcuts."));
|
||||||
getAndCreatePaths(PathType::Desktop_Directory, desktopLnkPath);
|
getAndCreatePaths(PathType::Desktop_Directory, desktopLnkPath);
|
||||||
desktopLnkPath += _T("\\HQ Launcher.lnk");
|
desktopLnkPath += _T("\\HQ Launcher.lnk");
|
||||||
BOOL success = LauncherUtils::deleteFileOrDirectory(desktopLnkPath);
|
BOOL success = LauncherUtils::deleteFileOrDirectory(desktopLnkPath);
|
||||||
|
@ -353,13 +395,17 @@ BOOL LauncherManager::uninstallApplication() {
|
||||||
|
|
||||||
void LauncherManager::onZipExtracted(ZipType type, int size) {
|
void LauncherManager::onZipExtracted(ZipType type, int size) {
|
||||||
if (type == ZipType::ZipContent) {
|
if (type == ZipType::ZipContent) {
|
||||||
|
addToLog(_T("Downloading application."));
|
||||||
downloadApplication();
|
downloadApplication();
|
||||||
} else if (type == ZipType::ZipApplication) {
|
} else if (type == ZipType::ZipApplication) {
|
||||||
createShortcuts();
|
createShortcuts();
|
||||||
CString versionPath;
|
CString versionPath;
|
||||||
getAndCreatePaths(LauncherManager::PathType::Launcher_Directory, versionPath);
|
getAndCreatePaths(LauncherManager::PathType::Launcher_Directory, versionPath);
|
||||||
createConfigJSON();
|
addToLog(_T("Creating config.json"));
|
||||||
|
createConfigJSON();
|
||||||
|
addToLog(_T("Launching application."));
|
||||||
launchApplication(_tokensJSON);
|
launchApplication(_tokensJSON);
|
||||||
|
addToLog(_T("Creating registry keys."));
|
||||||
createApplicationRegistryKeys(size);
|
createApplicationRegistryKeys(size);
|
||||||
_shouldShutdown = TRUE;
|
_shouldShutdown = TRUE;
|
||||||
}
|
}
|
||||||
|
@ -377,8 +423,10 @@ 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."));
|
||||||
installContent();
|
installContent();
|
||||||
} else if (type == DownloadType::DownloadApplication) {
|
} else if (type == DownloadType::DownloadApplication) {
|
||||||
|
addToLog(_T("Installing application."));
|
||||||
extractApplication();
|
extractApplication();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -412,6 +460,7 @@ BOOL LauncherManager::downloadFile(DownloadType type, const CString& url, CStrin
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL LauncherManager::downloadContent() {
|
BOOL LauncherManager::downloadContent() {
|
||||||
|
addToLog(_T("Downloading content."));
|
||||||
CString contentURL = getContentURL();
|
CString contentURL = getContentURL();
|
||||||
return downloadFile(DownloadType::DownloadContent, contentURL, _contentZipPath);
|
return downloadFile(DownloadType::DownloadContent, contentURL, _contentZipPath);
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,6 +53,9 @@ public:
|
||||||
LauncherManager();
|
LauncherManager();
|
||||||
~LauncherManager();
|
~LauncherManager();
|
||||||
void init();
|
void init();
|
||||||
|
BOOL initLog();
|
||||||
|
BOOL addToLog(const CString& line);
|
||||||
|
void closeLog();
|
||||||
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,
|
||||||
|
@ -105,5 +108,6 @@ private:
|
||||||
BOOL _shouldUpdate{ FALSE };
|
BOOL _shouldUpdate{ FALSE };
|
||||||
BOOL _shouldUninstall{ FALSE };
|
BOOL _shouldUninstall{ FALSE };
|
||||||
BOOL _shouldShutdown{ FALSE };
|
BOOL _shouldShutdown{ FALSE };
|
||||||
|
CStdioFile _logFile;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,24 @@
|
||||||
|
|
||||||
#include "LauncherUtils.h"
|
#include "LauncherUtils.h"
|
||||||
|
|
||||||
|
CString LauncherUtils::urlEncodeString(const CString& url) {
|
||||||
|
std::map<CString, CString> specialCharsMap = { { _T("$"), _T("%24") }, { _T(" "), _T("%20") }, { _T("#"), _T("%23") },
|
||||||
|
{ _T("@"), _T("%40") }, { _T("`"), _T("%60") }, { _T("&"), _T("%26") },
|
||||||
|
{ _T("/"), _T("%2F") }, { _T(":"), _T("%3A") }, { _T(";"), _T("%3B") },
|
||||||
|
{ _T("<"), _T("%3C") }, { _T(">"), _T("%3E") }, { _T("="), _T("%3D") },
|
||||||
|
{ _T("?"), _T("%3F") }, { _T("["), _T("%5B") }, { _T("\\"), _T("%5C") },
|
||||||
|
{ _T("]"), _T("%5D") }, { _T("^"), _T("%5E") }, { _T("{"), _T("%7B") },
|
||||||
|
{ _T("|"), _T("%7C") }, { _T("}"), _T("%7D") }, { _T("~"), _T("%7E") },
|
||||||
|
{ _T("“"), _T("%22") }, { _T("‘"), _T("%27") }, { _T("+"), _T("%2B") },
|
||||||
|
{ _T(","), _T("%2C") } };
|
||||||
|
CString stringOut = url;
|
||||||
|
stringOut.Replace(_T("%"), _T("%25"));
|
||||||
|
for (auto& itr = specialCharsMap.begin(); itr != specialCharsMap.end(); itr++) {
|
||||||
|
stringOut.Replace(itr->first, itr->second);
|
||||||
|
}
|
||||||
|
return stringOut;
|
||||||
|
}
|
||||||
|
|
||||||
BOOL LauncherUtils::IsProcessRunning(const wchar_t *processName) {
|
BOOL LauncherUtils::IsProcessRunning(const wchar_t *processName) {
|
||||||
bool exists = false;
|
bool exists = false;
|
||||||
PROCESSENTRY32 entry;
|
PROCESSENTRY32 entry;
|
||||||
|
@ -374,6 +392,19 @@ DWORD WINAPI LauncherUtils::downloadThread(LPVOID lpParameter)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DWORD WINAPI LauncherUtils::deleteDirectoriesThread(LPVOID lpParameter) {
|
||||||
|
DeleteThreadData& data = *((DeleteThreadData*)lpParameter);
|
||||||
|
DeleteDirError error = DeleteDirError::NoErrorDeleting;
|
||||||
|
if (!LauncherUtils::deleteFileOrDirectory(data._path1)) {
|
||||||
|
error = DeleteDirError::ErrorDeletingPath1;
|
||||||
|
}
|
||||||
|
if (!LauncherUtils::deleteFileOrDirectory(data._path2)) {
|
||||||
|
error = error == NoError ? DeleteDirError::ErrorDeletingPath2 : DeleteDirError::ErrorDeletingPaths;
|
||||||
|
}
|
||||||
|
data.callback(error);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
BOOL LauncherUtils::unzipFileOnThread(int type, const std::string& zipFile, const std::string& path, std::function<void(int, int)> callback) {
|
BOOL LauncherUtils::unzipFileOnThread(int type, const std::string& zipFile, const std::string& path, std::function<void(int, int)> callback) {
|
||||||
DWORD myThreadID;
|
DWORD myThreadID;
|
||||||
UnzipThreadData* unzipThreadData = new UnzipThreadData();
|
UnzipThreadData* unzipThreadData = new UnzipThreadData();
|
||||||
|
@ -402,4 +433,18 @@ BOOL LauncherUtils::downloadFileOnThread(int type, const CString& url, const CSt
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOL LauncherUtils::deleteDirectoriesOnThread(const CString& dir1, const CString& dir2, std::function<void(int)> callback) {
|
||||||
|
DWORD myThreadID;
|
||||||
|
DeleteThreadData* deleteThreadData = new DeleteThreadData();
|
||||||
|
deleteThreadData->_path1 = dir1;
|
||||||
|
deleteThreadData->_path2 = dir2;
|
||||||
|
deleteThreadData->setCallback(callback);
|
||||||
|
HANDLE myHandle = CreateThread(0, 0, deleteDirectoriesThread, deleteThreadData, 0, &myThreadID);
|
||||||
|
if (myHandle) {
|
||||||
|
CloseHandle(myHandle);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
|
@ -30,6 +30,13 @@ public:
|
||||||
NoError
|
NoError
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum DeleteDirError {
|
||||||
|
NoErrorDeleting = 0,
|
||||||
|
ErrorDeletingPath1,
|
||||||
|
ErrorDeletingPath2,
|
||||||
|
ErrorDeletingPaths
|
||||||
|
};
|
||||||
|
|
||||||
struct DownloadThreadData {
|
struct DownloadThreadData {
|
||||||
int _type;
|
int _type;
|
||||||
CString _url;
|
CString _url;
|
||||||
|
@ -52,6 +59,13 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct DeleteThreadData {
|
||||||
|
CString _path1;
|
||||||
|
CString _path2;
|
||||||
|
std::function<void(int)> callback;
|
||||||
|
void setCallback(std::function<void(int)> fn) { callback = std::bind(fn, std::placeholders::_1); }
|
||||||
|
};
|
||||||
|
|
||||||
static BOOL parseJSON(const CString& jsonTxt, Json::Value& jsonObject);
|
static BOOL parseJSON(const CString& jsonTxt, Json::Value& jsonObject);
|
||||||
static ResponseError makeHTTPCall(const CString& callerName, const CString& mainUrl,
|
static ResponseError makeHTTPCall(const CString& callerName, const CString& mainUrl,
|
||||||
const CString& dirUrl, const CString& contentType,
|
const CString& dirUrl, const CString& contentType,
|
||||||
|
@ -69,9 +83,12 @@ 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)> callback);
|
static BOOL downloadFileOnThread(int type, const CString& url, const CString& file, std::function<void(int)> callback);
|
||||||
|
static BOOL deleteDirectoriesOnThread(const CString& dir1, const CString& dir2, std::function<void(int)> callback);
|
||||||
|
static CString urlEncodeString(const CString& url);
|
||||||
|
|
||||||
private:
|
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);
|
||||||
};
|
};
|
Loading…
Reference in a new issue