From d04dee1b1c07ba25ae9e1629d95a6c5510ac98bb Mon Sep 17 00:00:00 2001 From: Charlie Kindel Date: Sun, 6 Feb 2022 12:06:56 -0700 Subject: [PATCH] Updated depedencies. Better logging. Attempt to fix Issue #24. - Commands file not saved at exit anymore - Only watching changes - Display log threshold settings dialog now works correctly --- Installer/MCEControl.commands | 324 ------------------ Installer/version.txt | 2 +- src/AssemblyFileVersion.tt | 6 +- src/Commands/CommandInvoker.cs | 17 +- src/Commands/McecCommand.cs | 2 +- src/Commands/SendInputCommand.cs | 2 +- src/Commands/SendMessageCommand.cs | 2 +- src/Commands/SerializedCommands.cs | 44 ++- src/Commands/SetForegroundWindowCmd.cs | 2 +- src/Commands/ShutdownCommand.cs | 4 +- src/Commands/StartProcessCommand.cs | 2 +- src/Dialogs/SettingsDialog.cs | 23 +- src/Helpers/CommandFileWatcher.cs | 31 +- src/Helpers/Logger.cs | 2 +- src/MCEControl.csproj | 50 +-- src/MCEControl.sln | 5 +- src/MainWindow.cs | 19 +- src/Properties/Resources.Designer.cs | 2 +- src/README.md | 29 ++ src/Services/AppSettings.cs | 2 +- src/Services/TelemetryService.tt.cs | 4 +- src/Services/UpdateService.cs | 11 +- src/app.config | 2 +- .../MCEControl.xUnit/MCEControl.xUnit.csproj | 7 +- 24 files changed, 148 insertions(+), 446 deletions(-) delete mode 100644 Installer/MCEControl.commands create mode 100644 src/README.md diff --git a/Installer/MCEControl.commands b/Installer/MCEControl.commands deleted file mode 100644 index 8b84c74..0000000 --- a/Installer/MCEControl.commands +++ /dev/null @@ -1,324 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Installer/version.txt b/Installer/version.txt index e0d6fed..b73ae2b 100644 --- a/Installer/version.txt +++ b/Installer/version.txt @@ -1 +1 @@ -2.2.8.10 \ No newline at end of file +2.2.8.62 \ No newline at end of file diff --git a/src/AssemblyFileVersion.tt b/src/AssemblyFileVersion.tt index 964be00..e33ad4a 100644 --- a/src/AssemblyFileVersion.tt +++ b/src/AssemblyFileVersion.tt @@ -10,6 +10,8 @@ if (n > -1) dir = dir.Remove(n, dir.Length - n) + "..\\..\\"; string file = Path.Combine(dir, "..\\Installer\\version.txt"); + Console.WriteLine("Generating " + file + " ..."); + string contents = File.ReadAllText(file); string[] parts = contents.Split('.'); @@ -22,11 +24,11 @@ string version = string.Join(".", parts); // write the new version number back to the file File.WriteAllText(file, version); - Console.WriteLine("Generated Build #: " + version); + Console.WriteLine("Wrote " + version + " to " + file); #> // This file was generated by a tool. Any changes made manually will be lost // the next time this project is built (via AssemblyFileVersion.tt). using System.Reflection; [assembly: AssemblyVersion("<#= version #>")] [assembly: AssemblyFileVersion("<#= version #>")] -[assembly: AssemblyCopyright("Copyright © 2021 Kindel Systems, LLC.")] \ No newline at end of file +[assembly: AssemblyCopyright("Copyright © 2022 Kindel Systems, LLC.")] \ No newline at end of file diff --git a/src/Commands/CommandInvoker.cs b/src/Commands/CommandInvoker.cs index 8270dbb..225183a 100644 --- a/src/Commands/CommandInvoker.cs +++ b/src/Commands/CommandInvoker.cs @@ -70,12 +70,17 @@ public static CommandInvoker Create(string userCommandsFile, string currentVersi serializedCmds = SerializedCommands.LoadCommands(userCommandsFile, currentVersion); if (serializedCmds != null && serializedCmds.commandArray != null) { foreach (var cmd in serializedCmds.commandArray) { - // TELEMETRY: Mark user defined commands as such so they don't get collected - if (!commands.ContainsKey(cmd.Cmd)) { - cmd.UserDefined = true; - } + if (!string.IsNullOrWhiteSpace(cmd.Cmd)) { + // TELEMETRY: Mark user defined commands as such so they don't get collected + if (!commands.ContainsKey(cmd.Cmd)) { + cmd.UserDefined = true; + } - commands.Add(cmd); + commands.Add(cmd); + } + else { + Logger.Instance.Log4.Error($"{commands.GetType().Name}: Cmd name can't be blank or whitespace ({cmd})"); + } } Logger.Instance.Log4.Info($"{commands.GetType().Name}: {serializedCmds.Count} commands loaded"); } @@ -115,7 +120,7 @@ private void Add(Command cmd, bool log = false) { } } else { - Logger.Instance.Log4.Info($"{this.GetType().Name}: Error parsing command: {cmd.ToString()}"); + Logger.Instance.Log4.Error($"{this.GetType().Name}: Error parsing command: {cmd}"); } } diff --git a/src/Commands/McecCommand.cs b/src/Commands/McecCommand.cs index a47d908..c93cef5 100644 --- a/src/Commands/McecCommand.cs +++ b/src/Commands/McecCommand.cs @@ -81,7 +81,7 @@ public override bool Execute() { } } catch (Exception e) { - Logger.Instance.Log4.Info($"{this.GetType().Name}: ({Cmd}:{Args}) <{match.Groups[1].Value} {cmd.ToString()}/> - {e.Message}"); + Logger.Instance.Log4.Error($"{this.GetType().Name}: ({Cmd}:{Args}) <{match.Groups[1].Value} {cmd.ToString()}/> - {e.Message}"); return false; } break; diff --git a/src/Commands/SendInputCommand.cs b/src/Commands/SendInputCommand.cs index 26c81e0..c8689a6 100644 --- a/src/Commands/SendInputCommand.cs +++ b/src/Commands/SendInputCommand.cs @@ -262,7 +262,7 @@ public override bool Execute() { } } catch (Exception e) { - Logger.Instance.Log4.Info($"{this.GetType().Name}: failed. {e.Message}"); + Logger.Instance.Log4.Error($"{this.GetType().Name}: failed. {e.Message}"); return false; } return true; diff --git a/src/Commands/SendMessageCommand.cs b/src/Commands/SendMessageCommand.cs index 8986f68..826e4af 100644 --- a/src/Commands/SendMessageCommand.cs +++ b/src/Commands/SendMessageCommand.cs @@ -88,7 +88,7 @@ public override bool Execute() { } } catch (Exception e) { - Logger.Instance.Log4.Info($"{this.GetType().Name}: Failed for {ClassName} with error: {e.Message}"); + Logger.Instance.Log4.Error($"{this.GetType().Name}: Failed for {ClassName} with error: {e.Message}"); return true; } return false; diff --git a/src/Commands/SerializedCommands.cs b/src/Commands/SerializedCommands.cs index 8c9a758..44847ba 100644 --- a/src/Commands/SerializedCommands.cs +++ b/src/Commands/SerializedCommands.cs @@ -68,32 +68,38 @@ static public SerializedCommands LoadCommands(string userCommandsFile, string cu SerializedCommands cmds = null; FileStream fs = null; try { - Logger.Instance.Log4.Info($"CommandInvoker: Loading user-defined commands from {userCommandsFile}"); + Logger.Instance.Log4.Info($"SerializedCommands: Loading user-defined commands from {userCommandsFile}"); fs = new FileStream(userCommandsFile, FileMode.Open, FileAccess.Read); cmds = Deserialize(fs); - // Is this a legacy load? If so, enable all commands and warn user - if (string.IsNullOrEmpty(cmds.Version)) { - var msg = $"{userCommandsFile} was created with a legacy version of MCE Controller.\n\nConverting it and enabling all commands it contains.\n\nDisable any commands that are not used using the Commands window."; - MessageBox.Show(msg, Application.ProductName); - Logger.Instance.Log4.Info($"CommandInvoker: {msg}"); - cmds.Version = currentVersion; - cmds.commandArray = cmds.commandArray.Select(c => { c.Enabled = true; return c; }).ToArray(); + if (cmds == null) { + // Deserialization failed. We could automatically rewrite the file, but that would be rude. + // Deserialize logged this } - - // If this was written by an older version, re-write it to update it - if (!string.IsNullOrEmpty(cmds.Version) && (new Version(currentVersion).CompareTo(new Version(cmds.Version))) > 0) { - Logger.Instance.Log4.Info($"CommandInvoker: Upgrading .commands file from v{cmds.Version}"); - SaveCommands(userCommandsFile, cmds, currentVersion); + else { + // Is this a legacy load? If so, enable all commands and warn user + if (string.IsNullOrEmpty(cmds.Version)) { + var msg = $"{userCommandsFile} was created with a legacy version of MCE Controller.\n\nConverting it and enabling all commands it contains.\n\nDisable any commands that are not used using the Commands window."; + MessageBox.Show(msg, Application.ProductName); + Logger.Instance.Log4.Info($"SerializedCommands: {msg}"); + cmds.Version = currentVersion; + cmds.commandArray = cmds.commandArray.Select(c => { c.Enabled = true; return c; }).ToArray(); + } + + // If this was written by an older version, re-write it to update it + if (!string.IsNullOrEmpty(cmds.Version) && (new Version(currentVersion).CompareTo(new Version(cmds.Version))) > 0) { + Logger.Instance.Log4.Info($"SerializedCommands: Upgrading .commands file from v{cmds.Version}"); + SaveCommands(userCommandsFile, cmds, currentVersion); + } } } catch (FileNotFoundException) { - Logger.Instance.Log4.Info($"CommandInvoker: {userCommandsFile} was not found"); + Logger.Instance.Log4.Error($"SerializedCommands: {userCommandsFile} was not found"); } catch (Exception ex) { var msg = $"No commands loaded. Error reading {userCommandsFile} - {ex.Message}.\n\nSee log file for details: {Logger.Instance.LogFile}\n\nFor help, open an issue at github.com/tig/mcec"; MessageBox.Show(msg, currentVersion); - Logger.Instance.Log4.Info($"CommandInvoker: {msg}"); + Logger.Instance.Log4.Error($"SerializedCommands: {msg}"); Logger.DumpException(ex); } finally { @@ -118,7 +124,7 @@ static public void SaveCommands(string userCommandsFile, SerializedCommands comm FileStream ucFS = null; try { commands.Version = currentVersion; - ucFS = new FileStream(userCommandsFile, FileMode.Create, FileAccess.ReadWrite); + ucFS = new FileStream(userCommandsFile, FileMode.Create); new XmlSerializer(typeof(SerializedCommands)).Serialize(ucFS, commands); } catch (Exception e) { @@ -127,7 +133,7 @@ static public void SaveCommands(string userCommandsFile, SerializedCommands comm $"See log file for details: {Logger.Instance.LogFile}\n\n" + $"For help, open an issue at github.com/tig/mcec"; MessageBox.Show(msg, Application.ProductName); - Logger.Instance.Log4.Info($"CommandInvoker: {msg}"); + Logger.Instance.Log4.Error($"SerializedCommands: {msg}"); Logger.DumpException(e); } finally { @@ -166,11 +172,11 @@ private static SerializedCommands Deserialize(Stream xmlStream) { cmds = (SerializedCommands)new XmlSerializer(typeof(SerializedCommands)).Deserialize(lcReader); } catch (InvalidOperationException ex) { - Logger.Instance.Log4.Info($"CommandInvoker: No commands loaded. Error parsing .commands XML. {ex.FullMessage()}"); + Logger.Instance.Log4.Error($"SerializedCommands: No commands loaded. Error parsing .commands XML. {ex.FullMessage()}"); Logger.DumpException(ex); } catch (Exception ex) { - Logger.Instance.Log4.Info($"CommandInvoker: Error parsing .commands XML. {ex.Message}"); + Logger.Instance.Log4.Error($"SerializedCommands: Error parsing .commands XML. {ex.Message}"); Logger.DumpException(ex); } finally { diff --git a/src/Commands/SetForegroundWindowCmd.cs b/src/Commands/SetForegroundWindowCmd.cs index 6126321..d323b5f 100644 --- a/src/Commands/SetForegroundWindowCmd.cs +++ b/src/Commands/SetForegroundWindowCmd.cs @@ -68,7 +68,7 @@ public override bool Execute() { } } catch (Exception e) { - Logger.Instance.Log4.Info($"{this.GetType().Name}: Failed for {ClassName} with error: {e.Message}"); + Logger.Instance.Log4.Error($"{this.GetType().Name}: Failed for {ClassName} with error: {e.Message}"); return false; } return true; diff --git a/src/Commands/ShutdownCommand.cs b/src/Commands/ShutdownCommand.cs index 058bf91..f99e63b 100644 --- a/src/Commands/ShutdownCommand.cs +++ b/src/Commands/ShutdownCommand.cs @@ -94,7 +94,7 @@ public override bool Execute() { break; default: - Logger.Instance.Log4.Info($"{this.GetType().Name}: ShutdownCommands: Invalid command: {ToString()}"); + Logger.Instance.Log4.Info($"{this.GetType().Name}: Invalid command: {ToString()}"); break; } } @@ -106,9 +106,11 @@ public override bool Execute() { } public static void Shutdown(string shutdownArgs) { + Logger.Instance.Log4.Debug($"ShutdownCommand: Invoking 'shutdown.exe {shutdownArgs}'"); var proc = System.Diagnostics.Process.Start("shutdown", shutdownArgs); proc.WaitForExit(1000); if (proc.ExitCode != 0x0) { + Logger.Instance.Log4.Error($"ShutdownCommand: 'shutdown.exe {shutdownArgs}' failed ({proc.ExitCode:X}). Forcing Win32Exception..."); throw new System.ComponentModel.Win32Exception(proc.ExitCode); } } diff --git a/src/Commands/StartProcessCommand.cs b/src/Commands/StartProcessCommand.cs index b533d04..4a4271b 100644 --- a/src/Commands/StartProcessCommand.cs +++ b/src/Commands/StartProcessCommand.cs @@ -124,7 +124,7 @@ public override bool Execute() { p.WaitForInputIdle(1000); // TODO: Make this settable } catch (System.InvalidOperationException e) { - Logger.Instance.Log4.Info($"{this.GetType().Name}: {e.Message}"); + Logger.Instance.Log4.Error($"{this.GetType().Name}: {e.Message}"); return false; } } diff --git a/src/Dialogs/SettingsDialog.cs b/src/Dialogs/SettingsDialog.cs index 02bd32a..a865b19 100644 --- a/src/Dialogs/SettingsDialog.cs +++ b/src/Dialogs/SettingsDialog.cs @@ -268,9 +268,9 @@ private void InitializeComponent() { this._labelLogLevel.AutoSize = true; this._labelLogLevel.Location = new System.Drawing.Point(13, 35); this._labelLogLevel.Name = "_labelLogLevel"; - this._labelLogLevel.Size = new System.Drawing.Size(78, 13); + this._labelLogLevel.Size = new System.Drawing.Size(277, 13); this._labelLogLevel.TabIndex = 1; - this._labelLogLevel.Text = "Log Threshold:"; + this._labelLogLevel.Text = "Log Threshold (display only; log files always contain ALL):"; // // _checkBoxHideOnStartup // @@ -311,7 +311,7 @@ private void InitializeComponent() { this._checkBoxEnableClient.Location = new System.Drawing.Point(20, 10); this._checkBoxEnableClient.Margin = new System.Windows.Forms.Padding(1); this._checkBoxEnableClient.Name = "_checkBoxEnableClient"; - this._checkBoxEnableClient.Size = new System.Drawing.Size(88, 17); + this._checkBoxEnableClient.Size = new System.Drawing.Size(95, 21); this._checkBoxEnableClient.TabIndex = 1; this._checkBoxEnableClient.Text = "Enable &Client"; this._toolTipClient.SetToolTip(this._checkBoxEnableClient, "Starts a TCP/IP client connection to the specified address:port. Commands will be" + @@ -408,7 +408,7 @@ private void InitializeComponent() { this._checkBoxEnableServer.Location = new System.Drawing.Point(20, 10); this._checkBoxEnableServer.Margin = new System.Windows.Forms.Padding(1); this._checkBoxEnableServer.Name = "_checkBoxEnableServer"; - this._checkBoxEnableServer.Size = new System.Drawing.Size(93, 17); + this._checkBoxEnableServer.Size = new System.Drawing.Size(100, 21); this._checkBoxEnableServer.TabIndex = 0; this._checkBoxEnableServer.Text = "Enable &Server"; this._toolTipServer.SetToolTip(this._checkBoxEnableServer, "Enables the TCP/IP server. It will listen on the specified port for commands."); @@ -570,7 +570,7 @@ private void InitializeComponent() { this._checkBoxEnableSerialServer.Location = new System.Drawing.Point(20, 10); this._checkBoxEnableSerialServer.Margin = new System.Windows.Forms.Padding(1); this._checkBoxEnableSerialServer.Name = "_checkBoxEnableSerialServer"; - this._checkBoxEnableSerialServer.Size = new System.Drawing.Size(122, 17); + this._checkBoxEnableSerialServer.Size = new System.Drawing.Size(129, 21); this._checkBoxEnableSerialServer.TabIndex = 1; this._checkBoxEnableSerialServer.Text = "Enable Serial Server"; this._checkBoxEnableSerialServer.UseVisualStyleBackColor = true; @@ -782,7 +782,7 @@ private void InitializeComponent() { this._checkBoxEnableActivityMonitor.Location = new System.Drawing.Point(20, 10); this._checkBoxEnableActivityMonitor.Margin = new System.Windows.Forms.Padding(1); this._checkBoxEnableActivityMonitor.Name = "_checkBoxEnableActivityMonitor"; - this._checkBoxEnableActivityMonitor.Size = new System.Drawing.Size(159, 17); + this._checkBoxEnableActivityMonitor.Size = new System.Drawing.Size(166, 21); this._checkBoxEnableActivityMonitor.TabIndex = 0; this._checkBoxEnableActivityMonitor.Text = "Enable &User Activity Monitor"; this._checkBoxEnableActivityMonitor.UseVisualStyleBackColor = true; @@ -810,7 +810,7 @@ private void InitializeComponent() { this._presenceDetection.AutoSize = true; this._presenceDetection.Location = new System.Drawing.Point(17, 76); this._presenceDetection.Name = "_presenceDetection"; - this._presenceDetection.Size = new System.Drawing.Size(368, 17); + this._presenceDetection.Size = new System.Drawing.Size(375, 21); this._presenceDetection.TabIndex = 3; this._presenceDetection.Text = "Don\'t send message if Power Broadcast API indicates user is not present"; this._presenceDetection.UseVisualStyleBackColor = true; @@ -821,7 +821,7 @@ private void InitializeComponent() { this._unlockDetection.AutoSize = true; this._unlockDetection.Location = new System.Drawing.Point(17, 53); this._unlockDetection.Name = "_unlockDetection"; - this._unlockDetection.Size = new System.Drawing.Size(216, 17); + this._unlockDetection.Size = new System.Drawing.Size(223, 21); this._unlockDetection.TabIndex = 1; this._unlockDetection.Text = "Don\'t send message if desktop is locked"; this._unlockDetection.UseVisualStyleBackColor = true; @@ -832,7 +832,7 @@ private void InitializeComponent() { this._inputDetection.AutoSize = true; this._inputDetection.Location = new System.Drawing.Point(17, 30); this._inputDetection.Name = "_inputDetection"; - this._inputDetection.Size = new System.Drawing.Size(289, 17); + this._inputDetection.Size = new System.Drawing.Size(296, 21); this._inputDetection.TabIndex = 0; this._inputDetection.Text = "Send message when keyboard/mouse input is detected"; this._inputDetection.UseVisualStyleBackColor = true; @@ -1012,9 +1012,6 @@ public SettingsDialog(AppSettings settings) { } _textBoxPacing.Text = $"{Settings.CommandPacing}"; - - //comboBoxLogThresholds.SelectedIndex = LogManager.GetLogger("MCEControl").Logger.Repository.LevelMap["ALL"].Value; - _buttonOk.Enabled = false; } @@ -1254,6 +1251,8 @@ private void SettingsDialog_Load(object sender, EventArgs e) { private void comboBoxLogThresholds_SelectedIndexChanged(object sender, EventArgs e) { Settings.TextBoxLogThreshold = _comboBoxLogThresholds.SelectedItem.ToString(); + Logger.Instance.TextBoxThreshold = LogManager.GetLogger("MCEControl").Logger.Repository.LevelMap[Settings.TextBoxLogThreshold]; + SettingsChanged(); } diff --git a/src/Helpers/CommandFileWatcher.cs b/src/Helpers/CommandFileWatcher.cs index 4ba4acc..3ff5178 100644 --- a/src/Helpers/CommandFileWatcher.cs +++ b/src/Helpers/CommandFileWatcher.cs @@ -42,27 +42,27 @@ the renaming of files or directories. */ // Add event handlers. watcher.Changed += new FileSystemEventHandler(OnChanged); - watcher.Created += new FileSystemEventHandler(OnChanged); - watcher.Deleted += new FileSystemEventHandler(OnChanged); - watcher.Renamed += new RenamedEventHandler(OnRenamed); + //watcher.Created += new FileSystemEventHandler(OnChanged); + //watcher.Deleted += new FileSystemEventHandler(OnChanged); + //watcher.Renamed += new RenamedEventHandler(OnRenamed); // Begin watching. watcher.EnableRaisingEvents = true; - Logger.Instance.Log4.Info($"CommandInvoker: Watching {watcher.Path}\\{watcher.Filter} for changes."); + Logger.Instance.Log4.Info($"{this.GetType().Name}: Watching {watcher.Path}\\{watcher.Filter} for changes"); return watcher; } private void OnChanged(object source, FileSystemEventArgs e) { - Logger.Instance.Log4.Info($"CommandInvoker:{e.FullPath} changed"); + Logger.Instance.Log4.Info($"{this.GetType().Name}: {e.FullPath} changed"); TelemetryService.Instance.TrackEvent("Commands file change detected"); OnChangedEvent(); } - private void OnRenamed(object source, RenamedEventArgs e) { - // Specify what is done when a file is renamed. - Logger.Instance.Log4.Info($"CommandInvoker:{e.OldFullPath} renamed to {e.FullPath}"); - } + //private void OnRenamed(object source, RenamedEventArgs e) { + // // Specify what is done when a file is renamed. + // Logger.Instance.Log4.Info($"CommandInvoker:{e.OldFullPath} renamed to {e.FullPath}"); + //} #region IDisposable Support private bool disposedValue = false; // To detect redundant calls @@ -71,10 +71,8 @@ protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { if (fileWatcher != null) { - fileWatcher.Changed -= OnChanged; - fileWatcher.Created -= OnChanged; - fileWatcher.Deleted -= OnChanged; - fileWatcher.Renamed -= OnRenamed; + Stop(); + fileWatcher.Dispose(); fileWatcher = null; } } @@ -96,7 +94,12 @@ public void Dispose() { } internal void Stop() { - throw new NotImplementedException(); + fileWatcher.EnableRaisingEvents = false; + fileWatcher.Changed -= OnChanged; + //fileWatcher.Created -= OnChanged; + //fileWatcher.Deleted -= OnChanged; + //fileWatcher.Renamed -= OnRenamed; + Logger.Instance.Log4.Info($"{this.GetType().Name}: Stopped watching {fileWatcher.Path}\\{fileWatcher.Filter} for changes"); } #endregion } diff --git a/src/Helpers/Logger.cs b/src/Helpers/Logger.cs index b767a65..b97ef48 100644 --- a/src/Helpers/Logger.cs +++ b/src/Helpers/Logger.cs @@ -120,7 +120,7 @@ private Logger() { Name = "File", AppendToFile = true, Layout = patternLayout, - MaxSizeRollBackups = 5, + MaxSizeRollBackups = 10, MaximumFileSize = "1MB", RollingStyle = RollingFileAppender.RollingMode.Size, StaticLogFileName = true, diff --git a/src/MCEControl.csproj b/src/MCEControl.csproj index ac32ca0..21105d1 100644 --- a/src/MCEControl.csproj +++ b/src/MCEControl.csproj @@ -21,7 +21,7 @@ MCEControl.Program - v4.7.2 + v4.8 0.0 @@ -29,6 +29,7 @@ false + 8.0 publish\ true Disk @@ -43,7 +44,6 @@ 1.0.0.%2a false true - 8.0 bin\Debug\ @@ -125,17 +125,17 @@ + + True + True + AssemblyFileVersion.tt + Form About.cs - - True - True - AssemblyFileVersion.tt - Code @@ -392,47 +392,23 @@ - 2.0.12 + 2.0.14 - 2.16.0 - - - 3.3.2 - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - 3.3.2 - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - 3.3.2 - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - 3.3.2 - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - 3.3.2 - runtime; build; native; contentfiles; analyzers; buildtransitive - all + 2.20.0 - 0.48.0 + 0.50.0 - 5.0.1 + 6.0.1 "$(DevEnvDir)TextTransform.exe" -out "$(SolutionDir)\AssemblyFileVersion.cs" "$(SolutionDir)\AssemblyFileVersion.tt" - "$(DevEnvDir)TextTransform.exe" "$(SolutionDir)..\Installer\Installer.tt" + @echo Post-build... +"$(DevEnvDir)TextTransform.exe" "$(SolutionDir)..\Installer\Installer.tt" copy "$(SolutionDir)bin\$(ConfigurationName)\MCEControl.exe.*" "$(SolutionDir)..\Installer\" copy "$(SolutionDir)bin\$(ConfigurationName)\*.dll" "$(SolutionDir)..\Installer\" "C:\Program Files (x86)\NSIS\makensis.exe" "$(SolutionDir)..\Installer\Installer.nsi" /WX /V4 diff --git a/src/MCEControl.sln b/src/MCEControl.sln index 3218cca..55bb8b8 100644 --- a/src/MCEControl.sln +++ b/src/MCEControl.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.29326.143 +# Visual Studio Version 17 +VisualStudioVersion = 17.1.32127.271 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MCEControl", "MCEControl.csproj", "{9489CAA5-2568-4ED5-A9AA-F5941CC608EB}" EndProject @@ -9,6 +9,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution ..\Installer\Installer.tt = ..\Installer\Installer.tt Installer\license.txt = Installer\license.txt ..\Installer\logging.nsh = ..\Installer\logging.nsh + README.md = README.md ..\Installer\version.txt = ..\Installer\version.txt EndProjectSection EndProject diff --git a/src/MainWindow.cs b/src/MainWindow.cs index da1ec7a..7646d6d 100644 --- a/src/MainWindow.cs +++ b/src/MainWindow.cs @@ -173,13 +173,13 @@ private void UpdateService_GotLatestVersion(object sender, Version version) { BeginInvoke((Action)(() => { UpdateService_GotLatestVersion(sender, version); })); } else { - if (version == null && !String.IsNullOrWhiteSpace(UpdateService.Instance.ErrorMessage)) { + if (version == null || !String.IsNullOrWhiteSpace(UpdateService.Instance.ErrorMessage)) { Logger.Instance.Log4.Info( - $"Could not access tig.github.io/mcec to see if a newer version is available. {UpdateService.Instance.ErrorMessage}"); + $"Could not access {UpdateService.Instance.ReleasePageUri} to see if a newer version is available. {UpdateService.Instance.ErrorMessage}"); } else if (UpdateService.Instance.CompareVersions() < 0) { installLatestVersionMenuItem.Enabled = true; - Logger.Instance.Log4.Info($"A newer version of MCE Controller ({version}) is available at"); + Logger.Instance.Log4.Info($"A newer version is available at"); Logger.Instance.Log4.Info($" {UpdateService.Instance.ReleasePageUri}"); if (!Settings.DisableUpdatePopup) @@ -187,10 +187,10 @@ private void UpdateService_GotLatestVersion(object sender, Version version) { } else if (UpdateService.Instance.CompareVersions() > 0) { Logger.Instance.Log4.Info( - $"You are are running a MORE recent version than can be found at tig.github.io/mcec ({version})"); + $"You are are running a more recent version than the latest published version ({UpdateService.Instance.ReleasePageUri})"); } else { - Logger.Instance.Log4.Info("You are running the most recent version of MCE Controller"); + Logger.Instance.Log4.Info("You are running the most recent version"); } } } @@ -239,7 +239,8 @@ private void mainWindow_Closing(object sender, CancelEventArgs e) { watcher.Dispose(); watcher = null; - Invoker.Save($@"{Program.ConfigPath}MCEControl.commands"); + // BUGBUG: Why do we need to save when exiting the app? Could this be the cause of Issue #24? + //Invoker.Save($@"{Program.ConfigPath}MCEControl.commands"); TelemetryService.Instance.Stop(); } } @@ -351,7 +352,7 @@ private void StartSerialServer() { Settings.SerialServerHandshake); } else { - Logger.Instance.Log4.Info("Serial: Attempt to StartSerialServer() while an instance already exists!"); + Logger.Instance.Log4.Error("Serial: Attempt to StartSerialServer() while an instance already exists!"); } } @@ -446,7 +447,7 @@ private void ReceivedData(Reply reply, String cmd) { Invoker.ExecuteNext(); } catch (Exception e) { - Logger.Instance.Log4.Info($"Command: ({cmd}) error: {e}"); + Logger.Instance.Log4.Error($"Command: ({cmd}) error: {e}"); } } } @@ -701,7 +702,7 @@ public void clientSocketNotificationHandler(ServiceNotification notify, ServiceS case ServiceNotification.Error: Logger.Instance.Log4.Debug($"ClientSocketNotificationHandler - ServiceStatus.Error: {(string)msg}"); - Logger.Instance.Log4.Info($"Client: Error; {(string)msg}"); + Logger.Instance.Log4.Error($"Client: Error; {(string)msg}"); RestartClient(); return; diff --git a/src/Properties/Resources.Designer.cs b/src/Properties/Resources.Designer.cs index 76a00d8..5f7323b 100644 --- a/src/Properties/Resources.Designer.cs +++ b/src/Properties/Resources.Designer.cs @@ -19,7 +19,7 @@ namespace MCEControl.Properties { // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { diff --git a/src/README.md b/src/README.md new file mode 100644 index 0000000..7cef5eb --- /dev/null +++ b/src/README.md @@ -0,0 +1,29 @@ +# Build & Deploy Info + +## Pre-requisites + +* Visual Studio 2022 or greater +* NSIS 3.x - `winget install nsis` + +## Versions & Updates + +Upon build + +* the build (major.minor.rev.build) in `Installer/version.txt` is bumped. +* `src/AssemblyFileVersion.tt` is processed by the T4 compiler. This generates `src/AssemblyFileVersion.cs` and updates `Installer/version.txt`. + +Releases are publishshed at https://github.com/tig/mcec/releases + +Debug builds check for pre-releases and there should ALWAYS be a fake, NEWER pre-release like https://github.com/tig/mcec/releases/tag/v2.3.6.0 to force testing of the update system. + + +## Installer + +* `Installer\MCEController Setup.exe` +* Built using NSIS. A post-build event runs `makensis.exe` against `Installer/Installer.nsi` + +## Unit Tests + +* uses xUnit + + diff --git a/src/Services/AppSettings.cs b/src/Services/AppSettings.cs index bc7c452..b265964 100644 --- a/src/Services/AppSettings.cs +++ b/src/Services/AppSettings.cs @@ -208,7 +208,7 @@ public static AppSettings Deserialize(String settingsFile) { "DisableInternalCommands", false), new NumberFormatInfo()); } catch (UnauthorizedAccessException e) { - Logger.Instance.Log4.Info($"Settings: Settings file could not be loaded. {e.Message}"); + Logger.Instance.Log4.Error($"Settings: Settings file could not be loaded. {e.Message}"); MessageBox.Show($"Settings file could not be loaded. {e.Message}"); } finally { diff --git a/src/Services/TelemetryService.tt.cs b/src/Services/TelemetryService.tt.cs index fa05238..a98fb11 100644 --- a/src/Services/TelemetryService.tt.cs +++ b/src/Services/TelemetryService.tt.cs @@ -4,6 +4,6 @@ // namespace MCEControl { public partial class TelemetryService { - public const string Key = "26132385-0150-4dd1-83da-ef861e0aee67"; - } + public const string Key = ""; + } } diff --git a/src/Services/UpdateService.cs b/src/Services/UpdateService.cs index 1ab829e..12c3b85 100644 --- a/src/Services/UpdateService.cs +++ b/src/Services/UpdateService.cs @@ -54,6 +54,7 @@ public void CheckVersion() { private async Task GetLatestStableVersionAsync() { ReleasePageUri = new Uri("https://github.com/tig/mcec/releases"); + ErrorMessage = null; Logger.Instance.Log4.Debug("Checking for new release..."); using (var client = new WebClient()) { try { @@ -70,9 +71,9 @@ private async Task GetLatestStableVersionAsync() { //Logger.Instance.Log4.Debug($"Releases {JsonSerializer.Serialize(releases, options: new JsonSerializerOptions() { WriteIndented = true })}"); if (releases.Length > 0) { #if DEBUG - Logger.Instance.Log4.Info($"The latest PRE-RELEASE is tagged at {releases[0].TagName} and is named {releases[0].Name}. Download Url: {releases[0].Assets[0].BrowserDownloadUrl}"); + Logger.Instance.Log4.Info($"The latest PRE-RELEASE is tagged at {releases[0].TagName} and is named '{releases[0].Name}' Download Url: {releases[0].Assets[0].BrowserDownloadUrl}"); #else - Logger.Instance.Log4.Debug($"The latest release is tagged at {releases[0].TagName} and is named {releases[0].Name}. Download Url: {releases[0].Assets[0].BrowserDownloadUrl}"); + Logger.Instance.Log4.Debug($"The latest release is tagged at {releases[0].TagName} and is named '{releases[0].Name}'. Download Url: {releases[0].Assets[0].BrowserDownloadUrl}"); #endif LatestStableVersion = new Version(releases[0].TagName.Replace('v', ' ')); @@ -80,12 +81,12 @@ private async Task GetLatestStableVersionAsync() { DownloadUri = new Uri(releases[0].Assets[0].BrowserDownloadUrl); } else { - ErrorMessage = "No release found."; + ErrorMessage = "No release found"; } } catch (Exception e) { ErrorMessage = $"({ReleasePageUri}) {e.Message}"; - Logger.Instance.Log4.Debug(ErrorMessage); + Logger.Instance.Log4.Info(ErrorMessage); TelemetryService.Instance.TrackException(e); } } @@ -143,7 +144,7 @@ private void Client_DownloadDataCompleted(object sender, DownloadDataCompletedEv //p.WaitForInputIdle(1000); } catch (Win32Exception we) { - Logger.Instance.Log4.Info($"{this.GetType().Name}: {_tempFilename} failed to run with error: {we.Message}"); + Logger.Instance.Log4.Error($"{this.GetType().Name}: {_tempFilename} failed to run with error: {we.Message}"); } MainWindow.Instance.BeginInvoke((Action)(() => { MainWindow.Instance.ShutDown(); })); } diff --git a/src/app.config b/src/app.config index 85a040d..6f7d503 100644 --- a/src/app.config +++ b/src/app.config @@ -1,7 +1,7 @@ - + diff --git a/tests/MCEControl.xUnit/MCEControl.xUnit.csproj b/tests/MCEControl.xUnit/MCEControl.xUnit.csproj index 76248cb..130d33c 100644 --- a/tests/MCEControl.xUnit/MCEControl.xUnit.csproj +++ b/tests/MCEControl.xUnit/MCEControl.xUnit.csproj @@ -9,11 +9,12 @@ Properties MCEControl.xUnit MCEControl.xUnit - v4.7.2 + v4.8 512 true + true @@ -59,7 +60,7 @@ 14.0.0 - 5.5.0 + 6.0.0 2.4.1 @@ -83,7 +84,7 @@ 2.4.1 - 2.4.1 + 2.4.3 runtime; build; native; contentfiles; analyzers; buildtransitive all