|
1 | 1 | using Newtonsoft.Json;
|
2 | 2 | using System;
|
| 3 | +using System.Collections.Immutable; |
3 | 4 | using System.IO;
|
| 5 | +using System.Text; |
4 | 6 | using System.Xml;
|
5 | 7 |
|
6 | 8 | namespace Schneegans.Unattend;
|
@@ -73,6 +75,39 @@ public record class CustomTaskbarIcons(
|
73 | 75 | string Xml
|
74 | 76 | ) : ITaskbarIcons;
|
75 | 77 |
|
| 78 | +public interface IEffects; |
| 79 | + |
| 80 | +public record class DefaultEffects : IEffects; |
| 81 | + |
| 82 | +public record class BestPerformanceEffects : IEffects; |
| 83 | + |
| 84 | +public record class BestAppearanceEffects : IEffects; |
| 85 | + |
| 86 | +public record class CustomEffects( |
| 87 | + ImmutableDictionary<Effect, bool> Settings |
| 88 | +) : IEffects; |
| 89 | + |
| 90 | +public enum Effect |
| 91 | +{ |
| 92 | + ControlAnimations, |
| 93 | + AnimateMinMax, |
| 94 | + TaskbarAnimations, |
| 95 | + DWMAeroPeekEnabled, |
| 96 | + MenuAnimation, |
| 97 | + TooltipAnimation, |
| 98 | + SelectionFade, |
| 99 | + DWMSaveThumbnailEnabled, |
| 100 | + CursorShadow, |
| 101 | + ListviewShadow, |
| 102 | + ThumbnailsOrIcon, |
| 103 | + ListviewAlphaSelect, |
| 104 | + DragFullWindows, |
| 105 | + ComboBoxAnimation, |
| 106 | + FontSmoothing, |
| 107 | + ListBoxSmoothScrolling, |
| 108 | + DropShadow |
| 109 | +} |
| 110 | + |
76 | 111 | class OptimizationsModifier(ModifierContext context) : Modifier(context)
|
77 | 112 | {
|
78 | 113 | public override void Process()
|
@@ -555,5 +590,45 @@ void SetStartTiles(string xml)
|
555 | 590 | DefaultUserScript.Append(@"reg.exe add ""HKU\DefaultUser\Software\Policies\Microsoft\Windows\Explorer"" /v DisableSearchBoxSuggestions /t REG_DWORD /d 1 /f;");
|
556 | 591 | }
|
557 | 592 | }
|
| 593 | + { |
| 594 | + static ImmutableDictionary<Effect, bool> MakeEffectsDictionary(bool value) |
| 595 | + { |
| 596 | + var builder = ImmutableDictionary.CreateBuilder<Effect, bool>(); |
| 597 | + foreach (var key in Enum.GetValues<Effect>()) |
| 598 | + { |
| 599 | + builder.Add(key, value); |
| 600 | + } |
| 601 | + return builder.ToImmutable(); |
| 602 | + } |
| 603 | + |
| 604 | + void SetEffects(CustomEffects effects, int setting) |
| 605 | + { |
| 606 | + StringBuilder sb = new(); |
| 607 | + foreach (var pair in effects.Settings) |
| 608 | + { |
| 609 | + sb.AppendLine(@$"Set-ItemProperty -LiteralPath ""Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VisualEffects\{pair.Key}"" -Name 'DefaultValue' -Value {(pair.Value ? 1 : 0)} -Type 'DWord' -Force;"); |
| 610 | + } |
| 611 | + SpecializeScript.Append(sb.ToString()); |
| 612 | + UserOnceScript.Append($@"Set-ItemProperty -LiteralPath 'Registry::HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\VisualEffects' -Name 'VisualFXSetting' -Type 'DWord' -Value {setting} -Force;"); |
| 613 | + } |
| 614 | + |
| 615 | + switch (Configuration.Effects) |
| 616 | + { |
| 617 | + case DefaultEffects: |
| 618 | + break; |
| 619 | + |
| 620 | + case BestAppearanceEffects: |
| 621 | + SetEffects(new CustomEffects(MakeEffectsDictionary(true)), 1); |
| 622 | + break; |
| 623 | + |
| 624 | + case BestPerformanceEffects: |
| 625 | + SetEffects(new CustomEffects(MakeEffectsDictionary(false)), 2); |
| 626 | + break; |
| 627 | + |
| 628 | + case CustomEffects effects: |
| 629 | + SetEffects(effects, 3); |
| 630 | + break; |
| 631 | + } |
| 632 | + } |
558 | 633 | }
|
559 | 634 | }
|
0 commit comments