2 * Copyright (C) 2009-2010 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, write to
17 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 * http://www.gnu.org/copyleft/gpl.html
22 #if defined(__APPLE__)
23 #include <CoreServices/CoreServices.h>
29 #include "AliasShortcutUtils.h"
31 bool IsAliasShortcut(CStdString
&path
)
35 #if defined(__APPLE__)
36 // Note: regular files that have an .alias extension can be
37 // reported as an alias when clearly, they are not. Trap them out.
38 if (CUtil::GetExtension(path
) != ".alias")
41 Boolean targetIsFolder
, wasAliased
;
43 // It is better to call FSPathMakeRefWithOptions and pass kFSPathMakeRefDefaultOptions
44 // since it will succeed for paths such as "/Volumes" unlike FSPathMakeRef.
45 if (noErr
== FSPathMakeRefWithOptions((UInt8
*)path
.c_str(), kFSPathMakeRefDefaultOptions
, &fileRef
, NULL
))
47 if (noErr
== FSIsAliasFile(&fileRef
, &wasAliased
, &targetIsFolder
))
57 // Linux does not use alias or shortcut methods
59 /* Needs testing under Windows platform so ignore shortcuts for now
60 if (CUtil::GetExtension(path) == ".lnk")
69 void TranslateAliasShortcut(CStdString
&path
)
71 #if defined(__APPLE__)
73 Boolean targetIsFolder
, wasAliased
;
75 if (noErr
== FSPathMakeRefWithOptions((UInt8
*)path
.c_str(), kFSPathMakeRefDefaultOptions
, &fileRef
, NULL
))
77 if (noErr
== FSResolveAliasFileWithMountFlags(&fileRef
, TRUE
, &targetIsFolder
, &wasAliased
, kResolveAliasFileNoUI
))
81 char real_path
[PATH_MAX
];
82 if (noErr
== FSRefMakePath(&fileRef
, (UInt8
*)real_path
, PATH_MAX
))
90 // Linux does not use alias or shortcut methods
93 /* Needs testing under Windows platform so ignore shortcuts for now
94 CComPtr<IShellLink> ipShellLink;
96 // Get a pointer to the IShellLink interface
97 if (NOERROR == CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void**)&ipShellLink))
98 WCHAR wszTemp[MAX_PATH];
100 // Get a pointer to the IPersistFile interface
101 CComQIPtr<IPersistFile> ipPersistFile(ipShellLink);
103 // IPersistFile is using LPCOLESTR so make sure that the string is Unicode
104 #if !defined _UNICODE
105 MultiByteToWideChar(CP_ACP, 0, lpszShortcutPath, -1, wszTemp, MAX_PATH);
107 wcsncpy(wszTemp, lpszShortcutPath, MAX_PATH);
110 // Open the shortcut file and initialize it from its contents
111 if (NOERROR == ipPersistFile->Load(wszTemp, STGM_READ))
113 // Try to find the target of a shortcut even if it has been moved or renamed
114 if (NOERROR == ipShellLink->Resolve(NULL, SLR_UPDATE))
117 TCHAR real_path[PATH_MAX];
118 // Get the path to the shortcut target
119 if (NOERROR == ipShellLink->GetPath(real_path, MAX_PATH, &wfd, SLGP_RAWPATH))
121 // Get the description of the target
122 TCHAR szDesc[MAX_PATH];
123 if (NOERROR == ipShellLink->GetDescription(szDesc, MAX_PATH))