From d2ea1a7a7c8d69fd44d44926beb7cb7892870ef3 Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Sat, 13 Nov 2021 17:11:08 +0100 Subject: [PATCH] Implemented application configuration setting to disable the busy indicator (by default). --- gui/App.config | 3 ++ gui/SlunkCryptGUI.csproj | 2 + gui/SlunkCryptGUI.xaml.cs | 6 +++ gui/Utilities/ApplicationConfig.cs | 65 ++++++++++++++++++++++++++++++ 4 files changed, 76 insertions(+) create mode 100644 gui/Utilities/ApplicationConfig.cs diff --git a/gui/App.config b/gui/App.config index 8e15646..87b3ead 100644 --- a/gui/App.config +++ b/gui/App.config @@ -3,4 +3,7 @@ + + + \ No newline at end of file diff --git a/gui/SlunkCryptGUI.csproj b/gui/SlunkCryptGUI.csproj index fd18c41..d320e15 100644 --- a/gui/SlunkCryptGUI.csproj +++ b/gui/SlunkCryptGUI.csproj @@ -56,6 +56,7 @@ + @@ -79,6 +80,7 @@ PasswordToggleBox.xaml + diff --git a/gui/SlunkCryptGUI.xaml.cs b/gui/SlunkCryptGUI.xaml.cs index 4952a85..c41e4af 100644 --- a/gui/SlunkCryptGUI.xaml.cs +++ b/gui/SlunkCryptGUI.xaml.cs @@ -37,6 +37,7 @@ namespace com.muldersoft.slunkcrypt.gui public event PropertyChangedEventHandler PropertyChanged; public const int MIN_PASSWD_LENGTH = 8, REC_PASSWD_LENGTH = 12, GEN_PASSWD_LENGTH = 24, MAX_PASSWD_LENGTH = 256, MAX_PATH = 259; + private readonly ApplicationConfig m_config = new ApplicationConfig(); private readonly Lazy m_about = new Lazy(CreateAboutText); private readonly Random m_random = new Random(); private readonly ObservableCollection m_logFile = new ObservableCollection(); @@ -63,6 +64,7 @@ namespace com.muldersoft.slunkcrypt.gui m_dispatcherTimer.Tick += DispatcherTimer_Tick; m_dispatcherTimer.Interval = TimeSpan.FromMilliseconds(200); m_logFileReadOnly = new ReadOnlyObservableCollection(m_logFile); + m_disableAnimation = m_config.DisableBusyIndicator; } // ============================================================================= @@ -373,6 +375,10 @@ namespace com.muldersoft.slunkcrypt.gui SystemMenu systemMenu = new SystemMenu(this, SystemMenu_Activated); m_menuId_disableAnimation = systemMenu.AppendMenu("Disable Busy Indicator"); m_menuId_enableExpertMode = systemMenu.AppendMenu("Expert Settings"); + if (m_disableAnimation && m_menuId_disableAnimation.HasValue) + { + systemMenu.ModifyMenu(m_menuId_disableAnimation.Value, m_disableAnimation); + } CreateIndicatorElements(); } diff --git a/gui/Utilities/ApplicationConfig.cs b/gui/Utilities/ApplicationConfig.cs new file mode 100644 index 0000000..6706b13 --- /dev/null +++ b/gui/Utilities/ApplicationConfig.cs @@ -0,0 +1,65 @@ +/******************************************************************************/ +/* SlunkCrypt, by LoRd_MuldeR */ +/* This work has been released under the CC0 1.0 Universal license! */ +/******************************************************************************/ + +using System; +using System.Configuration; + +namespace com.muldersoft.slunkcrypt.gui.utils +{ + class ApplicationConfig + { + private readonly Lazy m_settings = new Lazy(InitializeSettings); + + public bool DisableBusyIndicator + { + get + { + return GetConfigValueAsBool("DisableBusyIndicator"); + } + } + + protected string GetConfigValue(string name) + { + KeyValueConfigurationCollection settings = m_settings.Value; + if (!ReferenceEquals(settings, null)) + { + KeyValueConfigurationElement element = settings[name]; + if (!ReferenceEquals(element, null)) + { + string value = element.Value; + return string.IsNullOrWhiteSpace(value) ? string.Empty : value; + } + } + return string.Empty; + } + + protected bool GetConfigValueAsBool(string name) + { + string value; + if (!string.IsNullOrWhiteSpace(value = GetConfigValue(name))) + { + bool result; + if (bool.TryParse(value.Trim(), out result)) + { + return result; + } + } + return false; + } + + private static KeyValueConfigurationCollection InitializeSettings() + { + try + { + Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); + return configuration.AppSettings.Settings; + } + catch + { + return null; + } + } + } +}