From 77f5d77afa7fff95ff25cdb91e6993e32b1a77a8 Mon Sep 17 00:00:00 2001
From: xtqqczze <45661989+xtqqczze@users.noreply.github.com>
Date: Mon, 28 Jul 2025 21:24:56 +0100
Subject: [PATCH 1/6] Refactor known folder GUIDs to use static properties
instead of constants
internal const string ([a-z0-9]+) = "\{([a-z0-9]{8})-([a-z0-9]{4})-([a-z0-9]{4})-([a-z0-9]{2})([a-z0-9]{2})-([a-z0-9]{2})([a-z0-9]{2})([a-z0-9]{2})([a-z0-9]{2})([a-z0-9]{2})([a-z0-9]{2})\}";
internal static Guid $1 => new(0x$2, 0x$3, 0x$4, 0x$5, 0x$6, 0x$7, 0x$8, 0x$9, 0x$10, 0x$11, 0x$12);
---
.../Shell32/Interop.SHGetKnownFolderPath.cs | 150 ++++++++++++------
.../src/System/Environment.Win32.cs | 93 ++++++-----
2 files changed, 146 insertions(+), 97 deletions(-)
diff --git a/src/libraries/Common/src/Interop/Windows/Shell32/Interop.SHGetKnownFolderPath.cs b/src/libraries/Common/src/Interop/Windows/Shell32/Interop.SHGetKnownFolderPath.cs
index 136d93f8e43e9f..80dd2826b40c5e 100644
--- a/src/libraries/Common/src/Interop/Windows/Shell32/Interop.SHGetKnownFolderPath.cs
+++ b/src/libraries/Common/src/Interop/Windows/Shell32/Interop.SHGetKnownFolderPath.cs
@@ -25,289 +25,339 @@ internal static class KnownFolders
/// (CSIDL_ADMINTOOLS) Per user Administrative Tools
/// "%APPDATA%\Microsoft\Windows\Start Menu\Programs\Administrative Tools"
///
- internal const string AdminTools = "{724EF170-A42D-4FEF-9F26-B60E846FBA4F}";
+ internal static Guid AdminTools =>
+ new(0x724EF170, 0xA42D, 0x4FEF, 0x9F, 0x26, 0xB6, 0x0E, 0x84, 0x6F, 0xBA, 0x4F);
///
/// (CSIDL_CDBURN_AREA) Temporary Burn folder
/// "%LOCALAPPDATA%\Microsoft\Windows\Burn\Burn"
///
- internal const string CDBurning = "{9E52AB10-F80D-49DF-ACB8-4330F5687855}";
+ internal static Guid CDBurning =>
+ new(0x9E52AB10, 0xF80D, 0x49DF, 0xAC, 0xB8, 0x43, 0x30, 0xF5, 0x68, 0x78, 0x55);
///
/// (CSIDL_COMMON_ADMINTOOLS) Common Administrative Tools
/// "%ALLUSERSPROFILE%\Microsoft\Windows\Start Menu\Programs\Administrative Tools"
///
- internal const string CommonAdminTools = "{D0384E7D-BAC3-4797-8F14-CBA229B392B5}";
+ internal static Guid CommonAdminTools =>
+ new(0xD0384E7D, 0xBAC3, 0x4797, 0x8F, 0x14, 0xCB, 0xA2, 0x29, 0xB3, 0x92, 0xB5);
///
/// (CSIDL_COMMON_OEM_LINKS) OEM Links folder
/// "%ALLUSERSPROFILE%\OEM Links"
///
- internal const string CommonOEMLinks = "{C1BAE2D0-10DF-4334-BEDD-7AA20B227A9D}";
+ internal static Guid CommonOEMLinks =>
+ new(0xC1BAE2D0, 0x10DF, 0x4334, 0xBE, 0xDD, 0x7A, 0xA2, 0x0B, 0x22, 0x7A, 0x9D);
///
/// (CSIDL_COMMON_PROGRAMS) Common Programs folder
/// "%ALLUSERSPROFILE%\Microsoft\Windows\Start Menu\Programs"
///
- internal const string CommonPrograms = "{0139D44E-6AFE-49F2-8690-3DAFCAE6FFB8}";
+ internal static Guid CommonPrograms =>
+ new(0x0139D44E, 0x6AFE, 0x49F2, 0x86, 0x90, 0x3D, 0xAF, 0xCA, 0xE6, 0xFF, 0xB8);
///
/// (CSIDL_COMMON_STARTMENU) Common Start Menu folder
/// "%ALLUSERSPROFILE%\Microsoft\Windows\Start Menu"
///
- internal const string CommonStartMenu = "{A4115719-D62E-491D-AA7C-E74B8BE3B067}";
+ internal static Guid CommonStartMenu =>
+ new(0xA4115719, 0xD62E, 0x491D, 0xAA, 0x7C, 0xE7, 0x4B, 0x8B, 0xE3, 0xB0, 0x67);
///
/// (CSIDL_COMMON_STARTUP, CSIDL_COMMON_ALTSTARTUP) Common Startup folder
/// "%ALLUSERSPROFILE%\Microsoft\Windows\Start Menu\Programs\StartUp"
///
- internal const string CommonStartup = "{82A5EA35-D9CD-47C5-9629-E15D2F714E6E}";
+ internal static Guid CommonStartup =>
+ new(0x82A5EA35, 0xD9CD, 0x47C5, 0x96, 0x29, 0xE1, 0x5D, 0x2F, 0x71, 0x4E, 0x6E);
///
/// (CSIDL_COMMON_TEMPLATES) Common Templates folder
/// "%ALLUSERSPROFILE%\Microsoft\Windows\Templates"
///
- internal const string CommonTemplates = "{B94237E7-57AC-4347-9151-B08C6C32D1F7}";
+ internal static Guid CommonTemplates =>
+ new(0xB94237E7, 0x57AC, 0x4347, 0x91, 0x51, 0xB0, 0x8C, 0x6C, 0x32, 0xD1, 0xF7);
///
/// (CSIDL_DRIVES) Computer virtual folder
///
- internal const string ComputerFolder = "{0AC0837C-BBF8-452A-850D-79D08E667CA7}";
+ internal static Guid ComputerFolder =>
+ new(0x0AC0837C, 0xBBF8, 0x452A, 0x85, 0x0D, 0x79, 0xD0, 0x8E, 0x66, 0x7C, 0xA7);
///
/// (CSIDL_CONNECTIONS) Network Connections virtual folder
///
- internal const string ConnectionsFolder = "{6F0CD92B-2E97-45D1-88FF-B0D186B8DEDD}";
+ internal static Guid ConnectionsFolder =>
+ new(0x6F0CD92B, 0x2E97, 0x45D1, 0x88, 0xFF, 0xB0, 0xD1, 0x86, 0xB8, 0xDE, 0xDD);
///
/// (CSIDL_CONTROLS) Control Panel virtual folder
///
- internal const string ControlPanelFolder = "{82A74AEB-AEB4-465C-A014-D097EE346D63}";
+ internal static Guid ControlPanelFolder =>
+ new(0x82A74AEB, 0xAEB4, 0x465C, 0xA0, 0x14, 0xD0, 0x97, 0xEE, 0x34, 0x6D, 0x63);
///
/// (CSIDL_COOKIES) Cookies folder
/// "%APPDATA%\Microsoft\Windows\Cookies"
///
- internal const string Cookies = "{2B0F765D-C0E9-4171-908E-08A611B84FF6}";
+ internal static Guid Cookies =>
+ new(0x2B0F765D, 0xC0E9, 0x4171, 0x90, 0x8E, 0x08, 0xA6, 0x11, 0xB8, 0x4F, 0xF6);
///
/// (CSIDL_DESKTOP, CSIDL_DESKTOPDIRECTORY) Desktop folder
/// "%USERPROFILE%\Desktop"
///
- internal const string Desktop = "{B4BFCC3A-DB2C-424C-B029-7FE99A87C641}";
+ internal static Guid Desktop =>
+ new(0xB4BFCC3A, 0xDB2C, 0x424C, 0xB0, 0x29, 0x7F, 0xE9, 0x9A, 0x87, 0xC6, 0x41);
///
/// (CSIDL_MYDOCUMENTS, CSIDL_PERSONAL) Documents (My Documents) folder
/// "%USERPROFILE%\Documents"
///
- internal const string Documents = "{FDD39AD0-238F-46AF-ADB4-6C85480369C7}";
+ internal static Guid Documents =>
+ new(0xFDD39AD0, 0x238F, 0x46AF, 0xAD, 0xB4, 0x6C, 0x85, 0x48, 0x03, 0x69, 0xC7);
///
/// (CSIDL_FAVORITES, CSIDL_COMMON_FAVORITES) Favorites folder
/// "%USERPROFILE%\Favorites"
///
- internal const string Favorites = "{1777F761-68AD-4D8A-87BD-30B759FA33DD}";
+ internal static Guid Favorites =>
+ new(0x1777F761, 0x68AD, 0x4D8A, 0x87, 0xBD, 0x30, 0xB7, 0x59, 0xFA, 0x33, 0xDD);
///
/// (CSIDL_FONTS) Fonts folder
/// "%windir%\Fonts"
///
- internal const string Fonts = "{FD228CB7-AE11-4AE3-864C-16F3910AB8FE}";
+ internal static Guid Fonts =>
+ new(0xFD228CB7, 0xAE11, 0x4AE3, 0x86, 0x4C, 0x16, 0xF3, 0x91, 0x0A, 0xB8, 0xFE);
///
/// (CSIDL_HISTORY) History folder
/// "%LOCALAPPDATA%\Microsoft\Windows\History"
///
- internal const string History = "{D9DC8A3B-B784-432E-A781-5A1130A75963}";
+ internal static Guid History =>
+ new(0xD9DC8A3B, 0xB784, 0x432E, 0xA7, 0x81, 0x5A, 0x11, 0x30, 0xA7, 0x59, 0x63);
///
/// (CSIDL_INTERNET_CACHE) Temporary Internet Files folder
/// "%LOCALAPPDATA%\Microsoft\Windows\Temporary Internet Files"
///
- internal const string InternetCache = "{352481E8-33BE-4251-BA85-6007CAEDCF9D}";
+ internal static Guid InternetCache =>
+ new(0x352481E8, 0x33BE, 0x4251, 0xBA, 0x85, 0x60, 0x07, 0xCA, 0xED, 0xCF, 0x9D);
///
/// (CSIDL_INTERNET) The Internet virtual folder
///
- internal const string InternetFolder = "{4D9F7874-4E0C-4904-967B-40B0D20C3E4B}";
+ internal static Guid InternetFolder =>
+ new(0x4D9F7874, 0x4E0C, 0x4904, 0x96, 0x7B, 0x40, 0xB0, 0xD2, 0x0C, 0x3E, 0x4B);
///
/// (CSIDL_LOCAL_APPDATA) Local folder
/// "%LOCALAPPDATA%" ("%USERPROFILE%\AppData\Local")
///
- internal const string LocalAppData = "{F1B32785-6FBA-4FCF-9D55-7B8E7F157091}";
+ internal static Guid LocalAppData =>
+ new(0xF1B32785, 0x6FBA, 0x4FCF, 0x9D, 0x55, 0x7B, 0x8E, 0x7F, 0x15, 0x70, 0x91);
///
/// (CSIDL_RESOURCES_LOCALIZED) Fixed localized resources folder
/// "%windir%\resources\0409" (per active codepage)
///
- internal const string LocalizedResourcesDir = "{2A00375E-224C-49DE-B8D1-440DF7EF3DDC}";
+ internal static Guid LocalizedResourcesDir =>
+ new(0x2A00375E, 0x224C, 0x49DE, 0xB8, 0xD1, 0x44, 0x0D, 0xF7, 0xEF, 0x3D, 0xDC);
///
/// (CSIDL_MYMUSIC) Music folder
/// "%USERPROFILE%\Music"
///
- internal const string Music = "{4BD8D571-6D19-48D3-BE97-422220080E43}";
+ internal static Guid Music =>
+ new(0x4BD8D571, 0x6D19, 0x48D3, 0xBE, 0x97, 0x42, 0x22, 0x20, 0x08, 0x0E, 0x43);
///
/// (CSIDL_NETHOOD) Network shortcuts folder "%APPDATA%\Microsoft\Windows\Network Shortcuts"
///
- internal const string NetHood = "{C5ABBF53-E17F-4121-8900-86626FC2C973}";
+ internal static Guid NetHood =>
+ new(0xC5ABBF53, 0xE17F, 0x4121, 0x89, 0x00, 0x86, 0x62, 0x6F, 0xC2, 0xC9, 0x73);
///
/// (CSIDL_NETWORK, CSIDL_COMPUTERSNEARME) Network virtual folder
///
- internal const string NetworkFolder = "{D20BEEC4-5CA8-4905-AE3B-BF251EA09B53}";
+ internal static Guid NetworkFolder =>
+ new(0xD20BEEC4, 0x5CA8, 0x4905, 0xAE, 0x3B, 0xBF, 0x25, 0x1E, 0xA0, 0x9B, 0x53);
///
/// (CSIDL_MYPICTURES) Pictures folder "%USERPROFILE%\Pictures"
///
- internal const string Pictures = "{33E28130-4E1E-4676-835A-98395C3BC3BB}";
+ internal static Guid Pictures =>
+ new(0x33E28130, 0x4E1E, 0x4676, 0x83, 0x5A, 0x98, 0x39, 0x5C, 0x3B, 0xC3, 0xBB);
///
/// (CSIDL_PRINTERS) Printers virtual folder
///
- internal const string PrintersFolder = "{76FC4E2D-D6AD-4519-A663-37BD56068185}";
+ internal static Guid PrintersFolder =>
+ new(0x76FC4E2D, 0xD6AD, 0x4519, 0xA6, 0x63, 0x37, 0xBD, 0x56, 0x06, 0x81, 0x85);
///
/// (CSIDL_PRINTHOOD) Printer Shortcuts folder
/// "%APPDATA%\Microsoft\Windows\Printer Shortcuts"
///
- internal const string PrintHood = "{9274BD8D-CFD1-41C3-B35E-B13F55A758F4}";
+ internal static Guid PrintHood =>
+ new(0x9274BD8D, 0xCFD1, 0x41C3, 0xB3, 0x5E, 0xB1, 0x3F, 0x55, 0xA7, 0x58, 0xF4);
///
/// (CSIDL_PROFILE) The root users profile folder "%USERPROFILE%"
/// ("%SystemDrive%\Users\%USERNAME%")
///
- internal const string Profile = "{5E6C858F-0E22-4760-9AFE-EA3317B67173}";
+ internal static Guid Profile =>
+ new(0x5E6C858F, 0x0E22, 0x4760, 0x9A, 0xFE, 0xEA, 0x33, 0x17, 0xB6, 0x71, 0x73);
///
/// (CSIDL_COMMON_APPDATA) ProgramData folder
/// "%ALLUSERSPROFILE%" ("%ProgramData%", "%SystemDrive%\ProgramData")
///
- internal const string ProgramData = "{62AB5D82-FDC1-4DC3-A9DD-070D1D495D97}";
+ internal static Guid ProgramData =>
+ new(0x62AB5D82, 0xFDC1, 0x4DC3, 0xA9, 0xDD, 0x07, 0x0D, 0x1D, 0x49, 0x5D, 0x97);
///
/// (CSIDL_PROGRAM_FILES) Program Files folder for the current process architecture
/// "%ProgramFiles%" ("%SystemDrive%\Program Files")
///
- internal const string ProgramFiles = "{905e63b6-c1bf-494e-b29c-65b732d3d21a}";
+ internal static Guid ProgramFiles =>
+ new(0x905e63b6, 0xc1bf, 0x494e, 0xb2, 0x9c, 0x65, 0xb7, 0x32, 0xd3, 0xd2, 0x1a);
///
/// (CSIDL_PROGRAM_FILESX86) 32 bit Program Files folder (available to both 32/64 bit processes)
///
- internal const string ProgramFilesX86 = "{7C5A40EF-A0FB-4BFC-874A-C0F2E0B9FA8E}";
+ internal static Guid ProgramFilesX86 =>
+ new(0x7C5A40EF, 0xA0FB, 0x4BFC, 0x87, 0x4A, 0xC0, 0xF2, 0xE0, 0xB9, 0xFA, 0x8E);
///
/// (CSIDL_PROGRAM_FILES_COMMON) Common Program Files folder for the current process architecture
/// "%ProgramFiles%\Common Files"
///
- internal const string ProgramFilesCommon = "{F7F1ED05-9F6D-47A2-AAAE-29D317C6F066}";
+ internal static Guid ProgramFilesCommon =>
+ new(0xF7F1ED05, 0x9F6D, 0x47A2, 0xAA, 0xAE, 0x29, 0xD3, 0x17, 0xC6, 0xF0, 0x66);
///
/// (CSIDL_PROGRAM_FILES_COMMONX86) Common 32 bit Program Files folder (available to both 32/64 bit processes)
///
- internal const string ProgramFilesCommonX86 = "{DE974D24-D9C6-4D3E-BF91-F4455120B917}";
+ internal static Guid ProgramFilesCommonX86 =>
+ new(0xDE974D24, 0xD9C6, 0x4D3E, 0xBF, 0x91, 0xF4, 0x45, 0x51, 0x20, 0xB9, 0x17);
///
/// (CSIDL_PROGRAMS) Start menu Programs folder
/// "%APPDATA%\Microsoft\Windows\Start Menu\Programs"
///
- internal const string Programs = "{A77F5D77-2E2B-44C3-A6A2-ABA601054A51}";
+ internal static Guid Programs =>
+ new(0xA77F5D77, 0x2E2B, 0x44C3, 0xA6, 0xA2, 0xAB, 0xA6, 0x01, 0x05, 0x4A, 0x51);
///
/// (CSIDL_COMMON_DESKTOPDIRECTORY) Public Desktop folder
/// "%PUBLIC%\Desktop"
///
- internal const string PublicDesktop = "{C4AA340D-F20F-4863-AFEF-F87EF2E6BA25}";
+ internal static Guid PublicDesktop =>
+ new(0xC4AA340D, 0xF20F, 0x4863, 0xAF, 0xEF, 0xF8, 0x7E, 0xF2, 0xE6, 0xBA, 0x25);
///
/// (CSIDL_COMMON_DOCUMENTS) Public Documents folder
/// "%PUBLIC%\Documents"
///
- internal const string PublicDocuments = "{ED4824AF-DCE4-45A8-81E2-FC7965083634}";
+ internal static Guid PublicDocuments =>
+ new(0xED4824AF, 0xDCE4, 0x45A8, 0x81, 0xE2, 0xFC, 0x79, 0x65, 0x08, 0x36, 0x34);
///
/// (CSIDL_COMMON_MUSIC) Public Music folder
/// "%PUBLIC%\Music"
///
- internal const string PublicMusic = "{3214FAB5-9757-4298-BB61-92A9DEAA44FF}";
+ internal static Guid PublicMusic =>
+ new(0x3214FAB5, 0x9757, 0x4298, 0xBB, 0x61, 0x92, 0xA9, 0xDE, 0xAA, 0x44, 0xFF);
///
/// (CSIDL_COMMON_PICTURES) Public Pictures folder
/// "%PUBLIC%\Pictures"
///
- internal const string PublicPictures = "{B6EBFB86-6907-413C-9AF7-4FC2ABF07CC5}";
+ internal static Guid PublicPictures =>
+ new(0xB6EBFB86, 0x6907, 0x413C, 0x9A, 0xF7, 0x4F, 0xC2, 0xAB, 0xF0, 0x7C, 0xC5);
///
/// (CSIDL_COMMON_VIDEO) Public Videos folder
/// "%PUBLIC%\Videos"
///
- internal const string PublicVideos = "{2400183A-6185-49FB-A2D8-4A392A602BA3}";
+ internal static Guid PublicVideos =>
+ new(0x2400183A, 0x6185, 0x49FB, 0xA2, 0xD8, 0x4A, 0x39, 0x2A, 0x60, 0x2B, 0xA3);
///
/// (CSIDL_RECENT) Recent Items folder
/// "%APPDATA%\Microsoft\Windows\Recent"
///
- internal const string Recent = "{AE50C081-EBD2-438A-8655-8A092E34987A}";
+ internal static Guid Recent =>
+ new(0xAE50C081, 0xEBD2, 0x438A, 0x86, 0x55, 0x8A, 0x09, 0x2E, 0x34, 0x98, 0x7A);
///
/// (CSIDL_BITBUCKET) Recycle Bin virtual folder
///
- internal const string RecycleBinFolder = "{B7534046-3ECB-4C18-BE4E-64CD4CB7D6AC}";
+ internal static Guid RecycleBinFolder =>
+ new(0xB7534046, 0x3ECB, 0x4C18, 0xBE, 0x4E, 0x64, 0xCD, 0x4C, 0xB7, 0xD6, 0xAC);
///
/// (CSIDL_RESOURCES) Resources fixed folder
/// "%windir%\Resources"
///
- internal const string ResourceDir = "{8AD10C31-2ADB-4296-A8F7-E4701232C972}";
+ internal static Guid ResourceDir =>
+ new(0x8AD10C31, 0x2ADB, 0x4296, 0xA8, 0xF7, 0xE4, 0x70, 0x12, 0x32, 0xC9, 0x72);
///
/// (CSIDL_APPDATA) Roaming user application data folder
/// "%APPDATA%" ("%USERPROFILE%\AppData\Roaming")
///
- internal const string RoamingAppData = "{3EB685DB-65F9-4CF6-A03A-E3EF65729F3D}";
+ internal static Guid RoamingAppData =>
+ new(0x3EB685DB, 0x65F9, 0x4CF6, 0xA0, 0x3A, 0xE3, 0xEF, 0x65, 0x72, 0x9F, 0x3D);
///
/// (CSIDL_SENDTO) SendTo folder
/// "%APPDATA%\Microsoft\Windows\SendTo"
///
- internal const string SendTo = "{8983036C-27C0-404B-8F08-102D10DCFD74}";
+ internal static Guid SendTo =>
+ new(0x8983036C, 0x27C0, 0x404B, 0x8F, 0x08, 0x10, 0x2D, 0x10, 0xDC, 0xFD, 0x74);
///
/// (CSIDL_STARTMENU) Start Menu folder
/// "%APPDATA%\Microsoft\Windows\Start Menu"
///
- internal const string StartMenu = "{625B53C3-AB48-4EC1-BA1F-A1EF4146FC19}";
+ internal static Guid StartMenu =>
+ new(0x625B53C3, 0xAB48, 0x4EC1, 0xBA, 0x1F, 0xA1, 0xEF, 0x41, 0x46, 0xFC, 0x19);
///
/// (CSIDL_STARTUP, CSIDL_ALTSTARTUP) Startup folder
/// "%APPDATA%\Microsoft\Windows\Start Menu\Programs\StartUp"
///
- internal const string Startup = "{B97D20BB-F46A-4C97-BA10-5E3608430854}";
+ internal static Guid Startup =>
+ new(0xB97D20BB, 0xF46A, 0x4C97, 0xBA, 0x10, 0x5E, 0x36, 0x08, 0x43, 0x08, 0x54);
///
/// (CSIDL_SYSTEMX86) X86 System32 folder
/// "%windir%\system32" or "%windir%\syswow64"
///
- internal const string SystemX86 = "{D65231B0-B2F1-4857-A4CE-A8E7C6EA7D27}";
+ internal static Guid SystemX86 =>
+ new(0xD65231B0, 0xB2F1, 0x4857, 0xA4, 0xCE, 0xA8, 0xE7, 0xC6, 0xEA, 0x7D, 0x27);
///
/// (CSIDL_TEMPLATES) Templates folder
/// "%APPDATA%\Microsoft\Windows\Templates"
///
- internal const string Templates = "{A63293E8-664E-48DB-A079-DF759E0509F7}";
+ internal static Guid Templates =>
+ new(0xA63293E8, 0x664E, 0x48DB, 0xA0, 0x79, 0xDF, 0x75, 0x9E, 0x05, 0x09, 0xF7);
///
/// (CSIDL_MYVIDEO) Videos folder
/// "%USERPROFILE%\Videos"
///
- internal const string Videos = "{18989B1D-99B5-455B-841C-AB7C74E4DDFC}";
+ internal static Guid Videos =>
+ new(0x18989B1D, 0x99B5, 0x455B, 0x84, 0x1C, 0xAB, 0x7C, 0x74, 0xE4, 0xDD, 0xFC);
///
/// (CSIDL_WINDOWS) Windows folder "%windir%"
///
- internal const string Windows = "{F38BF404-1D43-42F2-9305-67DE0B28FC23}";
+ internal static Guid Windows =>
+ new(0xF38BF404, 0x1D43, 0x42F2, 0x93, 0x05, 0x67, 0xDE, 0x0B, 0x28, 0xFC, 0x23);
}
}
}
diff --git a/src/libraries/System.Private.CoreLib/src/System/Environment.Win32.cs b/src/libraries/System.Private.CoreLib/src/System/Environment.Win32.cs
index 70069ba483e1b5..fbd990ea25f597 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Environment.Win32.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Environment.Win32.cs
@@ -216,7 +216,7 @@ private static string GetFolderPathCore(SpecialFolder folder, SpecialFolderOptio
//
// The only SpecialFolderOption defines we have are equivalent to KnownFolderFlags.
- string folderGuid;
+ Guid folderId;
string? fallbackEnv = null;
switch (folder)
{
@@ -229,154 +229,153 @@ private static string GetFolderPathCore(SpecialFolder folder, SpecialFolderOptio
// Map the SpecialFolder to the appropriate Guid
case SpecialFolder.ApplicationData:
- folderGuid = Interop.Shell32.KnownFolders.RoamingAppData;
+ folderId = Interop.Shell32.KnownFolders.RoamingAppData;
fallbackEnv = "APPDATA";
break;
case SpecialFolder.CommonApplicationData:
- folderGuid = Interop.Shell32.KnownFolders.ProgramData;
+ folderId = Interop.Shell32.KnownFolders.ProgramData;
fallbackEnv = "ProgramData";
break;
case SpecialFolder.LocalApplicationData:
- folderGuid = Interop.Shell32.KnownFolders.LocalAppData;
+ folderId = Interop.Shell32.KnownFolders.LocalAppData;
fallbackEnv = "LOCALAPPDATA";
break;
case SpecialFolder.Cookies:
- folderGuid = Interop.Shell32.KnownFolders.Cookies;
+ folderId = Interop.Shell32.KnownFolders.Cookies;
break;
case SpecialFolder.Desktop:
- folderGuid = Interop.Shell32.KnownFolders.Desktop;
+ folderId = Interop.Shell32.KnownFolders.Desktop;
break;
case SpecialFolder.Favorites:
- folderGuid = Interop.Shell32.KnownFolders.Favorites;
+ folderId = Interop.Shell32.KnownFolders.Favorites;
break;
case SpecialFolder.History:
- folderGuid = Interop.Shell32.KnownFolders.History;
+ folderId = Interop.Shell32.KnownFolders.History;
break;
case SpecialFolder.InternetCache:
- folderGuid = Interop.Shell32.KnownFolders.InternetCache;
+ folderId = Interop.Shell32.KnownFolders.InternetCache;
break;
case SpecialFolder.Programs:
- folderGuid = Interop.Shell32.KnownFolders.Programs;
+ folderId = Interop.Shell32.KnownFolders.Programs;
break;
case SpecialFolder.MyComputer:
- folderGuid = Interop.Shell32.KnownFolders.ComputerFolder;
+ folderId = Interop.Shell32.KnownFolders.ComputerFolder;
break;
case SpecialFolder.MyMusic:
- folderGuid = Interop.Shell32.KnownFolders.Music;
+ folderId = Interop.Shell32.KnownFolders.Music;
break;
case SpecialFolder.MyPictures:
- folderGuid = Interop.Shell32.KnownFolders.Pictures;
+ folderId = Interop.Shell32.KnownFolders.Pictures;
break;
case SpecialFolder.MyVideos:
- folderGuid = Interop.Shell32.KnownFolders.Videos;
+ folderId = Interop.Shell32.KnownFolders.Videos;
break;
case SpecialFolder.Recent:
- folderGuid = Interop.Shell32.KnownFolders.Recent;
+ folderId = Interop.Shell32.KnownFolders.Recent;
break;
case SpecialFolder.SendTo:
- folderGuid = Interop.Shell32.KnownFolders.SendTo;
+ folderId = Interop.Shell32.KnownFolders.SendTo;
break;
case SpecialFolder.StartMenu:
- folderGuid = Interop.Shell32.KnownFolders.StartMenu;
+ folderId = Interop.Shell32.KnownFolders.StartMenu;
break;
case SpecialFolder.Startup:
- folderGuid = Interop.Shell32.KnownFolders.Startup;
+ folderId = Interop.Shell32.KnownFolders.Startup;
break;
case SpecialFolder.Templates:
- folderGuid = Interop.Shell32.KnownFolders.Templates;
+ folderId = Interop.Shell32.KnownFolders.Templates;
break;
case SpecialFolder.DesktopDirectory:
- folderGuid = Interop.Shell32.KnownFolders.Desktop;
+ folderId = Interop.Shell32.KnownFolders.Desktop;
break;
case SpecialFolder.Personal:
// Same as Personal
// case SpecialFolder.MyDocuments:
- folderGuid = Interop.Shell32.KnownFolders.Documents;
+ folderId = Interop.Shell32.KnownFolders.Documents;
break;
case SpecialFolder.ProgramFiles:
- folderGuid = Interop.Shell32.KnownFolders.ProgramFiles;
+ folderId = Interop.Shell32.KnownFolders.ProgramFiles;
fallbackEnv = "ProgramFiles";
break;
case SpecialFolder.CommonProgramFiles:
- folderGuid = Interop.Shell32.KnownFolders.ProgramFilesCommon;
+ folderId = Interop.Shell32.KnownFolders.ProgramFilesCommon;
fallbackEnv = "CommonProgramFiles";
break;
case SpecialFolder.AdminTools:
- folderGuid = Interop.Shell32.KnownFolders.AdminTools;
+ folderId = Interop.Shell32.KnownFolders.AdminTools;
break;
case SpecialFolder.CDBurning:
- folderGuid = Interop.Shell32.KnownFolders.CDBurning;
+ folderId = Interop.Shell32.KnownFolders.CDBurning;
break;
case SpecialFolder.CommonAdminTools:
- folderGuid = Interop.Shell32.KnownFolders.CommonAdminTools;
+ folderId = Interop.Shell32.KnownFolders.CommonAdminTools;
break;
case SpecialFolder.CommonDocuments:
- folderGuid = Interop.Shell32.KnownFolders.PublicDocuments;
+ folderId = Interop.Shell32.KnownFolders.PublicDocuments;
break;
case SpecialFolder.CommonMusic:
- folderGuid = Interop.Shell32.KnownFolders.PublicMusic;
+ folderId = Interop.Shell32.KnownFolders.PublicMusic;
break;
case SpecialFolder.CommonOemLinks:
- folderGuid = Interop.Shell32.KnownFolders.CommonOEMLinks;
+ folderId = Interop.Shell32.KnownFolders.CommonOEMLinks;
break;
case SpecialFolder.CommonPictures:
- folderGuid = Interop.Shell32.KnownFolders.PublicPictures;
+ folderId = Interop.Shell32.KnownFolders.PublicPictures;
break;
case SpecialFolder.CommonStartMenu:
- folderGuid = Interop.Shell32.KnownFolders.CommonStartMenu;
+ folderId = Interop.Shell32.KnownFolders.CommonStartMenu;
break;
case SpecialFolder.CommonPrograms:
- folderGuid = Interop.Shell32.KnownFolders.CommonPrograms;
+ folderId = Interop.Shell32.KnownFolders.CommonPrograms;
break;
case SpecialFolder.CommonStartup:
- folderGuid = Interop.Shell32.KnownFolders.CommonStartup;
+ folderId = Interop.Shell32.KnownFolders.CommonStartup;
break;
case SpecialFolder.CommonDesktopDirectory:
- folderGuid = Interop.Shell32.KnownFolders.PublicDesktop;
+ folderId = Interop.Shell32.KnownFolders.PublicDesktop;
break;
case SpecialFolder.CommonTemplates:
- folderGuid = Interop.Shell32.KnownFolders.CommonTemplates;
+ folderId = Interop.Shell32.KnownFolders.CommonTemplates;
break;
case SpecialFolder.CommonVideos:
- folderGuid = Interop.Shell32.KnownFolders.PublicVideos;
+ folderId = Interop.Shell32.KnownFolders.PublicVideos;
break;
case SpecialFolder.Fonts:
- folderGuid = Interop.Shell32.KnownFolders.Fonts;
+ folderId = Interop.Shell32.KnownFolders.Fonts;
break;
case SpecialFolder.NetworkShortcuts:
- folderGuid = Interop.Shell32.KnownFolders.NetHood;
+ folderId = Interop.Shell32.KnownFolders.NetHood;
break;
case SpecialFolder.PrinterShortcuts:
- folderGuid = Interop.Shell32.KnownFolders.PrintersFolder;
+ folderId = Interop.Shell32.KnownFolders.PrintersFolder;
break;
case SpecialFolder.UserProfile:
- folderGuid = Interop.Shell32.KnownFolders.Profile;
+ folderId = Interop.Shell32.KnownFolders.Profile;
fallbackEnv = "USERPROFILE";
break;
case SpecialFolder.CommonProgramFilesX86:
- folderGuid = Interop.Shell32.KnownFolders.ProgramFilesCommonX86;
+ folderId = Interop.Shell32.KnownFolders.ProgramFilesCommonX86;
fallbackEnv = "CommonProgramFiles(x86)";
break;
case SpecialFolder.ProgramFilesX86:
- folderGuid = Interop.Shell32.KnownFolders.ProgramFilesX86;
+ folderId = Interop.Shell32.KnownFolders.ProgramFilesX86;
fallbackEnv = "ProgramFiles(x86)";
break;
case SpecialFolder.Resources:
- folderGuid = Interop.Shell32.KnownFolders.ResourceDir;
+ folderId = Interop.Shell32.KnownFolders.ResourceDir;
break;
case SpecialFolder.LocalizedResources:
- folderGuid = Interop.Shell32.KnownFolders.LocalizedResourcesDir;
+ folderId = Interop.Shell32.KnownFolders.LocalizedResourcesDir;
break;
case SpecialFolder.SystemX86:
- folderGuid = Interop.Shell32.KnownFolders.SystemX86;
+ folderId = Interop.Shell32.KnownFolders.SystemX86;
break;
case SpecialFolder.Windows:
- folderGuid = Interop.Shell32.KnownFolders.Windows;
+ folderId = Interop.Shell32.KnownFolders.Windows;
fallbackEnv = "windir";
break;
}
- Guid folderId = new Guid(folderGuid);
int hr = Interop.Shell32.SHGetKnownFolderPath(folderId, (uint)option, IntPtr.Zero, out string path);
if (hr == 0)
return path;
From 180f3702f146fc0b09d6153a85892bc60002ea80 Mon Sep 17 00:00:00 2001
From: xtqqczze <45661989+xtqqczze@users.noreply.github.com>
Date: Fri, 1 Aug 2025 03:07:04 +0100
Subject: [PATCH 2/6] Use ReadOnlySpan for GUIDs
---
.../Shell32/Interop.SHGetKnownFolderPath.cs | 200 +++++++++---------
.../src/System/Environment.Win32.cs | 93 ++++----
2 files changed, 147 insertions(+), 146 deletions(-)
diff --git a/src/libraries/Common/src/Interop/Windows/Shell32/Interop.SHGetKnownFolderPath.cs b/src/libraries/Common/src/Interop/Windows/Shell32/Interop.SHGetKnownFolderPath.cs
index 80dd2826b40c5e..f93a1a82d3a5c4 100644
--- a/src/libraries/Common/src/Interop/Windows/Shell32/Interop.SHGetKnownFolderPath.cs
+++ b/src/libraries/Common/src/Interop/Windows/Shell32/Interop.SHGetKnownFolderPath.cs
@@ -25,339 +25,339 @@ internal static class KnownFolders
/// (CSIDL_ADMINTOOLS) Per user Administrative Tools
/// "%APPDATA%\Microsoft\Windows\Start Menu\Programs\Administrative Tools"
///
- internal static Guid AdminTools =>
- new(0x724EF170, 0xA42D, 0x4FEF, 0x9F, 0x26, 0xB6, 0x0E, 0x84, 0x6F, 0xBA, 0x4F);
+ internal static ReadOnlySpan AdminTools =>
+ [0x72, 0x4E, 0xF1, 0x70, 0xA4, 0x2D, 0x4F, 0xEF, 0x9F, 0x26, 0xB6, 0x0E, 0x84, 0x6F, 0xBA, 0x4F];
///
/// (CSIDL_CDBURN_AREA) Temporary Burn folder
/// "%LOCALAPPDATA%\Microsoft\Windows\Burn\Burn"
///
- internal static Guid CDBurning =>
- new(0x9E52AB10, 0xF80D, 0x49DF, 0xAC, 0xB8, 0x43, 0x30, 0xF5, 0x68, 0x78, 0x55);
+ internal static ReadOnlySpan CDBurning =>
+ [0x9E, 0x52, 0xAB, 0x10, 0xF8, 0x0D, 0x49, 0xDF, 0xAC, 0xB8, 0x43, 0x30, 0xF5, 0x68, 0x78, 0x55];
///
/// (CSIDL_COMMON_ADMINTOOLS) Common Administrative Tools
/// "%ALLUSERSPROFILE%\Microsoft\Windows\Start Menu\Programs\Administrative Tools"
///
- internal static Guid CommonAdminTools =>
- new(0xD0384E7D, 0xBAC3, 0x4797, 0x8F, 0x14, 0xCB, 0xA2, 0x29, 0xB3, 0x92, 0xB5);
+ internal static ReadOnlySpan CommonAdminTools =>
+ [0xD0, 0x38, 0x4E, 0x7D, 0xBA, 0xC3, 0x47, 0x97, 0x8F, 0x14, 0xCB, 0xA2, 0x29, 0xB3, 0x92, 0xB5];
///
/// (CSIDL_COMMON_OEM_LINKS) OEM Links folder
/// "%ALLUSERSPROFILE%\OEM Links"
///
- internal static Guid CommonOEMLinks =>
- new(0xC1BAE2D0, 0x10DF, 0x4334, 0xBE, 0xDD, 0x7A, 0xA2, 0x0B, 0x22, 0x7A, 0x9D);
+ internal static ReadOnlySpan CommonOEMLinks =>
+ [0xC1, 0xBA, 0xE2, 0xD0, 0x10, 0xDF, 0x43, 0x34, 0xBE, 0xDD, 0x7A, 0xA2, 0x0B, 0x22, 0x7A, 0x9D];
///
/// (CSIDL_COMMON_PROGRAMS) Common Programs folder
/// "%ALLUSERSPROFILE%\Microsoft\Windows\Start Menu\Programs"
///
- internal static Guid CommonPrograms =>
- new(0x0139D44E, 0x6AFE, 0x49F2, 0x86, 0x90, 0x3D, 0xAF, 0xCA, 0xE6, 0xFF, 0xB8);
+ internal static ReadOnlySpan CommonPrograms =>
+ [0x01, 0x39, 0xD4, 0x4E, 0x6A, 0xFE, 0x49, 0xF2, 0x86, 0x90, 0x3D, 0xAF, 0xCA, 0xE6, 0xFF, 0xB8];
///
/// (CSIDL_COMMON_STARTMENU) Common Start Menu folder
/// "%ALLUSERSPROFILE%\Microsoft\Windows\Start Menu"
///
- internal static Guid CommonStartMenu =>
- new(0xA4115719, 0xD62E, 0x491D, 0xAA, 0x7C, 0xE7, 0x4B, 0x8B, 0xE3, 0xB0, 0x67);
+ internal static ReadOnlySpan CommonStartMenu =>
+ [0xA4, 0x11, 0x57, 0x19, 0xD6, 0x2E, 0x49, 0x1D, 0xAA, 0x7C, 0xE7, 0x4B, 0x8B, 0xE3, 0xB0, 0x67];
///
/// (CSIDL_COMMON_STARTUP, CSIDL_COMMON_ALTSTARTUP) Common Startup folder
/// "%ALLUSERSPROFILE%\Microsoft\Windows\Start Menu\Programs\StartUp"
///
- internal static Guid CommonStartup =>
- new(0x82A5EA35, 0xD9CD, 0x47C5, 0x96, 0x29, 0xE1, 0x5D, 0x2F, 0x71, 0x4E, 0x6E);
+ internal static ReadOnlySpan CommonStartup =>
+ [0x82, 0xA5, 0xEA, 0x35, 0xD9, 0xCD, 0x47, 0xC5, 0x96, 0x29, 0xE1, 0x5D, 0x2F, 0x71, 0x4E, 0x6E];
///
/// (CSIDL_COMMON_TEMPLATES) Common Templates folder
/// "%ALLUSERSPROFILE%\Microsoft\Windows\Templates"
///
- internal static Guid CommonTemplates =>
- new(0xB94237E7, 0x57AC, 0x4347, 0x91, 0x51, 0xB0, 0x8C, 0x6C, 0x32, 0xD1, 0xF7);
+ internal static ReadOnlySpan CommonTemplates =>
+ [0xB9, 0x42, 0x37, 0xE7, 0x57, 0xAC, 0x43, 0x47, 0x91, 0x51, 0xB0, 0x8C, 0x6C, 0x32, 0xD1, 0xF7];
///
/// (CSIDL_DRIVES) Computer virtual folder
///
- internal static Guid ComputerFolder =>
- new(0x0AC0837C, 0xBBF8, 0x452A, 0x85, 0x0D, 0x79, 0xD0, 0x8E, 0x66, 0x7C, 0xA7);
+ internal static ReadOnlySpan ComputerFolder =>
+ [0x0A, 0xC0, 0x83, 0x7C, 0xBB, 0xF8, 0x45, 0x2A, 0x85, 0x0D, 0x79, 0xD0, 0x8E, 0x66, 0x7C, 0xA7];
///
/// (CSIDL_CONNECTIONS) Network Connections virtual folder
///
- internal static Guid ConnectionsFolder =>
- new(0x6F0CD92B, 0x2E97, 0x45D1, 0x88, 0xFF, 0xB0, 0xD1, 0x86, 0xB8, 0xDE, 0xDD);
+ internal static ReadOnlySpan ConnectionsFolder =>
+ [0x6F, 0x0C, 0xD9, 0x2B, 0x2E, 0x97, 0x45, 0xD1, 0x88, 0xFF, 0xB0, 0xD1, 0x86, 0xB8, 0xDE, 0xDD];
///
/// (CSIDL_CONTROLS) Control Panel virtual folder
///
- internal static Guid ControlPanelFolder =>
- new(0x82A74AEB, 0xAEB4, 0x465C, 0xA0, 0x14, 0xD0, 0x97, 0xEE, 0x34, 0x6D, 0x63);
+ internal static ReadOnlySpan ControlPanelFolder =>
+ [0x82, 0xA7, 0x4A, 0xEB, 0xAE, 0xB4, 0x46, 0x5C, 0xA0, 0x14, 0xD0, 0x97, 0xEE, 0x34, 0x6D, 0x63];
///
/// (CSIDL_COOKIES) Cookies folder
/// "%APPDATA%\Microsoft\Windows\Cookies"
///
- internal static Guid Cookies =>
- new(0x2B0F765D, 0xC0E9, 0x4171, 0x90, 0x8E, 0x08, 0xA6, 0x11, 0xB8, 0x4F, 0xF6);
+ internal static ReadOnlySpan Cookies =>
+ [0x2B, 0x0F, 0x76, 0x5D, 0xC0, 0xE9, 0x41, 0x71, 0x90, 0x8E, 0x08, 0xA6, 0x11, 0xB8, 0x4F, 0xF6];
///
/// (CSIDL_DESKTOP, CSIDL_DESKTOPDIRECTORY) Desktop folder
/// "%USERPROFILE%\Desktop"
///
- internal static Guid Desktop =>
- new(0xB4BFCC3A, 0xDB2C, 0x424C, 0xB0, 0x29, 0x7F, 0xE9, 0x9A, 0x87, 0xC6, 0x41);
+ internal static ReadOnlySpan Desktop =>
+ [0xB4, 0xBF, 0xCC, 0x3A, 0xDB, 0x2C, 0x42, 0x4C, 0xB0, 0x29, 0x7F, 0xE9, 0x9A, 0x87, 0xC6, 0x41];
///
/// (CSIDL_MYDOCUMENTS, CSIDL_PERSONAL) Documents (My Documents) folder
/// "%USERPROFILE%\Documents"
///
- internal static Guid Documents =>
- new(0xFDD39AD0, 0x238F, 0x46AF, 0xAD, 0xB4, 0x6C, 0x85, 0x48, 0x03, 0x69, 0xC7);
+ internal static ReadOnlySpan Documents =>
+ [0xFD, 0xD3, 0x9A, 0xD0, 0x23, 0x8F, 0x46, 0xAF, 0xAD, 0xB4, 0x6C, 0x85, 0x48, 0x03, 0x69, 0xC7];
///
/// (CSIDL_FAVORITES, CSIDL_COMMON_FAVORITES) Favorites folder
/// "%USERPROFILE%\Favorites"
///
- internal static Guid Favorites =>
- new(0x1777F761, 0x68AD, 0x4D8A, 0x87, 0xBD, 0x30, 0xB7, 0x59, 0xFA, 0x33, 0xDD);
+ internal static ReadOnlySpan Favorites =>
+ [0x17, 0x77, 0xF7, 0x61, 0x68, 0xAD, 0x4D, 0x8A, 0x87, 0xBD, 0x30, 0xB7, 0x59, 0xFA, 0x33, 0xDD];
///
/// (CSIDL_FONTS) Fonts folder
/// "%windir%\Fonts"
///
- internal static Guid Fonts =>
- new(0xFD228CB7, 0xAE11, 0x4AE3, 0x86, 0x4C, 0x16, 0xF3, 0x91, 0x0A, 0xB8, 0xFE);
+ internal static ReadOnlySpan Fonts =>
+ [0xFD, 0x22, 0x8C, 0xB7, 0xAE, 0x11, 0x4A, 0xE3, 0x86, 0x4C, 0x16, 0xF3, 0x91, 0x0A, 0xB8, 0xFE];
///
/// (CSIDL_HISTORY) History folder
/// "%LOCALAPPDATA%\Microsoft\Windows\History"
///
- internal static Guid History =>
- new(0xD9DC8A3B, 0xB784, 0x432E, 0xA7, 0x81, 0x5A, 0x11, 0x30, 0xA7, 0x59, 0x63);
+ internal static ReadOnlySpan History =>
+ [0xD9, 0xDC, 0x8A, 0x3B, 0xB7, 0x84, 0x43, 0x2E, 0xA7, 0x81, 0x5A, 0x11, 0x30, 0xA7, 0x59, 0x63];
///
/// (CSIDL_INTERNET_CACHE) Temporary Internet Files folder
/// "%LOCALAPPDATA%\Microsoft\Windows\Temporary Internet Files"
///
- internal static Guid InternetCache =>
- new(0x352481E8, 0x33BE, 0x4251, 0xBA, 0x85, 0x60, 0x07, 0xCA, 0xED, 0xCF, 0x9D);
+ internal static ReadOnlySpan InternetCache =>
+ [0x35, 0x24, 0x81, 0xE8, 0x33, 0xBE, 0x42, 0x51, 0xBA, 0x85, 0x60, 0x07, 0xCA, 0xED, 0xCF, 0x9D];
///
/// (CSIDL_INTERNET) The Internet virtual folder
///
- internal static Guid InternetFolder =>
- new(0x4D9F7874, 0x4E0C, 0x4904, 0x96, 0x7B, 0x40, 0xB0, 0xD2, 0x0C, 0x3E, 0x4B);
+ internal static ReadOnlySpan InternetFolder =>
+ [0x4D, 0x9F, 0x78, 0x74, 0x4E, 0x0C, 0x49, 0x04, 0x96, 0x7B, 0x40, 0xB0, 0xD2, 0x0C, 0x3E, 0x4B];
///
/// (CSIDL_LOCAL_APPDATA) Local folder
/// "%LOCALAPPDATA%" ("%USERPROFILE%\AppData\Local")
///
- internal static Guid LocalAppData =>
- new(0xF1B32785, 0x6FBA, 0x4FCF, 0x9D, 0x55, 0x7B, 0x8E, 0x7F, 0x15, 0x70, 0x91);
+ internal static ReadOnlySpan LocalAppData =>
+ [0xF1, 0xB3, 0x27, 0x85, 0x6F, 0xBA, 0x4F, 0xCF, 0x9D, 0x55, 0x7B, 0x8E, 0x7F, 0x15, 0x70, 0x91];
///
/// (CSIDL_RESOURCES_LOCALIZED) Fixed localized resources folder
/// "%windir%\resources\0409" (per active codepage)
///
- internal static Guid LocalizedResourcesDir =>
- new(0x2A00375E, 0x224C, 0x49DE, 0xB8, 0xD1, 0x44, 0x0D, 0xF7, 0xEF, 0x3D, 0xDC);
+ internal static ReadOnlySpan LocalizedResourcesDir =>
+ [0x2A, 0x00, 0x37, 0x5E, 0x22, 0x4C, 0x49, 0xDE, 0xB8, 0xD1, 0x44, 0x0D, 0xF7, 0xEF, 0x3D, 0xDC];
///
/// (CSIDL_MYMUSIC) Music folder
/// "%USERPROFILE%\Music"
///
- internal static Guid Music =>
- new(0x4BD8D571, 0x6D19, 0x48D3, 0xBE, 0x97, 0x42, 0x22, 0x20, 0x08, 0x0E, 0x43);
+ internal static ReadOnlySpan Music =>
+ [0x4B, 0xD8, 0xD5, 0x71, 0x6D, 0x19, 0x48, 0xD3, 0xBE, 0x97, 0x42, 0x22, 0x20, 0x08, 0x0E, 0x43];
///
/// (CSIDL_NETHOOD) Network shortcuts folder "%APPDATA%\Microsoft\Windows\Network Shortcuts"
///
- internal static Guid NetHood =>
- new(0xC5ABBF53, 0xE17F, 0x4121, 0x89, 0x00, 0x86, 0x62, 0x6F, 0xC2, 0xC9, 0x73);
+ internal static ReadOnlySpan NetHood =>
+ [0xC5, 0xAB, 0xBF, 0x53, 0xE1, 0x7F, 0x41, 0x21, 0x89, 0x00, 0x86, 0x62, 0x6F, 0xC2, 0xC9, 0x73];
///
/// (CSIDL_NETWORK, CSIDL_COMPUTERSNEARME) Network virtual folder
///
- internal static Guid NetworkFolder =>
- new(0xD20BEEC4, 0x5CA8, 0x4905, 0xAE, 0x3B, 0xBF, 0x25, 0x1E, 0xA0, 0x9B, 0x53);
+ internal static ReadOnlySpan NetworkFolder =>
+ [0xD2, 0x0B, 0xEE, 0xC4, 0x5C, 0xA8, 0x49, 0x05, 0xAE, 0x3B, 0xBF, 0x25, 0x1E, 0xA0, 0x9B, 0x53];
///
/// (CSIDL_MYPICTURES) Pictures folder "%USERPROFILE%\Pictures"
///
- internal static Guid Pictures =>
- new(0x33E28130, 0x4E1E, 0x4676, 0x83, 0x5A, 0x98, 0x39, 0x5C, 0x3B, 0xC3, 0xBB);
+ internal static ReadOnlySpan Pictures =>
+ [0x33, 0xE2, 0x81, 0x30, 0x4E, 0x1E, 0x46, 0x76, 0x83, 0x5A, 0x98, 0x39, 0x5C, 0x3B, 0xC3, 0xBB];
///
/// (CSIDL_PRINTERS) Printers virtual folder
///
- internal static Guid PrintersFolder =>
- new(0x76FC4E2D, 0xD6AD, 0x4519, 0xA6, 0x63, 0x37, 0xBD, 0x56, 0x06, 0x81, 0x85);
+ internal static ReadOnlySpan PrintersFolder =>
+ [0x76, 0xFC, 0x4E, 0x2D, 0xD6, 0xAD, 0x45, 0x19, 0xA6, 0x63, 0x37, 0xBD, 0x56, 0x06, 0x81, 0x85];
///
/// (CSIDL_PRINTHOOD) Printer Shortcuts folder
/// "%APPDATA%\Microsoft\Windows\Printer Shortcuts"
///
- internal static Guid PrintHood =>
- new(0x9274BD8D, 0xCFD1, 0x41C3, 0xB3, 0x5E, 0xB1, 0x3F, 0x55, 0xA7, 0x58, 0xF4);
+ internal static ReadOnlySpan PrintHood =>
+ [0x92, 0x74, 0xBD, 0x8D, 0xCF, 0xD1, 0x41, 0xC3, 0xB3, 0x5E, 0xB1, 0x3F, 0x55, 0xA7, 0x58, 0xF4];
///
/// (CSIDL_PROFILE) The root users profile folder "%USERPROFILE%"
/// ("%SystemDrive%\Users\%USERNAME%")
///
- internal static Guid Profile =>
- new(0x5E6C858F, 0x0E22, 0x4760, 0x9A, 0xFE, 0xEA, 0x33, 0x17, 0xB6, 0x71, 0x73);
+ internal static ReadOnlySpan Profile =>
+ [0x5E, 0x6C, 0x85, 0x8F, 0x0E, 0x22, 0x47, 0x60, 0x9A, 0xFE, 0xEA, 0x33, 0x17, 0xB6, 0x71, 0x73];
///
/// (CSIDL_COMMON_APPDATA) ProgramData folder
/// "%ALLUSERSPROFILE%" ("%ProgramData%", "%SystemDrive%\ProgramData")
///
- internal static Guid ProgramData =>
- new(0x62AB5D82, 0xFDC1, 0x4DC3, 0xA9, 0xDD, 0x07, 0x0D, 0x1D, 0x49, 0x5D, 0x97);
+ internal static ReadOnlySpan ProgramData =>
+ [0x62, 0xAB, 0x5D, 0x82, 0xFD, 0xC1, 0x4D, 0xC3, 0xA9, 0xDD, 0x07, 0x0D, 0x1D, 0x49, 0x5D, 0x97];
///
/// (CSIDL_PROGRAM_FILES) Program Files folder for the current process architecture
/// "%ProgramFiles%" ("%SystemDrive%\Program Files")
///
- internal static Guid ProgramFiles =>
- new(0x905e63b6, 0xc1bf, 0x494e, 0xb2, 0x9c, 0x65, 0xb7, 0x32, 0xd3, 0xd2, 0x1a);
+ internal static ReadOnlySpan ProgramFiles =>
+ [0x90, 0x5e, 0x63, 0xb6, 0xc1, 0xbf, 0x49, 0x4e, 0xb2, 0x9c, 0x65, 0xb7, 0x32, 0xd3, 0xd2, 0x1a];
///
/// (CSIDL_PROGRAM_FILESX86) 32 bit Program Files folder (available to both 32/64 bit processes)
///
- internal static Guid ProgramFilesX86 =>
- new(0x7C5A40EF, 0xA0FB, 0x4BFC, 0x87, 0x4A, 0xC0, 0xF2, 0xE0, 0xB9, 0xFA, 0x8E);
+ internal static ReadOnlySpan ProgramFilesX86 =>
+ [0x7C, 0x5A, 0x40, 0xEF, 0xA0, 0xFB, 0x4B, 0xFC, 0x87, 0x4A, 0xC0, 0xF2, 0xE0, 0xB9, 0xFA, 0x8E];
///
/// (CSIDL_PROGRAM_FILES_COMMON) Common Program Files folder for the current process architecture
/// "%ProgramFiles%\Common Files"
///
- internal static Guid ProgramFilesCommon =>
- new(0xF7F1ED05, 0x9F6D, 0x47A2, 0xAA, 0xAE, 0x29, 0xD3, 0x17, 0xC6, 0xF0, 0x66);
+ internal static ReadOnlySpan ProgramFilesCommon =>
+ [0xF7, 0xF1, 0xED, 0x05, 0x9F, 0x6D, 0x47, 0xA2, 0xAA, 0xAE, 0x29, 0xD3, 0x17, 0xC6, 0xF0, 0x66];
///
/// (CSIDL_PROGRAM_FILES_COMMONX86) Common 32 bit Program Files folder (available to both 32/64 bit processes)
///
- internal static Guid ProgramFilesCommonX86 =>
- new(0xDE974D24, 0xD9C6, 0x4D3E, 0xBF, 0x91, 0xF4, 0x45, 0x51, 0x20, 0xB9, 0x17);
+ internal static ReadOnlySpan ProgramFilesCommonX86 =>
+ [0xDE, 0x97, 0x4D, 0x24, 0xD9, 0xC6, 0x4D, 0x3E, 0xBF, 0x91, 0xF4, 0x45, 0x51, 0x20, 0xB9, 0x17];
///
/// (CSIDL_PROGRAMS) Start menu Programs folder
/// "%APPDATA%\Microsoft\Windows\Start Menu\Programs"
///
- internal static Guid Programs =>
- new(0xA77F5D77, 0x2E2B, 0x44C3, 0xA6, 0xA2, 0xAB, 0xA6, 0x01, 0x05, 0x4A, 0x51);
+ internal static ReadOnlySpan Programs =>
+ [0xA7, 0x7F, 0x5D, 0x77, 0x2E, 0x2B, 0x44, 0xC3, 0xA6, 0xA2, 0xAB, 0xA6, 0x01, 0x05, 0x4A, 0x51];
///
/// (CSIDL_COMMON_DESKTOPDIRECTORY) Public Desktop folder
/// "%PUBLIC%\Desktop"
///
- internal static Guid PublicDesktop =>
- new(0xC4AA340D, 0xF20F, 0x4863, 0xAF, 0xEF, 0xF8, 0x7E, 0xF2, 0xE6, 0xBA, 0x25);
+ internal static ReadOnlySpan PublicDesktop =>
+ [0xC4, 0xAA, 0x34, 0x0D, 0xF2, 0x0F, 0x48, 0x63, 0xAF, 0xEF, 0xF8, 0x7E, 0xF2, 0xE6, 0xBA, 0x25];
///
/// (CSIDL_COMMON_DOCUMENTS) Public Documents folder
/// "%PUBLIC%\Documents"
///
- internal static Guid PublicDocuments =>
- new(0xED4824AF, 0xDCE4, 0x45A8, 0x81, 0xE2, 0xFC, 0x79, 0x65, 0x08, 0x36, 0x34);
+ internal static ReadOnlySpan PublicDocuments =>
+ [0xED, 0x48, 0x24, 0xAF, 0xDC, 0xE4, 0x45, 0xA8, 0x81, 0xE2, 0xFC, 0x79, 0x65, 0x08, 0x36, 0x34];
///
/// (CSIDL_COMMON_MUSIC) Public Music folder
/// "%PUBLIC%\Music"
///
- internal static Guid PublicMusic =>
- new(0x3214FAB5, 0x9757, 0x4298, 0xBB, 0x61, 0x92, 0xA9, 0xDE, 0xAA, 0x44, 0xFF);
+ internal static ReadOnlySpan PublicMusic =>
+ [0x32, 0x14, 0xFA, 0xB5, 0x97, 0x57, 0x42, 0x98, 0xBB, 0x61, 0x92, 0xA9, 0xDE, 0xAA, 0x44, 0xFF];
///
/// (CSIDL_COMMON_PICTURES) Public Pictures folder
/// "%PUBLIC%\Pictures"
///
- internal static Guid PublicPictures =>
- new(0xB6EBFB86, 0x6907, 0x413C, 0x9A, 0xF7, 0x4F, 0xC2, 0xAB, 0xF0, 0x7C, 0xC5);
+ internal static ReadOnlySpan PublicPictures =>
+ [0xB6, 0xEB, 0xFB, 0x86, 0x69, 0x07, 0x41, 0x3C, 0x9A, 0xF7, 0x4F, 0xC2, 0xAB, 0xF0, 0x7C, 0xC5];
///
/// (CSIDL_COMMON_VIDEO) Public Videos folder
/// "%PUBLIC%\Videos"
///
- internal static Guid PublicVideos =>
- new(0x2400183A, 0x6185, 0x49FB, 0xA2, 0xD8, 0x4A, 0x39, 0x2A, 0x60, 0x2B, 0xA3);
+ internal static ReadOnlySpan PublicVideos =>
+ [0x24, 0x00, 0x18, 0x3A, 0x61, 0x85, 0x49, 0xFB, 0xA2, 0xD8, 0x4A, 0x39, 0x2A, 0x60, 0x2B, 0xA3];
///
/// (CSIDL_RECENT) Recent Items folder
/// "%APPDATA%\Microsoft\Windows\Recent"
///
- internal static Guid Recent =>
- new(0xAE50C081, 0xEBD2, 0x438A, 0x86, 0x55, 0x8A, 0x09, 0x2E, 0x34, 0x98, 0x7A);
+ internal static ReadOnlySpan Recent =>
+ [0xAE, 0x50, 0xC0, 0x81, 0xEB, 0xD2, 0x43, 0x8A, 0x86, 0x55, 0x8A, 0x09, 0x2E, 0x34, 0x98, 0x7A];
///
/// (CSIDL_BITBUCKET) Recycle Bin virtual folder
///
- internal static Guid RecycleBinFolder =>
- new(0xB7534046, 0x3ECB, 0x4C18, 0xBE, 0x4E, 0x64, 0xCD, 0x4C, 0xB7, 0xD6, 0xAC);
+ internal static ReadOnlySpan RecycleBinFolder =>
+ [0xB7, 0x53, 0x40, 0x46, 0x3E, 0xCB, 0x4C, 0x18, 0xBE, 0x4E, 0x64, 0xCD, 0x4C, 0xB7, 0xD6, 0xAC];
///
/// (CSIDL_RESOURCES) Resources fixed folder
/// "%windir%\Resources"
///
- internal static Guid ResourceDir =>
- new(0x8AD10C31, 0x2ADB, 0x4296, 0xA8, 0xF7, 0xE4, 0x70, 0x12, 0x32, 0xC9, 0x72);
+ internal static ReadOnlySpan ResourceDir =>
+ [0x8A, 0xD1, 0x0C, 0x31, 0x2A, 0xDB, 0x42, 0x96, 0xA8, 0xF7, 0xE4, 0x70, 0x12, 0x32, 0xC9, 0x72];
///
/// (CSIDL_APPDATA) Roaming user application data folder
/// "%APPDATA%" ("%USERPROFILE%\AppData\Roaming")
///
- internal static Guid RoamingAppData =>
- new(0x3EB685DB, 0x65F9, 0x4CF6, 0xA0, 0x3A, 0xE3, 0xEF, 0x65, 0x72, 0x9F, 0x3D);
+ internal static ReadOnlySpan RoamingAppData =>
+ [0x3E, 0xB6, 0x85, 0xDB, 0x65, 0xF9, 0x4C, 0xF6, 0xA0, 0x3A, 0xE3, 0xEF, 0x65, 0x72, 0x9F, 0x3D];
///
/// (CSIDL_SENDTO) SendTo folder
/// "%APPDATA%\Microsoft\Windows\SendTo"
///
- internal static Guid SendTo =>
- new(0x8983036C, 0x27C0, 0x404B, 0x8F, 0x08, 0x10, 0x2D, 0x10, 0xDC, 0xFD, 0x74);
+ internal static ReadOnlySpan SendTo =>
+ [0x89, 0x83, 0x03, 0x6C, 0x27, 0xC0, 0x40, 0x4B, 0x8F, 0x08, 0x10, 0x2D, 0x10, 0xDC, 0xFD, 0x74];
///
/// (CSIDL_STARTMENU) Start Menu folder
/// "%APPDATA%\Microsoft\Windows\Start Menu"
///
- internal static Guid StartMenu =>
- new(0x625B53C3, 0xAB48, 0x4EC1, 0xBA, 0x1F, 0xA1, 0xEF, 0x41, 0x46, 0xFC, 0x19);
+ internal static ReadOnlySpan StartMenu =>
+ [0x62, 0x5B, 0x53, 0xC3, 0xAB, 0x48, 0x4E, 0xC1, 0xBA, 0x1F, 0xA1, 0xEF, 0x41, 0x46, 0xFC, 0x19];
///
/// (CSIDL_STARTUP, CSIDL_ALTSTARTUP) Startup folder
/// "%APPDATA%\Microsoft\Windows\Start Menu\Programs\StartUp"
///
- internal static Guid Startup =>
- new(0xB97D20BB, 0xF46A, 0x4C97, 0xBA, 0x10, 0x5E, 0x36, 0x08, 0x43, 0x08, 0x54);
+ internal static ReadOnlySpan Startup =>
+ [0xB9, 0x7D, 0x20, 0xBB, 0xF4, 0x6A, 0x4C, 0x97, 0xBA, 0x10, 0x5E, 0x36, 0x08, 0x43, 0x08, 0x54];
///
/// (CSIDL_SYSTEMX86) X86 System32 folder
/// "%windir%\system32" or "%windir%\syswow64"
///
- internal static Guid SystemX86 =>
- new(0xD65231B0, 0xB2F1, 0x4857, 0xA4, 0xCE, 0xA8, 0xE7, 0xC6, 0xEA, 0x7D, 0x27);
+ internal static ReadOnlySpan SystemX86 =>
+ [0xD6, 0x52, 0x31, 0xB0, 0xB2, 0xF1, 0x48, 0x57, 0xA4, 0xCE, 0xA8, 0xE7, 0xC6, 0xEA, 0x7D, 0x27];
///
/// (CSIDL_TEMPLATES) Templates folder
/// "%APPDATA%\Microsoft\Windows\Templates"
///
- internal static Guid Templates =>
- new(0xA63293E8, 0x664E, 0x48DB, 0xA0, 0x79, 0xDF, 0x75, 0x9E, 0x05, 0x09, 0xF7);
+ internal static ReadOnlySpan Templates =>
+ [0xA6, 0x32, 0x93, 0xE8, 0x66, 0x4E, 0x48, 0xDB, 0xA0, 0x79, 0xDF, 0x75, 0x9E, 0x05, 0x09, 0xF7];
///
/// (CSIDL_MYVIDEO) Videos folder
/// "%USERPROFILE%\Videos"
///
- internal static Guid Videos =>
- new(0x18989B1D, 0x99B5, 0x455B, 0x84, 0x1C, 0xAB, 0x7C, 0x74, 0xE4, 0xDD, 0xFC);
+ internal static ReadOnlySpan Videos =>
+ [0x18, 0x98, 0x9B, 0x1D, 0x99, 0xB5, 0x45, 0x5B, 0x84, 0x1C, 0xAB, 0x7C, 0x74, 0xE4, 0xDD, 0xFC];
///
/// (CSIDL_WINDOWS) Windows folder "%windir%"
///
- internal static Guid Windows =>
- new(0xF38BF404, 0x1D43, 0x42F2, 0x93, 0x05, 0x67, 0xDE, 0x0B, 0x28, 0xFC, 0x23);
+ internal static ReadOnlySpan Windows =>
+ [0xF3, 0x8B, 0xF4, 0x04, 0x1D, 0x43, 0x42, 0xF2, 0x93, 0x05, 0x67, 0xDE, 0x0B, 0x28, 0xFC, 0x23];
}
}
}
diff --git a/src/libraries/System.Private.CoreLib/src/System/Environment.Win32.cs b/src/libraries/System.Private.CoreLib/src/System/Environment.Win32.cs
index fbd990ea25f597..8f251888400cf4 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Environment.Win32.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Environment.Win32.cs
@@ -216,7 +216,7 @@ private static string GetFolderPathCore(SpecialFolder folder, SpecialFolderOptio
//
// The only SpecialFolderOption defines we have are equivalent to KnownFolderFlags.
- Guid folderId;
+ ReadOnlySpan folderGuid;
string? fallbackEnv = null;
switch (folder)
{
@@ -229,153 +229,154 @@ private static string GetFolderPathCore(SpecialFolder folder, SpecialFolderOptio
// Map the SpecialFolder to the appropriate Guid
case SpecialFolder.ApplicationData:
- folderId = Interop.Shell32.KnownFolders.RoamingAppData;
+ folderGuid = Interop.Shell32.KnownFolders.RoamingAppData;
fallbackEnv = "APPDATA";
break;
case SpecialFolder.CommonApplicationData:
- folderId = Interop.Shell32.KnownFolders.ProgramData;
+ folderGuid = Interop.Shell32.KnownFolders.ProgramData;
fallbackEnv = "ProgramData";
break;
case SpecialFolder.LocalApplicationData:
- folderId = Interop.Shell32.KnownFolders.LocalAppData;
+ folderGuid = Interop.Shell32.KnownFolders.LocalAppData;
fallbackEnv = "LOCALAPPDATA";
break;
case SpecialFolder.Cookies:
- folderId = Interop.Shell32.KnownFolders.Cookies;
+ folderGuid = Interop.Shell32.KnownFolders.Cookies;
break;
case SpecialFolder.Desktop:
- folderId = Interop.Shell32.KnownFolders.Desktop;
+ folderGuid = Interop.Shell32.KnownFolders.Desktop;
break;
case SpecialFolder.Favorites:
- folderId = Interop.Shell32.KnownFolders.Favorites;
+ folderGuid = Interop.Shell32.KnownFolders.Favorites;
break;
case SpecialFolder.History:
- folderId = Interop.Shell32.KnownFolders.History;
+ folderGuid = Interop.Shell32.KnownFolders.History;
break;
case SpecialFolder.InternetCache:
- folderId = Interop.Shell32.KnownFolders.InternetCache;
+ folderGuid = Interop.Shell32.KnownFolders.InternetCache;
break;
case SpecialFolder.Programs:
- folderId = Interop.Shell32.KnownFolders.Programs;
+ folderGuid = Interop.Shell32.KnownFolders.Programs;
break;
case SpecialFolder.MyComputer:
- folderId = Interop.Shell32.KnownFolders.ComputerFolder;
+ folderGuid = Interop.Shell32.KnownFolders.ComputerFolder;
break;
case SpecialFolder.MyMusic:
- folderId = Interop.Shell32.KnownFolders.Music;
+ folderGuid = Interop.Shell32.KnownFolders.Music;
break;
case SpecialFolder.MyPictures:
- folderId = Interop.Shell32.KnownFolders.Pictures;
+ folderGuid = Interop.Shell32.KnownFolders.Pictures;
break;
case SpecialFolder.MyVideos:
- folderId = Interop.Shell32.KnownFolders.Videos;
+ folderGuid = Interop.Shell32.KnownFolders.Videos;
break;
case SpecialFolder.Recent:
- folderId = Interop.Shell32.KnownFolders.Recent;
+ folderGuid = Interop.Shell32.KnownFolders.Recent;
break;
case SpecialFolder.SendTo:
- folderId = Interop.Shell32.KnownFolders.SendTo;
+ folderGuid = Interop.Shell32.KnownFolders.SendTo;
break;
case SpecialFolder.StartMenu:
- folderId = Interop.Shell32.KnownFolders.StartMenu;
+ folderGuid = Interop.Shell32.KnownFolders.StartMenu;
break;
case SpecialFolder.Startup:
- folderId = Interop.Shell32.KnownFolders.Startup;
+ folderGuid = Interop.Shell32.KnownFolders.Startup;
break;
case SpecialFolder.Templates:
- folderId = Interop.Shell32.KnownFolders.Templates;
+ folderGuid = Interop.Shell32.KnownFolders.Templates;
break;
case SpecialFolder.DesktopDirectory:
- folderId = Interop.Shell32.KnownFolders.Desktop;
+ folderGuid = Interop.Shell32.KnownFolders.Desktop;
break;
case SpecialFolder.Personal:
// Same as Personal
// case SpecialFolder.MyDocuments:
- folderId = Interop.Shell32.KnownFolders.Documents;
+ folderGuid = Interop.Shell32.KnownFolders.Documents;
break;
case SpecialFolder.ProgramFiles:
- folderId = Interop.Shell32.KnownFolders.ProgramFiles;
+ folderGuid = Interop.Shell32.KnownFolders.ProgramFiles;
fallbackEnv = "ProgramFiles";
break;
case SpecialFolder.CommonProgramFiles:
- folderId = Interop.Shell32.KnownFolders.ProgramFilesCommon;
+ folderGuid = Interop.Shell32.KnownFolders.ProgramFilesCommon;
fallbackEnv = "CommonProgramFiles";
break;
case SpecialFolder.AdminTools:
- folderId = Interop.Shell32.KnownFolders.AdminTools;
+ folderGuid = Interop.Shell32.KnownFolders.AdminTools;
break;
case SpecialFolder.CDBurning:
- folderId = Interop.Shell32.KnownFolders.CDBurning;
+ folderGuid = Interop.Shell32.KnownFolders.CDBurning;
break;
case SpecialFolder.CommonAdminTools:
- folderId = Interop.Shell32.KnownFolders.CommonAdminTools;
+ folderGuid = Interop.Shell32.KnownFolders.CommonAdminTools;
break;
case SpecialFolder.CommonDocuments:
- folderId = Interop.Shell32.KnownFolders.PublicDocuments;
+ folderGuid = Interop.Shell32.KnownFolders.PublicDocuments;
break;
case SpecialFolder.CommonMusic:
- folderId = Interop.Shell32.KnownFolders.PublicMusic;
+ folderGuid = Interop.Shell32.KnownFolders.PublicMusic;
break;
case SpecialFolder.CommonOemLinks:
- folderId = Interop.Shell32.KnownFolders.CommonOEMLinks;
+ folderGuid = Interop.Shell32.KnownFolders.CommonOEMLinks;
break;
case SpecialFolder.CommonPictures:
- folderId = Interop.Shell32.KnownFolders.PublicPictures;
+ folderGuid = Interop.Shell32.KnownFolders.PublicPictures;
break;
case SpecialFolder.CommonStartMenu:
- folderId = Interop.Shell32.KnownFolders.CommonStartMenu;
+ folderGuid = Interop.Shell32.KnownFolders.CommonStartMenu;
break;
case SpecialFolder.CommonPrograms:
- folderId = Interop.Shell32.KnownFolders.CommonPrograms;
+ folderGuid = Interop.Shell32.KnownFolders.CommonPrograms;
break;
case SpecialFolder.CommonStartup:
- folderId = Interop.Shell32.KnownFolders.CommonStartup;
+ folderGuid = Interop.Shell32.KnownFolders.CommonStartup;
break;
case SpecialFolder.CommonDesktopDirectory:
- folderId = Interop.Shell32.KnownFolders.PublicDesktop;
+ folderGuid = Interop.Shell32.KnownFolders.PublicDesktop;
break;
case SpecialFolder.CommonTemplates:
- folderId = Interop.Shell32.KnownFolders.CommonTemplates;
+ folderGuid = Interop.Shell32.KnownFolders.CommonTemplates;
break;
case SpecialFolder.CommonVideos:
- folderId = Interop.Shell32.KnownFolders.PublicVideos;
+ folderGuid = Interop.Shell32.KnownFolders.PublicVideos;
break;
case SpecialFolder.Fonts:
- folderId = Interop.Shell32.KnownFolders.Fonts;
+ folderGuid = Interop.Shell32.KnownFolders.Fonts;
break;
case SpecialFolder.NetworkShortcuts:
- folderId = Interop.Shell32.KnownFolders.NetHood;
+ folderGuid = Interop.Shell32.KnownFolders.NetHood;
break;
case SpecialFolder.PrinterShortcuts:
- folderId = Interop.Shell32.KnownFolders.PrintersFolder;
+ folderGuid = Interop.Shell32.KnownFolders.PrintersFolder;
break;
case SpecialFolder.UserProfile:
- folderId = Interop.Shell32.KnownFolders.Profile;
+ folderGuid = Interop.Shell32.KnownFolders.Profile;
fallbackEnv = "USERPROFILE";
break;
case SpecialFolder.CommonProgramFilesX86:
- folderId = Interop.Shell32.KnownFolders.ProgramFilesCommonX86;
+ folderGuid = Interop.Shell32.KnownFolders.ProgramFilesCommonX86;
fallbackEnv = "CommonProgramFiles(x86)";
break;
case SpecialFolder.ProgramFilesX86:
- folderId = Interop.Shell32.KnownFolders.ProgramFilesX86;
+ folderGuid = Interop.Shell32.KnownFolders.ProgramFilesX86;
fallbackEnv = "ProgramFiles(x86)";
break;
case SpecialFolder.Resources:
- folderId = Interop.Shell32.KnownFolders.ResourceDir;
+ folderGuid = Interop.Shell32.KnownFolders.ResourceDir;
break;
case SpecialFolder.LocalizedResources:
- folderId = Interop.Shell32.KnownFolders.LocalizedResourcesDir;
+ folderGuid = Interop.Shell32.KnownFolders.LocalizedResourcesDir;
break;
case SpecialFolder.SystemX86:
- folderId = Interop.Shell32.KnownFolders.SystemX86;
+ folderGuid = Interop.Shell32.KnownFolders.SystemX86;
break;
case SpecialFolder.Windows:
- folderId = Interop.Shell32.KnownFolders.Windows;
+ folderGuid = Interop.Shell32.KnownFolders.Windows;
fallbackEnv = "windir";
break;
}
+ Guid folderId = new Guid(folderGuid);
int hr = Interop.Shell32.SHGetKnownFolderPath(folderId, (uint)option, IntPtr.Zero, out string path);
if (hr == 0)
return path;
From bef98596124891e2d8aad79fffba02205cd1ae59 Mon Sep 17 00:00:00 2001
From: xtqqczze <45661989+xtqqczze@users.noreply.github.com>
Date: Fri, 1 Aug 2025 13:06:12 +0100
Subject: [PATCH 3/6] Fix byte ordering
---
.../Shell32/Interop.SHGetKnownFolderPath.cs | 150 ++++++++++++------
1 file changed, 100 insertions(+), 50 deletions(-)
diff --git a/src/libraries/Common/src/Interop/Windows/Shell32/Interop.SHGetKnownFolderPath.cs b/src/libraries/Common/src/Interop/Windows/Shell32/Interop.SHGetKnownFolderPath.cs
index f93a1a82d3a5c4..740ea18cc5526f 100644
--- a/src/libraries/Common/src/Interop/Windows/Shell32/Interop.SHGetKnownFolderPath.cs
+++ b/src/libraries/Common/src/Interop/Windows/Shell32/Interop.SHGetKnownFolderPath.cs
@@ -24,340 +24,390 @@ internal static class KnownFolders
///
/// (CSIDL_ADMINTOOLS) Per user Administrative Tools
/// "%APPDATA%\Microsoft\Windows\Start Menu\Programs\Administrative Tools"
+ /// {724EF170-A42D-4FEF-9F26-B60E846FBA4F}
///
internal static ReadOnlySpan AdminTools =>
- [0x72, 0x4E, 0xF1, 0x70, 0xA4, 0x2D, 0x4F, 0xEF, 0x9F, 0x26, 0xB6, 0x0E, 0x84, 0x6F, 0xBA, 0x4F];
+ [0x70, 0xF1, 0x4E, 0x72, 0x2D, 0xA4, 0xEF, 0x4F, 0x9F, 0x26, 0xB6, 0x0E, 0x84, 0x6F, 0xBA, 0x4F];
///
/// (CSIDL_CDBURN_AREA) Temporary Burn folder
/// "%LOCALAPPDATA%\Microsoft\Windows\Burn\Burn"
+ /// {9E52AB10-F80D-49DF-ACB8-4330F5687855}
///
internal static ReadOnlySpan CDBurning =>
- [0x9E, 0x52, 0xAB, 0x10, 0xF8, 0x0D, 0x49, 0xDF, 0xAC, 0xB8, 0x43, 0x30, 0xF5, 0x68, 0x78, 0x55];
+ [0x10, 0xAB, 0x52, 0x9E, 0x0D, 0xF8, 0xDF, 0x49, 0xAC, 0xB8, 0x43, 0x30, 0xF5, 0x68, 0x78, 0x55];
///
/// (CSIDL_COMMON_ADMINTOOLS) Common Administrative Tools
/// "%ALLUSERSPROFILE%\Microsoft\Windows\Start Menu\Programs\Administrative Tools"
+ /// {D0384E7D-BAC3-4797-8F14-CBA229B392B5}
///
internal static ReadOnlySpan CommonAdminTools =>
- [0xD0, 0x38, 0x4E, 0x7D, 0xBA, 0xC3, 0x47, 0x97, 0x8F, 0x14, 0xCB, 0xA2, 0x29, 0xB3, 0x92, 0xB5];
+ [0x7D, 0x4E, 0x38, 0xD0, 0xC3, 0xBA, 0x97, 0x47, 0x8F, 0x14, 0xCB, 0xA2, 0x29, 0xB3, 0x92, 0xB5];
///
/// (CSIDL_COMMON_OEM_LINKS) OEM Links folder
/// "%ALLUSERSPROFILE%\OEM Links"
+ /// {C1BAE2D0-10DF-4334-BEDD-7AA20B227A9D}
///
internal static ReadOnlySpan CommonOEMLinks =>
- [0xC1, 0xBA, 0xE2, 0xD0, 0x10, 0xDF, 0x43, 0x34, 0xBE, 0xDD, 0x7A, 0xA2, 0x0B, 0x22, 0x7A, 0x9D];
+ [0xD0, 0xE2, 0xBA, 0xC1, 0xDF, 0x10, 0x34, 0x43, 0xBE, 0xDD, 0x7A, 0xA2, 0x0B, 0x22, 0x7A, 0x9D];
///
/// (CSIDL_COMMON_PROGRAMS) Common Programs folder
/// "%ALLUSERSPROFILE%\Microsoft\Windows\Start Menu\Programs"
+ /// {0139D44E-6AFE-49F2-8690-3DAFCAE6FFB8}
///
internal static ReadOnlySpan CommonPrograms =>
- [0x01, 0x39, 0xD4, 0x4E, 0x6A, 0xFE, 0x49, 0xF2, 0x86, 0x90, 0x3D, 0xAF, 0xCA, 0xE6, 0xFF, 0xB8];
+ [0x4E, 0xD4, 0x39, 0x01, 0xFE, 0x6A, 0xF2, 0x49, 0x86, 0x90, 0x3D, 0xAF, 0xCA, 0xE6, 0xFF, 0xB8];
///
/// (CSIDL_COMMON_STARTMENU) Common Start Menu folder
/// "%ALLUSERSPROFILE%\Microsoft\Windows\Start Menu"
+ /// {A4115719-D62E-491D-AA7C-E74B8BE3B067}
///
internal static ReadOnlySpan CommonStartMenu =>
- [0xA4, 0x11, 0x57, 0x19, 0xD6, 0x2E, 0x49, 0x1D, 0xAA, 0x7C, 0xE7, 0x4B, 0x8B, 0xE3, 0xB0, 0x67];
+ [0x19, 0x57, 0x11, 0xA4, 0x2E, 0xD6, 0x1D, 0x49, 0xAA, 0x7C, 0xE7, 0x4B, 0x8B, 0xE3, 0xB0, 0x67];
///
/// (CSIDL_COMMON_STARTUP, CSIDL_COMMON_ALTSTARTUP) Common Startup folder
/// "%ALLUSERSPROFILE%\Microsoft\Windows\Start Menu\Programs\StartUp"
+ /// {82A5EA35-D9CD-47C5-9629-E15D2F714E6E}
///
internal static ReadOnlySpan CommonStartup =>
- [0x82, 0xA5, 0xEA, 0x35, 0xD9, 0xCD, 0x47, 0xC5, 0x96, 0x29, 0xE1, 0x5D, 0x2F, 0x71, 0x4E, 0x6E];
+ [0x35, 0xEA, 0xA5, 0x82, 0xCD, 0xD9, 0xC5, 0x47, 0x96, 0x29, 0xE1, 0x5D, 0x2F, 0x71, 0x4E, 0x6E];
///
/// (CSIDL_COMMON_TEMPLATES) Common Templates folder
/// "%ALLUSERSPROFILE%\Microsoft\Windows\Templates"
+ /// {B94237E7-57AC-4347-9151-B08C6C32D1F7}
///
internal static ReadOnlySpan CommonTemplates =>
- [0xB9, 0x42, 0x37, 0xE7, 0x57, 0xAC, 0x43, 0x47, 0x91, 0x51, 0xB0, 0x8C, 0x6C, 0x32, 0xD1, 0xF7];
+ [0xE7, 0x37, 0x42, 0xB9, 0xAC, 0x57, 0x47, 0x43, 0x91, 0x51, 0xB0, 0x8C, 0x6C, 0x32, 0xD1, 0xF7];
///
/// (CSIDL_DRIVES) Computer virtual folder
+ /// {0AC0837C-BBF8-452A-850D-79D08E667CA7}
///
internal static ReadOnlySpan ComputerFolder =>
- [0x0A, 0xC0, 0x83, 0x7C, 0xBB, 0xF8, 0x45, 0x2A, 0x85, 0x0D, 0x79, 0xD0, 0x8E, 0x66, 0x7C, 0xA7];
+ [0x7C, 0x83, 0xC0, 0x0A, 0xF8, 0xBB, 0x2A, 0x45, 0x85, 0x0D, 0x79, 0xD0, 0x8E, 0x66, 0x7C, 0xA7];
///
/// (CSIDL_CONNECTIONS) Network Connections virtual folder
+ /// {6F0CD92B-2E97-45D1-88FF-B0D186B8DEDD}
///
internal static ReadOnlySpan ConnectionsFolder =>
- [0x6F, 0x0C, 0xD9, 0x2B, 0x2E, 0x97, 0x45, 0xD1, 0x88, 0xFF, 0xB0, 0xD1, 0x86, 0xB8, 0xDE, 0xDD];
+ [0x2B, 0xD9, 0x0C, 0x6F, 0x97, 0x2E, 0xD1, 0x45, 0x88, 0xFF, 0xB0, 0xD1, 0x86, 0xB8, 0xDE, 0xDD];
///
/// (CSIDL_CONTROLS) Control Panel virtual folder
+ /// {82A74AEB-AEB4-465C-A014-D097EE346D63}
///
internal static ReadOnlySpan ControlPanelFolder =>
- [0x82, 0xA7, 0x4A, 0xEB, 0xAE, 0xB4, 0x46, 0x5C, 0xA0, 0x14, 0xD0, 0x97, 0xEE, 0x34, 0x6D, 0x63];
+ [0xEB, 0x4A, 0xA7, 0x82, 0xB4, 0xAE, 0x5C, 0x46, 0xA0, 0x14, 0xD0, 0x97, 0xEE, 0x34, 0x6D, 0x63];
///
/// (CSIDL_COOKIES) Cookies folder
/// "%APPDATA%\Microsoft\Windows\Cookies"
+ /// {2B0F765D-C0E9-4171-908E-08A611B84FF6}
///
internal static ReadOnlySpan Cookies =>
- [0x2B, 0x0F, 0x76, 0x5D, 0xC0, 0xE9, 0x41, 0x71, 0x90, 0x8E, 0x08, 0xA6, 0x11, 0xB8, 0x4F, 0xF6];
+ [0x5D, 0x76, 0x0F, 0x2B, 0xE9, 0xC0, 0x71, 0x41, 0x90, 0x8E, 0x08, 0xA6, 0x11, 0xB8, 0x4F, 0xF6];
///
/// (CSIDL_DESKTOP, CSIDL_DESKTOPDIRECTORY) Desktop folder
/// "%USERPROFILE%\Desktop"
+ /// {B4BFCC3A-DB2C-424C-B029-7FE99A87C641}
///
internal static ReadOnlySpan Desktop =>
- [0xB4, 0xBF, 0xCC, 0x3A, 0xDB, 0x2C, 0x42, 0x4C, 0xB0, 0x29, 0x7F, 0xE9, 0x9A, 0x87, 0xC6, 0x41];
+ [0x3A, 0xCC, 0xBF, 0xB4, 0x2C, 0xDB, 0x4C, 0x42, 0xB0, 0x29, 0x7F, 0xE9, 0x9A, 0x87, 0xC6, 0x41];
///
/// (CSIDL_MYDOCUMENTS, CSIDL_PERSONAL) Documents (My Documents) folder
/// "%USERPROFILE%\Documents"
+ /// {FDD39AD0-238F-46AF-ADB4-6C85480369C7}
///
internal static ReadOnlySpan Documents =>
- [0xFD, 0xD3, 0x9A, 0xD0, 0x23, 0x8F, 0x46, 0xAF, 0xAD, 0xB4, 0x6C, 0x85, 0x48, 0x03, 0x69, 0xC7];
+ [0xD0, 0x9A, 0xD3, 0xFD, 0x8F, 0x23, 0xAF, 0x46, 0xAD, 0xB4, 0x6C, 0x85, 0x48, 0x03, 0x69, 0xC7];
///
/// (CSIDL_FAVORITES, CSIDL_COMMON_FAVORITES) Favorites folder
/// "%USERPROFILE%\Favorites"
+ /// {1777F761-68AD-4D8A-87BD-30B759FA33DD}
///
internal static ReadOnlySpan Favorites =>
- [0x17, 0x77, 0xF7, 0x61, 0x68, 0xAD, 0x4D, 0x8A, 0x87, 0xBD, 0x30, 0xB7, 0x59, 0xFA, 0x33, 0xDD];
+ [0x61, 0xF7, 0x77, 0x17, 0xAD, 0x68, 0x8A, 0x4D, 0x87, 0xBD, 0x30, 0xB7, 0x59, 0xFA, 0x33, 0xDD];
///
/// (CSIDL_FONTS) Fonts folder
/// "%windir%\Fonts"
+ /// {FD228CB7-AE11-4AE3-864C-16F3910AB8FE}
///
internal static ReadOnlySpan Fonts =>
- [0xFD, 0x22, 0x8C, 0xB7, 0xAE, 0x11, 0x4A, 0xE3, 0x86, 0x4C, 0x16, 0xF3, 0x91, 0x0A, 0xB8, 0xFE];
+ [0xB7, 0x8C, 0x22, 0xFD, 0x11, 0xAE, 0xE3, 0x4A, 0x86, 0x4C, 0x16, 0xF3, 0x91, 0x0A, 0xB8, 0xFE];
///
/// (CSIDL_HISTORY) History folder
/// "%LOCALAPPDATA%\Microsoft\Windows\History"
+ /// {D9DC8A3B-B784-432E-A781-5A1130A75963}
///
internal static ReadOnlySpan History =>
- [0xD9, 0xDC, 0x8A, 0x3B, 0xB7, 0x84, 0x43, 0x2E, 0xA7, 0x81, 0x5A, 0x11, 0x30, 0xA7, 0x59, 0x63];
+ [0x3B, 0x8A, 0xDC, 0xD9, 0x84, 0xB7, 0x2E, 0x43, 0xA7, 0x81, 0x5A, 0x11, 0x30, 0xA7, 0x59, 0x63];
///
/// (CSIDL_INTERNET_CACHE) Temporary Internet Files folder
/// "%LOCALAPPDATA%\Microsoft\Windows\Temporary Internet Files"
+ /// {352481E8-33BE-4251-BA85-6007CAEDCF9D}
///
internal static ReadOnlySpan InternetCache =>
- [0x35, 0x24, 0x81, 0xE8, 0x33, 0xBE, 0x42, 0x51, 0xBA, 0x85, 0x60, 0x07, 0xCA, 0xED, 0xCF, 0x9D];
+ [0xE8, 0x81, 0x24, 0x35, 0xBE, 0x33, 0x51, 0x42, 0xBA, 0x85, 0x60, 0x07, 0xCA, 0xED, 0xCF, 0x9D];
///
/// (CSIDL_INTERNET) The Internet virtual folder
+ /// {4D9F7874-4E0C-4904-967B-40B0D20C3E4B}
///
internal static ReadOnlySpan InternetFolder =>
- [0x4D, 0x9F, 0x78, 0x74, 0x4E, 0x0C, 0x49, 0x04, 0x96, 0x7B, 0x40, 0xB0, 0xD2, 0x0C, 0x3E, 0x4B];
+ [0x74, 0x78, 0x9F, 0x4D, 0x0C, 0x4E, 0x04, 0x49, 0x96, 0x7B, 0x40, 0xB0, 0xD2, 0x0C, 0x3E, 0x4B];
///
/// (CSIDL_LOCAL_APPDATA) Local folder
/// "%LOCALAPPDATA%" ("%USERPROFILE%\AppData\Local")
+ /// {F1B32785-6FBA-4FCF-9D55-7B8E7F157091}
///
internal static ReadOnlySpan LocalAppData =>
- [0xF1, 0xB3, 0x27, 0x85, 0x6F, 0xBA, 0x4F, 0xCF, 0x9D, 0x55, 0x7B, 0x8E, 0x7F, 0x15, 0x70, 0x91];
+ [0x85, 0x27, 0xB3, 0xF1, 0xBA, 0x6F, 0xCF, 0x4F, 0x9D, 0x55, 0x7B, 0x8E, 0x7F, 0x15, 0x70, 0x91];
///
/// (CSIDL_RESOURCES_LOCALIZED) Fixed localized resources folder
/// "%windir%\resources\0409" (per active codepage)
+ /// {2A00375E-224C-49DE-B8D1-440DF7EF3DDC}
///
internal static ReadOnlySpan LocalizedResourcesDir =>
- [0x2A, 0x00, 0x37, 0x5E, 0x22, 0x4C, 0x49, 0xDE, 0xB8, 0xD1, 0x44, 0x0D, 0xF7, 0xEF, 0x3D, 0xDC];
+ [0x5E, 0x37, 0x00, 0x2A, 0x4C, 0x22, 0xDE, 0x49, 0xB8, 0xD1, 0x44, 0x0D, 0xF7, 0xEF, 0x3D, 0xDC];
///
/// (CSIDL_MYMUSIC) Music folder
/// "%USERPROFILE%\Music"
+ /// {4BD8D571-6D19-48D3-BE97-422220080E43}
///
internal static ReadOnlySpan Music =>
- [0x4B, 0xD8, 0xD5, 0x71, 0x6D, 0x19, 0x48, 0xD3, 0xBE, 0x97, 0x42, 0x22, 0x20, 0x08, 0x0E, 0x43];
+ [0x71, 0xD5, 0xD8, 0x4B, 0x19, 0x6D, 0xD3, 0x48, 0xBE, 0x97, 0x42, 0x22, 0x20, 0x08, 0x0E, 0x43];
///
/// (CSIDL_NETHOOD) Network shortcuts folder "%APPDATA%\Microsoft\Windows\Network Shortcuts"
+ /// {C5ABBF53-E17F-4121-8900-86626FC2C973}
///
internal static ReadOnlySpan NetHood =>
- [0xC5, 0xAB, 0xBF, 0x53, 0xE1, 0x7F, 0x41, 0x21, 0x89, 0x00, 0x86, 0x62, 0x6F, 0xC2, 0xC9, 0x73];
+ [0x53, 0xBF, 0xAB, 0xC5, 0x7F, 0xE1, 0x21, 0x41, 0x89, 0x00, 0x86, 0x62, 0x6F, 0xC2, 0xC9, 0x73];
///
/// (CSIDL_NETWORK, CSIDL_COMPUTERSNEARME) Network virtual folder
+ /// {D20BEEC4-5CA8-4905-AE3B-BF251EA09B53}
///
internal static ReadOnlySpan NetworkFolder =>
- [0xD2, 0x0B, 0xEE, 0xC4, 0x5C, 0xA8, 0x49, 0x05, 0xAE, 0x3B, 0xBF, 0x25, 0x1E, 0xA0, 0x9B, 0x53];
+ [0xC4, 0xEE, 0x0B, 0xD2, 0xA8, 0x5C, 0x05, 0x49, 0xAE, 0x3B, 0xBF, 0x25, 0x1E, 0xA0, 0x9B, 0x53];
///
/// (CSIDL_MYPICTURES) Pictures folder "%USERPROFILE%\Pictures"
+ /// {33E28130-4E1E-4676-835A-98395C3BC3BB}
///
internal static ReadOnlySpan Pictures =>
- [0x33, 0xE2, 0x81, 0x30, 0x4E, 0x1E, 0x46, 0x76, 0x83, 0x5A, 0x98, 0x39, 0x5C, 0x3B, 0xC3, 0xBB];
+ [0x30, 0x81, 0xE2, 0x33, 0x1E, 0x4E, 0x76, 0x46, 0x83, 0x5A, 0x98, 0x39, 0x5C, 0x3B, 0xC3, 0xBB];
///
/// (CSIDL_PRINTERS) Printers virtual folder
+ /// {76FC4E2D-D6AD-4519-A663-37BD56068185}
///
internal static ReadOnlySpan PrintersFolder =>
- [0x76, 0xFC, 0x4E, 0x2D, 0xD6, 0xAD, 0x45, 0x19, 0xA6, 0x63, 0x37, 0xBD, 0x56, 0x06, 0x81, 0x85];
+ [0x2D, 0x4E, 0xFC, 0x76, 0xAD, 0xD6, 0x19, 0x45, 0xA6, 0x63, 0x37, 0xBD, 0x56, 0x06, 0x81, 0x85];
///
/// (CSIDL_PRINTHOOD) Printer Shortcuts folder
/// "%APPDATA%\Microsoft\Windows\Printer Shortcuts"
+ /// {9274BD8D-CFD1-41C3-B35E-B13F55A758F4}
///
internal static ReadOnlySpan PrintHood =>
- [0x92, 0x74, 0xBD, 0x8D, 0xCF, 0xD1, 0x41, 0xC3, 0xB3, 0x5E, 0xB1, 0x3F, 0x55, 0xA7, 0x58, 0xF4];
+ [0x8D, 0xBD, 0x74, 0x92, 0xD1, 0xCF, 0xC3, 0x41, 0xB3, 0x5E, 0xB1, 0x3F, 0x55, 0xA7, 0x58, 0xF4];
///
/// (CSIDL_PROFILE) The root users profile folder "%USERPROFILE%"
/// ("%SystemDrive%\Users\%USERNAME%")
+ /// {5E6C858F-0E22-4760-9AFE-EA3317B67173}
///
internal static ReadOnlySpan Profile =>
- [0x5E, 0x6C, 0x85, 0x8F, 0x0E, 0x22, 0x47, 0x60, 0x9A, 0xFE, 0xEA, 0x33, 0x17, 0xB6, 0x71, 0x73];
+ [0x8F, 0x85, 0x6C, 0x5E, 0x22, 0x0E, 0x60, 0x47, 0x9A, 0xFE, 0xEA, 0x33, 0x17, 0xB6, 0x71, 0x73];
///
/// (CSIDL_COMMON_APPDATA) ProgramData folder
/// "%ALLUSERSPROFILE%" ("%ProgramData%", "%SystemDrive%\ProgramData")
+ /// {62AB5D82-FDC1-4DC3-A9DD-070D1D495D97}
///
internal static ReadOnlySpan ProgramData =>
- [0x62, 0xAB, 0x5D, 0x82, 0xFD, 0xC1, 0x4D, 0xC3, 0xA9, 0xDD, 0x07, 0x0D, 0x1D, 0x49, 0x5D, 0x97];
+ [0x82, 0x5D, 0xAB, 0x62, 0xC1, 0xFD, 0xC3, 0x4D, 0xA9, 0xDD, 0x07, 0x0D, 0x1D, 0x49, 0x5D, 0x97];
///
/// (CSIDL_PROGRAM_FILES) Program Files folder for the current process architecture
/// "%ProgramFiles%" ("%SystemDrive%\Program Files")
+ /// {905e63b6-c1bf-494e-b29c-65b732d3d21a}
///
internal static ReadOnlySpan ProgramFiles =>
- [0x90, 0x5e, 0x63, 0xb6, 0xc1, 0xbf, 0x49, 0x4e, 0xb2, 0x9c, 0x65, 0xb7, 0x32, 0xd3, 0xd2, 0x1a];
+ [0xb6, 0x63, 0x5e, 0x90, 0xbf, 0xc1, 0x4e, 0x49, 0xb2, 0x9c, 0x65, 0xb7, 0x32, 0xd3, 0xd2, 0x1a];
///
/// (CSIDL_PROGRAM_FILESX86) 32 bit Program Files folder (available to both 32/64 bit processes)
+ /// {7C5A40EF-A0FB-4BFC-874A-C0F2E0B9FA8E}
///
internal static ReadOnlySpan ProgramFilesX86 =>
- [0x7C, 0x5A, 0x40, 0xEF, 0xA0, 0xFB, 0x4B, 0xFC, 0x87, 0x4A, 0xC0, 0xF2, 0xE0, 0xB9, 0xFA, 0x8E];
+ [0xEF, 0x40, 0x5A, 0x7C, 0xFB, 0xA0, 0xFC, 0x4B, 0x87, 0x4A, 0xC0, 0xF2, 0xE0, 0xB9, 0xFA, 0x8E];
///
/// (CSIDL_PROGRAM_FILES_COMMON) Common Program Files folder for the current process architecture
/// "%ProgramFiles%\Common Files"
+ /// {F7F1ED05-9F6D-47A2-AAAE-29D317C6F066}
///
internal static ReadOnlySpan ProgramFilesCommon =>
- [0xF7, 0xF1, 0xED, 0x05, 0x9F, 0x6D, 0x47, 0xA2, 0xAA, 0xAE, 0x29, 0xD3, 0x17, 0xC6, 0xF0, 0x66];
+ [0x05, 0xED, 0xF1, 0xF7, 0x6D, 0x9F, 0xA2, 0x47, 0xAA, 0xAE, 0x29, 0xD3, 0x17, 0xC6, 0xF0, 0x66];
///
/// (CSIDL_PROGRAM_FILES_COMMONX86) Common 32 bit Program Files folder (available to both 32/64 bit processes)
+ /// {DE974D24-D9C6-4D3E-BF91-F4455120B917}
///
internal static ReadOnlySpan ProgramFilesCommonX86 =>
- [0xDE, 0x97, 0x4D, 0x24, 0xD9, 0xC6, 0x4D, 0x3E, 0xBF, 0x91, 0xF4, 0x45, 0x51, 0x20, 0xB9, 0x17];
+ [0x24, 0x4D, 0x97, 0xDE, 0xC6, 0xD9, 0x3E, 0x4D, 0xBF, 0x91, 0xF4, 0x45, 0x51, 0x20, 0xB9, 0x17];
///
/// (CSIDL_PROGRAMS) Start menu Programs folder
/// "%APPDATA%\Microsoft\Windows\Start Menu\Programs"
+ /// {A77F5D77-2E2B-44C3-A6A2-ABA601054A51}
///
internal static ReadOnlySpan Programs =>
- [0xA7, 0x7F, 0x5D, 0x77, 0x2E, 0x2B, 0x44, 0xC3, 0xA6, 0xA2, 0xAB, 0xA6, 0x01, 0x05, 0x4A, 0x51];
+ [0x77, 0x5D, 0x7F, 0xA7, 0x2B, 0x2E, 0xC3, 0x44, 0xA6, 0xA2, 0xAB, 0xA6, 0x01, 0x05, 0x4A, 0x51];
///
/// (CSIDL_COMMON_DESKTOPDIRECTORY) Public Desktop folder
/// "%PUBLIC%\Desktop"
+ /// {C4AA340D-F20F-4863-AFEF-F87EF2E6BA25}
///
internal static ReadOnlySpan PublicDesktop =>
- [0xC4, 0xAA, 0x34, 0x0D, 0xF2, 0x0F, 0x48, 0x63, 0xAF, 0xEF, 0xF8, 0x7E, 0xF2, 0xE6, 0xBA, 0x25];
+ [0x0D, 0x34, 0xAA, 0xC4, 0x0F, 0xF2, 0x63, 0x48, 0xAF, 0xEF, 0xF8, 0x7E, 0xF2, 0xE6, 0xBA, 0x25];
///
/// (CSIDL_COMMON_DOCUMENTS) Public Documents folder
/// "%PUBLIC%\Documents"
+ /// {ED4824AF-DCE4-45A8-81E2-FC7965083634}
///
internal static ReadOnlySpan PublicDocuments =>
- [0xED, 0x48, 0x24, 0xAF, 0xDC, 0xE4, 0x45, 0xA8, 0x81, 0xE2, 0xFC, 0x79, 0x65, 0x08, 0x36, 0x34];
+ [0xAF, 0x24, 0x48, 0xED, 0xE4, 0xDC, 0xA8, 0x45, 0x81, 0xE2, 0xFC, 0x79, 0x65, 0x08, 0x36, 0x34];
///
/// (CSIDL_COMMON_MUSIC) Public Music folder
/// "%PUBLIC%\Music"
+ /// {3214FAB5-9757-4298-BB61-92A9DEAA44FF}
///
internal static ReadOnlySpan PublicMusic =>
- [0x32, 0x14, 0xFA, 0xB5, 0x97, 0x57, 0x42, 0x98, 0xBB, 0x61, 0x92, 0xA9, 0xDE, 0xAA, 0x44, 0xFF];
+ [0xB5, 0xFA, 0x14, 0x32, 0x57, 0x97, 0x98, 0x42, 0xBB, 0x61, 0x92, 0xA9, 0xDE, 0xAA, 0x44, 0xFF];
///
/// (CSIDL_COMMON_PICTURES) Public Pictures folder
/// "%PUBLIC%\Pictures"
+ /// {B6EBFB86-6907-413C-9AF7-4FC2ABF07CC5}
///
internal static ReadOnlySpan PublicPictures =>
- [0xB6, 0xEB, 0xFB, 0x86, 0x69, 0x07, 0x41, 0x3C, 0x9A, 0xF7, 0x4F, 0xC2, 0xAB, 0xF0, 0x7C, 0xC5];
+ [0x86, 0xFB, 0xEB, 0xB6, 0x07, 0x69, 0x3C, 0x41, 0x9A, 0xF7, 0x4F, 0xC2, 0xAB, 0xF0, 0x7C, 0xC5];
///
/// (CSIDL_COMMON_VIDEO) Public Videos folder
/// "%PUBLIC%\Videos"
+ /// {2400183A-6185-49FB-A2D8-4A392A602BA3}
///
internal static ReadOnlySpan PublicVideos =>
- [0x24, 0x00, 0x18, 0x3A, 0x61, 0x85, 0x49, 0xFB, 0xA2, 0xD8, 0x4A, 0x39, 0x2A, 0x60, 0x2B, 0xA3];
+ [0x3A, 0x18, 0x00, 0x24, 0x85, 0x61, 0xFB, 0x49, 0xA2, 0xD8, 0x4A, 0x39, 0x2A, 0x60, 0x2B, 0xA3];
///
/// (CSIDL_RECENT) Recent Items folder
/// "%APPDATA%\Microsoft\Windows\Recent"
+ /// {AE50C081-EBD2-438A-8655-8A092E34987A}
///
internal static ReadOnlySpan Recent =>
- [0xAE, 0x50, 0xC0, 0x81, 0xEB, 0xD2, 0x43, 0x8A, 0x86, 0x55, 0x8A, 0x09, 0x2E, 0x34, 0x98, 0x7A];
+ [0x81, 0xC0, 0x50, 0xAE, 0xD2, 0xEB, 0x8A, 0x43, 0x86, 0x55, 0x8A, 0x09, 0x2E, 0x34, 0x98, 0x7A];
///
/// (CSIDL_BITBUCKET) Recycle Bin virtual folder
+ /// {B7534046-3ECB-4C18-BE4E-64CD4CB7D6AC}
///
internal static ReadOnlySpan RecycleBinFolder =>
- [0xB7, 0x53, 0x40, 0x46, 0x3E, 0xCB, 0x4C, 0x18, 0xBE, 0x4E, 0x64, 0xCD, 0x4C, 0xB7, 0xD6, 0xAC];
+ [0x46, 0x40, 0x53, 0xB7, 0xCB, 0x3E, 0x18, 0x4C, 0xBE, 0x4E, 0x64, 0xCD, 0x4C, 0xB7, 0xD6, 0xAC];
///
/// (CSIDL_RESOURCES) Resources fixed folder
/// "%windir%\Resources"
+ /// {8AD10C31-2ADB-4296-A8F7-E4701232C972}
///
internal static ReadOnlySpan ResourceDir =>
- [0x8A, 0xD1, 0x0C, 0x31, 0x2A, 0xDB, 0x42, 0x96, 0xA8, 0xF7, 0xE4, 0x70, 0x12, 0x32, 0xC9, 0x72];
+ [0x31, 0x0C, 0xD1, 0x8A, 0xDB, 0x2A, 0x96, 0x42, 0xA8, 0xF7, 0xE4, 0x70, 0x12, 0x32, 0xC9, 0x72];
///
/// (CSIDL_APPDATA) Roaming user application data folder
/// "%APPDATA%" ("%USERPROFILE%\AppData\Roaming")
+ /// {3EB685DB-65F9-4CF6-A03A-E3EF65729F3D}
///
internal static ReadOnlySpan RoamingAppData =>
- [0x3E, 0xB6, 0x85, 0xDB, 0x65, 0xF9, 0x4C, 0xF6, 0xA0, 0x3A, 0xE3, 0xEF, 0x65, 0x72, 0x9F, 0x3D];
+ [0xDB, 0x85, 0xB6, 0x3E, 0xF9, 0x65, 0xF6, 0x4C, 0xA0, 0x3A, 0xE3, 0xEF, 0x65, 0x72, 0x9F, 0x3D];
///
/// (CSIDL_SENDTO) SendTo folder
/// "%APPDATA%\Microsoft\Windows\SendTo"
+ /// {8983036C-27C0-404B-8F08-102D10DCFD74}
///
internal static ReadOnlySpan SendTo =>
- [0x89, 0x83, 0x03, 0x6C, 0x27, 0xC0, 0x40, 0x4B, 0x8F, 0x08, 0x10, 0x2D, 0x10, 0xDC, 0xFD, 0x74];
+ [0x6C, 0x03, 0x83, 0x89, 0xC0, 0x27, 0x4B, 0x40, 0x8F, 0x08, 0x10, 0x2D, 0x10, 0xDC, 0xFD, 0x74];
///
/// (CSIDL_STARTMENU) Start Menu folder
/// "%APPDATA%\Microsoft\Windows\Start Menu"
+ /// {625B53C3-AB48-4EC1-BA1F-A1EF4146FC19}
///
internal static ReadOnlySpan StartMenu =>
- [0x62, 0x5B, 0x53, 0xC3, 0xAB, 0x48, 0x4E, 0xC1, 0xBA, 0x1F, 0xA1, 0xEF, 0x41, 0x46, 0xFC, 0x19];
+ [0xC3, 0x53, 0x5B, 0x62, 0x48, 0xAB, 0xC1, 0x4E, 0xBA, 0x1F, 0xA1, 0xEF, 0x41, 0x46, 0xFC, 0x19];
///
/// (CSIDL_STARTUP, CSIDL_ALTSTARTUP) Startup folder
/// "%APPDATA%\Microsoft\Windows\Start Menu\Programs\StartUp"
+ /// {B97D20BB-F46A-4C97-BA10-5E3608430854}
///
internal static ReadOnlySpan Startup =>
- [0xB9, 0x7D, 0x20, 0xBB, 0xF4, 0x6A, 0x4C, 0x97, 0xBA, 0x10, 0x5E, 0x36, 0x08, 0x43, 0x08, 0x54];
+ [0xBB, 0x20, 0x7D, 0xB9, 0x6A, 0xF4, 0x97, 0x4C, 0xBA, 0x10, 0x5E, 0x36, 0x08, 0x43, 0x08, 0x54];
///
/// (CSIDL_SYSTEMX86) X86 System32 folder
/// "%windir%\system32" or "%windir%\syswow64"
+ /// {D65231B0-B2F1-4857-A4CE-A8E7C6EA7D27}
///
internal static ReadOnlySpan SystemX86 =>
- [0xD6, 0x52, 0x31, 0xB0, 0xB2, 0xF1, 0x48, 0x57, 0xA4, 0xCE, 0xA8, 0xE7, 0xC6, 0xEA, 0x7D, 0x27];
+ [0xB0, 0x31, 0x52, 0xD6, 0xF1, 0xB2, 0x57, 0x48, 0xA4, 0xCE, 0xA8, 0xE7, 0xC6, 0xEA, 0x7D, 0x27];
///
/// (CSIDL_TEMPLATES) Templates folder
/// "%APPDATA%\Microsoft\Windows\Templates"
+ /// {A63293E8-664E-48DB-A079-DF759E0509F7}
///
internal static ReadOnlySpan Templates =>
- [0xA6, 0x32, 0x93, 0xE8, 0x66, 0x4E, 0x48, 0xDB, 0xA0, 0x79, 0xDF, 0x75, 0x9E, 0x05, 0x09, 0xF7];
+ [0xE8, 0x93, 0x32, 0xA6, 0x4E, 0x66, 0xDB, 0x48, 0xA0, 0x79, 0xDF, 0x75, 0x9E, 0x05, 0x09, 0xF7];
///
/// (CSIDL_MYVIDEO) Videos folder
/// "%USERPROFILE%\Videos"
+ /// {18989B1D-99B5-455B-841C-AB7C74E4DDFC}
///
internal static ReadOnlySpan Videos =>
- [0x18, 0x98, 0x9B, 0x1D, 0x99, 0xB5, 0x45, 0x5B, 0x84, 0x1C, 0xAB, 0x7C, 0x74, 0xE4, 0xDD, 0xFC];
+ [0x1D, 0x9B, 0x98, 0x18, 0xB5, 0x99, 0x5B, 0x45, 0x84, 0x1C, 0xAB, 0x7C, 0x74, 0xE4, 0xDD, 0xFC];
///
/// (CSIDL_WINDOWS) Windows folder "%windir%"
+ /// {F38BF404-1D43-42F2-9305-67DE0B28FC23}
///
internal static ReadOnlySpan Windows =>
- [0xF3, 0x8B, 0xF4, 0x04, 0x1D, 0x43, 0x42, 0xF2, 0x93, 0x05, 0x67, 0xDE, 0x0B, 0x28, 0xFC, 0x23];
+ [0x04, 0xF4, 0x8B, 0xF3, 0x43, 0x1D, 0xF2, 0x42, 0x93, 0x05, 0x67, 0xDE, 0x0B, 0x28, 0xFC, 0x23];
}
}
}
From 5c92f53c0cdc4d97fa731d1b46e2418ddb375bc2 Mon Sep 17 00:00:00 2001
From: xtqqczze <45661989+xtqqczze@users.noreply.github.com>
Date: Fri, 1 Aug 2025 22:41:37 +0100
Subject: [PATCH 4/6] Refactor GetFolderPath methods to eliminate redundant
checks
---
.../src/System/Environment.Android.cs | 6 +++++-
.../System/Environment.GetFolderPathCore.Unix.cs | 13 ++++++++-----
.../src/System/Environment.Win32.cs | 5 +++--
.../src/System/Environment.cs | 11 +++++++----
.../src/System/Environment.iOS.cs | 6 +++++-
5 files changed, 28 insertions(+), 13 deletions(-)
diff --git a/src/libraries/System.Private.CoreLib/src/System/Environment.Android.cs b/src/libraries/System.Private.CoreLib/src/System/Environment.Android.cs
index d5e3fae3a9e2b4..70add55d98e849 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Environment.Android.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Environment.Android.cs
@@ -15,6 +15,8 @@ public static partial class Environment
private static string GetFolderPathCore(SpecialFolder folder, SpecialFolderOption _ /*option*/)
{
+ // We don't need to check if the folder is defined here, as GetSpecialFolder will do it.
+
if (s_specialFolders == null)
{
Interlocked.CompareExchange(ref s_specialFolders, new Dictionary(), null);
@@ -92,7 +94,9 @@ private static string GetFolderPathCore(SpecialFolder folder, SpecialFolderOptio
return "/usr/share";
default:
- return string.Empty;
+ if (!Enum.IsDefined(folder))
+ throw new ArgumentOutOfRangeException(nameof(folder), folder, SR.Format(SR.Arg_EnumIllegalVal, folder));
+ return null;
}
}
}
diff --git a/src/libraries/System.Private.CoreLib/src/System/Environment.GetFolderPathCore.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/Environment.GetFolderPathCore.Unix.cs
index 694310874e95de..c5f910f20d73ea 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Environment.GetFolderPathCore.Unix.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Environment.GetFolderPathCore.Unix.cs
@@ -19,9 +19,9 @@ public static partial class Environment
{
private static string GetFolderPathCore(SpecialFolder folder, SpecialFolderOption option)
{
- // Get the path for the SpecialFolder
- string path = GetFolderPathCoreWithoutValidation(folder) ?? string.Empty;
- Debug.Assert(path != null);
+ // We don't need to check if the folder is defined here, as GetSpecialFolder will do it.
+
+ string path = GetSpecialFolder(folder) ?? string.Empty;
// If we didn't get one, or if we got one but we're not supposed to verify it,
// or if we're supposed to verify it and it passes verification, return the path.
@@ -46,7 +46,7 @@ private static string GetFolderPathCore(SpecialFolder folder, SpecialFolderOptio
return path;
}
- private static string? GetFolderPathCoreWithoutValidation(SpecialFolder folder)
+ private static string? GetSpecialFolder(SpecialFolder folder)
{
// First handle any paths that involve only static paths, avoiding the overheads of getting user-local paths.
// https://www.freedesktop.org/software/systemd/man/file-hierarchy.html
@@ -143,8 +143,11 @@ private static string GetFolderPathCore(SpecialFolder folder, SpecialFolderOptio
#endif
}
+ if (!Enum.IsDefined(folder))
+ throw new ArgumentOutOfRangeException(nameof(folder), folder, SR.Format(SR.Arg_EnumIllegalVal, folder));
+
// No known path for the SpecialFolder
- return string.Empty;
+ return null;
}
private static string GetXdgConfig(string home)
diff --git a/src/libraries/System.Private.CoreLib/src/System/Environment.Win32.cs b/src/libraries/System.Private.CoreLib/src/System/Environment.Win32.cs
index 8f251888400cf4..f424a7324b56ed 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Environment.Win32.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Environment.Win32.cs
@@ -224,8 +224,6 @@ private static string GetFolderPathCore(SpecialFolder folder, SpecialFolderOptio
case SpecialFolder.System:
// This assumes the system directory always exists and thus we don't need to do anything special for any SpecialFolderOption.
return SystemDirectory;
- default:
- return string.Empty;
// Map the SpecialFolder to the appropriate Guid
case SpecialFolder.ApplicationData:
@@ -374,6 +372,9 @@ private static string GetFolderPathCore(SpecialFolder folder, SpecialFolderOptio
folderGuid = Interop.Shell32.KnownFolders.Windows;
fallbackEnv = "windir";
break;
+ default:
+ Debug.Assert(Enum.IsDefined(folder), $"Unexpected SpecialFolder value: {folder}. Please ensure all SpecialFolder enum values are handled in the switch statement.");
+ throw new ArgumentOutOfRangeException(nameof(folder), folder, SR.Format(SR.Arg_EnumIllegalVal, folder));
}
Guid folderId = new Guid(folderGuid);
diff --git a/src/libraries/System.Private.CoreLib/src/System/Environment.cs b/src/libraries/System.Private.CoreLib/src/System/Environment.cs
index 81cd182e7da155..bb5f0720d5e7b1 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Environment.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Environment.cs
@@ -152,11 +152,14 @@ public static string ExpandEnvironmentVariables(string name)
public static string GetFolderPath(SpecialFolder folder, SpecialFolderOption option)
{
- if (!Enum.IsDefined(folder))
- throw new ArgumentOutOfRangeException(nameof(folder), folder, SR.Format(SR.Arg_EnumIllegalVal, folder));
+ // We don't need to check if folder is defined here, as GetFolderPathCore will do it.
- if (option != SpecialFolderOption.None && !Enum.IsDefined(option))
- throw new ArgumentOutOfRangeException(nameof(option), option, SR.Format(SR.Arg_EnumIllegalVal, option));
+ if (option is not SpecialFolderOption.None and not SpecialFolderOption.Create and not SpecialFolderOption.DoNotVerify)
+ {
+ Throw(folder, option);
+ static void Throw(SpecialFolder _, SpecialFolderOption option) =>
+ throw new ArgumentOutOfRangeException(nameof(option), option, SR.Format(SR.Arg_EnumIllegalVal, option));
+ }
return GetFolderPathCore(folder, option);
}
diff --git a/src/libraries/System.Private.CoreLib/src/System/Environment.iOS.cs b/src/libraries/System.Private.CoreLib/src/System/Environment.iOS.cs
index 973790e0785a01..eff028a0c9e79e 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Environment.iOS.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Environment.iOS.cs
@@ -20,6 +20,8 @@ public static partial class Environment
private static string GetFolderPathCore(SpecialFolder folder, SpecialFolderOption _ /*option*/)
{
+ // We don't need to check if the folder is defined here, as GetSpecialFolder will do it.
+
if (s_specialFolders == null)
{
Interlocked.CompareExchange(ref s_specialFolders, new Dictionary(), null);
@@ -91,7 +93,9 @@ private static string GetFolderPathCore(SpecialFolder folder, SpecialFolderOptio
return "/usr/share";
default:
- return string.Empty;
+ if (!Enum.IsDefined(folder))
+ throw new ArgumentOutOfRangeException(nameof(folder), folder, SR.Format(SR.Arg_EnumIllegalVal, folder));
+ return null;
}
static string CombineSearchPath(NSSearchPathDirectory searchPath, string subdirectory)
From 706ebe0a8d144b4edb8be71a829be8e7535cd56e Mon Sep 17 00:00:00 2001
From: xtqqczze <45661989+xtqqczze@users.noreply.github.com>
Date: Sat, 2 Aug 2025 00:34:19 +0100
Subject: [PATCH 5/6] Update
src/libraries/System.Private.CoreLib/src/System/Environment.Win32.cs
Co-authored-by: Jan Kotas
---
.../System.Private.CoreLib/src/System/Environment.Win32.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/libraries/System.Private.CoreLib/src/System/Environment.Win32.cs b/src/libraries/System.Private.CoreLib/src/System/Environment.Win32.cs
index f424a7324b56ed..8e1a8e86014af7 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Environment.Win32.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Environment.Win32.cs
@@ -373,7 +373,7 @@ private static string GetFolderPathCore(SpecialFolder folder, SpecialFolderOptio
fallbackEnv = "windir";
break;
default:
- Debug.Assert(Enum.IsDefined(folder), $"Unexpected SpecialFolder value: {folder}. Please ensure all SpecialFolder enum values are handled in the switch statement.");
+ Debug.Assert(!Enum.IsDefined(folder), $"Unexpected SpecialFolder value: {folder}. Please ensure all SpecialFolder enum values are handled in the switch statement.");
throw new ArgumentOutOfRangeException(nameof(folder), folder, SR.Format(SR.Arg_EnumIllegalVal, folder));
}
From b3452c2b93c4f3150007308678fe28d7d74a4bc9 Mon Sep 17 00:00:00 2001
From: xtqqczze <45661989+xtqqczze@users.noreply.github.com>
Date: Sat, 2 Aug 2025 12:49:58 +0100
Subject: [PATCH 6/6] Address review comments
---
.../src/System/Environment.Android.cs | 2 +-
.../src/System/Environment.GetFolderPathCore.Unix.cs | 2 +-
.../System.Private.CoreLib/src/System/Environment.cs | 10 ++++++----
.../src/System/Environment.iOS.cs | 2 +-
4 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/src/libraries/System.Private.CoreLib/src/System/Environment.Android.cs b/src/libraries/System.Private.CoreLib/src/System/Environment.Android.cs
index 70add55d98e849..23499bfc2bc5ff 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Environment.Android.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Environment.Android.cs
@@ -15,7 +15,7 @@ public static partial class Environment
private static string GetFolderPathCore(SpecialFolder folder, SpecialFolderOption _ /*option*/)
{
- // We don't need to check if the folder is defined here, as GetSpecialFolder will do it.
+ // No need to validate if 'folder' is defined; GetSpecialFolder handles this check.
if (s_specialFolders == null)
{
diff --git a/src/libraries/System.Private.CoreLib/src/System/Environment.GetFolderPathCore.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/Environment.GetFolderPathCore.Unix.cs
index c5f910f20d73ea..9d7cf66b226dc8 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Environment.GetFolderPathCore.Unix.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Environment.GetFolderPathCore.Unix.cs
@@ -19,7 +19,7 @@ public static partial class Environment
{
private static string GetFolderPathCore(SpecialFolder folder, SpecialFolderOption option)
{
- // We don't need to check if the folder is defined here, as GetSpecialFolder will do it.
+ // No need to validate if 'folder' is defined; GetSpecialFolder handles this check.
string path = GetSpecialFolder(folder) ?? string.Empty;
diff --git a/src/libraries/System.Private.CoreLib/src/System/Environment.cs b/src/libraries/System.Private.CoreLib/src/System/Environment.cs
index bb5f0720d5e7b1..11c712fc68d6c1 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Environment.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Environment.cs
@@ -148,16 +148,18 @@ public static string ExpandEnvironmentVariables(string name)
return ExpandEnvironmentVariablesCore(name);
}
- public static string GetFolderPath(SpecialFolder folder) => GetFolderPath(folder, SpecialFolderOption.None);
+ public static string GetFolderPath(SpecialFolder folder) => GetFolderPathCore(folder, SpecialFolderOption.None);
public static string GetFolderPath(SpecialFolder folder, SpecialFolderOption option)
{
- // We don't need to check if folder is defined here, as GetFolderPathCore will do it.
+ // No need to validate if 'folder' is defined; GetFolderPathCore handles this check.
if (option is not SpecialFolderOption.None and not SpecialFolderOption.Create and not SpecialFolderOption.DoNotVerify)
{
- Throw(folder, option);
- static void Throw(SpecialFolder _, SpecialFolderOption option) =>
+ // Use a throw helper so that if 'option' is a constant,
+ // the JIT can inline this method and remove the validation check entirely.
+ Throw(option);
+ static void Throw(SpecialFolderOption option) =>
throw new ArgumentOutOfRangeException(nameof(option), option, SR.Format(SR.Arg_EnumIllegalVal, option));
}
diff --git a/src/libraries/System.Private.CoreLib/src/System/Environment.iOS.cs b/src/libraries/System.Private.CoreLib/src/System/Environment.iOS.cs
index eff028a0c9e79e..3464790bb489ee 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Environment.iOS.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Environment.iOS.cs
@@ -20,7 +20,7 @@ public static partial class Environment
private static string GetFolderPathCore(SpecialFolder folder, SpecialFolderOption _ /*option*/)
{
- // We don't need to check if the folder is defined here, as GetSpecialFolder will do it.
+ // No need to validate if 'folder' is defined; GetSpecialFolder handles this check.
if (s_specialFolders == null)
{