|
10 | 10 | using BepInEx.Logging; |
11 | 11 | using KSP.Messages; |
12 | 12 | using KSP.Sim.DeltaV; |
| 13 | +using BepInEx.Bootstrap; |
| 14 | +using SpaceWarp.API.Mods; |
13 | 15 |
|
14 | 16 | namespace MicroMod |
15 | 17 | { |
@@ -257,6 +259,62 @@ internal static bool ToggleGameInputOnControlInFocus(bool gameInputState, bool s |
257 | 259 | return false; |
258 | 260 | } |
259 | 261 | } |
| 262 | + |
| 263 | + internal static (int major, int minor, int patch)? GetModVersion(string modId) |
| 264 | + { |
| 265 | + var plugin = Chainloader.Plugins?.OfType<BaseSpaceWarpPlugin>().ToList().FirstOrDefault(p => p.SpaceWarpMetadata.ModID.ToLowerInvariant() == modId.ToLowerInvariant()); |
| 266 | + string versionString = plugin?.SpaceWarpMetadata?.Version; |
| 267 | + |
| 268 | + string[] versionNumbers = versionString?.Split(new char[] { '.' }, 3); |
| 269 | + |
| 270 | + if (versionNumbers != null && versionNumbers.Length >= 1) |
| 271 | + { |
| 272 | + int majorVersion = 0; |
| 273 | + int minorVersion = 0; |
| 274 | + int patchVersion = 0; |
| 275 | + |
| 276 | + if (versionNumbers.Length >= 1) |
| 277 | + int.TryParse(versionNumbers[0], out majorVersion); |
| 278 | + if (versionNumbers.Length >= 2) |
| 279 | + int.TryParse(versionNumbers[1], out minorVersion); |
| 280 | + if (versionNumbers.Length == 3) |
| 281 | + int.TryParse(versionNumbers[2], out patchVersion); |
| 282 | + |
| 283 | + return (majorVersion, minorVersion, patchVersion); |
| 284 | + } |
| 285 | + else return null; |
| 286 | + } |
| 287 | + |
| 288 | + /// <summary> |
| 289 | + /// Check if installed mod is older than the specified version |
| 290 | + /// </summary> |
| 291 | + /// <param name="modId">SpaceWarp mod ID</param> |
| 292 | + /// <param name="major">Specified major version (X.0.0)</param> |
| 293 | + /// <param name="minor">Specified minor version (0.X.0)</param> |
| 294 | + /// <param name="patch">Specified patch version (0.0.X)</param> |
| 295 | + /// <returns>True = installed mod is older. False = installed mod has the same version or it's newer or version isn't declared or version declared is gibberish that cannot be parsed</returns> |
| 296 | + internal static bool IsModOlderThan (string modId, int major, int minor, int patch) |
| 297 | + { |
| 298 | + var modVersion = MicroUtility.GetModVersion(modId); |
| 299 | + |
| 300 | + if (!modVersion.HasValue || modVersion.Value == (0, 0, 0)) |
| 301 | + return false; |
| 302 | + |
| 303 | + if (modVersion.Value.Item1 < major) |
| 304 | + return true; |
| 305 | + else if (modVersion.Value.Item1 > major) |
| 306 | + return false; |
| 307 | + |
| 308 | + if (modVersion.Value.Item2 < minor) |
| 309 | + return true; |
| 310 | + else if (modVersion.Value.Item2 > minor) |
| 311 | + return false; |
| 312 | + |
| 313 | + if (modVersion.Value.Item3 < patch) |
| 314 | + return true; |
| 315 | + else |
| 316 | + return false; |
| 317 | + } |
260 | 318 | } |
261 | 319 |
|
262 | 320 | public static class AeroForces |
|
0 commit comments