コード例 #1
0
        public void IntersectWithWorksCorrectly(GameVersionRange left, GameVersionRange right, GameVersionRange expected)
        {
            // Act
            var result = left.IntersectWith(right);

            // Assert
            Assert.That(result, Is.EqualTo(expected));
        }
コード例 #2
0
        public void ToStringWorksCorrectly(GameVersionRange vr, string expected)
        {
            // Act
            var result = vr.ToString();

            // Assert
            Assert.That(result, Is.EqualTo(expected));
        }
コード例 #3
0
        public void IsSupersetOfWorksCorrectly(GameVersionRange left, GameVersionRange right, bool expected)
        {
            // Act
            var result = left.IsSupersetOf(right);

            // Assert
            Assert.That(result, Is.EqualTo(expected));
        }
コード例 #4
0
ファイル: KspVersionTests.cs プロジェクト: zxasqwsss/CKAN
        public void ToVersionRangeWorksCorrectly(GameVersion version, GameVersionRange expectedRange)
        {
            // Act
            var result = version.ToVersionRange();

            // Assert
            Assert.AreEqual(expectedRange, result);
        }
コード例 #5
0
        public void IsSupersetOfThrowsOnNullParameter()
        {
            // Arrange
            var sut = new GameVersionRange(new GameVersionBound(), new GameVersionBound());

            // Act
            TestDelegate act = () => sut.IsSupersetOf(null);

            // Assert
            Assert.That(act, Throws.Exception);
        }
コード例 #6
0
        public void VersionSpan_MaxOnly_CorrectString()
        {
            // Arrange
            IGame       game = new KerbalSpaceProgram();
            GameVersion min  = GameVersion.Any;
            GameVersion max  = new GameVersion(1, 0, 0);
            // Act
            string s = GameVersionRange.VersionSpan(game, min, max);

            // Assert
            Assert.AreEqual("KSP 1.0.0 and earlier", s);
        }
コード例 #7
0
        public void VersionSpan_AllVersions_CorrectString()
        {
            // Arrange
            IGame       game = new KerbalSpaceProgram();
            GameVersion min  = GameVersion.Any;
            GameVersion max  = GameVersion.Any;
            // Act
            string s = GameVersionRange.VersionSpan(game, min, max);

            // Assert
            Assert.AreEqual("KSP all versions", s);
        }
コード例 #8
0
ファイル: IRegistryQuerier.cs プロジェクト: mioackerman/CKAN
        /// <summary>
        /// Generate a string describing the range of game versions
        /// compatible with the given module.
        /// </summary>
        /// <param name="identifier">Mod name to findDependencyShallow</param>
        /// <returns>
        /// String describing range of compatible game versions.
        /// </returns>
        public static string CompatibleGameVersions(this IRegistryQuerier querier, IGame game, CkanModule module)
        {
            ModuleVersion minMod = null, maxMod = null;
            GameVersion   minKsp = null, maxKsp = null;

            Registry.GetMinMaxVersions(
                new CkanModule[] { module },
                out minMod, out maxMod,
                out minKsp, out maxKsp
                );
            return(GameVersionRange.VersionSpan(game, minKsp, maxKsp));
        }
コード例 #9
0
        public void VersionSpan_FiniteRange_CorrectString()
        {
            // Arrange
            IGame       game = new KerbalSpaceProgram();
            GameVersion min  = new GameVersion(1, 0, 0);
            GameVersion max  = new GameVersion(1, 1, 1);
            // Act
            string s = GameVersionRange.VersionSpan(game, min, max);

            // Assert
            Assert.AreEqual("KSP 1.0.0–1.1.1", s);
        }
