diff options
| author | Victor Tran <vicr12345@gmail.com> | 2020-08-03 23:33:12 +1000 |
|---|---|---|
| committer | Victor Tran <vicr12345@gmail.com> | 2020-08-03 23:33:12 +1000 |
| commit | 52e80e6d4405e16378471003dd8b30aa920c1f9c (patch) | |
| tree | b3b4439f6a1f4d23398a61a78d9678f39afeef3e /installer/process | |
| parent | 2917d1830456828461171f3b9e1bffd37eba0b97 (diff) | |
| parent | fef992a12c81ad728b44617e02c3f5180c4a3cc0 (diff) | |
| download | theInstaller-continuous.tar.gz theInstaller-continuous.tar.bz2 theInstaller-continuous.zip | |
Merge branch 'refs/heads/master' into blueprintcontinuousblueprint
Diffstat (limited to 'installer/process')
| -rw-r--r-- | installer/process/installworker.cpp | 67 | ||||
| -rw-r--r-- | installer/process/removeworker.cpp | 14 |
2 files changed, 78 insertions, 3 deletions
diff --git a/installer/process/installworker.cpp b/installer/process/installworker.cpp index d4f5c5b..e1c0dbc 100644 --- a/installer/process/installworker.cpp +++ b/installer/process/installworker.cpp @@ -1,5 +1,15 @@ #include "installworker.h" +#include <unknwn.h> +#include <winrt/base.h> +#include <winrt/Windows.Foundation.h> +#include <propkey.h> +#include <propsys.h> +#include <propvarutil.h> +#include <shlobj.h> +#include <objidl.h> + + extern QString calculateSize(quint64 size); InstallWorker::InstallWorker(QObject *parent) : QObject(parent) @@ -8,7 +18,7 @@ InstallWorker::InstallWorker(QObject *parent) : QObject(parent) bool InstallWorker::startWork() { QLocalSocket* sock = new QLocalSocket(); - QString vendor, name, url, destPath, executable; + QString vendor, name, url, destPath, executable, clsid; bool isStableStream = true, isGlobalInstall = true; QString previousToken; @@ -26,10 +36,12 @@ bool InstallWorker::startWork() { destPath = arg; } else if (previousToken == "--executable") { executable = arg; + } else if (previousToken == "--clsid") { + clsid = arg; } previousToken = ""; } else { - if (arg == "--socket" || arg == "--vendor" || arg == "--name" || arg == "--url" || arg == "--destdir" || arg == "--executable") { + if (arg == "--socket" || arg == "--vendor" || arg == "--name" || arg == "--url" || arg == "--destdir" || arg == "--executable" || arg == "--clsid") { previousToken = arg; } else if (arg == "--blueprint") { isStableStream = false; @@ -135,9 +147,54 @@ bool InstallWorker::startWork() { if (QFile::exists(linkFile)) { QFile::remove(linkFile); } - QFile::link(executableFile.absoluteFilePath(), linkFile); QFile::copy(QApplication::applicationFilePath(), dest.absoluteFilePath("uninstall.exe")); + bool shouldUseQFileLink = false; + if (!clsid.isEmpty()) { + QString appUMID = QStringLiteral("%1.%2").arg(vendor.toLower()).arg(name.toLower()); + QSettings* comServer; + if (isGlobalInstall) { + comServer = new QSettings(QStringLiteral("HKEY_LOCAL_MACHINE\\SOFTWARE\\Classes\\CLSID\\%1\\LocalServer32").arg(clsid), QSettings::NativeFormat); + } else { + comServer = new QSettings(QStringLiteral("HKEY_CURRENT_USER\\SOFTWARE\\Classes\\CLSID\\%1\\LocalServer32").arg(clsid), QSettings::NativeFormat); + } + + comServer->setValue(".", "\"" + executableFile.absoluteFilePath() + "\" -ToastActivated"); + + comServer->deleteLater(); + + try { + auto link{ winrt::create_instance<IShellLink>(CLSID_ShellLink) }; + winrt::check_hresult(link->SetPath(executableFile.absoluteFilePath().toStdWString().c_str())); + + auto store = link.as<IPropertyStore>(); + PROPVARIANT value; + winrt::check_hresult(::InitPropVariantFromString(appUMID.toStdWString().c_str(), &value)); + winrt::check_hresult(store->SetValue(PKEY_AppUserModel_ID, value)); + ::PropVariantClear(&value); + + CLSID clsidVar; + winrt::check_hresult(::CLSIDFromString(clsid.toStdWString().c_str(), &clsidVar)); + winrt::check_hresult(::InitPropVariantFromCLSID(clsidVar, &value)); + winrt::check_hresult(store->SetValue(PKEY_AppUserModel_ToastActivatorCLSID, value)); + + auto file{ store.as<IPersistFile>() }; + winrt::check_hresult(file->Save(linkFile.toStdWString().c_str(), TRUE)); + + ::PropVariantClear(&value); + } catch (...) { + sock->write(QString("DEBUG Error while creating link; falling back to QFile::link\n").toUtf8()); + + shouldUseQFileLink = true; + } + } else { + shouldUseQFileLink = true; + } + + if (shouldUseQFileLink) { + QFile::link(executableFile.absoluteFilePath(), linkFile); + } + QJsonObject dataRoot; dataRoot.insert("vendor", vendor); dataRoot.insert("name", name); @@ -147,6 +204,10 @@ bool InstallWorker::startWork() { dataRoot.insert("stream", isStableStream); dataRoot.insert("registryUuid", name); + if (!clsid.isEmpty()) { + dataRoot.insert("clsid", clsid); + } + QSettings* settings; if (isGlobalInstall) { settings = new QSettings("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + name, QSettings::NativeFormat); diff --git a/installer/process/removeworker.cpp b/installer/process/removeworker.cpp index 5356f26..39a890b 100644 --- a/installer/process/removeworker.cpp +++ b/installer/process/removeworker.cpp @@ -74,6 +74,20 @@ bool RemoveWorker::startWork() { QDir dest(metadata.value("installPath").toString()); dest.removeRecursively(); + if (metadata.contains("clsid")) { + QSettings* comServer; + if (metadata.value("global").toBool()) { + comServer = new QSettings(QStringLiteral("HKEY_LOCAL_MACHINE\\SOFTWARE\\Classes\\CLSID"), QSettings::NativeFormat); + } else { + comServer = new QSettings(QStringLiteral("HKEY_CURRENT_USER\\SOFTWARE\\Classes\\CLSID"), QSettings::NativeFormat); + } + + comServer->remove(metadata.value("clsid").toString()); + comServer->sync(); + + comServer->deleteLater(); + } + //Remove registry entry QSettings* settings; if (metadata.value("global").toBool()) { |
