From c6346cf4fcd431812b4d8a171289e4a65f16da6c Mon Sep 17 00:00:00 2001 From: theFONZ Date: Thu, 7 May 2020 14:06:03 +0100 Subject: [PATCH] Added ability to see active audio profile Added registry checks to see which audio profile is currently active. Reflect the active profile within the UI --- MiToolz/App.xaml | 6 +- MiToolz/ConfigManager.cs | 93 +++++++++++++++++++ MiToolz/IniFile.cs | 51 ---------- MiToolz/MainWindow.xaml | 10 +- MiToolz/MainWindow.xaml.cs | 89 ++++++++++++------ MiToolz/MiToolz.csproj | 2 +- MiToolz/Properties/AssemblyInfo.cs | 2 +- MiToolz/Properties/Resources.Designer.cs | 22 ++++- MiToolz/Properties/Resources.resx | 8 +- .../MiToolz.csproj.FileListAbsolute.txt | 0 10 files changed, 194 insertions(+), 89 deletions(-) create mode 100644 MiToolz/ConfigManager.cs delete mode 100644 MiToolz/IniFile.cs create mode 100644 MiToolz/obj/Release/MiToolz.csproj.FileListAbsolute.txt diff --git a/MiToolz/App.xaml b/MiToolz/App.xaml index ebfabcb..24e3522 100644 --- a/MiToolz/App.xaml +++ b/MiToolz/App.xaml @@ -1,8 +1,10 @@ - - + MiToolz v2.7.0 + Build Date : 07-05-2020 diff --git a/MiToolz/ConfigManager.cs b/MiToolz/ConfigManager.cs new file mode 100644 index 0000000..5f7749d --- /dev/null +++ b/MiToolz/ConfigManager.cs @@ -0,0 +1,93 @@ +using Microsoft.Win32; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Runtime.InteropServices; +using System.Text; +using System.Xml.Linq; + +namespace MiToolz +{ + class ConfigManager + { + readonly string Path; + readonly string EXE = Assembly.GetExecutingAssembly().GetName().Name; + + [DllImport("kernel32", CharSet = CharSet.Unicode)] + static extern long WritePrivateProfileString(string Section, string Key, string Value, string FilePath); + + [DllImport("kernel32", CharSet = CharSet.Unicode)] + static extern int GetPrivateProfileString(string Section, string Key, string Default, StringBuilder RetVal, int Size, string FilePath); + + //ini file management > + public ConfigManager(string IniPath = null) + { + Path = new FileInfo(IniPath ?? EXE + ".ini").FullName; + } + + public string IniRead(string Key, string Section = null) + { + var RetVal = new StringBuilder(255); + GetPrivateProfileString(Section ?? EXE, Key, "", RetVal, 255, Path); + return RetVal.ToString(); + } + + public void IniWrite(string Key, string Value, string Section = null) + { + WritePrivateProfileString(Section ?? EXE, Key, Value, Path); + } + + public void IniDeleteKey(string Key, string Section = null) + { + IniWrite(Key, null, Section ?? EXE); + } + + public void IniDeleteSection(string Section = null) + { + IniWrite(null, null, Section ?? EXE); + } + + public bool IniKeyExists(string Key, string Section = null) + { + return IniRead(Key, Section).Length > 0; + } + + //registry key management > + public string RegReadKeyValue(string subKey, string key) + + { + string str = string.Empty; + + using (RegistryKey registryKey = Registry.CurrentUser.OpenSubKey(subKey)) + + { + if (registryKey != null) + { + str = registryKey.GetValue(key).ToString(); + registryKey.Close(); + } + } + return str; + } + + //xml file management > + public string XmlRead(string FullXmlFilePath) + { + string str = string.Empty; + + //read xml entry for 'profile_name' in xml located in 'FullXmlFilePath' return profile name value + + XDocument doc = XDocument.Load(FullXmlFilePath); + var selectors = from elements in doc.Elements("profile").Elements("info") + select elements; + + foreach (var element in selectors) + { + str = element.Element("profile_name").Value; + //MessageBox.Show(element.Element("profile_name").Value); + } + + return str; + } + } +} diff --git a/MiToolz/IniFile.cs b/MiToolz/IniFile.cs deleted file mode 100644 index 5a393a2..0000000 --- a/MiToolz/IniFile.cs +++ /dev/null @@ -1,51 +0,0 @@ -using System.IO; -using System.Reflection; -using System.Runtime.InteropServices; -using System.Text; - -namespace MiToolz -{ - class IniFile - { - readonly string Path; - readonly string EXE = Assembly.GetExecutingAssembly().GetName().Name; - - [DllImport("kernel32", CharSet = CharSet.Unicode)] - static extern long WritePrivateProfileString(string Section, string Key, string Value, string FilePath); - - [DllImport("kernel32", CharSet = CharSet.Unicode)] - static extern int GetPrivateProfileString(string Section, string Key, string Default, StringBuilder RetVal, int Size, string FilePath); - - public IniFile(string IniPath = null) - { - Path = new FileInfo(IniPath ?? EXE + ".ini").FullName; - } - - public string Read(string Key, string Section = null) - { - var RetVal = new StringBuilder(255); - GetPrivateProfileString(Section ?? EXE, Key, "", RetVal, 255, Path); - return RetVal.ToString(); - } - - public void Write(string Key, string Value, string Section = null) - { - WritePrivateProfileString(Section ?? EXE, Key, Value, Path); - } - - public void DeleteKey(string Key, string Section = null) - { - Write(Key, null, Section ?? EXE); - } - - public void DeleteSection(string Section = null) - { - Write(null, null, Section ?? EXE); - } - - public bool KeyExists(string Key, string Section = null) - { - return Read(Key, Section).Length > 0; - } - } -} diff --git a/MiToolz/MainWindow.xaml b/MiToolz/MainWindow.xaml index 131e639..88eafd4 100644 --- a/MiToolz/MainWindow.xaml +++ b/MiToolz/MainWindow.xaml @@ -4,7 +4,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" - Title="MiToolz" Height="260" Width="394" ResizeMode="NoResize" WindowStartupLocation="CenterScreen"> + Title="MiToolz" Height="260" Width="394" ResizeMode="NoResize" WindowStartupLocation="CenterScreen" Activated="Window_Activated">