コード例 #10
0
ファイル: IRegistryQuerier.cs プロジェクト: mioackerman/CKAN
        /// <summary>
        /// Generate a string describing the range of game versions
        /// compatible with the given module.
        /// </summary>
        /// <param name="identifier">Mod name to findDependencyShallow</param>
        /// <returns>
        /// String describing range of compatible game versions.
        /// </returns>
        public static string CompatibleGameVersions(this IRegistryQuerier querier, IGame game, string identifier)
        {
            List <CkanModule> releases = querier.AvailableByIdentifier(identifier).ToList();

            if (releases != null && releases.Count > 0)
            {
                ModuleVersion minMod = null, maxMod = null;
                GameVersion   minKsp = null, maxKsp = null;
                Registry.GetMinMaxVersions(releases, out minMod, out maxMod, out minKsp, out maxKsp);
                return(GameVersionRange.VersionSpan(game, minKsp, maxKsp));
            }
            return("");
        }
コード例 #11
0
        public void CtorWorksCorrectly()
        {
            // Arrange
            var lower = new GameVersionBound(new GameVersion(1, 2, 3, 4), false);
            var upper = new GameVersionBound(new GameVersion(5, 6, 7, 8), true);

            // Act
            var result = new GameVersionRange(lower, upper);

            // Assert
            Assert.That(result.Lower, Is.EqualTo(lower));
            Assert.That(result.Upper, Is.EqualTo(upper));
        }
コード例 #12
0
        public void ReferenceEqualityWorksCorrectly()
        {
            // Arrange
            var sut = new GameVersionRange(new GameVersionBound(), new GameVersionBound());

            // Act
            var genericEquals    = sut.Equals(sut);
            var nonGenericEquals = sut.Equals((object)sut);

            // Assert
            Assert.IsTrue(genericEquals);
            Assert.IsTrue(nonGenericEquals);
        }
コード例 #13
0
 public string[] AdjustCommandLine(string[] args, GameVersion installedVersion)
 {
     // -single-instance crashes KSP 1.8 to KSP 1.11 on Linux
     // https://issuetracker.unity3d.com/issues/linux-segmentation-fault-when-running-a-built-project-with-single-instance-argument
     if (Platform.IsUnix)
     {
         var brokenVersionRange = new GameVersionRange(
             new GameVersion(1, 8),
             new GameVersion(1, 11)
             );
         args = filterCmdLineArgs(args, installedVersion, brokenVersionRange, "-single-instance");
     }
     return(args);
 }
コード例 #14
0
        public void RangeFromVersionsEqualsRangeFromBounds()
        {
            // Arrange
            var lowerBound   = new GameVersionBound(new GameVersion(1, 2, 0, 0), true);
            var upperBound   = new GameVersionBound(new GameVersion(2, 4, 7, 0), false);
            var lowerVersion = new GameVersion(1, 2);
            var upperVersion = new GameVersion(2, 4, 6);

            // Act
            var resultFromBounds   = new GameVersionRange(lowerBound, upperBound);
            var resultFromVersions = new GameVersionRange(lowerVersion, upperVersion);

            // Assert
            Assert.That(resultFromBounds.Lower, Is.EqualTo(resultFromVersions.Lower));
            Assert.That(resultFromBounds.Upper, Is.EqualTo(resultFromVersions.Upper));
        }
コード例 #15
0
        public void EqualityWorksCorrectly(GameVersionRange vr1, GameVersionRange vr2, bool areEqual)
        {
            // Act
            var genericEquals            = vr1.Equals(vr2);
            var nonGenericEquals         = vr1.Equals((object)vr2);
            var equalsOperator           = vr1 == vr2;
            var notEqualsOperator        = vr1 != vr2;
            var reverseEqualsOperator    = vr2 == vr1;
            var reverseNotEqualsOperator = vr2 != vr1;

            // Assert
            Assert.AreEqual(areEqual, genericEquals);
            Assert.AreEqual(areEqual, nonGenericEquals);
            Assert.AreEqual(areEqual, equalsOperator);
            Assert.AreNotEqual(areEqual, notEqualsOperator);
            Assert.AreEqual(areEqual, reverseEqualsOperator);
            Assert.AreNotEqual(areEqual, reverseNotEqualsOperator);
        }
