50 lines
2.4 KiB
C#
50 lines
2.4 KiB
C#
namespace FluidExplorer.Services.Icons;
|
|
|
|
/// <summary>
|
|
/// 外壳解析名(parsing name)的小工具。
|
|
/// 资源管理器/地址栏里出现的 "shell:RecycleBinFolder"、"{20D04FE0-3AEA-1069-A2D8-08002B30309D}"(此电脑)
|
|
/// 都不是文件系统路径,必须先经 SHParseDisplayName 解析成 PIDL 才能取图标。
|
|
/// </summary>
|
|
internal static class ShellParsingName
|
|
{
|
|
/// <summary>"shell:" 前缀(大小写不敏感)。</summary>
|
|
internal const string ShellPrefix = "shell:";
|
|
|
|
/// <summary>是不是 "shell:xxx" 形式的解析名。</summary>
|
|
internal static bool IsShellPrefix(string? parsingName)
|
|
=> !string.IsNullOrEmpty(parsingName)
|
|
&& parsingName.StartsWith(ShellPrefix, StringComparison.OrdinalIgnoreCase);
|
|
|
|
/// <summary>是不是 "::{CLSID}" 形式的解析名(此电脑、回收站等已知外壳对象的经典写法)。</summary>
|
|
internal static bool IsGuidPidl(string? parsingName)
|
|
=> !string.IsNullOrEmpty(parsingName)
|
|
&& parsingName.StartsWith("::", StringComparison.Ordinal);
|
|
|
|
/// <summary>本工程支持的外壳解析名(取图标时可以走 PIDL 路径)。</summary>
|
|
internal static bool IsParsingName(string? parsingName)
|
|
=> IsShellPrefix(parsingName) || IsGuidPidl(parsingName);
|
|
|
|
/// <summary>补全 "shell:" 前缀:传入 "RecycleBinFolder" 也能用。</summary>
|
|
internal static string Normalize(string parsingName)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(parsingName)) return string.Empty;
|
|
|
|
string trimmed = parsingName.Trim();
|
|
return IsParsingName(trimmed) ? trimmed : ShellPrefix + trimmed;
|
|
}
|
|
|
|
// 常用已知外壳文件夹的解析名(全部是 Windows 自带原版对象)
|
|
internal const string RecycleBin = "shell:RecycleBinFolder";
|
|
internal const string ThisPcClassic = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}";
|
|
internal const string ThisPc = "shell:MyComputerFolder";
|
|
internal const string Network = "shell:NetworkPlacesFolder";
|
|
internal const string UserProfile = "shell:UserProfile";
|
|
internal const string Desktop = "shell:Desktop";
|
|
internal const string Downloads = "shell:Downloads";
|
|
internal const string Documents = "shell:Personal";
|
|
internal const string Pictures = "shell:MyPictures";
|
|
internal const string Music = "shell:MyMusic";
|
|
internal const string Videos = "shell:MyVideos";
|
|
internal const string ControlPanel = "shell:ControlPanelFolder";
|
|
}
|