Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Environment.SystemDirectory from GetFolderPath(System) on Windows #83593

Merged
merged 4 commits into from Mar 18, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -220,6 +220,13 @@ private static string GetFolderPathCore(SpecialFolder folder, SpecialFolderOptio

switch (folder)
{
// Special-cased values to not use SHGetFolderPath when we have a more direct option available.
case SpecialFolder.System when option == SpecialFolderOption.None:
stephentoub marked this conversation as resolved.
Show resolved Hide resolved
return SystemDirectory;
default:
return string.Empty;

// Map the SpecialFolder to the appropriate Guid
case SpecialFolder.ApplicationData:
folderGuid = Interop.Shell32.KnownFolders.RoamingAppData;
break;
Expand Down Expand Up @@ -271,7 +278,7 @@ private static string GetFolderPathCore(SpecialFolder folder, SpecialFolderOptio
case SpecialFolder.Startup:
folderGuid = Interop.Shell32.KnownFolders.Startup;
break;
case SpecialFolder.System:
case SpecialFolder.System when option != SpecialFolderOption.None:
folderGuid = Interop.Shell32.KnownFolders.System;
stephentoub marked this conversation as resolved.
Show resolved Hide resolved
break;
case SpecialFolder.Templates:
Expand Down Expand Up @@ -360,15 +367,8 @@ private static string GetFolderPathCore(SpecialFolder folder, SpecialFolderOptio
case SpecialFolder.Windows:
folderGuid = Interop.Shell32.KnownFolders.Windows;
break;
default:
return string.Empty;
}

return GetKnownFolderPath(folderGuid, option);
}

private static string GetKnownFolderPath(string folderGuid, SpecialFolderOption option)
{
Guid folderId = new Guid(folderGuid);

int hr = Interop.Shell32.SHGetKnownFolderPath(folderId, (uint)option, IntPtr.Zero, out string path);
Expand Down