Skip to content

Commit

Permalink
added configureawait, sealed, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
fgsfds committed Sep 26, 2024
1 parent 3b3b9f2 commit 89ca137
Show file tree
Hide file tree
Showing 52 changed files with 248 additions and 172 deletions.
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<PackageVersion Include="SharpCompress" Version="0.38.0" />
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageVersion Include="System.Private.Uri" Version="4.3.2" />
<PackageVersion Include="xunit" Version="2.9.0" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
<PackageVersion Include="AWSSDK.S3" Version="3.7.402.11" />
Expand Down
6 changes: 3 additions & 3 deletions Web.Blazor/Components/AddonsList.razor
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ else
}

<br />
<div>@((MarkupString)@Markdown.ToHtml(addon.Description))</div>
<div>@((MarkupString)@Markdown.ToHtml(addon.Description ?? string.Empty))</div>
<a href="@addon.DownloadUrl">Download</a>
<br />
<br />
Expand All @@ -44,7 +44,7 @@ else
{
<h4>@addon.Title</h4>
<br />
<div>@((MarkupString)@Markdown.ToHtml(addon.Description))</div>
<div>@((MarkupString)@Markdown.ToHtml(addon.Description ?? string.Empty))</div>
<a href="@addon.DownloadUrl">Download</a>
<br />
<br />
Expand All @@ -55,7 +55,7 @@ else
{
<h4>@addon.Title</h4>
<br />
<div>@((MarkupString)@Markdown.ToHtml(addon.Description))</div>
<div>@((MarkupString)@Markdown.ToHtml(addon.Description ?? string.Empty))</div>
<a href="@addon.DownloadUrl">Download</a>
<br />
<br />
Expand Down
2 changes: 1 addition & 1 deletion Web.Blazor/Pages/Error.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Web.Blazor.Pages;

[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
[IgnoreAntiforgeryToken]
public class ErrorModel : PageModel
public sealed class ErrorModel : PageModel
{
public string? RequestId { get; set; }

Expand Down
2 changes: 1 addition & 1 deletion Web.Blazor/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Web.Blazor;

public class Program
public sealed class Program
{
public static void Main(string[] args)
{
Expand Down
4 changes: 4 additions & 0 deletions Web.Blazor/Web.Blazor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AddSealed">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Markdig" />
<PackageReference Include="AWSSDK.S3" />
</ItemGroup>
Expand Down
5 changes: 5 additions & 0 deletions src/Avalonia.Desktop/Avalonia.Desktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,17 @@
</PackageReference>
<PackageReference Include="Avalonia.Desktop" />
<PackageReference Include="Avalonia.Diagnostics" />
<PackageReference Include="ConfigureAwaitAnalyzer">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Projektanker.Icons.Avalonia.FontAwesome" />
<PackageReference Include="Avalonia" />
<PackageReference Include="Avalonia.Controls.DataGrid" />
<PackageReference Include="Avalonia.Themes.Fluent" />
<PackageReference Include="CommunityToolkit.Mvvm" />
<PackageReference Include="Markdown.Avalonia" />
<PackageReference Include="System.Private.Uri" />
</ItemGroup>

<ItemGroup>
Expand Down
14 changes: 7 additions & 7 deletions src/Avalonia.Desktop/Controls/MapsControl.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private void CreateSkillsFlyout()

foreach (var skill in skills)
{
flyout.Items.Add(skill);
_ = flyout.Items.Add(skill);
}

_flyout = flyout;
Expand Down Expand Up @@ -176,7 +176,7 @@ private void AddContextMenuButtons()

foreach (var skill in skills)
{
portButton.Items.Add(skill);
_ = portButton.Items.Add(skill);
}
}
else
Expand All @@ -188,12 +188,12 @@ private void AddContextMenuButtons()
};
}

MapsList.ContextMenu.Items.Add(portButton);
_ = MapsList.ContextMenu.Items.Add(portButton);
}

if (MapsList.ContextMenu.Items.Count > 0)
{
MapsList.ContextMenu.Items.Add(new Separator());
_ = MapsList.ContextMenu.Items.Add(new Separator());
}

var deleteButton = new MenuItem()
Expand All @@ -205,7 +205,7 @@ private void AddContextMenuButtons()
)
};

MapsList.ContextMenu.Items.Add(deleteButton);
_ = MapsList.ContextMenu.Items.Add(deleteButton);
}


