diff --git a/Main.cs b/Main.cs index 4190a9f..1d25e4b 100644 --- a/Main.cs +++ b/Main.cs @@ -345,7 +345,8 @@ public record class Configuration( IStartTilesSettings StartTilesSettings, CompactOsModes CompactOsMode, ITaskbarIcons TaskbarIcons, - IEffects Effects + IEffects Effects, + IDesktopIconSettings DesktopIcons ) { public static Configuration Default => new( @@ -408,7 +409,8 @@ IEffects Effects StartTilesSettings: new DefaultStartTilesSettings(), CompactOsMode: CompactOsModes.Default, TaskbarIcons: new DefaultTaskbarIcons(), - Effects: new DefaultEffects() + Effects: new DefaultEffects(), + DesktopIcons: new DefaultDesktopIconSettings() ); } @@ -689,6 +691,19 @@ InputType type public InputType Type { get; } = type; } +public class DesktopIcon( + string id, + string displayName, + string guid +) : IKeyed +{ + public string Id { get; } = id; + + public string DisplayName { get; } = displayName; + + public string Guid { get; } = guid; +} + public class TimeOffset( string id, string displayName @@ -830,6 +845,10 @@ public UnattendGenerator() string json = Util.StringFromResource("TimeOffset.json"); TimeOffsets = JsonConvert.DeserializeObject(json).ToKeyedDictionary(); } + { + string json = Util.StringFromResource("DesktopIcon.json"); + DesktopIcons = JsonConvert.DeserializeObject(json).ToKeyedDictionary(); + } { VerifyUniqueKeys(Components.Values, e => e.Id); @@ -855,6 +874,11 @@ public UnattendGenerator() VerifyUniqueKeys(TimeOffsets.Values, e => e.Id); VerifyUniqueKeys(TimeOffsets.Values, e => e.DisplayName); } + { + VerifyUniqueKeys(DesktopIcons.Values, e => e.Id); + VerifyUniqueKeys(DesktopIcons.Values, e => e.Guid); + VerifyUniqueKeys(DesktopIcons.Values, e => e.DisplayName); + } } private static void VerifyUniqueKeys(IEnumerable items, Func keySelector) @@ -875,6 +899,8 @@ public ExplicitTimeZoneSettings CreateExplicitTimeZoneSettings(string id) ); } + public IImmutableDictionary DesktopIcons { get; } + public IImmutableDictionary TimeOffsets { get; } public IImmutableDictionary GeoLocations { get; } @@ -935,6 +961,10 @@ public T Lookup(string key) where T : class, IKeyed { return (T)(object)Lookup(GeoLocations, key); } + if (typeof(T) == typeof(DesktopIcon)) + { + return (T)(object)Lookup(DesktopIcons, key); + } throw new NotSupportedException(); } @@ -1120,7 +1150,7 @@ public string AddTextFile(string resourceName, Action? before = nu { return AddTextFile(resourceName, content: Util.StringFromResource(resourceName), before: before, after: after); } - + private void AddFile(string content, string path) { { diff --git a/UnattendGenerator.csproj b/UnattendGenerator.csproj index 65ab915..c6eae1b 100644 --- a/UnattendGenerator.csproj +++ b/UnattendGenerator.csproj @@ -10,6 +10,7 @@ + @@ -33,6 +34,7 @@ + diff --git a/modifier/Optimizations.cs b/modifier/Optimizations.cs index 440c90d..ff3f3d8 100644 --- a/modifier/Optimizations.cs +++ b/modifier/Optimizations.cs @@ -108,6 +108,14 @@ public enum Effect DropShadow } +public interface IDesktopIconSettings; + +public record class DefaultDesktopIconSettings : IDesktopIconSettings; + +public record class CustomDesktopIconSettings( + ImmutableDictionary Settings +) : IDesktopIconSettings; + class OptimizationsModifier(ModifierContext context) : Modifier(context) { public override void Process() @@ -628,6 +636,32 @@ void SetEffects(CustomEffects effects, int setting) case CustomEffects effects: SetEffects(effects, 3); break; + + default: + throw new NotSupportedException(); + } + } + { + switch (Configuration.DesktopIcons) + { + case DefaultDesktopIconSettings: + break; + case CustomDesktopIconSettings icons: + StringBuilder sb = new(); + foreach (string key in new string[] { "ClassicStartMenu", "NewStartPanel" }) + { + string path = @$"Registry::HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\{key}"; + sb.AppendLine(@$"New-Item -Path '{path}' -Force;"); + foreach (var pair in icons.Settings) + { + sb.AppendLine(@$"Set-ItemProperty -Path '{path}' -Name '{pair.Key.Guid}' -Value {(pair.Value ? 0 : 1)} -Type 'DWord';"); + } + } + UserOnceScript.Append(sb.ToString()); + UserOnceScript.RestartExplorer(); + break; + default: + throw new NotSupportedException(); } } } diff --git a/resource/DesktopIcon.json b/resource/DesktopIcon.json new file mode 100644 index 0000000..ffd7c76 --- /dev/null +++ b/resource/DesktopIcon.json @@ -0,0 +1,67 @@ +[ + { + "Id": "Music", + "DisplayName": "Music", + "Guid": "{1cf1260c-4dd0-4ebb-811f-33c572699fde}" + }, + { + "Id": "ThisPC", + "DisplayName": "This PC", + "Guid": "{20d04fe0-3aea-1069-a2d8-08002b30309d}" + }, + { + "Id": "Downloads", + "DisplayName": "Downloads", + "Guid": "{374de290-123f-4565-9164-39c4925e467b}" + }, + { + "Id": "Pictures", + "DisplayName": "Pictures", + "Guid": "{3add1653-eb32-4cb0-bbd7-dfa0abb5acca}" + }, + { + "Id": "ControlPanel", + "DisplayName": "Control Panel", + "Guid": "{5399e694-6ce5-4d6c-8fce-1d8870fdcba0}" + }, + { + "Id": "UserFiles", + "DisplayName": "User's Files", + "Guid": "{59031a47-3f72-44a7-89c5-5595fe6b30ee}" + }, + { + "Id": "RecycleBin", + "DisplayName": "Recycle bin", + "Guid": "{645ff040-5081-101b-9f08-00aa002f954e}" + }, + { + "Id": "Videos", + "DisplayName": "Videos", + "Guid": "{a0953c92-50dc-43bf-be83-3742fed03c9c}" + }, + { + "Id": "Documents", + "DisplayName": "Documents", + "Guid": "{a8cdff1c-4878-43be-b5fd-f8091c1c60d0}" + }, + { + "Id": "Desktop", + "DisplayName": "Desktop", + "Guid": "{b4bfcc3a-db2c-424c-b029-7fe99a87c641}" + }, + { + "Id": "Gallery", + "DisplayName": "Gallery", + "Guid": "{e88865ea-0e1c-4e20-9aa6-edcd0212c87c}" + }, + { + "Id": "Network", + "DisplayName": "Network", + "Guid": "{f02c1a0d-be21-4350-88b0-7367fc96ef3c}" + }, + { + "Id": "Home", + "DisplayName": "Home", + "Guid": "{f874310e-b6b7-47dc-bc84-b9e6b38f5903}" + } +] \ No newline at end of file