Skip to content

Commit

Permalink
Merge pull request #559 from emoacht/hotfix
Browse files Browse the repository at this point in the history
Hotfix
  • Loading branch information
emoacht authored Jan 9, 2024
2 parents 482c039 + abdd517 commit f3fa173
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Source/Installer/Product.wxs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="Monitorian" Manufacturer="emoacht" Version="4.6.2"
<Product Id="*" Name="Monitorian" Manufacturer="emoacht" Version="4.6.4"
Language="1033" Codepage="1252" UpgradeCode="{81A4D148-75D3-462E-938D-8C208FB48E3C}">
<Package Id="*" InstallerVersion="500" Compressed="yes"
InstallScope="perMachine" InstallPrivileges="elevated"
Expand Down
8 changes: 4 additions & 4 deletions Source/Monitorian.Core/AppKeeper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ public AppKeeper()
StartupAgent = new StartupAgent();
}

public Task<bool> StartAsync(StartupEventArgs e) => StartAsync(e, []);
public Task<bool> StartAsync(StartupEventArgs e) => StartAsync(e, null);

public async Task<bool> StartAsync(StartupEventArgs e, IEnumerable<string> 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
Expand Down Expand Up @@ -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() ?? [];
Expand All @@ -113,7 +113,7 @@ private async Task ParseArgumentsAsync(StartupEventArgs e, string[] standardOpti

public Task<string> 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

Expand Down
15 changes: 14 additions & 1 deletion Source/Monitorian.Core/Models/AppDataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,23 @@ public static async Task<string> ReadAsync(string fileName)
return await sr.ReadToEndAsync();
}

public static async Task WriteAsync(string fileName, bool append, string content)
/// <summary>
/// Asynchronously writes to a specified file.
/// </summary>
/// <param name="fileName">File name to write to</param>
/// <param name="append">True to append to the file; False to overwrite the file</param>
/// <param name="delete">True to delete the file if content is null or empty; False to leave the file</param>
/// <param name="content">Content to write to the file</param>
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);
}
Expand Down
4 changes: 2 additions & 2 deletions Source/Monitorian.Core/Models/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private static async Task<string[]> 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
Expand Down Expand Up @@ -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)
{
Expand Down
4 changes: 2 additions & 2 deletions Source/Monitorian.Core/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("4.6.2.0")]
[assembly: AssemblyFileVersion("4.6.2.0")]
[assembly: AssemblyVersion("4.6.4.0")]
[assembly: AssemblyFileVersion("4.6.4.0")]
[assembly: NeutralResourcesLanguage("en-US")]

// For unit test
Expand Down
4 changes: 2 additions & 2 deletions Source/Monitorian/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("4.6.2.0")]
[assembly: AssemblyFileVersion("4.6.2.0")]
[assembly: AssemblyVersion("4.6.4.0")]
[assembly: AssemblyFileVersion("4.6.4.0")]
[assembly: Guid("a4cc5362-9b08-465b-ad64-5cfabc72a4c7")]
[assembly: NeutralResourcesLanguage("en-US")]

0 comments on commit f3fa173

Please sign in to comment.