diff --git a/SandboxiePlus/SandMan/Helpers/WinHelper.cpp b/SandboxiePlus/SandMan/Helpers/WinHelper.cpp index 6dc9d5a9..ce2b0a75 100644 --- a/SandboxiePlus/SandMan/Helpers/WinHelper.cpp +++ b/SandboxiePlus/SandMan/Helpers/WinHelper.cpp @@ -10,9 +10,56 @@ #include #include +QString ResolveShortcutUrl(const QString& LinkPath) +{ + QUrl Url; + + IShellLink* pShellLink = nullptr; + HRESULT hr = CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_IShellLink, reinterpret_cast(&pShellLink)); + + if (SUCCEEDED(hr)) + { + IPersistFile* pPersistFile = nullptr; + hr = pShellLink->QueryInterface(IID_IPersistFile, reinterpret_cast(&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; + QVariantMap Link; HRESULT hRes = E_FAIL; IShellLink* psl = NULL; @@ -41,14 +88,14 @@ 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; - Link["Path"] = QString::fromWCharArray(szPath); + 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; - Link["Arguments"] = QString::fromWCharArray(szPath); + if (!FAILED(hRes)) + Link["Arguments"] = QString::fromWCharArray(szPath); hRes = psl->GetWorkingDirectory(szPath, ARRAYSIZE(szPath)); if (!FAILED(hRes)) diff --git a/SandboxiePlus/SandMan/SbiePlusAPI.cpp b/SandboxiePlus/SandMan/SbiePlusAPI.cpp index b6583e7e..6703e86a 100644 --- a/SandboxiePlus/SandMan/SbiePlusAPI.cpp +++ b/SandboxiePlus/SandMan/SbiePlusAPI.cpp @@ -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();