Browse Source

Fix KnownFolder for x86 Windows (#17705)

* Fix KnownFolder for x86 Windows

* Remove try-finally
release/11.2.3
Stephen Monaco 2 years ago
committed by Max Katz
parent
commit
261a08a355
  1. 23
      src/Avalonia.Base/Platform/Storage/FileIO/BclStorageProvider.cs

23
src/Avalonia.Base/Platform/Storage/FileIO/BclStorageProvider.cs

@ -150,29 +150,24 @@ internal abstract class BclStorageProvider : IStorageProvider
private static unsafe string? TryGetWindowsKnownFolder(Guid guid) private static unsafe string? TryGetWindowsKnownFolder(Guid guid)
{ {
nint path = IntPtr.Zero; char* path = null;
string? result = null; string? result = null;
try var hr = SHGetKnownFolderPath(&guid, 0, null, &path);
if (hr == 0)
{ {
var hr = SHGetKnownFolderPath(guid, 0, 0, &path); result = Marshal.PtrToStringUni((IntPtr)path);
if (hr == 0)
{
result = Marshal.PtrToStringUni(path);
}
} }
finally
if (path != null)
{ {
if (path != IntPtr.Zero) Marshal.FreeCoTaskMem((IntPtr)path);
{
Marshal.FreeCoTaskMem(path);
}
} }
return result; return result;
} }
private static readonly Guid s_folderDownloads = new Guid("374DE290-123F-4565-9164-39C4925E467B"); private static readonly Guid s_folderDownloads = new Guid("374DE290-123F-4565-9164-39C4925E467B");
[DllImport("shell32.dll")] [DllImport("shell32.dll", ExactSpelling = true)]
private static unsafe extern int SHGetKnownFolderPath([MarshalAs(UnmanagedType.LPStruct)] Guid id, int flags, nint token, nint* ppszPath); private static unsafe extern int SHGetKnownFolderPath(Guid* rfid, uint dwFlags, void* hToken, char** ppszPath);
} }

Loading…
Cancel
Save