refactor(installer): use shared VersionComparer in InstallModeDetector
This commit is contained in:
@@ -33,7 +33,9 @@ public sealed class InstallModeDetector
|
||||
return new DetectedState(InstallerMode.Config, manifest, null, null);
|
||||
|
||||
var latestVersion = release.TagName.TrimStart('v', 'V');
|
||||
var newer = IsNewer(latestVersion, manifest.Version, out var unparseable);
|
||||
var cmp = VersionComparer.Compare(latestVersion, manifest.Version);
|
||||
var newer = cmp.IsNewer;
|
||||
var unparseable = cmp.Unparseable;
|
||||
if (newer)
|
||||
return new DetectedState(InstallerMode.Update, manifest, release, latestVersion);
|
||||
|
||||
@@ -43,16 +45,4 @@ public sealed class InstallModeDetector
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true only when both versions parse as System.Version (major.minor[.build[.revision]])
|
||||
/// AND latest > current. Semver pre-release tags like "0.2.0-beta" fail to parse and are
|
||||
/// treated as "not newer" — the user drops into Config mode with no update offered, but
|
||||
/// <paramref name="unparseable"/> is set so the UI can surface a hint.
|
||||
/// </summary>
|
||||
private static bool IsNewer(string latest, string current, out bool unparseable)
|
||||
{
|
||||
unparseable = !Version.TryParse(latest, out var lv) | !Version.TryParse(current, out var cv);
|
||||
if (unparseable) return false;
|
||||
return lv > cv;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user