Skip to content

Commit

Permalink
Configure desktop icons
Browse files Browse the repository at this point in the history
  • Loading branch information
cschneegans committed Jan 28, 2025
1 parent dd90e8c commit a40678e
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 3 deletions.
36 changes: 33 additions & 3 deletions Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -408,7 +409,8 @@ IEffects Effects
StartTilesSettings: new DefaultStartTilesSettings(),
CompactOsMode: CompactOsModes.Default,
TaskbarIcons: new DefaultTaskbarIcons(),
Effects: new DefaultEffects()
Effects: new DefaultEffects(),
DesktopIcons: new DefaultDesktopIconSettings()
);
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -830,6 +845,10 @@ public UnattendGenerator()
string json = Util.StringFromResource("TimeOffset.json");
TimeOffsets = JsonConvert.DeserializeObject<TimeOffset[]>(json).ToKeyedDictionary();
}
{
string json = Util.StringFromResource("DesktopIcon.json");
DesktopIcons = JsonConvert.DeserializeObject<DesktopIcon[]>(json).ToKeyedDictionary();
}

{
VerifyUniqueKeys(Components.Values, e => e.Id);
Expand All @@ -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<T>(IEnumerable<T> items, Func<T, object> keySelector)
Expand All @@ -875,6 +899,8 @@ public ExplicitTimeZoneSettings CreateExplicitTimeZoneSettings(string id)
);
}

public IImmutableDictionary<string, DesktopIcon> DesktopIcons { get; }

public IImmutableDictionary<string, TimeOffset> TimeOffsets { get; }

public IImmutableDictionary<string, GeoLocation> GeoLocations { get; }
Expand Down Expand Up @@ -935,6 +961,10 @@ public T Lookup<T>(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();
}

Expand Down Expand Up @@ -1120,7 +1150,7 @@ public string AddTextFile(string resourceName, Action<StringWriter>? before = nu
{
return AddTextFile(resourceName, content: Util.StringFromResource(resourceName), before: before, after: after);
}

private void AddFile(string content, string path)
{
{
Expand Down
2 changes: 2 additions & 0 deletions UnattendGenerator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

<ItemGroup>
<None Remove="resource\ClassicContextMenu.ps1" />
<None Remove="resource\DesktopIcon.json" />
<None Remove="resource\DisableDefender.vbs" />
<None Remove="resource\MakeEdgeUninstallable.ps1" />
<None Remove="resource\MoveActiveHours.vbs" />
Expand All @@ -33,6 +34,7 @@
<EmbeddedResource Include="resource\autounattend.xml" />
<EmbeddedResource Include="resource\autounattend.xsd" />
<EmbeddedResource Include="resource\Component.json" />
<EmbeddedResource Include="resource\DesktopIcon.json" />
<EmbeddedResource Include="resource\DisableDefender.vbs" />
<EmbeddedResource Include="resource\ExtractScripts.ps1" />
<EmbeddedResource Include="resource\GeoId.json" />
Expand Down
34 changes: 34 additions & 0 deletions modifier/Optimizations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ public enum Effect
DropShadow
}

public interface IDesktopIconSettings;

public record class DefaultDesktopIconSettings : IDesktopIconSettings;

public record class CustomDesktopIconSettings(
ImmutableDictionary<DesktopIcon, bool> Settings
) : IDesktopIconSettings;

class OptimizationsModifier(ModifierContext context) : Modifier(context)
{
public override void Process()
Expand Down Expand Up @@ -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();
}
}
}
Expand Down
67 changes: 67 additions & 0 deletions resource/DesktopIcon.json
Original file line number Diff line number Diff line change
@@ -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}"
}
]

0 comments on commit a40678e

Please sign in to comment.