|
|
@ -1,6 +1,7 @@ |
|
|
|
using System; |
|
|
|
using System; |
|
|
|
using System.Diagnostics; |
|
|
|
using System.Diagnostics; |
|
|
|
using System.IO; |
|
|
|
using System.IO; |
|
|
|
|
|
|
|
using System.Linq; |
|
|
|
using System.Net.Http; |
|
|
|
using System.Net.Http; |
|
|
|
using System.Text.RegularExpressions; |
|
|
|
using System.Text.RegularExpressions; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using System.Threading.Tasks; |
|
|
@ -53,6 +54,11 @@ public partial class UpdateViewModel : ContentDialogViewModelBase |
|
|
|
[ObservableProperty] |
|
|
|
[ObservableProperty] |
|
|
|
private string? newVersionText; |
|
|
|
private string? newVersionText; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[GeneratedRegex( |
|
|
|
|
|
|
|
@"(##\s*(v[0-9]+\.[0-9]+\.[0-9]+)((?:\n|.)+?))(?=(##\s*v[0-9]+\.[0-9]+\.[0-9]+)|\z)" |
|
|
|
|
|
|
|
)] |
|
|
|
|
|
|
|
private static partial Regex RegexChangelog(); |
|
|
|
|
|
|
|
|
|
|
|
public UpdateViewModel( |
|
|
|
public UpdateViewModel( |
|
|
|
ISettingsManager settingsManager, |
|
|
|
ISettingsManager settingsManager, |
|
|
|
IHttpClientFactory httpClientFactory, |
|
|
|
IHttpClientFactory httpClientFactory, |
|
|
@ -76,11 +82,39 @@ public partial class UpdateViewModel : ContentDialogViewModelBase |
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
|
internal static string? FormatChangelog(string markdown, SemVersion currentVersion) |
|
|
|
internal static string? FormatChangelog(string markdown, SemVersion currentVersion) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var pattern = $@"(##[\s\S]+?)(?:## v{currentVersion.WithoutPrereleaseOrMetadata()})"; |
|
|
|
var pattern = RegexChangelog(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var results = pattern |
|
|
|
|
|
|
|
.Matches(markdown) |
|
|
|
|
|
|
|
.Select( |
|
|
|
|
|
|
|
m => |
|
|
|
|
|
|
|
new |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Block = m.Groups[1].Value.Trim(), |
|
|
|
|
|
|
|
Version = m.Groups[2].Value.Trim(), |
|
|
|
|
|
|
|
Content = m.Groups[3].Value.Trim() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
.ToList(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Join all blocks until and excluding the current version |
|
|
|
|
|
|
|
// If we're on a pre-release, include the current release |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var currentVersionBlock = results.FindIndex( |
|
|
|
|
|
|
|
x => x.Version == $"v{currentVersion.WithoutPrereleaseOrMetadata()}" |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (currentVersionBlock == -1) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var match = Regex.Match(markdown, pattern); |
|
|
|
var blocks = results |
|
|
|
|
|
|
|
.Take(currentVersionBlock + (currentVersion.IsPrerelease ? 1 : 0)) |
|
|
|
|
|
|
|
.Select(x => x.Block) |
|
|
|
|
|
|
|
.ToList(); |
|
|
|
|
|
|
|
|
|
|
|
return match.Success ? match.Groups[1].Value.TrimEnd() : null; |
|
|
|
return string.Join(Environment.NewLine + Environment.NewLine, blocks); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public async Task Preload() |
|
|
|
public async Task Preload() |
|
|
@ -99,7 +133,7 @@ public partial class UpdateViewModel : ContentDialogViewModelBase |
|
|
|
if (UpdateInfo.ChangelogUrl.EndsWith(".md", StringComparison.OrdinalIgnoreCase)) |
|
|
|
if (UpdateInfo.ChangelogUrl.EndsWith(".md", StringComparison.OrdinalIgnoreCase)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
ReleaseNotes = |
|
|
|
ReleaseNotes = |
|
|
|
FormatChangelog(changelog, UpdateInfo.Version) |
|
|
|
FormatChangelog(changelog, Compat.AppVersion) |
|
|
|
?? "## Unable to format release notes"; |
|
|
|
?? "## Unable to format release notes"; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|