Expand Down Expand Up @@ -264,7 +264,7 @@ private BasePort GetPort(BasePort? port)
{
if (_flyout?.Target is not null)
{
return ((Button)_flyout.Target!).CommandParameter as BasePort;
return ((Button)_flyout.Target!).CommandParameter as BasePort ?? ThrowHelper.Exception<BasePort>();
}
else if (port is not null)
{
Expand Down Expand Up @@ -325,7 +325,7 @@ private void OnListBoxEmptySpaceClicked(object? sender, Input.PointerPressedEven
{
MapsList.SelectedItem = null;
MapsList.Focusable = true;
MapsList.Focus();
_ = MapsList.Focus();
MapsList.Focusable = false;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Avalonia.Desktop/ViewModels/AboutViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public sealed partial class AboutViewModel(AppUpdateInstaller updateInstaller) :
[RelayCommand(CanExecute = (nameof(CheckForUpdatesCanExecute)))]
private async Task CheckForUpdatesAsync()
{
await CheckForUpdateAsync();
await CheckForUpdateAsync().ConfigureAwait(true);
}

private bool CheckForUpdatesCanExecute() => IsInProgress is false;
Expand Down Expand Up @@ -91,7 +91,7 @@ private async Task CheckForUpdateAsync()
try
{
CheckForUpdatesButtonText = "Checking...";
updates = await _updateInstaller.CheckForUpdates(CurrentVersion);
updates = await _updateInstaller.CheckForUpdates(CurrentVersion).ConfigureAwait(true);
}
catch
{
Expand Down
11 changes: 6 additions & 5 deletions src/Avalonia.Desktop/ViewModels/CampaignsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public override IAddon? SelectedAddon
/// </summary>
private async Task UpdateAsync(bool createNew)
{
await _installedAddonsProvider.CreateCache(createNew);
await _installedAddonsProvider.CreateCache(createNew).ConfigureAwait(true);

OnPropertyChanged(nameof(CampaignsList));
}
Expand All @@ -135,7 +135,7 @@ private async Task StartCampaignAsync(object? command)

var args = port.GetStartGameArgs(Game, SelectedAddon, mods, _config.SkipIntro, _config.SkipStartup);

await StartPortAsync(SelectedAddon.Id, port.FullPathToExe, args);
await StartPortAsync(SelectedAddon.Id, port.FullPathToExe, args).ConfigureAwait(true);
}


Expand All @@ -145,7 +145,7 @@ private async Task StartCampaignAsync(object? command)
[RelayCommand]
private void OpenFolder()
{
Process.Start(new ProcessStartInfo
_ = Process.Start(new ProcessStartInfo
{
FileName = Game.CampaignsFolderPath,
UseShellExecute = true,
Expand All @@ -159,7 +159,7 @@ private void OpenFolder()
[RelayCommand]
private async Task RefreshListAsync()
{
await UpdateAsync(true);
await UpdateAsync(true).ConfigureAwait(true);
}


Expand Down Expand Up @@ -190,6 +190,7 @@ private void DeleteCampaign()
/// <summary>
/// Start port with command line args
/// </summary>
/// <param name="id">Campaign id</param>
/// <param name="exe">Path to port exe</param>
/// <param name="args">Command line arguments</param>
private async Task StartPortAsync(string id, string exe, string args)
Expand All @@ -202,7 +203,7 @@ await Process.Start(new ProcessStartInfo
UseShellExecute = true,
Arguments = args,
WorkingDirectory = Path.GetDirectoryName(exe)
})!.WaitForExitAsync();
})!.WaitForExitAsync().ConfigureAwait(true);

sw.Stop();
var time = sw.Elapsed;
Expand Down
5 changes: 2 additions & 3 deletions src/Avalonia.Desktop/ViewModels/DevViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
using SharpCompress.Archives;
using SharpCompress.Archives.Zip;
using SharpCompress.Common;
using System;
using System.Collections.Immutable;
using System.Text;
using System.Text.Json;
Expand Down Expand Up @@ -364,7 +363,7 @@ private async Task AddAddonAsync()
return;
}

var result = await _filesUploader.AddAddonToDatabaseAsync(files[0].Path.LocalPath);
var result = await _filesUploader.AddAddonToDatabaseAsync(files[0].Path.LocalPath).ConfigureAwait(true);

if (result)
{
Expand Down Expand Up @@ -800,7 +799,7 @@ private async Task UploadAddonAsync()
return;
}

var uploadResult = await _filesUploader.UploadFilesToFtpAsync(files[0].Path.LocalPath, CancellationToken.None);
var uploadResult = await _filesUploader.UploadFilesToFtpAsync(files[0].Path.LocalPath, CancellationToken.None).ConfigureAwait(true);

if (uploadResult)
{
Expand Down
11 changes: 6 additions & 5 deletions src/Avalonia.Desktop/ViewModels/MapsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ DownloadableAddonsProviderFactory _downloadableAddonsProviderFactory
/// </summary>
private async Task UpdateAsync(bool createNew)
{
await _installedAddonsProvider.CreateCache(createNew);
await _installedAddonsProvider.CreateCache(createNew).ConfigureAwait(true);

OnPropertyChanged(nameof(MapsList));
}
Expand Down Expand Up @@ -135,7 +135,7 @@ private async Task StartMapAsync(object? command)

var args = parameter.Item1.GetStartGameArgs(Game, SelectedAddon, mods, _config.SkipIntro, _config.SkipStartup, parameter.Item2);

await StartPortAsync(SelectedAddon.Id, parameter.Item1.FullPathToExe, args);
await StartPortAsync(SelectedAddon.Id, parameter.Item1.FullPathToExe, args).ConfigureAwait(true);
}


Expand All @@ -145,7 +145,7 @@ private async Task StartMapAsync(object? command)
[RelayCommand]
private void OpenFolder()
{
Process.Start(new ProcessStartInfo
_ = Process.Start(new ProcessStartInfo
{
FileName = Game.MapsFolderPath,
UseShellExecute = true,
Expand All @@ -159,7 +159,7 @@ private void OpenFolder()
[RelayCommand]
private async Task RefreshListAsync()
{
await UpdateAsync(true);
await UpdateAsync(true).ConfigureAwait(true);
}


Expand Down Expand Up @@ -190,6 +190,7 @@ private void DeleteMap()
/// <summary>
/// Start port with command line args
/// </summary>
/// <param name="id">Map id</param>
/// <param name="exe">Path to port exe</param>
/// <param name="args">Command line arguments</param>
private async Task StartPortAsync(string id, string exe, string args)
Expand All @@ -202,7 +203,7 @@ await Process.Start(new ProcessStartInfo
UseShellExecute = true,
Arguments = args,
WorkingDirectory = Path.GetDirectoryName(exe)
})!.WaitForExitAsync();
})!.WaitForExitAsync().ConfigureAwait(true);

sw.Stop();
var time = sw.Elapsed;
Expand Down
8 changes: 3 additions & 5 deletions src/Avalonia.Desktop/ViewModels/ModsViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using Common.Client.API;
using Common.Client.Config;
using Common.Client.Providers;
using Common.Enums;
using Common.Helpers;
Expand Down Expand Up @@ -54,7 +52,7 @@ DownloadableAddonsProviderFactory _downloadableAddonsProviderFactory
/// </summary>
private async Task UpdateAsync(bool createNew)
{
await _installedAddonsProvider.CreateCache(createNew);
await _installedAddonsProvider.CreateCache(createNew).ConfigureAwait(true);

OnPropertyChanged(nameof(ModsList));
}
Expand Down Expand Up @@ -98,7 +96,7 @@ public override IAddon? SelectedAddon
[RelayCommand]
private void OpenFolder()
{
Process.Start(new ProcessStartInfo
_ = Process.Start(new ProcessStartInfo
{
FileName = Game.ModsFolderPath,
UseShellExecute = true,
Expand All @@ -112,7 +110,7 @@ private void OpenFolder()
[RelayCommand]
private async Task RefreshListAsync()
{
await UpdateAsync(true);
await UpdateAsync(true).ConfigureAwait(true);
}


Expand Down
4 changes: 2 additions & 2 deletions src/Avalonia.Desktop/ViewModels/PortViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ out var newVersion
/// </summary>
public async Task InitializeAsync()
{
_release = await _portsReleasesProvider.GetLatestReleaseAsync(_port.PortEnum);
_release = await _portsReleasesProvider.GetLatestReleaseAsync(_port.PortEnum).ConfigureAwait(true);

OnPropertyChanged(nameof(LatestVersion));
OnPropertyChanged(nameof(InstallButtonText));
Expand All @@ -165,7 +165,7 @@ private async Task InstallAsync()
ProgressBarValue = 0;
OnPropertyChanged(nameof(ProgressBarValue));

await installer.InstallAsync(_port);
await installer.InstallAsync(_port).ConfigureAwait(true);

installer.Progress.ProgressChanged -= OnProgressChanged;
ProgressBarValue = 0;
Expand Down
2 changes: 0 additions & 2 deletions src/Avalonia.Desktop/ViewModels/RightPanelViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using Common.Client.API;
using Common.Client.Config;
using Common.Client.Providers;
using Common.Enums;
using Common.Helpers;
Expand Down
8 changes: 4 additions & 4 deletions src/Avalonia.Desktop/ViewModels/ToolViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public string InstallButtonText
/// </summary>
public async Task InitializeAsync()
{
_release = await _toolsReleasesProvider.GetLatestReleaseAsync(_tool);
_release = await _toolsReleasesProvider.GetLatestReleaseAsync(_tool).ConfigureAwait(true);

OnPropertyChanged(nameof(LatestVersion));
OnPropertyChanged(nameof(InstallButtonText));
Expand All @@ -130,7 +130,7 @@ private async Task InstallAsync()
ProgressBarValue = 0;
OnPropertyChanged(nameof(ProgressBarValue));

await installer.InstallAsync(_tool);
await installer.InstallAsync(_tool).ConfigureAwait(true);

installer.Progress.ProgressChanged -= OnProgressChanged;
ProgressBarValue = 0;
Expand All @@ -151,7 +151,7 @@ private async Task CheckUpdateAsync()
{
IsInProgress = true;

_release = await _toolsReleasesProvider.GetLatestReleaseAsync(_tool);
_release = await _toolsReleasesProvider.GetLatestReleaseAsync(_tool).ConfigureAwait(true);

OnPropertyChanged(nameof(LatestVersion));
OnPropertyChanged(nameof(InstallButtonText));
Expand All @@ -169,7 +169,7 @@ public void Start()
{
var args = _tool.GetStartToolArgs();

Process.Start(new ProcessStartInfo
_ = Process.Start(new ProcessStartInfo
{
FileName = _tool.FullPathToExe,
UseShellExecute = true,
Expand Down
Loading

0 comments on commit 89ca137

Please sign in to comment.