Skip to content

Commit eea897b

Browse files
authored
Cleanup (#128)
* remove dispatcher * Cleanup * revert * Formatting * remove using
1 parent beaaa60 commit eea897b

File tree

5 files changed

+11
-23
lines changed

5 files changed

+11
-23
lines changed

KoAR.SaveEditor/Updates/UpdateMethods.cs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static class UpdateMethods
2727
public static async void ExecuteUpdate(string zipFilePath)
2828
{
2929
string scriptFileName = await UpdateMethods.ExtractPowershellScript().ConfigureAwait(false);
30-
using Process process = Process.Start(new ProcessStartInfo
30+
using Process process = Process.Start(startInfo: new()
3131
{
3232
WorkingDirectory = Path.GetTempPath(),
3333
UseShellExecute = false,
@@ -44,7 +44,7 @@ public static async void ExecuteUpdate(string zipFilePath)
4444
/// <param name="majorVersion">The major version of the release.</param>
4545
/// <param name="cancellationToken">Optionally used to propagate cancellation requests.</param>
4646
/// <returns>Information related to a release. Returns <see langword="null"/> if not found or an error occurs.</returns>
47-
public static async Task<IReleaseInfo?> FetchLatestVersionedRelease(int majorVersion, CancellationToken cancellationToken = default)
47+
public static async Task<IReleaseInfo?> FetchLatestVersionedReleaseAsync(int majorVersion, CancellationToken cancellationToken = default)
4848
{
4949
try
5050
{
@@ -66,14 +66,6 @@ public static async void ExecuteUpdate(string zipFilePath)
6666
return default;
6767
}
6868

69-
/// <summary>
70-
/// Fetches the latest 2.x release.
71-
/// </summary>
72-
/// <param name="cancellationToken">Optionally used to propagate cancellation requests.</param>
73-
/// <returns>Information related to a release. Returns <see langword="null"/> if not found or an error occurs.</returns>
74-
public static Task<IReleaseInfo?> FetchLatest2xReleaseAsync(CancellationToken cancellationToken = default) =>
75-
UpdateMethods.FetchLatestVersionedRelease(2, cancellationToken);
76-
7769
/// <summary>
7870
/// Fetches an array of the interim update releases for the current major version of the application to the latest.
7971
/// Only checks up to <paramref name="maxReleases"/> number of tags/releases.
@@ -116,8 +108,8 @@ private static async Task<string> ExtractPowershellScript()
116108
{
117109
try
118110
{
119-
return await UpdateMethods._client.GetFromJsonAsync<T>($"https://api.github.com/repos/mburbea/koar-item-editor/{suffix}", UpdateMethods._jsonOptions, cancellationToken)
120-
.ConfigureAwait(false);
111+
string uri = $"https://api.github.com/repos/mburbea/koar-item-editor/{suffix}";
112+
return await UpdateMethods._client.GetFromJsonAsync<T>(uri, UpdateMethods._jsonOptions, cancellationToken).ConfigureAwait(false);
121113
}
122114
catch (HttpRequestException e) when (e.StatusCode == HttpStatusCode.NotFound)
123115
{
@@ -169,7 +161,7 @@ private sealed class Release : IReleaseInfo
169161

170162
public Version Version => this._version ??= new(this.TagName.Length != 0 ? this.TagName[1..] : "0.0.0");
171163

172-
public ReleaseAsset? ZipFileAsset => this._zipFileAsset ??= this.Assets.FirstOrDefault(asset => asset.IsZipFile);
164+
public ReleaseAsset? ZipFileAsset => this._zipFileAsset ??= this.Assets.FirstOrDefault(asset => asset.ContentType == "application/zip");
173165

174166
public int ZipFileSize => this.ZipFileAsset?.Size ?? 0;
175167

@@ -182,8 +174,6 @@ private sealed class ReleaseAsset
182174

183175
public string ContentType { get; set; } = string.Empty;
184176

185-
public bool IsZipFile => this.ContentType == "application/zip";
186-
187177
public int Size { get; set; }
188178
}
189179

KoAR.SaveEditor/Views/Main/MainWindow.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ 1. Your saves are usually not in the same folder as the game. The editor attemps
6767
IReleaseInfo? release = default;
6868
try
6969
{
70-
if ((release = await UpdateMethods.FetchLatest2xReleaseAsync(source.Token)) != null)
70+
if ((release = await UpdateMethods.FetchLatestVersionedReleaseAsync(2, source.Token)) != null)
7171
{
7272
using OriginalUpdateViewModel viewModel = new(release);
7373
UpdateWindow window = new() { DataContext = viewModel, Owner = this };

KoAR.SaveEditor/Views/Main/MainWindowViewModel.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Threading;
66
using System.Windows.Forms;
77
using System.Windows.Interop;
8-
using System.Windows.Threading;
98
using KoAR.Core;
109
using KoAR.SaveEditor.Constructs;
1110
using KoAR.SaveEditor.Properties;
@@ -19,7 +18,6 @@ namespace KoAR.SaveEditor.Views.Main;
1918

2019
public sealed class MainWindowViewModel : NotifierBase
2120
{
22-
private readonly Dispatcher _dispatcher = Dispatcher.CurrentDispatcher;
2321
private bool _hasUnsavedChanges;
2422
private InventoryManagerViewModel? _inventoryManager;
2523
private bool _isCheckingForUpdate;

KoAR.SaveEditor/Views/Updates/UpdateControl.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ private void ViewModel_DialogResultChanged(object? sender, PropertyChangedEventA
4949

5050
private void Window_Closing(object? sender, CancelEventArgs e)
5151
{
52-
((Window)sender!).Closing -= Window_Closing;
52+
((Window)sender!).Closing -= this.Window_Closing;
5353
UpdateViewModelBase viewModel = (UpdateViewModelBase)this.DataContext;
5454
PropertyChangedEventManager.RemoveHandler(viewModel, this.ViewModel_DialogResultChanged, nameof(viewModel.DialogResult));
5555
}

KoAR.SaveEditor/Views/Updates/UpdateViewModelBase.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,10 @@ private static FlowDocument CreateDocument(IEnumerable<IReleaseInfo> releases)
111111
section.Blocks.Add(new Paragraph
112112
{
113113
Inlines =
114-
{
115-
new Run($"{release.Name}{Environment.NewLine}Released:") { FontWeight = FontWeights.SemiBold },
116-
new Run($" {GetDescriptiveText(DateTime.UtcNow - release.PublishedAt)} ago."),
117-
}
114+
{
115+
new Run($"{release.Name}{Environment.NewLine}Released:") { FontWeight = FontWeights.SemiBold },
116+
new Run($" {GetDescriptiveText(DateTime.UtcNow - release.PublishedAt)} ago."),
117+
}
118118
});
119119
section.Blocks.AddRange(engine.Transform(release.Body).Blocks.ToList());
120120
document.Blocks.Add(section);

0 commit comments

Comments
 (0)