Stephen Monaco
1 year ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with
26 additions and
2 deletions
-
src/Avalonia.Base/Platform/Storage/FileIO/BclStorageProvider.cs
|
|
|
@ -109,7 +109,7 @@ internal abstract class BclStorageProvider : IStorageProvider |
|
|
|
if (OperatingSystemEx.IsWindows()) |
|
|
|
{ |
|
|
|
return Environment.OSVersion.Version.Major < 6 ? null : |
|
|
|
Marshal.PtrToStringUni(SHGetKnownFolderPath(s_folderDownloads, 0, IntPtr.Zero)); |
|
|
|
TryGetWindowsKnownFolder(s_folderDownloads); |
|
|
|
} |
|
|
|
|
|
|
|
if (OperatingSystemEx.IsLinux()) |
|
|
|
@ -148,7 +148,31 @@ internal abstract class BclStorageProvider : IStorageProvider |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private static unsafe string? TryGetWindowsKnownFolder(Guid guid) |
|
|
|
{ |
|
|
|
nint path = IntPtr.Zero; |
|
|
|
string? result = null; |
|
|
|
|
|
|
|
try |
|
|
|
{ |
|
|
|
var hr = SHGetKnownFolderPath(guid, 0, 0, &path); |
|
|
|
if (hr == 0) |
|
|
|
{ |
|
|
|
result = Marshal.PtrToStringUni(path); |
|
|
|
} |
|
|
|
} |
|
|
|
finally |
|
|
|
{ |
|
|
|
if (path != IntPtr.Zero) |
|
|
|
{ |
|
|
|
Marshal.FreeCoTaskMem(path); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
private static readonly Guid s_folderDownloads = new Guid("374DE290-123F-4565-9164-39C4925E467B"); |
|
|
|
[DllImport("shell32.dll")] |
|
|
|
private static extern IntPtr SHGetKnownFolderPath([MarshalAs(UnmanagedType.LPStruct)] Guid id, int flags, IntPtr token); |
|
|
|
private static unsafe extern int SHGetKnownFolderPath([MarshalAs(UnmanagedType.LPStruct)] Guid id, int flags, nint token, nint* ppszPath); |
|
|
|
} |
|
|
|
|