Skip to content

Commit 11fa8cc

Browse files
committed
nicer version compare
1 parent 08615de commit 11fa8cc

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

OpenUtau/ViewModels/UpdaterViewModel.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public async void OnUpdate() {
155155
item = item ?? downloadedItem;
156156
if (item == null) {
157157
Log.Error("DownloadFinished unexpected null item.");
158-
} else {
158+
} else {
159159
sparkle.InstallUpdate(downloadedItem, path);
160160
}
161161
};
@@ -183,12 +183,20 @@ public void OnClosing() {
183183

184184
// Force allow downgrading so that switching between beta and stable works.
185185
public class DowngradableFilter : IAppCastFilter {
186+
static bool Eq(int a, int b) {
187+
a = a == -1 ? 0 : a;
188+
b = b == -1 ? 0 : b;
189+
return a == b;
190+
}
191+
// Ambiguous version equal where 1.2 == 1.2.0 == 1.2.0.0.
192+
static bool Eq(Version a, Version b) {
193+
return Eq(a.Major, b.Major)
194+
&& Eq(a.Minor, b.Minor)
195+
&& Eq(a.Build, b.Build)
196+
&& Eq(a.Revision, b.Revision);
197+
}
186198
public FilterResult GetFilteredAppCastItems(Version installed, List<AppCastItem> items) {
187-
items = items.Where(item => {
188-
var v = new Version(item.Version);
189-
// Only check first three numbers.
190-
return v.Major != installed.Major || v.Minor != installed.Minor || v.Build != installed.Build;
191-
}).ToList();
199+
items = items.Where(item => !Eq(new Version(item.Version), installed)).ToList();
192200
return new FilterResult(/*forceInstallOfLatestInFilteredList=*/true, items);
193201
}
194202
}

0 commit comments

Comments
 (0)