コード例 #16
0
        public override bool SingleVersionsCompatible(GameVersion gameVersion, CkanModule module)
        {
            var gameVersionRange = gameVersion.ToVersionRange();

            var moduleRange = GameVersionRange.Any;

            if (module.ksp_version != null)
            {
                moduleRange = module.ksp_version.ToVersionRange();
            }
            else if (module.ksp_version_min != null || module.ksp_version_max != null)
            {
                if (module.ksp_version_min != null && module.ksp_version_max != null)
                {
                    moduleRange = new GameVersionRange(module.ksp_version_min, module.ksp_version_max);
                    if (moduleRange.Lower.Value > moduleRange.Upper.Value)
                    {
                        log.WarnFormat("{0} is not less or equal to {1}",
                                       module.ksp_version_min, module.ksp_version_max);
                        return(false);
                    }
                }
                else if (module.ksp_version_min != null)
                {
                    moduleRange = new GameVersionRange(module.ksp_version_min, GameVersion.Any);
                }
                else if (module.ksp_version_max != null)
                {
                    moduleRange = new GameVersionRange(GameVersion.Any, module.ksp_version_max);
                }
            }
            else
            {
                return(true);
            }

            return(gameVersionRange.IntersectWith(moduleRange) != null);
        }
コード例 #17
0
        private void ShowVersionTable(CKAN.GameInstance inst, List <CkanModule> modules)
        {
            var versions     = modules.Select(m => m.version.ToString()).ToList();
            var gameVersions = modules.Select(m =>
            {
                GameVersion minKsp = null, maxKsp = null;
                Registry.GetMinMaxVersions(new List <CkanModule>()
                {
                    m
                }, out _, out _, out minKsp, out maxKsp);
                return(GameVersionRange.VersionSpan(inst.game, minKsp, maxKsp));
            }).ToList();

            string[] headers           = new string[] { "Version", "Game Versions" };
            int      versionLength     = Math.Max(headers[0].Length, versions.Max(v => v.Length));
            int      gameVersionLength = Math.Max(headers[1].Length, gameVersions.Max(v => v.Length));

            user.RaiseMessage("");
            user.RaiseMessage(
                "{0}  {1}",
                headers[0].PadRight(versionLength),
                headers[1].PadRight(gameVersionLength)
                );
            user.RaiseMessage(
                "{0}  {1}",
                new string('-', versionLength),
                new string('-', gameVersionLength)
                );
            for (int row = 0; row < versions.Count; ++row)
            {
                user.RaiseMessage(
                    "{0}  {1}",
                    versions[row].PadRight(versionLength),
                    gameVersions[row].PadRight(gameVersionLength)
                    );
            }
        }
コード例 #18
0
        private void addVersionBox(int l, int t, int r, int b, Func <string> title, Func <ConsoleTheme, ConsoleColor> color, bool doubleLine, List <CkanModule> releases)
        {
            AddObject(new ConsoleFrame(
                          l, t, r, b,
                          title,
                          color,
                          doubleLine
                          ));

            if (releases != null && releases.Count > 0)
            {
                ModuleVersion minMod = null, maxMod = null;
                GameVersion   minKsp = null, maxKsp = null;
                Registry.GetMinMaxVersions(releases, out minMod, out maxMod, out minKsp, out maxKsp);
                AddObject(new ConsoleLabel(
                              l + 2, t + 1, r - 2,
                              () => minMod == maxMod
                        ? $"{ModuleInstaller.WithAndWithoutEpoch(minMod?.ToString() ?? "???")}"
                        : $"{ModuleInstaller.WithAndWithoutEpoch(minMod?.ToString() ?? "???")} - {ModuleInstaller.WithAndWithoutEpoch(maxMod?.ToString() ?? "???")}",
                              null,
                              color
                              ));
                AddObject(new ConsoleLabel(
                              l + 2, t + 2, r - 2,
                              () => "Compatible with:",
                              null,
                              th => th.DimLabelFg
                              ));
                AddObject(new ConsoleLabel(
                              l + 4, t + 3, r - 2,
                              () => GameVersionRange.VersionSpan(manager.CurrentInstance.game, minKsp, maxKsp),
                              null,
                              color
                              ));
            }
        }
