Portable Tool for an Ideal Windows Setup
C# activatorbloatware-removalcsharpdebloatdebloaterdisable-servicesmonitoring-systemportableprivacy-toolsregistry-tweakssystem-tuningsystem-utilitytelemetrytweakerwindows-10windows-11windows-debloatwindows-defenderwindows-optimizationwindows-tweaks
upd. MVVM icon binding and extraction provider
Greedekse659f544bb07
diff --git a/.Source/GTweak/Core/ViewModel/InterfaceViewModel.cs b/.Source/GTweak/Core/ViewModel/InterfaceViewModel.csindex 4ab6d117..07b1cd75 100644--- a/.Source/GTweak/Core/ViewModel/InterfaceViewModel.cs+++ b/.Source/GTweak/Core/ViewModel/InterfaceViewModel.cs@@ -11,21 +11,28 @@ namespace GTweak.Core.ViewModel{internal class InterfaceViewModel : ViewModelPageBase<InterfaceModel, InterfaceTweaks>{+ public IReadOnlyDictionary<string, ImageSource> Icons { get; }public Visibility Win11FeatureOnly => HardwareData.OS.IsWin11 ? Visibility.Visible : Visibility.Collapsed;public Visibility Win11FeatureAvailable => HardwareData.OS.IsWin11 && HardwareData.OS.Build.CompareTo(22621.2361m) >= 0 ? Visibility.Visible : Visibility.Collapsed;public bool IsBlockWithoutLicense => WinLicenseHandler.IsWindowsActivated;public Visibility OneDriveAvailable => UninstallingPakages.IsOneDriveInstalled ? Visibility.Visible : Visibility.Collapsed;- public ImageSource HomeIcon => IconExtractProvider.GetStockIcon(IconExtractProvider.StockIconType.Home);- public ImageSource GalleryIcon => IconExtractProvider.GetStockIcon(IconExtractProvider.StockIconType.Gallery);- public ImageSource OneDriveIcon => IconExtractProvider.GetStockIcon(IconExtractProvider.StockIconType.OneDrive);- public ImageSource PCIcon => IconExtractProvider.GetStockIcon(IconExtractProvider.StockIconType.PC);- public ImageSource NetworkIcon => IconExtractProvider.GetStockIcon(IconExtractProvider.StockIconType.Network);- public ImageSource TrashIcon => IconExtractProvider.GetStockIcon(IconExtractProvider.StockIconType.Trash);- public ImageSource PanelIcon => IconExtractProvider.GetStockIcon(IconExtractProvider.StockIconType.Panel);- public ImageSource UserIcon => IconExtractProvider.GetStockIcon(IconExtractProvider.StockIconType.User);+ protected override void Analyze(InterfaceTweaks tweaks) => tweaks?.AnalyzeAndUpdate();protected override IReadOnlyDictionary<string, object> GetControlStates() => InterfaceTweaks.ControlStates;- protected override void Analyze(InterfaceTweaks tweaks) => tweaks?.AnalyzeAndUpdate();+ public InterfaceViewModel()+ {+ Icons = new Dictionary<string, ImageSource>+ {+ { "Home", IconExtractProvider.GetStockIcon(IconExtractProvider.StockIconType.Home) },+ { "Gallery", IconExtractProvider.GetStockIcon(IconExtractProvider.StockIconType.Gallery) },+ { "OneDrive", IconExtractProvider.GetStockIcon(IconExtractProvider.StockIconType.OneDrive) },+ { "PC", IconExtractProvider.GetStockIcon(IconExtractProvider.StockIconType.PC) },+ { "Network", IconExtractProvider.GetStockIcon(IconExtractProvider.StockIconType.Network) },+ { "Trash", IconExtractProvider.GetStockIcon(IconExtractProvider.StockIconType.Trash) },+ { "Panel", IconExtractProvider.GetStockIcon(IconExtractProvider.StockIconType.Panel) },+ { "UserFile", IconExtractProvider.GetStockIcon(IconExtractProvider.StockIconType.UserFile) }+ };+ }}}diff --git a/.Source/GTweak/Utilities/Configuration/IconExtractProvider.cs b/.Source/GTweak/Utilities/Configuration/IconExtractProvider.csindex d91f9a49..fcf54fb0 100644--- a/.Source/GTweak/Utilities/Configuration/IconExtractProvider.cs+++ b/.Source/GTweak/Utilities/Configuration/IconExtractProvider.cs@@ -1,6 +1,5 @@using System;using System.Collections.Concurrent;-using System.Collections.Generic;using System.Runtime.InteropServices;using System.Windows;using System.Windows.Interop;@@ -19,27 +18,24 @@ namespace GTweak.Utilities.Configurationprivate static readonly ConcurrentDictionary<(string, int, bool), ImageSource> _iconCache = new ConcurrentDictionary<(string, int, bool), ImageSource>();- internal enum StockIconType { Home, Gallery, PC, Network, Trash, Panel, User, OneDrive }-- private static readonly Dictionary<StockIconType, (string file, int index)> _stockIconMappings = new Dictionary<StockIconType, (string, int)>- {- { StockIconType.Home, ("shell32.dll", -51380) },- { StockIconType.Gallery, ("shell32.dll", -51586) },- { StockIconType.PC, ("imageres.dll", -109) },- { StockIconType.Network, ("imageres.dll", -25) },- { StockIconType.Trash, ("imageres.dll", -54) },- { StockIconType.Panel, ("imageres.dll", -27) },- { StockIconType.User, ("imageres.dll", -123) },- { StockIconType.OneDrive, ("imageres.dll", -1040) }- };+ internal enum StockIconType { Home, Gallery, OneDrive, PC, Network, Trash, Panel, UserFile }internal static ImageSource GetStockIcon(StockIconType type){- if (_stockIconMappings.TryGetValue(type, out (string file, int index) iconInfo))+ (string file, int index) = type switch{- return GetIcon(iconInfo.file, iconInfo.index);- }- return null;+ StockIconType.Home => ("shell32.dll", -51380),+ StockIconType.Gallery => ("shell32.dll", -51586),+ StockIconType.OneDrive => ("imageres.dll", -1040),+ StockIconType.PC => ("imageres.dll", -109),+ StockIconType.Network => ("imageres.dll", -25),+ StockIconType.Trash => ("imageres.dll", -54),+ StockIconType.Panel => ("imageres.dll", -27),+ StockIconType.UserFile => ("imageres.dll", -123),+ _ => (null, 0)+ };++ return file != null ? GetIcon(file, index) : null;}internal static ImageSource GetIcon(string file, int index, bool large = true)diff --git a/.Source/GTweak/View/InterfaceView.xaml b/.Source/GTweak/View/InterfaceView.xamlindex 3b764562..4d7983c9 100644--- a/.Source/GTweak/View/InterfaceView.xaml+++ b/.Source/GTweak/View/InterfaceView.xaml@@ -45,19 +45,19 @@<uc:ExpandableBox Text="{DynamicResource btn_change}" Margin="7,5,5,0" Height="32" VerticalAlignment="Center" Closed="ExpandableBox_Closed"><CheckBox x:Uid="Checkbox1" IsChecked="{Binding [Checkbox1].State}" Click="CheckBox_Click"><StackPanel Orientation="Horizontal" Background="Transparent">- <Image Source="{Binding HomeIcon}" Width="16" Height="16"/>+ <Image Source="{Binding Icons[Home]}" Width="16" Height="16"/><TextBlock Text="{DynamicResource chk_home_intf}" Margin="5,0,0,0"/></StackPanel></CheckBox><CheckBox x:Uid="Checkbox2" IsChecked="{Binding [Checkbox2].State}" Margin="0,4,0,0" Click="CheckBox_Click"><StackPanel Orientation="Horizontal" Background="Transparent">- <Image Source="{Binding GalleryIcon}" Width="16" Height="16"/>+ <Image Source="{Binding Icons[Gallery]}" Width="16" Height="16"/><TextBlock Text="{DynamicResource chk_gallery_intf}" Margin="5,0,0,0"/></StackPanel></CheckBox><CheckBox x:Uid="Checkbox3" Visibility="{Binding OneDriveAvailable}" IsChecked="{Binding [Checkbox3].State}" Margin="0,4,0,0" Click="CheckBox_Click"><StackPanel Orientation="Horizontal" Background="Transparent">- <Image Source="{Binding OneDriveIcon}" Width="16" Height="16"/>+ <Image Source="{Binding Icons[OneDrive]}" Width="16" Height="16"/><TextBlock Text="{DynamicResource OneDrive_pkg}" Margin="5,0,0,0"/></StackPanel></CheckBox>@@ -81,40 +81,40 @@<uc:ExpandableBox Text="{DynamicResource btn_change}" Margin="7,5,5,0" Height="32" VerticalAlignment="Center" Closed="ExpandableBox_Closed"><CheckBox x:Uid="Checkbox8" IsChecked="{Binding [Checkbox8].State}" Click="CheckBox_Click"><StackPanel Orientation="Horizontal" Background="Transparent">- <Image Source="{Binding PCIcon}" Width="16" Height="16"/>+ <Image Source="{Binding Icons[PC]}" Width="16" Height="16"/><TextBlock Text="{DynamicResource chk_pc_intf}" Margin="5,0,0,0"/></StackPanel></CheckBox><CheckBox x:Uid="Checkbox9" IsChecked="{Binding [Checkbox9].State}" Click="CheckBox_Click" Margin="0,4,0,0"><StackPanel Orientation="Horizontal" Background="Transparent">- <Image Source="{Binding NetworkIcon}" Width="16" Height="16"/>+ <Image Source="{Binding Icons[Network]}" Width="16" Height="16"/><TextBlock Text="{DynamicResource chk_net_intf}" Style="{StaticResource TextDefault}" Margin="5,0,0,0" FontSize="14px"/></StackPanel></CheckBox><CheckBox x:Uid="Checkbox10" IsChecked="{Binding [Checkbox10].State}" Click="CheckBox_Click" Margin="0,4,0,0"><StackPanel Orientation="Horizontal" Background="Transparent">- <Image Source="{Binding TrashIcon}" Width="16" Height="16"/>+ <Image Source="{Binding Icons[Trash]}" Width="16" Height="16"/><TextBlock Text="{DynamicResource chk_trash_intf}" Style="{StaticResource TextDefault}" Margin="5,0,0,0" FontSize="14px"/></StackPanel></CheckBox><CheckBox x:Uid="Checkbox11" IsChecked="{Binding [Checkbox11].State}" Click="CheckBox_Click" Margin="0,4,0,0"><StackPanel Orientation="Horizontal" Background="Transparent">- <Image Source="{Binding PanelIcon}" Width="16" Height="16"/>+ <Image Source="{Binding Icons[Panel]}" Width="16" Height="16"/><TextBlock Text="{DynamicResource chk_panel_intf}" Style="{StaticResource TextDefault}" Margin="5,0,0,0" FontSize="14px"/></StackPanel></CheckBox><CheckBox x:Uid="Checkbox12" IsChecked="{Binding [Checkbox12].State}" Click="CheckBox_Click" Margin="0,4,0,0"><StackPanel Orientation="Horizontal" Background="Transparent">- <Image Source="{Binding UserIcon}" Width="16" Height="16"/>+ <Image Source="{Binding Icons[UserFile]}" Width="16" Height="16"/><TextBlock Text="{DynamicResource chk_user_intf}" Style="{StaticResource TextDefault}" Margin="5,0,0,0" FontSize="14px"/></StackPanel></CheckBox><CheckBox x:Uid="Checkbox13" Visibility="{Binding OneDriveAvailable}" IsChecked="{Binding [Checkbox13].State}" Click="CheckBox_Click" Margin="0,4,0,0"><StackPanel Orientation="Horizontal" Background="Transparent">- <Image Source="{Binding OneDriveIcon}" Width="16" Height="16"/>+ <Image Source="{Binding Icons[OneDrive]}" Width="16" Height="16"/><TextBlock Text="{DynamicResource OneDrive_pkg}" Style="{StaticResource TextDefault}" Margin="5,0,0,0" FontSize="14px"/></StackPanel></CheckBox>