This commit is contained in:
DavidXanatos 2023-08-12 09:15:17 +02:00
parent be8bc16c14
commit 27ceada829
2 changed files with 56 additions and 7 deletions

View File

@ -10,6 +10,53 @@
#include <Shlwapi.h>
#include <Shlobj.h>
QString ResolveShortcutUrl(const QString& LinkPath)
{
QUrl Url;
IShellLink* pShellLink = nullptr;
HRESULT hr = CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_IShellLink, reinterpret_cast<void**>(&pShellLink));
if (SUCCEEDED(hr))
{
IPersistFile* pPersistFile = nullptr;
hr = pShellLink->QueryInterface(IID_IPersistFile, reinterpret_cast<void**>(&pPersistFile));
if (SUCCEEDED(hr))
{
hr = pPersistFile->Load(LinkPath.toStdWString().c_str(), STGM_READ);
if (SUCCEEDED(hr))
{
PIDLIST_ABSOLUTE pidl;
hr = pShellLink->GetIDList(&pidl);
if (SUCCEEDED(hr))
{
LPWSTR url = nullptr;
SHGetNameFromIDList(pidl, SIGDN_URL, &url);
if (url) {
Url = QString::fromWCharArray(url);
CoTaskMemFree(url);
}
CoTaskMemFree(pidl);
}
}
pPersistFile->Release();
}
pShellLink->Release();
}
if (Url.isLocalFile())
return Url.path().mid(1).replace("/", "\\");
return Url.toString();;
}
QVariantMap ResolveShortcut(const QString& LinkPath)
{
QVariantMap Link;
@ -41,13 +88,13 @@ QVariantMap ResolveShortcut(const QString& LinkPath)
{
// Get the path to the shortcut target
hRes = psl->GetPath(szPath, ARRAYSIZE(szPath), &wfd, SLGP_RAWPATH);
if (FAILED(hRes))
return Link;
if (hRes == S_OK)
Link["Path"] = QString::fromWCharArray(szPath);
else
Link["Path"] = ResolveShortcutUrl(LinkPath);
hRes = psl->GetArguments(szPath, ARRAYSIZE(szPath));
if (FAILED(hRes))
return Link;
if (!FAILED(hRes))
Link["Arguments"] = QString::fromWCharArray(szPath);
hRes = psl->GetWorkingDirectory(szPath, ARRAYSIZE(szPath));

View File

@ -507,6 +507,8 @@ void CSandBoxPlus::ScanStartMenu()
bChanged = true;
pLink->Target = Link["Path"].toString();
if(pLink->Target.mid(1,2) != ":\\")
pLink->Url = true;
pLink->Arguments = Link["Arguments"].toString();
pLink->Icon = Link["IconPath"].toString();
pLink->IconIndex = Link["IconIndex"].toInt();