コード例 #19
0
        public void NullEqualityWorksCorrectly()
        {
            // Arrange
            var sut = new GameVersionRange(new GameVersionBound(), new GameVersionBound());

            // Act
            // ReSharper disable ConditionIsAlwaysTrueOrFalse
            var genericEquals              = sut.Equals(null);
            var nonGenericEquals           = sut.Equals((object)null);
            var equalsOperatorNullLeft     = null == sut;
            var equalsOperatorNullRight    = sut == null;
            var notEqualsOperatorNullLeft  = null != sut;
            var notEqualsOperatorNullRight = sut != null;

            // ReSharper restore ConditionIsAlwaysTrueOrFalse

            // ASsert
            Assert.IsFalse(genericEquals);
            Assert.IsFalse(nonGenericEquals);
            Assert.IsFalse(equalsOperatorNullLeft);
            Assert.IsFalse(equalsOperatorNullRight);
            Assert.IsTrue(notEqualsOperatorNullLeft);
            Assert.IsTrue(notEqualsOperatorNullRight);
        }
コード例 #20
0
        public void Validate(Metadata metadata)
        {
            var mod = CkanModule.FromJson(metadata.Json().ToString());

            if (!mod.IsCompatibleKSP(new GameVersionCriteria(null, knownVersions)))
            {
                GameVersion minKsp = null, maxKsp = null;
                Registry.GetMinMaxVersions(new List <CkanModule>()
                {
                    mod
                }, out _, out _, out minKsp, out maxKsp);
                var game = new KerbalSpaceProgram();
                throw new Kraken($"{metadata.Identifier} doesn't match any valid game version: {GameVersionRange.VersionSpan(game, minKsp, maxKsp)}");
            }
        }
コード例 #21
0
        /// <summary>
        /// If the installed game version is in the given range,
        /// return the given array without the given parameter,
        /// otherwise return the array as-is.
        /// </summary>
        /// <param name="args">Command line parameters to check</param>
        /// <param name="crashyKspRange">Game versions that should not use this parameter</param>
        /// <param name="parameter">The parameter to remove on version match</param>
        /// <returns>
        /// args or args minus parameter
        /// </returns>
        private string[] filterCmdLineArgs(string[] args, GameVersion installedVersion, GameVersionRange crashyKspRange, string parameter)
        {
            var installedRange = installedVersion.ToVersionRange();

            if (crashyKspRange.IntersectWith(installedRange) != null &&
                args.Contains(parameter))
            {
                log.DebugFormat(
                    "Parameter {0} found on incompatible KSP version {1}, pruning",
                    parameter,
                    installedVersion.ToString());
                return(args.Where(s => s != parameter).ToArray());
            }
            return(args);
        }
コード例 #22
0
        private bool VersionsNeedManualReview(Metadata metadata, out string reason)
        {
            JObject json   = metadata.Json();
            var     minStr = json["ksp_version_min"] ?? json["ksp_version"];
            var     maxStr = json["ksp_version_max"] ?? json["ksp_version"];
            var     minVer = minStr == null ? GameVersion.Any : GameVersion.Parse((string)minStr);
            var     maxVer = maxStr == null ? GameVersion.Any : GameVersion.Parse((string)maxStr);

            if (currentRelease.IntersectWith(new GameVersionRange(minVer, maxVer)) == null)
            {
                var game = new KerbalSpaceProgram();
                reason = $"Hard-coded game versions not compatible with current release: {GameVersionRange.VersionSpan(game, minVer, maxVer)}\r\nPlease check that they match the forum thread.";
                return(true);
            }
            else
            {
                // Compatible with latest release, no manual review needed
                reason = "";
                return(false);
            }
        }