From 308483f4e71eb30e9955cede166e6d427418b9c2 Mon Sep 17 00:00:00 2001 From: danteruiz Date: Wed, 25 Sep 2019 18:15:15 -0700 Subject: [PATCH] working on file system links --- launchers/qt/CMakeLists.txt | 10 +++- launchers/qt/src/Helper.h | 8 +++ launchers/qt/src/Helper_windows.cpp | 51 +++++++++++++++++-- launchers/qt/src/Launcher.cpp | 1 - .../qt/src/LauncherInstaller_windows.cpp | 12 ++++- launchers/qt/src/LauncherState.cpp | 5 +- launchers/qt/src/main.cpp | 2 - 7 files changed, 76 insertions(+), 13 deletions(-) diff --git a/launchers/qt/CMakeLists.txt b/launchers/qt/CMakeLists.txt index 169240c647..c10d78de47 100644 --- a/launchers/qt/CMakeLists.txt +++ b/launchers/qt/CMakeLists.txt @@ -16,6 +16,10 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) include("cmake/init.cmake") include("cmake/macros/SetPackagingParameters.cmake") +if (WIN32) + set(CMAKE_MFC_FLAG 1) +endif() + function(set_from_env _RESULT_NAME _ENV_VAR_NAME _DEFAULT_VALUE) if (NOT DEFINED ${_RESULT_NAME}) @@ -119,6 +123,8 @@ foreach(plugin ${Qt5Gui_PLUGINS}) set(plugin_libs ${plugin_libs} ${_loc}) endforeach() +qt5_add_resources(EXAMPLE_RCC_SRC build/resources.qrc) + set(src_files src/main.cpp src/Launcher.h @@ -135,7 +141,7 @@ set(src_files src/Helper.cpp deps/miniz/miniz.h deps/miniz/miniz.cpp - ${RES_SOURCES} + #${RES_SOURCES} ) @@ -159,7 +165,7 @@ set(TARGET_NAME ${PROJECT_NAME}) set_packaging_parameters() if (WIN32) - add_executable(${PROJECT_NAME} ${src_files} build/resources.qrc) + add_executable(${PROJECT_NAME} ${src_files})#build/resources.qrc ${EXAMPLE_RCC_SRC}) elseif (APPLE) set_target_properties(${this_target} PROPERTIES MACOSX_BUNDLE_INFO_PLIST MacOSXBundleInfo.plist.in) diff --git a/launchers/qt/src/Helper.h b/launchers/qt/src/Helper.h index 7d1f54a949..975eb383d7 100644 --- a/launchers/qt/src/Helper.h +++ b/launchers/qt/src/Helper.h @@ -1,6 +1,10 @@ #include #include +#ifdef Q_OS_WIN +#include "Windows.h" +#endif + void launchClient(const QString& clientPath, const QString& homePath, const QString& defaultScriptOverride, const QString& displayName, const QString& contentCachePath, QString loginResponseToken = QString()); @@ -11,3 +15,7 @@ void swapLaunchers(const QString& oldLauncherPath = QString(), const QString& ne #ifdef Q_OS_MAC bool replaceDirectory(const QString& orginalDirectory, const QString& newDirectory); #endif + +#ifdef Q_OS_WIN +HRESULT createSymbolicLink(LPCSTR lpszPathObj, LPCSTR lpszPathLink, LPCSTR lpszDesc, LPCSTR lpszArgs); +#endif diff --git a/launchers/qt/src/Helper_windows.cpp b/launchers/qt/src/Helper_windows.cpp index cb3671f274..5295943a4e 100644 --- a/launchers/qt/src/Helper_windows.cpp +++ b/launchers/qt/src/Helper_windows.cpp @@ -1,7 +1,12 @@ #include "Helper.h" +#include "windows.h" +#include "winnls.h" +#include "shobjidl.h" +#include "objbase.h" +#include "objidl.h" +#include "shlguid.h" #include -#include void launchClient(const QString& clientPath, const QString& homePath, const QString& defaultScriptsPath, const QString& displayName, const QString& contentCachePath, QString loginResponseToken) { @@ -34,12 +39,12 @@ void launchClient(const QString& clientPath, const QString& homePath, const QStr FALSE, // Set handle inheritance to FALSE CREATE_NEW_CONSOLE, // Opens file in a separate console nullptr, // Use parent's environment block - nullptr, // Use parent's starting directory + nullptr, // Use parent's starting directory &si, // Pointer to STARTUPINFO structure &pi // Pointer to PROCESS_INFORMATION structure ); - // Close process and thread handles. + // Close process and thread handles. CloseHandle(pi.hProcess); CloseHandle(pi.hThread); @@ -68,3 +73,43 @@ void launchAutoUpdater(const QString& autoUpdaterPath) { &pi // Pointer to PROCESS_INFORMATION structure ); } + + +HRESULT createSymbolicLink(LPCSTR lpszPathObj, LPCSTR lpszPathLink, LPCSTR lpszDesc, LPCSTR lpszArgs) { + IShellLink* psl; + + // Get a pointer to the IShellLink interface. It is assumed that CoInitialize + // has already been called. + CoInitialize(NULL); + HRESULT hres = E_INVALIDARG; + hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&psl); + if (SUCCEEDED(hres)) { + IPersistFile* ppf; + + // Set the path to the shortcut target and add the description. + psl->SetPath(lpszPathObj); + psl->SetDescription(lpszDesc); + psl->SetArguments(lpszArgs); + + // Query IShellLink for the IPersistFile interface, used for saving the + // shortcut in persistent storage. + hres = psl->QueryInterface(IID_IPersistFile, (LPVOID*)&ppf); + + if (SUCCEEDED(hres)) { + WCHAR wsz[MAX_PATH]; + + // Ensure that the string is Unicode. + MultiByteToWideChar(CP_ACP, 0, lpszPathLink, -1, wsz, MAX_PATH); + + // Add code here to check return value from MultiByteWideChar + // for success. + + // Save the link by calling IPersistFile::Save. + hres = ppf->Save(wsz, TRUE); + ppf->Release(); + } + psl->Release(); + } + CoUninitialize(); + return SUCCEEDED(hres); +} diff --git a/launchers/qt/src/Launcher.cpp b/launchers/qt/src/Launcher.cpp index 8ad9085cc8..2d5fd8dc21 100644 --- a/launchers/qt/src/Launcher.cpp +++ b/launchers/qt/src/Launcher.cpp @@ -9,7 +9,6 @@ #include "PathUtils.h" Launcher::Launcher(int& argc, char**argv) : QGuiApplication(argc, argv) { - Q_INIT_RESOURCE(resources); QString resourceBinaryLocation = QGuiApplication::applicationDirPath() + "/resources.rcc"; qDebug() << "resources.rcc path: " << resourceBinaryLocation; QResource::registerResource(resourceBinaryLocation); diff --git a/launchers/qt/src/LauncherInstaller_windows.cpp b/launchers/qt/src/LauncherInstaller_windows.cpp index 4a3f819c23..dc49c7d738 100644 --- a/launchers/qt/src/LauncherInstaller_windows.cpp +++ b/launchers/qt/src/LauncherInstaller_windows.cpp @@ -1,6 +1,7 @@ #include "LauncherInstaller_windows.h" +#include "Helper.h" -#include +#include #include #include @@ -37,6 +38,15 @@ void LauncherInstaller::install() { } else { qDebug() << "not successful"; } + + qDebug() << "LauncherInstaller: create uninstall link"; + QString uninstallLinkPath = _launcherInstallDir.absolutePath() + "/Uninstall HQ.link"; + if (QFile::exists(uninstallLinkPath)) { + QFile::remove(uninstallLinkPath); + } + + createSymbolicLink((LPCSTR)oldLauncherPath.toStdString().c_str(), (LPCSTR)uninstallLinkPath.toStdString().c_str(), + (LPCSTR)("Click to Uninstall HQ"), (LPCSTR)("--uninstall")); } } diff --git a/launchers/qt/src/LauncherState.cpp b/launchers/qt/src/LauncherState.cpp index 1a8023e236..f9ada2bc41 100644 --- a/launchers/qt/src/LauncherState.cpp +++ b/launchers/qt/src/LauncherState.cpp @@ -4,9 +4,6 @@ #include "Unzipper.h" #include "Helper.h" -#ifdef Q_OS_WIN -#include -#endif #include #include @@ -70,7 +67,7 @@ bool LatestBuilds::getBuild(QString tag, Build* outBuild) { } static const std::array QML_FILE_FOR_UI_STATE = - { { "SplashScreen.qml", "qml/HFBase/CreateAccountBase.qml", "DisplayName.qml", + { { "qml/SplashScreen.qml", "qml/HFBase/CreateAccountBase.qml", "DisplayName.qml", "qml/Download.qml", "qml/DownloadFinished.qml", "qml/HFBase/Error.qml" } }; void LauncherState::ASSERT_STATE(LauncherState::ApplicationState state) { diff --git a/launchers/qt/src/main.cpp b/launchers/qt/src/main.cpp index df5987dd62..3c810434e7 100644 --- a/launchers/qt/src/main.cpp +++ b/launchers/qt/src/main.cpp @@ -37,7 +37,6 @@ bool containsOption(int argc, char* argv[], const std::string& option) { } int main(int argc, char *argv[]) { - //std::cout << "Launcher version: " << LAUNCHER_BUILD_VERSION; #ifdef Q_OS_MAC // auto updater @@ -60,7 +59,6 @@ int main(int argc, char *argv[]) { QString name { "High Fidelity" }; QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QCoreApplication::setOrganizationName(name); - Launcher launcher(argc, argv); return launcher.exec();