working on file system links

This commit is contained in:
danteruiz 2019-09-25 18:15:15 -07:00
parent f1fa2f8cd2
commit 308483f4e7
7 changed files with 76 additions and 13 deletions

View file

@ -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)

View file

@ -1,6 +1,10 @@
#include <QString>
#include <string>
#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

View file

@ -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 <QCoreApplication>
#include <Windows.h>
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);
}

View file

@ -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);

View file

@ -1,6 +1,7 @@
#include "LauncherInstaller_windows.h"
#include "Helper.h"
#include <Windows.h>
#include <string>
#include <QStandardPaths>
#include <QFileInfo>
@ -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"));
}
}

View file

@ -4,9 +4,6 @@
#include "Unzipper.h"
#include "Helper.h"
#ifdef Q_OS_WIN
#include <Windows.h>
#endif
#include <array>
#include <cstdlib>
@ -70,7 +67,7 @@ bool LatestBuilds::getBuild(QString tag, Build* outBuild) {
}
static const std::array<QString, LauncherState::UIState::UI_STATE_NUM> 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) {

View file

@ -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();