aboutsummaryrefslogtreecommitdiff
path: root/Src/external_dependencies/openmpt-trunk/mptrack/LinkResolver.cpp
diff options
context:
space:
mode:
authorJean-Francois Mauguit <jfmauguit@mac.com>2024-09-24 09:03:25 -0400
committerGitHub <noreply@github.com>2024-09-24 09:03:25 -0400
commitbab614c421ed7ae329d26bf028c4a3b1d2450f5a (patch)
tree12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/external_dependencies/openmpt-trunk/mptrack/LinkResolver.cpp
parent4bde6044fddf053f31795b9eaccdd2a5a527d21f (diff)
parent20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (diff)
downloadwinamp-bab614c421ed7ae329d26bf028c4a3b1d2450f5a.tar.gz
Merge pull request #5 from WinampDesktop/community
Merge to main
Diffstat (limited to 'Src/external_dependencies/openmpt-trunk/mptrack/LinkResolver.cpp')
-rw-r--r--Src/external_dependencies/openmpt-trunk/mptrack/LinkResolver.cpp62
1 files changed, 62 insertions, 0 deletions
diff --git a/Src/external_dependencies/openmpt-trunk/mptrack/LinkResolver.cpp b/Src/external_dependencies/openmpt-trunk/mptrack/LinkResolver.cpp
new file mode 100644
index 00000000..af74514e
--- /dev/null
+++ b/Src/external_dependencies/openmpt-trunk/mptrack/LinkResolver.cpp
@@ -0,0 +1,62 @@
+/*
+ * LinkResolver.cpp
+ * ----------------
+ * Purpose: Resolve Windows shell link targets
+ * Notes : (currently none)
+ * Authors: OpenMPT Devs
+ * The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
+ */
+
+
+#include "stdafx.h"
+#include "LinkResolver.h"
+
+#include <atlconv.h>
+
+OPENMPT_NAMESPACE_BEGIN
+
+LinkResolver::LinkResolver()
+{
+ HRESULT result = CoCreateInstance(CLSID_ShellLink,
+ 0,
+ CLSCTX_INPROC_SERVER,
+ IID_IShellLink,
+ reinterpret_cast<LPVOID *>(&psl));
+ if(SUCCEEDED(result) && psl != nullptr)
+ {
+ psl->QueryInterface(IID_IPersistFile, reinterpret_cast<LPVOID *>(&ppf));
+ }
+}
+
+LinkResolver::~LinkResolver()
+{
+ if(ppf != nullptr)
+ ppf->Release();
+ if(psl != nullptr)
+ psl->Release();
+}
+
+mpt::PathString LinkResolver::Resolve(const TCHAR *inPath)
+{
+ if(ppf == nullptr)
+ return {};
+
+ SHFILEINFO info;
+ Clear(info);
+ if((SHGetFileInfo(inPath, 0, &info, sizeof(info), SHGFI_ATTRIBUTES) == 0) || !(info.dwAttributes & SFGAO_LINK))
+ return {};
+
+ USES_CONVERSION; // T2COLE needs this
+ if(ppf != nullptr && SUCCEEDED(ppf->Load(T2COLE(inPath), STGM_READ)))
+ {
+ if(SUCCEEDED(psl->Resolve(AfxGetMainWnd()->m_hWnd, MAKELONG(SLR_ANY_MATCH | SLR_NO_UI | SLR_NOSEARCH, 100))))
+ {
+ TCHAR outPath[MAX_PATH];
+ psl->GetPath(outPath, mpt::saturate_cast<int>(std::size(outPath)), nullptr, 0);
+ return mpt::PathString::FromNative(outPath);
+ }
+ }
+ return {};
+}
+
+OPENMPT_NAMESPACE_END