Skip to content

Commit

Permalink
nicer version compare
Browse files Browse the repository at this point in the history
  • Loading branch information
stakira committed May 21, 2023
1 parent 08615de commit 11fa8cc
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions OpenUtau/ViewModels/UpdaterViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public async void OnUpdate() {
item = item ?? downloadedItem;
if (item == null) {
Log.Error("DownloadFinished unexpected null item.");
} else {
} else {
sparkle.InstallUpdate(downloadedItem, path);
}
};
Expand Down Expand Up @@ -183,12 +183,20 @@ public void OnClosing() {

// Force allow downgrading so that switching between beta and stable works.
public class DowngradableFilter : IAppCastFilter {
static bool Eq(int a, int b) {
a = a == -1 ? 0 : a;
b = b == -1 ? 0 : b;
return a == b;
}
// Ambiguous version equal where 1.2 == 1.2.0 == 1.2.0.0.
static bool Eq(Version a, Version b) {
return Eq(a.Major, b.Major)
&& Eq(a.Minor, b.Minor)
&& Eq(a.Build, b.Build)
&& Eq(a.Revision, b.Revision);
}
public FilterResult GetFilteredAppCastItems(Version installed, List<AppCastItem> items) {
items = items.Where(item => {
var v = new Version(item.Version);
// Only check first three numbers.
return v.Major != installed.Major || v.Minor != installed.Minor || v.Build != installed.Build;
}).ToList();
items = items.Where(item => !Eq(new Version(item.Version), installed)).ToList();
return new FilterResult(/*forceInstallOfLatestInFilteredList=*/true, items);
}
}
Expand Down

0 comments on commit 11fa8cc

Please sign in to comment.