aboutsummaryrefslogtreecommitdiff
path: root/launcher
diff options
context:
space:
mode:
authorADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com>2022-10-28 15:46:54 +0300
committerADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com>2022-11-12 20:19:27 +0200
commitb83f9be1bd65f784bbed603e550fbe9f650b0367 (patch)
treea4913692157fcf296dbaedd28d01aef2984c57a1 /launcher
parent6ae3b183fdb1f6e4887617fc7230d52c803e63fd (diff)
downloadPrismLauncher-b83f9be1bd65f784bbed603e550fbe9f650b0367.tar.gz
PrismLauncher-b83f9be1bd65f784bbed603e550fbe9f650b0367.tar.bz2
PrismLauncher-b83f9be1bd65f784bbed603e550fbe9f650b0367.zip
Add missing fail check for CoInitialize
Add a few comments Signed-off-by: ADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com>
Diffstat (limited to 'launcher')
-rw-r--r--launcher/FileSystem.cpp20
1 files changed, 15 insertions, 5 deletions
diff --git a/launcher/FileSystem.cpp b/launcher/FileSystem.cpp
index 90f0313f..587753a0 100644
--- a/launcher/FileSystem.cpp
+++ b/launcher/FileSystem.cpp
@@ -427,14 +427,21 @@ bool createShortcut(QString destination, QString target, QStringList args, QStri
return false;
}
- WCHAR wsz[MAX_PATH];
+ HRESULT hres;
+
+ // ...yes, you need to initialize the entire COM stack just to make a shortcut
+ hres = CoInitialize(nullptr);
+ if (FAILED(hres))
+ {
+ qWarning() << "Failed to initialize COM!";
+ return false;
+ }
- // ...yes, you need to initialize the entire COM stack to make a shortcut in Windows
- CoInitialize(nullptr);
+ WCHAR wsz[MAX_PATH];
- HRESULT hres;
IShellLink* psl;
+ // create an IShellLink instance - this stores the shortcut's attributes
hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&psl);
if (SUCCEEDED(hres))
{
@@ -448,7 +455,7 @@ bool createShortcut(QString destination, QString target, QStringList args, QStri
wmemset(wsz, 0, MAX_PATH);
targetInfo.absolutePath().toWCharArray(wsz);
- psl->SetWorkingDirectory(wsz);
+ psl->SetWorkingDirectory(wsz); // "Starts in" attribute
if (!icon.isEmpty())
{
@@ -457,6 +464,8 @@ bool createShortcut(QString destination, QString target, QStringList args, QStri
psl->SetIconLocation(wsz, 0);
}
+ // query an IPersistFile interface from our IShellLink instance
+ // this is the interface that will actually let us save the shortcut to disk!
IPersistFile* ppf;
hres = psl->QueryInterface(IID_IPersistFile, (LPVOID*)&ppf);
if (SUCCEEDED(hres))
@@ -484,6 +493,7 @@ bool createShortcut(QString destination, QString target, QStringList args, QStri
qWarning() << "hres = " << hres;
}
+ // go away COM, nobody likes you
CoUninitialize();
return SUCCEEDED(hres);