New org http, interface on front and copy all

This commit is contained in:
luiscuenca 2019-06-12 12:12:29 -07:00
parent c02df55186
commit c5b1024bac
6 changed files with 86 additions and 26 deletions

View file

@ -120,8 +120,16 @@ BOOL CLauncherDlg::OnInitDialog() {
BOOL CLauncherDlg::PreTranslateMessage(MSG* pMsg) { BOOL CLauncherDlg::PreTranslateMessage(MSG* pMsg) {
if ((pMsg->message == WM_KEYDOWN)) if ((pMsg->message == WM_KEYDOWN))
{ {
if (pMsg->wParam == VK_RETURN) if (pMsg->wParam == 'A' && GetKeyState(VK_CONTROL) < 0) {
{ CWnd* wnd = GetFocus();
CWnd* myWnd = this->GetDlgItem(IDC_ORGNAME);
if (wnd && (wnd == this->GetDlgItem(IDC_ORGNAME) ||
wnd == this->GetDlgItem(IDC_USERNAME) ||
wnd == this->GetDlgItem(IDC_PASSWORD))) {
((CEdit*)wnd)->SetSel(0, -1);
}
return TRUE;
} else if (pMsg->wParam == VK_RETURN) {
OnNextClicked(); OnNextClicked();
return TRUE; return TRUE;
} }
@ -140,7 +148,6 @@ void CLauncherDlg::setCustomDialog() {
SetWindowLong(GetSafeHwnd(), GWL_EXSTYLE, lExStyle); SetWindowLong(GetSafeHwnd(), GWL_EXSTYLE, lExStyle);
SetWindowPos(NULL, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER); SetWindowPos(NULL, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER);
// theApp.setDialogOnFront();
} }
void CLauncherDlg::OnPaint() void CLauncherDlg::OnPaint()
@ -210,7 +217,7 @@ BOOL CLauncherDlg::getHQInfo(const CString& orgname) {
} }
afx_msg void CLauncherDlg::OnTroubleClicked() { afx_msg void CLauncherDlg::OnTroubleClicked() {
ShellExecute(0, NULL, TROUBLE_URL, NULL, NULL, SW_SHOWDEFAULT); LauncherUtils::executeOnForeground(TROUBLE_URL, _T(""));
} }
afx_msg void CLauncherDlg::OnNextClicked() { afx_msg void CLauncherDlg::OnNextClicked() {
@ -584,10 +591,14 @@ void CLauncherDlg::OnTimer(UINT_PTR nIDEvent) {
} else { } else {
theApp._manager.addToLog(_T("Start splash screen")); theApp._manager.addToLog(_T("Start splash screen"));
setDrawDialog(DrawStep::DrawLogo); setDrawDialog(DrawStep::DrawLogo);
} }
} else if (_splashStep > 100) { } else if (_splashStep > 100) {
_showSplash = false; _showSplash = false;
if (theApp._manager.shouldShutDown()) { if (theApp._manager.shouldShutDown()) {
if (_applicationWND != NULL) {
::SetForegroundWindow(_applicationWND);
::SetActiveWindow(_applicationWND);
}
if (LauncherUtils::IsProcessRunning(L"interface.exe")) { if (LauncherUtils::IsProcessRunning(L"interface.exe")) {
exit(0); exit(0);
} }
@ -607,6 +618,9 @@ void CLauncherDlg::OnTimer(UINT_PTR nIDEvent) {
exit(0); exit(0);
} }
} }
if (theApp._manager.shouldLaunch()) {
_applicationWND = theApp._manager.launchApplication();
}
} }
void CLauncherDlg::setDrawDialog(DrawStep step, BOOL isUpdate) { void CLauncherDlg::setDrawDialog(DrawStep step, BOOL isUpdate) {

View file

@ -90,6 +90,8 @@ protected:
CStatic* m_username_banner; CStatic* m_username_banner;
CStatic* m_password_banner; CStatic* m_password_banner;
HWND _applicationWND { 0 };
void drawBackground(CHwndRenderTarget* pRenderTarget); void drawBackground(CHwndRenderTarget* pRenderTarget);
void drawLogo(CHwndRenderTarget* pRenderTarget); void drawLogo(CHwndRenderTarget* pRenderTarget);
void drawSmallLogo(CHwndRenderTarget* pRenderTarget); void drawSmallLogo(CHwndRenderTarget* pRenderTarget);

View file

@ -34,7 +34,7 @@ void LauncherManager::init() {
addToLog(_T("Installed version: ") + currentVersion); addToLog(_T("Installed version: ") + currentVersion);
if (_latestVersion.Compare(currentVersion) == 0) { if (_latestVersion.Compare(currentVersion) == 0) {
addToLog(_T("Already running most recent build. Launching interface.exe")); addToLog(_T("Already running most recent build. Launching interface.exe"));
launchApplication(); _shouldLaunch = TRUE;
_shouldShutdown = TRUE; _shouldShutdown = TRUE;
} else { } else {
addToLog(_T("New build found. Updating")); addToLog(_T("New build found. Updating"));
@ -94,7 +94,7 @@ BOOL LauncherManager::installLauncher() {
// The installer is not running on the desired location and has to be installed // The installer is not running on the desired location and has to be installed
// Kill of running before self-copy // Kill of running before self-copy
if (LauncherUtils::IsProcessRunning(LAUNCHER_EXE_FILENAME)) { if (LauncherUtils::IsProcessRunning(LAUNCHER_EXE_FILENAME)) {
::ShellExecute(NULL, NULL, L"taskkill", L"/F /T /IM " + LAUNCHER_EXE_FILENAME, NULL, SW_HIDE); ShellExecute(NULL, NULL, L"taskkill", L"/F /T /IM " + LAUNCHER_EXE_FILENAME, NULL, SW_HIDE);
} }
CopyFile(appPath, instalationPath, FALSE); CopyFile(appPath, instalationPath, FALSE);
} }
@ -218,24 +218,27 @@ BOOL LauncherManager::getInstalledVersion(const CString& path, CString& version)
} }
BOOL LauncherManager::launchApplication(const CString& tokensJSON) { HWND LauncherManager::launchApplication() {
CString installDir; CString installDir;
LauncherManager::getAndCreatePaths(PathType::Interface_Directory, installDir); LauncherManager::getAndCreatePaths(PathType::Interface_Directory, installDir);
CString interfaceExe = installDir + _T("\\interface.exe"); CString interfaceExe = installDir + _T("\\interface.exe");
CString params1 = _T("--url \"") + _domainURL + ("\" "); CString urlParam = _T("--url \"") + _domainURL + ("\" ");
CString scriptsURL = installDir + _T("\\scripts\\simplifiedUI"); CString scriptsURL = installDir + _T("\\scripts\\simplifiedUI");
CString params2 = _T("--scripts \"") + scriptsURL + ("\" "); CString scriptsParam = _T("--scripts \"") + scriptsURL + ("\" ");
CString cacheDir; CString cacheDir;
LauncherManager::getAndCreatePaths(PathType::Content_Directory, cacheDir); LauncherManager::getAndCreatePaths(PathType::Content_Directory, cacheDir);
CString params3 = _T("--cache \"") + cacheDir + ("\" "); CString cacheParam = _T("--cache \"") + cacheDir + ("\" ");
CString params4 = !_displayName.IsEmpty() ? _T("--displayName \"") + _displayName + ("\" ") : _T(""); CString nameParam = !_displayName.IsEmpty() ? _T("--displayName \"") + _displayName + ("\" ") : _T("");
CString parsedTokens = tokensJSON; CString tokensParam = _T("");
parsedTokens.Replace(_T("\""), _T("\\\"")); if (!_tokensJSON.IsEmpty()) {
CString params5 = !tokensJSON.IsEmpty() ? _T("--tokens \"") + parsedTokens + ("\"") : _T(""); CString parsedTokens = _tokensJSON;
CString params = params1 + params2 + params3 + params4 + params5 + EXTRA_PARAMETERS; parsedTokens.Replace(_T("\""), _T("\\\""));
tokensParam = _T("--tokens \"");
auto rs = ShellExecute(NULL, L"open", interfaceExe, params, NULL, SW_SHOW); tokensParam += parsedTokens + _T("\"");
return (rs != NULL); }
CString params = urlParam + scriptsParam + cacheParam + nameParam + tokensParam + EXTRA_PARAMETERS;
_shouldLaunch = FALSE;
return LauncherUtils::executeOnForeground(interfaceExe, params);
} }
BOOL LauncherManager::createConfigJSON() { BOOL LauncherManager::createConfigJSON() {
@ -288,8 +291,8 @@ LauncherUtils::ResponseError LauncherManager::readConfigJSON(CString& version, C
LauncherUtils::ResponseError LauncherManager::readOrganizationJSON(const CString& hash) { LauncherUtils::ResponseError LauncherManager::readOrganizationJSON(const CString& hash) {
CString contentTypeJson = L"content-type:application/json"; CString contentTypeJson = L"content-type:application/json";
CString response; CString response;
CString url = _T("/hifi-public/huffman/organizations/") + hash + _T(".json"); CString url = _T("/organizations/") + hash + _T(".json");
LauncherUtils::ResponseError error = LauncherUtils::makeHTTPCall(L"HQ Launcher", L"s3.amazonaws.com", url, LauncherUtils::ResponseError error = LauncherUtils::makeHTTPCall(L"HQ Launcher", L"orgs.highfidelity.com", url,
contentTypeJson, CStringA(), response, false); contentTypeJson, CStringA(), response, false);
if (error != LauncherUtils::ResponseError::NoError) { if (error != LauncherUtils::ResponseError::NoError) {
return error; return error;
@ -407,9 +410,11 @@ void LauncherManager::onZipExtracted(ZipType type, int size) {
addToLog(_T("Creating config.json")); addToLog(_T("Creating config.json"));
createConfigJSON(); createConfigJSON();
addToLog(_T("Launching application.")); addToLog(_T("Launching application."));
launchApplication(_tokensJSON); _shouldLaunch = TRUE;
addToLog(_T("Creating registry keys.")); if (!_shouldUpdate) {
createApplicationRegistryKeys(size); addToLog(_T("Creating registry keys."));
createApplicationRegistryKeys(size);
}
_shouldShutdown = TRUE; _shouldShutdown = TRUE;
} }
} }
@ -429,7 +434,7 @@ void LauncherManager::onFileDownloaded(DownloadType type) {
addToLog(_T("Installing content.")); addToLog(_T("Installing content."));
installContent(); installContent();
} else if (type == DownloadType::DownloadApplication) { } else if (type == DownloadType::DownloadApplication) {
addToLog(_T("Installing application.")); addToLog(_T("Installing application."));
extractApplication(); extractApplication();
} }
} }

View file

@ -70,7 +70,7 @@ public:
BOOL deleteApplicationRegistryKeys(); BOOL deleteApplicationRegistryKeys();
BOOL createShortcuts(); BOOL createShortcuts();
BOOL deleteShortcuts(); BOOL deleteShortcuts();
BOOL launchApplication(const CString& tokensJSON = _T("")); HWND launchApplication();
BOOL uninstallApplication(); BOOL uninstallApplication();
BOOL installLauncher(); BOOL installLauncher();
@ -79,6 +79,7 @@ public:
const CString& getdomainURL() const { return _domainURL; } const CString& getdomainURL() const { return _domainURL; }
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 needsUpdate() { return _shouldUpdate; } BOOL needsUpdate() { return _shouldUpdate; }
BOOL needsUninstall() { return _shouldUninstall; } BOOL needsUninstall() { return _shouldUninstall; }
void setDisplayName(const CString& displayName) { _displayName = displayName; } void setDisplayName(const CString& displayName) { _displayName = displayName; }
@ -108,6 +109,7 @@ private:
BOOL _shouldUpdate{ FALSE }; BOOL _shouldUpdate{ FALSE };
BOOL _shouldUninstall{ FALSE }; BOOL _shouldUninstall{ FALSE };
BOOL _shouldShutdown{ FALSE }; BOOL _shouldShutdown{ FALSE };
BOOL _shouldLaunch{ FALSE };
CStdioFile _logFile; CStdioFile _logFile;
}; };

View file

@ -13,6 +13,7 @@
#include <tlhelp32.h> #include <tlhelp32.h>
#include <strsafe.h> #include <strsafe.h>
#include <winhttp.h> #include <winhttp.h>
#pragma comment(lib, "winhttp") #pragma comment(lib, "winhttp")
#include "LauncherUtils.h" #include "LauncherUtils.h"
@ -450,3 +451,38 @@ BOOL LauncherUtils::deleteDirectoriesOnThread(const CString& applicationDir,
} }
return FALSE; return FALSE;
} }
HWND LauncherUtils::executeOnForeground(const CString& path, const CString& params) {
SHELLEXECUTEINFO info;
info.cbSize = sizeof(SHELLEXECUTEINFO);
info.lpVerb = _T("open");
info.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_NOASYNC | SEE_MASK_WAITFORINPUTIDLE;
info.hwnd = NULL;
info.lpVerb = NULL;
info.lpParameters = NULL;
info.lpDirectory = NULL;
info.nShow = SW_SHOWNORMAL;
info.hInstApp = NULL;
info.lpFile = path;
info.lpParameters = params;
HWND hwnd = NULL;
if (!ShellExecuteEx(&info)) {
return FALSE;
} else {
DWORD infopid = GetProcessId(info.hProcess);
AllowSetForegroundWindow(infopid);
hwnd = GetTopWindow(0);
while (hwnd) {
DWORD pid;
DWORD dwTheardId = ::GetWindowThreadProcessId(hwnd, &pid);
if (pid == infopid) {
SetForegroundWindow(hwnd);
SetActiveWindow(hwnd);
break;
}
hwnd = ::GetNextWindow(hwnd, GW_HWNDNEXT);
}
CloseHandle(info.hProcess);
}
return hwnd;
}

View file

@ -87,6 +87,7 @@ public:
const CString& downloadsDir, const CString& downloadsDir,
std::function<void(int)> callback); 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);
private: private:
// Threads // Threads