OSDN Git Service

Implemented application configuration setting to disable the busy indicator (by default). 1.1.0
authorLoRd_MuldeR <mulder2@gmx.de>
Sat, 13 Nov 2021 16:11:08 +0000 (17:11 +0100)
committerLoRd_MuldeR <mulder2@gmx.de>
Sat, 13 Nov 2021 16:18:42 +0000 (17:18 +0100)
gui/App.config
gui/SlunkCryptGUI.csproj
gui/SlunkCryptGUI.xaml.cs
gui/Utilities/ApplicationConfig.cs [new file with mode: 0644]

index 8e15646..87b3ead 100644 (file)
@@ -3,4 +3,7 @@
     <startup> 
         <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
     </startup>
+    <appSettings>
+        <add key="DisableBusyIndicator" value="false" />
+    </appSettings>
 </configuration>
\ No newline at end of file
index fd18c41..d320e15 100644 (file)
@@ -56,6 +56,7 @@
   <ItemGroup>
     <Reference Include="System" />
     <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Configuration" />
     <Reference Include="System.Core" />
     <Reference Include="System.Xaml" />
     <Reference Include="PresentationCore" />
@@ -79,6 +80,7 @@
     <Compile Include="Controls\PasswordToggleBox.xaml.cs">
       <DependentUpon>PasswordToggleBox.xaml</DependentUpon>
     </Compile>
+    <Compile Include="Utilities\ApplicationConfig.cs" />
     <Compile Include="Utilities\CPUFeatures.cs" />
     <Compile Include="Process\SlunkCryptRunner.cs" />
     <Compile Include="Utilities\BusyManager.cs" />
index 4952a85..c41e4af 100644 (file)
@@ -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<string> m_about = new Lazy<string>(CreateAboutText);
         private readonly Random m_random = new Random();
         private readonly ObservableCollection<string> m_logFile = new ObservableCollection<string>();
@@ -63,6 +64,7 @@ namespace com.muldersoft.slunkcrypt.gui
             m_dispatcherTimer.Tick += DispatcherTimer_Tick;
             m_dispatcherTimer.Interval = TimeSpan.FromMilliseconds(200);
             m_logFileReadOnly = new ReadOnlyObservableCollection<string>(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 (file)
index 0000000..6706b13
--- /dev/null
@@ -0,0 +1,65 @@
+/******************************************************************************/
+/* SlunkCrypt, by LoRd_MuldeR <MuldeR2@GMX.de>                                */
+/* 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<KeyValueConfigurationCollection> m_settings = new Lazy<KeyValueConfigurationCollection>(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;
+            }
+        }
+    }
+}