Merge pull request #26148 from ksooo/fix-secondstotimestring-warning
[xbmc.git] / xbmc / utils / AliasShortcutUtils.cpp
blob6eed4274ffc34ef0d19d797d38e38c5b81bc05f3
1 /*
2 * Copyright (C) 2009-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #if defined(TARGET_DARWIN_OSX)
10 #include "utils/URIUtils.h"
11 #include "platform/darwin/DarwinUtils.h"
12 #elif defined(TARGET_POSIX)
13 #else
14 #endif
16 #include "AliasShortcutUtils.h"
17 #include "utils/log.h"
19 bool IsAliasShortcut(const std::string& path, bool isdirectory)
21 bool rtn = false;
23 #if defined(TARGET_DARWIN_OSX)
24 // Note: regular files that have an .alias extension can be
25 // reported as an alias when clearly, they are not. Trap them out.
26 if (!URIUtils::HasExtension(path, ".alias"))//! @todo - check if this is still needed with the new API
28 rtn = CDarwinUtils::IsAliasShortcut(path, isdirectory);
30 #elif defined(TARGET_POSIX)
31 // Linux does not use alias or shortcut methods
32 #elif defined(TARGET_WINDOWS)
33 /* Needs testing under Windows platform so ignore shortcuts for now
34 if (CUtil::GetExtension(path) == ".lnk")
36 rtn = true;
39 #endif
40 return(rtn);
43 void TranslateAliasShortcut(std::string& path)
45 #if defined(TARGET_DARWIN_OSX)
46 CDarwinUtils::TranslateAliasShortcut(path);
47 #elif defined(TARGET_POSIX)
48 // Linux does not use alias or shortcut methods
49 #elif defined(TARGET_WINDOWS_STORE)
50 // Win10 does not use alias or shortcut methods
51 CLog::Log(LOGDEBUG, "{} is not implemented", __FUNCTION__);
52 #elif defined(TARGET_WINDOWS)
53 /* Needs testing under Windows platform so ignore shortcuts for now
54 CComPtr<IShellLink> ipShellLink;
56 // Get a pointer to the IShellLink interface
57 if (NOERROR == CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void**)&ipShellLink))
58 WCHAR wszTemp[MAX_PATH];
60 // Get a pointer to the IPersistFile interface
61 CComQIPtr<IPersistFile> ipPersistFile(ipShellLink);
63 // IPersistFile is using LPCOLESTR so make sure that the string is Unicode
64 #if !defined _UNICODE
65 MultiByteToWideChar(CP_ACP, 0, lpszShortcutPath, -1, wszTemp, MAX_PATH);
66 #else
67 wcsncpy(wszTemp, lpszShortcutPath, MAX_PATH);
68 #endif
70 // Open the shortcut file and initialize it from its contents
71 if (NOERROR == ipPersistFile->Load(wszTemp, STGM_READ))
73 // Try to find the target of a shortcut even if it has been moved or renamed
74 if (NOERROR == ipShellLink->Resolve(NULL, SLR_UPDATE))
76 WIN32_FIND_DATA wfd;
77 TCHAR real_path[PATH_MAX];
78 // Get the path to the shortcut target
79 if (NOERROR == ipShellLink->GetPath(real_path, MAX_PATH, &wfd, SLGP_RAWPATH))
81 // Get the description of the target
82 TCHAR szDesc[MAX_PATH];
83 if (NOERROR == ipShellLink->GetDescription(szDesc, MAX_PATH))
85 path = real_path;
92 #endif