Skip to content

Commit 5c0083d

Browse files
authored
Boom (#130)
* update * Hard code tag for 2x * Move adornerdecorator * Stop using tags * add check
1 parent 5aad87e commit 5c0083d

File tree

6 files changed

+39
-67
lines changed

6 files changed

+39
-67
lines changed

KoAR.SaveEditor/Themes/Generic.BuffIcon.xaml

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,30 @@
1010
<Setter Property="Focusable" Value="False" />
1111
<Setter Property="Width" Value="18" />
1212
<Setter Property="Height" Value="18" />
13-
<Setter Property="views:FateswornAdorner.RequiresFatesworn" Value="{Binding Buff.RequiresFatesworn, RelativeSource={RelativeSource Self}}" />
1413
<Setter Property="Template">
1514
<Setter.Value>
1615
<ControlTemplate TargetType="{x:Type views:BuffIcon}">
17-
<views:BuffDescriptionIcon Width="{TemplateBinding Width}" Height="{TemplateBinding Height}">
18-
<views:BuffDescriptionIcon.Style>
19-
<Style TargetType="{x:Type views:BuffDescriptionIcon}">
20-
<Style.Triggers>
21-
<DataTrigger Binding="{Binding Buff, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource EqualityConverter}}" Value="False">
22-
<Setter Property="Description" Value="{x:Static core:BuffDescription.Empty}" />
23-
</DataTrigger>
24-
<MultiDataTrigger>
25-
<MultiDataTrigger.Conditions>
26-
<Condition Binding="{Binding Buff, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource EqualityConverter}}" Value="False" />
27-
<Condition Binding="{Binding Buff.Descriptions.Length, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource EqualityConverter}, ConverterParameter={StaticResource Zero}}" Value="False" />
28-
</MultiDataTrigger.Conditions>
29-
<Setter Property="Description" Value="{Binding Buff.Descriptions/, RelativeSource={RelativeSource TemplatedParent}}" />
30-
</MultiDataTrigger>
31-
</Style.Triggers>
32-
</Style>
33-
</views:BuffDescriptionIcon.Style>
34-
</views:BuffDescriptionIcon>
16+
<AdornerDecorator>
17+
<views:BuffDescriptionIcon Width="{TemplateBinding Width}" Height="{TemplateBinding Height}"
18+
views:FateswornAdorner.RequiresFatesworn="{Binding Buff.RequiresFatesworn, RelativeSource={RelativeSource TemplatedParent}}">
19+
<views:BuffDescriptionIcon.Style>
20+
<Style TargetType="{x:Type views:BuffDescriptionIcon}">
21+
<Style.Triggers>
22+
<DataTrigger Binding="{Binding Buff, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource EqualityConverter}}" Value="False">
23+
<Setter Property="Description" Value="{x:Static core:BuffDescription.Empty}" />
24+
</DataTrigger>
25+
<MultiDataTrigger>
26+
<MultiDataTrigger.Conditions>
27+
<Condition Binding="{Binding Buff, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource EqualityConverter}}" Value="False" />
28+
<Condition Binding="{Binding Buff.Descriptions.Length, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource EqualityConverter}, ConverterParameter={StaticResource Zero}}" Value="False" />
29+
</MultiDataTrigger.Conditions>
30+
<Setter Property="Description" Value="{Binding Buff.Descriptions/, RelativeSource={RelativeSource TemplatedParent}}" />
31+
</MultiDataTrigger>
32+
</Style.Triggers>
33+
</Style>
34+
</views:BuffDescriptionIcon.Style>
35+
</views:BuffDescriptionIcon>
36+
</AdornerDecorator>
3537
</ControlTemplate>
3638
</Setter.Value>
3739
</Setter>

KoAR.SaveEditor/Themes/Generic.ItemCollectionManager.xaml

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -493,12 +493,8 @@
493493
</Style>
494494
</DataTemplate.Resources>
495495
<StackPanel Orientation="Horizontal">
496-
<AdornerDecorator>
497-
<views:BuffIcon Margin="1,0" Buff="{Binding Prefix}" />
498-
</AdornerDecorator>
499-
<AdornerDecorator>
500-
<views:BuffIcon Margin="1,0" Buff="{Binding Suffix}" />
501-
</AdornerDecorator>
496+
<views:BuffIcon Margin="1,0" Buff="{Binding Prefix}" />
497+
<views:BuffIcon Margin="1,0" Buff="{Binding Suffix}" />
502498
</StackPanel>
503499
</DataTemplate>
504500
</GridViewColumn.CellTemplate>
@@ -519,9 +515,7 @@
519515
<Setter Property="ContentTemplate" Value="{StaticResource BuffToolTipTemplate}" />
520516
</Style>
521517
</DataTemplate.Resources>
522-
<AdornerDecorator>
523-
<views:BuffIcon Buff="{Binding}" Margin="1,0" ToolTip="{Binding}" />
524-
</AdornerDecorator>
518+
<views:BuffIcon Buff="{Binding}" Margin="1,0" ToolTip="{Binding}" />
525519
</DataTemplate>
526520
</ItemsControl.ItemTemplate>
527521
</ItemsControl>
@@ -544,9 +538,7 @@
544538
<Setter Property="ContentTemplate" Value="{StaticResource BuffToolTipTemplate}" />
545539
</Style>
546540
</DataTemplate.Resources>
547-
<AdornerDecorator>
548-
<views:BuffIcon Buff="{Binding}" Margin="1,0" ToolTip="{Binding}" />
549-
</AdornerDecorator>
541+
<views:BuffIcon Buff="{Binding}" Margin="1,0" ToolTip="{Binding}" />
550542
</DataTemplate>
551543
</ItemsControl.ItemTemplate>
552544
</ItemsControl>

KoAR.SaveEditor/Themes/Generic.SocketIcon.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
<Setter.Value>
5959
<ControlTemplate TargetType="{x:Type views:SocketIcon}">
6060
<Image Height="{TemplateBinding Height}" Width="{TemplateBinding Width}"
61-
Source="{Binding IconName, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource BitmapConverter}}">
61+
Source="{Binding IconName, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource BitmapConverter}}">
6262
<Image.ToolTip>
6363
<ToolTip Content="{TemplateBinding Socket}" ContentTemplate="{StaticResource SocketContentTemplate}" />
6464
</Image.ToolTip>

KoAR.SaveEditor/Updates/UpdateMethods.cs

Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace KoAR.SaveEditor.Updates;
1717

1818
public static class UpdateMethods
1919
{
20-
private static readonly HttpClient _client = InitializeClient();
20+
private static readonly HttpClient _client = UpdateMethods.InitializeClient();
2121
private static readonly JsonSerializerOptions _jsonOptions = new() { PropertyNamingPolicy = JsonSnakeCaseNamingPolicy.Instance };
2222

2323
/// <summary>
@@ -44,21 +44,12 @@ 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?> FetchLatestVersionedReleaseAsync(int majorVersion, CancellationToken cancellationToken = default)
47+
public static async Task<IReleaseInfo?> FetchLatest2xReleaseAsync(CancellationToken cancellationToken = default)
4848
{
4949
try
5050
{
51-
foreach (Tag tag in await UpdateMethods.FetchTagsAsync(cancellationToken).ConfigureAwait(false))
52-
{
53-
if (tag.Version.Major != majorVersion)
54-
{
55-
continue;
56-
}
57-
if (await UpdateMethods.FetchReleaseAsync(tag.Name, cancellationToken).ConfigureAwait(false) is { HasUpdateAsset: true } release)
58-
{
59-
return release;
60-
}
61-
}
51+
const string tagName = "v2.1.189";
52+
return await UpdateMethods.FetchReleaseAsync(tagName, cancellationToken).ConfigureAwait(false);
6253
}
6354
catch
6455
{
@@ -76,14 +67,9 @@ public static async void ExecuteUpdate(string zipFilePath)
7667
{
7768
try
7869
{
79-
string[] tagNames = (await UpdateMethods.FetchTagsAsync(cancellationToken).ConfigureAwait(false))
80-
.Where(tag => tag.Version.Major == App.Version.Major && tag.Version > App.Version)
70+
Release[] array = (await UpdateMethods.FetchReleasesAsync(cancellationToken).ConfigureAwait(false))
71+
.Where(release => release.Version.Major == App.Version.Major && release.Version > App.Version && release.HasUpdateAsset)
8172
.Take(maxReleases)
82-
.Select(tag => tag.Name)
83-
.ToArray();
84-
Release[] array = (await Task.WhenAll(Array.ConvertAll(tagNames, tag => UpdateMethods.FetchReleaseAsync(tag, cancellationToken))).ConfigureAwait(false))
85-
.OfType<Release>()
86-
.Where(release => release.HasUpdateAsset)
8773
.ToArray();
8874
if (array.Length != 0)
8975
{
@@ -125,7 +111,7 @@ private static async Task<string> ExtractPowershellScript()
125111
/// <returns>A model representing the GitHub release. Returns <see langword="null"/> if the release was deleted or an error occurs.</returns>
126112
private static Task<Release?> FetchReleaseAsync(string tag, CancellationToken cancellationToken) => UpdateMethods.FetchDataAsync<Release>($"releases/tags/{tag}", cancellationToken);
127113

128-
private static async Task<Tag[]> FetchTagsAsync(CancellationToken cancellationToken) => (await UpdateMethods.FetchDataAsync<Tag[]>("tags", cancellationToken).ConfigureAwait(false))!;
114+
private static Task<Release[]> FetchReleasesAsync(CancellationToken cancellationToken) => UpdateMethods.FetchDataAsync<Release[]>("releases", cancellationToken)!;
129115

130116
private static Stream GetResourceFileStream(string name) => Application.GetResourceStream(new($"/Updates/{name}", UriKind.Relative)).Stream;
131117

@@ -144,6 +130,8 @@ private static HttpClient InitializeClient()
144130

145131
private sealed class Release : IReleaseInfo
146132
{
133+
private static readonly Regex _regex = new(@"^v(?<version>\d+\.\d+\.\d+)$", RegexOptions.ExplicitCapture | RegexOptions.Compiled);
134+
147135
private Version? _version;
148136
private ReleaseAsset? _zipFileAsset;
149137

@@ -159,7 +147,7 @@ private sealed class Release : IReleaseInfo
159147

160148
public string TagName { get; set; } = string.Empty;
161149

162-
public Version Version => this._version ??= new(this.TagName.Length != 0 ? this.TagName[1..] : "0.0.0");
150+
public Version Version => this._version ??= new(this.TagName.Length != 0 && Release._regex.IsMatch(this.TagName) ? this.TagName[1..] : "0.0.0");
163151

164152
public ReleaseAsset? ZipFileAsset => this._zipFileAsset ??= this.Assets.FirstOrDefault(asset => asset.ContentType == "application/zip");
165153

@@ -176,15 +164,4 @@ private sealed class ReleaseAsset
176164

177165
public int Size { get; set; }
178166
}
179-
180-
private sealed class Tag
181-
{
182-
private static readonly Regex _regex = new(@"^v(?<version>\d+\.\d+\.\d+)$", RegexOptions.ExplicitCapture | RegexOptions.Compiled);
183-
184-
private Version? _version;
185-
186-
public string Name { get; set; } = string.Empty;
187-
188-
public Version Version => this._version ??= new(Tag._regex.IsMatch(this.Name) ? this.Name[1..] : "0.0.0");
189-
}
190167
}

KoAR.SaveEditor/Views/IndicatorAdornerBase.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,13 @@ public static void DetachAdorner(FrameworkElement element)
124124
if (adorner != null)
125125
{
126126
(element.FindVisualTreeAncestor<AdornerLayer>() ?? AdornerLayer.GetAdornerLayer(element)).Remove(adorner);
127+
element.ClearValue(AdornerAttacher<TAdorner>._adornerProperty);
127128
}
128129
else
129130
{
130131
element.Loaded -= AdornerAttacher<TAdorner>.Element_Loaded;
132+
element.ClearValue(AdornerAttacher<TAdorner>._factoryProperty);
131133
}
132-
element.ClearValue(AdornerAttacher<TAdorner>._adornerProperty);
133134
}
134135

135136
private static Func<FrameworkElement, TAdorner> CreateFactory()

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.FetchLatestVersionedReleaseAsync(2, source.Token)) != null)
70+
if ((release = await UpdateMethods.FetchLatest2xReleaseAsync(source.Token)) != null)
7171
{
7272
using OriginalUpdateViewModel viewModel = new(release);
7373
UpdateWindow window = new() { DataContext = viewModel, Owner = this };

0 commit comments

Comments
 (0)