From d9a19ed51f9055a7d86c165486c2420b1f690c99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 10 Oct 2024 15:38:50 +0200 Subject: [PATCH] Fix ShowFileInFolder --- Windows/W32Util/Misc.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Windows/W32Util/Misc.cpp b/Windows/W32Util/Misc.cpp index 0583c5963f..5aed03198a 100644 --- a/Windows/W32Util/Misc.cpp +++ b/Windows/W32Util/Misc.cpp @@ -10,6 +10,7 @@ #include "Common/Data/Encoding/Utf8.h" #include "Common/StringUtils.h" #include "Common/File/FileUtil.h" +#include "Common/Log.h" bool KeyDownAsync(int vkey) { #if PPSSPP_PLATFORM(UWP) @@ -101,14 +102,22 @@ namespace W32Util // SHParseDisplayName can't handle relative paths, so normalize first. std::string resolved = ReplaceAll(File::ResolvePath(path), "/", "\\"); - SFGAOF flags{}; + // Shell also can't handle \\?\UNC\ paths. + // TODO: Move this to ResolvePath? + if (startsWith(resolved, "\\\\?\\UNC\\")) { + resolved = "\\" + resolved.substr(7); + } + PIDLIST_ABSOLUTE pidl = nullptr; - HRESULT hr = SHParseDisplayName(ConvertUTF8ToWString(resolved).c_str(), nullptr, &pidl, 0, &flags); + std::wstring wresolved = ConvertUTF8ToWString(resolved); + HRESULT hr = SHParseDisplayName(wresolved.c_str(), nullptr, &pidl, 0, nullptr); if (pidl) { if (SUCCEEDED(hr)) SHOpenFolderAndSelectItems(pidl, 0, nullptr, 0); - CoTaskMemFree(pidl); + ILFree(pidl); + } else { + ERROR_LOG(Log::System, "SHParseDisplayName failed: %s", resolved.c_str()); } }