Merge pull request #15750 from luiscuenca/windowsLauncherUpdates

Windows Launcher fixes and updates
This commit is contained in:
Shannon Romano 2019-06-12 13:27:44 -07:00 committed by GitHub
commit 9f57363382
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 86 additions and 26 deletions

View file

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

View file

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

View file

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

View file

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

View file

@ -13,6 +13,7 @@
#include <tlhelp32.h>
#include <strsafe.h>
#include <winhttp.h>
#pragma comment(lib, "winhttp")
#include "LauncherUtils.h"
@ -450,3 +451,38 @@ BOOL LauncherUtils::deleteDirectoriesOnThread(const CString& applicationDir,
}
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,
std::function<void(int)> callback);
static CString urlEncodeString(const CString& url);
static HWND executeOnForeground(const CString& path, const CString& params);
private:
// Threads