MCPcopy Create free account
hub / github.com/bumptop/BumpTop / getShortcutTarget

Method getShortcutTarget

trunk/win/Source/BT_FileSystemManager.cpp:835–910  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

833}
834
835bool FileSystemManager::getShortcutTarget(QString shortcutFileName, QString * targetOut, QString * argsOut, QString * workingDirOut)
836{
837 assert(targetOut);
838
839 // return true if _any_ of the attributes can be resolved
840
841 bool targetResolved = false;
842 bool result = false;
843 IShellLink * psl = NULL;
844
845 // Accounting for the newer "Advertised Shortcuts" which refer to MSI operations which may pre-empt the
846 // launching of the specified shortcut
847 DWORD targetPathLen = MAX_PATH;
848 TCHAR targetPath[MAX_PATH];
849 TCHAR productCode[MAX_PATH];
850 TCHAR featureId[MAX_PATH];
851 TCHAR componentCode[MAX_PATH];
852 if (pfnMsiGetShortcutTarget && pfnMsiGetComponentPath)
853 {
854 if (ERROR_SUCCESS == pfnMsiGetShortcutTarget((LPCTSTR) shortcutFileName.utf16(), productCode, featureId, componentCode))
855 {
856 if (INSTALLSTATE_LOCAL == pfnMsiGetComponentPath(productCode, componentCode, targetPath, &targetPathLen))
857 {
858 *targetOut = QString::fromUtf16((const ushort *) targetPath);
859 targetResolved = true;
860 result = true;
861 }
862 }
863 }
864
865 // Get a pointer to the IShellLink interface.
866 TCHAR args[MAX_PATH];
867 TCHAR workingDir[MAX_PATH];
868
869 HRESULT hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID *) &psl);
870 if (SUCCEEDED(hres))
871 {
872 IPersistFile * ppf = NULL;
873
874 // Get a pointer to the IPersistFile interface.
875 if (SUCCEEDED(psl->QueryInterface(IID_IPersistFile, (LPVOID *) &ppf)))
876 {
877 // Load the shortcut.
878 if (SUCCEEDED(ppf->Load((LPCOLESTR) shortcutFileName.utf16(), STGM_READ)))
879 {
880 // Resolve the link.
881 if (SUCCEEDED(psl->Resolve(winOS->GetWindowsHandle(), SLR_NOUPDATE | SLR_NO_UI)))
882 {
883 // Get the path to the link target.
884 if (!targetResolved && SUCCEEDED(psl->GetPath(targetPath, MAX_PATH, NULL, 0)))
885 {
886 *targetOut = QString::fromUtf16((const ushort *) targetPath);
887 result = true;
888 }
889 if (argsOut && SUCCEEDED(psl->GetArguments(args, MAX_PATH)))
890 {
891 *argsOut = QString::fromUtf16((const ushort *) args);
892 result = true;

Callers 4

setFilePathMethod · 0.80
for_eachFunction · 0.80
GetSystemIconMethod · 0.80
GetSystemIconInfoMethod · 0.80

Calls 6

assertClass · 0.85
LoadMethod · 0.80
GetWindowsHandleMethod · 0.80
GetPathMethod · 0.80
QueryInterfaceMethod · 0.45
ReleaseMethod · 0.45

Tested by

no test coverage detected