From e1a5cc05e1803056d3576678060fa550c37734ae Mon Sep 17 00:00:00 2001 From: emoacht Date: Tue, 9 Jan 2024 15:43:36 +0900 Subject: [PATCH 1/5] Fix ArgumentNullException --- Source/Monitorian.Core/AppKeeper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Monitorian.Core/AppKeeper.cs b/Source/Monitorian.Core/AppKeeper.cs index 4dfb9ab4..b6a11c1b 100644 --- a/Source/Monitorian.Core/AppKeeper.cs +++ b/Source/Monitorian.Core/AppKeeper.cs @@ -99,7 +99,7 @@ private async Task ParseArgumentsAsync(StartupEventArgs e, string[] standardOpti const char optionMark = '/'; var isStandard = false; - var buffer = args + var buffer = args? .Where(x => !string.IsNullOrWhiteSpace(x)) .GroupBy(x => (x[0] == optionMark) ? (isStandard = standardOptions.Contains(x.ToLower())) : isStandard) .ToArray() ?? []; From 24a4f0f436e30f82fa330efcd6cc33611830e784 Mon Sep 17 00:00:00 2001 From: emoacht Date: Tue, 9 Jan 2024 15:47:55 +0900 Subject: [PATCH 2/5] Increment version to 4.6.3 --- Source/Installer/Product.wxs | 2 +- Source/Monitorian.Core/Properties/AssemblyInfo.cs | 4 ++-- Source/Monitorian/Properties/AssemblyInfo.cs | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Source/Installer/Product.wxs b/Source/Installer/Product.wxs index 6f774b64..53792dd2 100644 --- a/Source/Installer/Product.wxs +++ b/Source/Installer/Product.wxs @@ -1,6 +1,6 @@  - Date: Tue, 9 Jan 2024 16:44:48 +0900 Subject: [PATCH 3/5] Modify to delete file if null or empty --- Source/Monitorian.Core/AppKeeper.cs | 2 +- Source/Monitorian.Core/Models/AppDataService.cs | 15 ++++++++++++++- Source/Monitorian.Core/Models/Logger.cs | 4 ++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Source/Monitorian.Core/AppKeeper.cs b/Source/Monitorian.Core/AppKeeper.cs index b6a11c1b..69e93ec9 100644 --- a/Source/Monitorian.Core/AppKeeper.cs +++ b/Source/Monitorian.Core/AppKeeper.cs @@ -113,7 +113,7 @@ private async Task ParseArgumentsAsync(StartupEventArgs e, string[] standardOpti public Task LoadArgumentsAsync() => AppDataService.ReadAsync(ArgumentsFileName); - public Task SaveArgumentsAsync(string content) => AppDataService.WriteAsync(ArgumentsFileName, false, content); + public Task SaveArgumentsAsync(string content) => AppDataService.WriteAsync(ArgumentsFileName, append: false, delete: true, content); #endregion diff --git a/Source/Monitorian.Core/Models/AppDataService.cs b/Source/Monitorian.Core/Models/AppDataService.cs index f2a71bda..17378e36 100644 --- a/Source/Monitorian.Core/Models/AppDataService.cs +++ b/Source/Monitorian.Core/Models/AppDataService.cs @@ -44,10 +44,23 @@ public static async Task ReadAsync(string fileName) return await sr.ReadToEndAsync(); } - public static async Task WriteAsync(string fileName, bool append, string content) + /// + /// Asynchronously writes to a specified file. + /// + /// File name to write to + /// True to append to the file; False to overwrite the file + /// True to delete the file if content is null or empty; False to leave the file + /// Content to write to the file + public static async Task WriteAsync(string fileName, bool append, bool delete, string content) { var filePath = Path.Combine(EnsureFolderPath(), fileName); + if (delete && string.IsNullOrEmpty(content)) + { + File.Delete(filePath); + return; + } + using var sw = new StreamWriter(filePath, append, Encoding.UTF8); // BOM will be emitted. await sw.WriteAsync(content); } diff --git a/Source/Monitorian.Core/Models/Logger.cs b/Source/Monitorian.Core/Models/Logger.cs index 1f178fc3..9b4809f8 100644 --- a/Source/Monitorian.Core/Models/Logger.cs +++ b/Source/Monitorian.Core/Models/Logger.cs @@ -105,7 +105,7 @@ private static async Task GetOperationFileNamesAsync() if (fileNames.Any()) { content += await AppDataService.ReadAsync(fileNames.First()); - await AppDataService.WriteAsync(fileNames.First(), append: false, content); + await AppDataService.WriteAsync(fileNames.First(), append: false, delete: false, content); AppDataService.Delete(OperationFileName); } else @@ -134,7 +134,7 @@ public static async Task RecordOperationAsync(string content) try { - await AppDataService.WriteAsync(fileName, append: true, content); + await AppDataService.WriteAsync(fileName, append: true, delete: false, content); } catch (Exception ex) { From 427441a461ae4964d30a20aeac4367e3830077c0 Mon Sep 17 00:00:00 2001 From: emoacht Date: Tue, 9 Jan 2024 19:07:35 +0900 Subject: [PATCH 4/5] Refactor additional arguments --- Source/Monitorian.Core/AppKeeper.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Monitorian.Core/AppKeeper.cs b/Source/Monitorian.Core/AppKeeper.cs index 69e93ec9..8d0f84b8 100644 --- a/Source/Monitorian.Core/AppKeeper.cs +++ b/Source/Monitorian.Core/AppKeeper.cs @@ -21,13 +21,13 @@ public AppKeeper() StartupAgent = new StartupAgent(); } - public Task StartAsync(StartupEventArgs e) => StartAsync(e, []); + public Task StartAsync(StartupEventArgs e) => StartAsync(e, null); public async Task StartAsync(StartupEventArgs e, IEnumerable additionalOptions) { // This method must be called before StandardArguments or OtherArguments property is consumed. // An exception thrown in this method will not be handled. - await ParseArgumentsAsync(e, EnumerateStandardOptions().Concat(additionalOptions).ToArray()); + await ParseArgumentsAsync(e, EnumerateStandardOptions().Concat(additionalOptions ?? []).ToArray()); #if DEBUG ConsoleService.TryStartWrite(); #else From abdd5178a82376800acd35fa1876fcc642ff8eb4 Mon Sep 17 00:00:00 2001 From: emoacht Date: Tue, 9 Jan 2024 19:09:01 +0900 Subject: [PATCH 5/5] Increment version to 4.6.4 --- Source/Installer/Product.wxs | 2 +- Source/Monitorian.Core/Properties/AssemblyInfo.cs | 4 ++-- Source/Monitorian/Properties/AssemblyInfo.cs | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Source/Installer/Product.wxs b/Source/Installer/Product.wxs index 53792dd2..bd56fb2f 100644 --- a/Source/Installer/Product.wxs +++ b/Source/Installer/Product.wxs @@ -1,6 +1,6 @@  -