diff --git a/W10SS_GUI/Classes/Gui.cs b/W10SS_GUI/Classes/Gui.cs index dbf2e5db..be38b8b2 100644 --- a/W10SS_GUI/Classes/Gui.cs +++ b/W10SS_GUI/Classes/Gui.cs @@ -17,25 +17,20 @@ namespace W10SS_GUI.Classes private Dictionary _togglesCategoryAndPanels = new Dictionary(); private MainWindow MainWindow = Application.Current.MainWindow as MainWindow; private HamburgerCategoryButton _lastclickedbutton; + private List TogglesSwitches = new List(); - internal string LastClickedButtonName - { - get - { - return _lastclickedbutton.Name as string; - } - } + internal string LastClickedButtonName => _lastclickedbutton.Name as string; internal Gui() { - InitializeVariables(); + InitializeGuiVariables(); } - private void InitializeVariables() + private void InitializeGuiVariables() { - foreach (var tagValue in Application.Current.Resources.MergedDictionaries.Where(r => r.Source.Segments[2] == "tags.xaml").FirstOrDefault().Values) + foreach (var tagValue in Application.Current.Resources.MergedDictionaries.Where(r => r.Source.LocalPath == "/Resource/tags.xaml").First().Values) { - _togglesCategoryAndPanels.Add(tagValue.ToString(), MainWindow.panelTogglesCategoryContainer.Children.OfType().Where(p => p.Tag == tagValue).FirstOrDefault()); + _togglesCategoryAndPanels.Add(tagValue.ToString(), MainWindow.panelTogglesCategoryContainer.Children.OfType().Where(p => p.Tag == tagValue).First()); } } @@ -51,7 +46,7 @@ namespace W10SS_GUI.Classes MainWindow.textTogglesHeader.Text = MainWindow.Resources[button.Name] as string; } - internal void HamburgerReopen() + internal void HamburgerReOpen() { MouseEventArgs mouseLeaveArgs = new MouseEventArgs(Mouse.PrimaryDevice, 0) { @@ -80,21 +75,121 @@ namespace W10SS_GUI.Classes { for (int i = 0; i < _togglesCategoryAndPanels.Keys.Count; i++) { - string scriptsCategoryDirs = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, _togglesCategoryAndPanels.Keys.ToList()[i]); - List scriptsFiles = Directory.Exists(scriptsCategoryDirs) - && Directory.EnumerateFiles(scriptsCategoryDirs, "*.*", SearchOption.AllDirectories).Where(f => f.EndsWith(".ps1")).Count() > 0 - ? Directory.EnumerateFiles(scriptsCategoryDirs, "*.*", SearchOption.AllDirectories).Where(f => f.EndsWith(".ps1")).ToList() - : null ; - - scriptsFiles?.ForEach(s => - { - Gui.ReadToggleData(s); - - - }); + string categoryName = _togglesCategoryAndPanels[_togglesCategoryAndPanels.Keys.ToList()[i]].Name; + string psScriptsDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, categoryName.Name); + + TogglesSwitches = Directory.Exists(psScriptsDir) + && Directory.EnumerateFiles(psScriptsDir, "*.*", SearchOption.AllDirectories) + .Where(f => f.EndsWith(".ps1")) + .Count() > 0 + + ? Directory.EnumerateFiles(psScriptsDir, "*.*", SearchOption.AllDirectories) + .Where(f => f.EndsWith(".ps1")) + .Select(p => CreateToogleSwitchFromScript(scriptPath:p, panelName:categoryName)) + .ToList() + : null; + + + } } - internal StackPanel GetPanelByName(string name) => _togglesCategoryAndPanels[name] as StackPanel; + internal ToggleSwitch CreateToogleSwitchFromScript(string scriptPath, string panelName) + { + ToggleSwitch toggleSwitch = new ToggleSwitch(); + //{ + // ScriptPath = scriptPath, + // PanelName = panel + //}; + + //try + //{ + // using (StreamReader streamReader = new StreamReader(scriptPath, Encoding.UTF8)) + // { + // for (int i = 0; i < 4; i++) + // { + // string textLine = streamReader.ReadLine(); + // toggleInfo.IsValid = textLine.StartsWith("# ") && textLine.Length >= 10 ? true : false; + + // switch (i) + // { + // case 0: + // toggleInfo.HeaderEN = textLine.Replace("# ", ""); + // break; + + // case 1: + // toggleInfo.DescriptionEN = textLine.Replace("# ", ""); + // break; + + // case 2: + // toggleInfo.HeaderRU = textLine.Replace("# ", ""); + // break; + + // case 3: + // toggleInfo.DescriptionRU = textLine.Replace("# ", ""); + // break; + + // default: + // break; + // } + // } + // } + //} + //catch (Exception) + //{ + + //} + + return toggleSwitch; + } + + //internal ToggleInfo NewToogleInfoFromScript(string scriptPath, string panelName) + //{ + // ToggleInfo toggleInfo = new ToggleInfo + // { + // ScriptPath = scriptPath, + // PanelName = panelName + // }; + + // try + // { + // using (StreamReader streamReader = new StreamReader(scriptPath, Encoding.UTF8)) + // { + // for (int i = 0; i < 4; i++) + // { + // string textLine = streamReader.ReadLine(); + // toggleInfo.IsValid = textLine.StartsWith("# ") && textLine.Length >= 10 ? true : false; + + // switch (i) + // { + // case 0: + // toggleInfo.HeaderEN = textLine.Replace("# ", ""); + // break; + + // case 1: + // toggleInfo.DescriptionEN = textLine.Replace("# ", ""); + // break; + + // case 2: + // toggleInfo.HeaderRU = textLine.Replace("# ", ""); + // break; + + // case 3: + // toggleInfo.DescriptionRU = textLine.Replace("# ", ""); + // break; + + // default: + // break; + // } + // } + // } + // } + // catch (Exception) + // { + + // } + + // return toggleInfo; + //} } } \ No newline at end of file diff --git a/W10SS_GUI/Classes/Tags.cs b/W10SS_GUI/Classes/Tags.cs deleted file mode 100644 index c7151ca7..00000000 --- a/W10SS_GUI/Classes/Tags.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; - -namespace W10SS_GUI -{ - internal static class Tags - { - internal static readonly string Privacy = string.Format("{0}", Application.Current.Resources["tagCategoryPrivacy"]); - internal static readonly string Ui = string.Format("{0}", Application.Current.Resources["tagCategoryUi"]); - internal static readonly string OneDrive = string.Format("{0}", Application.Current.Resources["tagCategoryOneDrive"]); - internal static readonly string System = string.Format("{0}", Application.Current.Resources["tagCategorySystem"]); - internal static readonly string StartMenu = string.Format("{0}", Application.Current.Resources["tagCategoryStartMenu"]); - internal static readonly string Uwp = string.Format("{0}", Application.Current.Resources["tagCategoryUwp"]); - internal static readonly string WinGame = string.Format("{0}", Application.Current.Resources["tagCategoryWinGame"]); - internal static readonly string TaskScheduler = string.Format("{0}", Application.Current.Resources["tagCategoryTaskScheduler"]); - internal static readonly string Defender = string.Format("{0}", Application.Current.Resources["tagCategoryDefender"]); - internal static readonly string ContextMenu = string.Format("{0}", Application.Current.Resources["tagCategoryContextMenu"]); - } -} diff --git a/W10SS_GUI/Classes/ToggleInfo.cs b/W10SS_GUI/Classes/ToggleInfo.cs new file mode 100644 index 00000000..b3d953a9 --- /dev/null +++ b/W10SS_GUI/Classes/ToggleInfo.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace W10SS_GUI.Classes +{ + internal class ToggleInfo + { + internal string DescriptionEN { get; set; } = default(string); + internal string DescriptionRU { get; set; } = default(string); + internal string HeaderEN { get; set; } = default(string); + internal string HeaderRU { get; set; } = default(string); + internal string PanelName { get; set; } = default(string); + internal string ScriptPath { get; set; } = default(string); + internal bool IsValid { get; set; } = default(bool); + } +} diff --git a/W10SS_GUI/Controls/ToggleSwitch.xaml.cs b/W10SS_GUI/Controls/ToggleSwitch.xaml.cs index 6c4a7a10..99857fb1 100644 --- a/W10SS_GUI/Controls/ToggleSwitch.xaml.cs +++ b/W10SS_GUI/Controls/ToggleSwitch.xaml.cs @@ -68,8 +68,26 @@ namespace W10SS_GUI.Controls public static readonly DependencyProperty DescriptionProperty = DependencyProperty.Register("Description", typeof(string), typeof(ToggleSwitch), new PropertyMetadata(default(string))); + public bool IsValid + { + get { return (bool)GetValue(IsValidProperty); } + set { SetValue(IsValidProperty, value); } + } + + // Using a DependencyProperty as the backing store for IsValid. This enables animation, styling, binding, etc... + public static readonly DependencyProperty IsValidProperty = + DependencyProperty.Register("IsValid", typeof(bool), typeof(ToggleSwitch), new PropertyMetadata(default(bool))); + public string ScriptPath + { + get { return (string)GetValue(ScriptPathProperty); } + set { SetValue(ScriptPathProperty, value); } + } + + // Using a DependencyProperty as the backing store for ScriptPath. This enables animation, styling, binding, etc... + public static readonly DependencyProperty ScriptPathProperty = + DependencyProperty.Register("ScriptPath", typeof(string), typeof(ToggleSwitch), new PropertyMetadata(default(string))); private void ToggleSwitch_Click(object sender, RoutedEventArgs e) @@ -80,14 +98,11 @@ namespace W10SS_GUI.Controls private void GridToggleSwitch_MouseEnter(object sender, MouseEventArgs e) { if (toggleSwitch.IsChecked == false) gridToggleSwitch.Background = brushBackgroundHover; - } private void GridToggleSwitch_MouseLeave(object sender, MouseEventArgs e) { if (toggleSwitch.IsChecked == false) gridToggleSwitch.Background = brushBackground; - - } } } diff --git a/W10SS_GUI/MainWindow.xaml.cs b/W10SS_GUI/MainWindow.xaml.cs index 5e9dc397..554e3b23 100644 --- a/W10SS_GUI/MainWindow.xaml.cs +++ b/W10SS_GUI/MainWindow.xaml.cs @@ -60,7 +60,7 @@ namespace W10SS_GUI { Resources.MergedDictionaries.Add(AppCulture.ChangeCulture()); Gui.SetHamburgerWidth(AppCulture.CurrentCultureName); - Gui.HamburgerReopen(); + Gui.HamburgerReOpen(); textTogglesHeader.Text = Convert.ToString(Resources[Gui.LastClickedButtonName]); } @@ -69,8 +69,7 @@ namespace W10SS_GUI InitializeVariables(); Gui.InitializeToggles(); SetUiLanguage(); - Gui.SetHamburgerWidth(AppCulture.CurrentCultureName); - + Gui.SetHamburgerWidth(AppCulture.CurrentCultureName); Gui.SetActivePanel(HamburgerPrivacy); } } diff --git a/W10SS_GUI/Model/ModelGui.cs b/W10SS_GUI/Model/ModelGui.cs deleted file mode 100644 index 9d5006d1..00000000 --- a/W10SS_GUI/Model/ModelGui.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; - -namespace W10SS_GUI.Model -{ - class ModelGui - { - - } -} diff --git a/W10SS_GUI/Resource/tags.xaml b/W10SS_GUI/Resource/tags.xaml index 19b32701..94a3b6c0 100644 --- a/W10SS_GUI/Resource/tags.xaml +++ b/W10SS_GUI/Resource/tags.xaml @@ -1,15 +1,15 @@  - - Privacy & Telemetry - UI & Personalization - OneDrive - System - Start Menu - UWP Apps - Game Mode - Task Scheduler - Microsoft Defender - Context Menu + + 1. Privacy & Telemetry + 2. UI & Personalization + 3. OneDrive + 4. System + 5. Start Menu + 6. UWP Apps + 7. Gaming + 8. Task Scheduler + 9. Defender & Security + 10. Context Menu \ No newline at end of file diff --git a/W10SS_GUI/W10SS_GUI.csproj b/W10SS_GUI/W10SS_GUI.csproj index 1af7f241..efff2a08 100644 --- a/W10SS_GUI/W10SS_GUI.csproj +++ b/W10SS_GUI/W10SS_GUI.csproj @@ -112,7 +112,7 @@ Code - + HamburgerCategoryButton.xaml