From 815d2cdc7f608f74522383a2127d1b66126bfd62 Mon Sep 17 00:00:00 2001 From: Bryan Biedenkapp Date: Sat, 22 Mar 2025 22:31:55 -0400 Subject: [PATCH] add command line argument support (specifically for --userprofile= so the directory where UserProfile.yaml can be overridden by the user); expand the Audio device list with the window; --- dvmconsole/App.xaml | 1 + dvmconsole/App.xaml.cs | 60 ++++++++++++++++++++++- dvmconsole/AudioSettingsWindow.xaml | 2 +- dvmconsole/Properties/launchSettings.json | 8 +++ dvmconsole/SettingsManager.cs | 17 +++++-- 5 files changed, 82 insertions(+), 6 deletions(-) create mode 100644 dvmconsole/Properties/launchSettings.json diff --git a/dvmconsole/App.xaml b/dvmconsole/App.xaml index c1064e9..5671c61 100644 --- a/dvmconsole/App.xaml +++ b/dvmconsole/App.xaml @@ -1,6 +1,7 @@  diff --git a/dvmconsole/App.xaml.cs b/dvmconsole/App.xaml.cs index abb4dc9..a108df3 100644 --- a/dvmconsole/App.xaml.cs +++ b/dvmconsole/App.xaml.cs @@ -12,17 +12,22 @@ * */ +using fnecore.Utility; +using NAudio.Wave; using System.IO; using System.Reflection; +using System.Text; using System.Windows; namespace dvmconsole { /// - /// + /// Encapsulates a Windows Presentation Foundation application. /// public partial class App : Application { + public static string USER_PROFILE_PATH_OVERRIDE = string.Empty; + /* ** Methods */ @@ -44,5 +49,58 @@ namespace dvmconsole return; } } + + /// + /// Internal helper to prints the program usage. + /// + private static void Usage(OptionSet p) + { + string messageBoxText = "[-h | --help][--userprofile ]\r\nOptions:\r\n"; + + using (MemoryStream ms = new MemoryStream()) + { + using (TextWriter writer = new StreamWriter(ms)) + p.WriteOptionDescriptions(writer); + + messageBoxText += Encoding.UTF8.GetString(ms.ToArray()); + } + + MessageBox.Show(messageBoxText, "Digital Voice Modem - Desktop Dispatch Console", + MessageBoxButton.OK, MessageBoxImage.Information); + + Application.Current.Shutdown(); + } + + /// + /// + /// + /// + /// + private void Application_Startup(object sender, StartupEventArgs e) + { + bool showHelp = false; + string configFile = string.Empty; + + // command line parameters + OptionSet options = new OptionSet() + { + { "h|help", "show this message and exit", v => showHelp = v != null }, + { "userprofile=", "sets the path to the UserProfile.yaml", v => USER_PROFILE_PATH_OVERRIDE = v }, + }; + + // attempt to parse the commandline + try + { + options.Parse(e.Args); + } + catch (OptionException) + { + /* ignore */ + } + + // show help? + if (showHelp) + Usage(options); + } } // public partial class App : Application } // namespace dvmconsole diff --git a/dvmconsole/AudioSettingsWindow.xaml b/dvmconsole/AudioSettingsWindow.xaml index 90f93be..2aeec3e 100644 --- a/dvmconsole/AudioSettingsWindow.xaml +++ b/dvmconsole/AudioSettingsWindow.xaml @@ -15,7 +15,7 @@ - + diff --git a/dvmconsole/Properties/launchSettings.json b/dvmconsole/Properties/launchSettings.json new file mode 100644 index 0000000..8582f22 --- /dev/null +++ b/dvmconsole/Properties/launchSettings.json @@ -0,0 +1,8 @@ +{ + "profiles": { + "dvmconsole": { + "commandName": "Project", + "commandLineArgs": "--userprofile=." + } + } +} \ No newline at end of file diff --git a/dvmconsole/SettingsManager.cs b/dvmconsole/SettingsManager.cs index 9910e4a..6726f13 100644 --- a/dvmconsole/SettingsManager.cs +++ b/dvmconsole/SettingsManager.cs @@ -31,9 +31,9 @@ namespace dvmconsole Environment.SpecialFolder.ApplicationData); public static readonly string RootAppDataPath = "DVMProject" + Path.DirectorySeparatorChar + "dvmconsole"; - public static readonly string UserAppDataPath = UserAppData + Path.DirectorySeparatorChar + RootAppDataPath; + public static string UserAppDataPath = UserAppData + Path.DirectorySeparatorChar + RootAppDataPath; - private static readonly string SettingsFilePath = UserAppDataPath + Path.DirectorySeparatorChar + "UserSettings.json"; + private static string SettingsFilePath = UserAppDataPath + Path.DirectorySeparatorChar + "UserSettings.json"; /* ** Properties @@ -139,8 +139,17 @@ namespace dvmconsole /// public bool LoadSettings() { - if (!Directory.Exists(UserAppDataPath)) - Directory.CreateDirectory(UserAppDataPath); + // was the user profile path being overridden? + if (App.USER_PROFILE_PATH_OVERRIDE != string.Empty) + { + UserAppDataPath = App.USER_PROFILE_PATH_OVERRIDE; + SettingsFilePath = UserAppDataPath + Path.DirectorySeparatorChar + "UserSettings.json"; + } + else + { + if (!Directory.Exists(UserAppDataPath)) + Directory.CreateDirectory(UserAppDataPath); + } if (!File.Exists(SettingsFilePath)) return false;