From 34e63dd30e323d8943afe3d394a59fd2eb5ce235 Mon Sep 17 00:00:00 2001 From: Anairkoen Schno Date: Mon, 15 Jul 2019 21:10:59 -0500 Subject: [PATCH] Mod yeeter now only compares 'important' parts of version for equality --- IPA.Loader/Loader/PluginManager.cs | 2 +- IPA.Loader/Utilities/Utils.cs | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/IPA.Loader/Loader/PluginManager.cs b/IPA.Loader/Loader/PluginManager.cs index 8febf337..cad6dd88 100644 --- a/IPA.Loader/Loader/PluginManager.cs +++ b/IPA.Loader/Loader/PluginManager.cs @@ -296,7 +296,7 @@ namespace IPA.Loader var lastVerS = SelfConfig.SelfConfigRef.Value.LastGameVersion; var lastVer = lastVerS != null ? new SemVer.Version(lastVerS, true) : null; - if (lastVer != null && gameVer != lastVer) + if (lastVer != null && Utils.VersionCompareNoPrerelease(gameVer, lastVer) != 0) { var oldPluginsName = Path.Combine(BeatSaber.InstallPath, $"Old {lastVer} Plugins"); var newPluginsName = Path.Combine(BeatSaber.InstallPath, $"Old {gameVer} Plugins"); diff --git a/IPA.Loader/Utilities/Utils.cs b/IPA.Loader/Utilities/Utils.cs index a9147d86..6f71ecd1 100644 --- a/IPA.Loader/Utilities/Utils.cs +++ b/IPA.Loader/Utilities/Utils.cs @@ -166,5 +166,21 @@ namespace IPA.Utilities else return DateTime.MinValue.AddTicks((long)UnsafeAdvanceTicks++); // return MinValue as a fallback } } + + /// + /// Compares a pair of s ignoring both the prerelease and build fields. + /// + /// the left value + /// the right value + /// -1 if l is less than r, 0 if they are equal in the numeric portion, or 1 if l is greater than r + public static int VersionCompareNoPrerelease(SemVer.Version l, SemVer.Version r) + { + var cmpVal = l.Major - r.Major; + if (cmpVal != 0) return cmpVal; + cmpVal = l.Minor - r.Minor; + if (cmpVal != 0) return cmpVal; + cmpVal = l.Patch - r.Patch; + return cmpVal; + } } }