public void VersionWithinBounds_MinMax_vs_AutoDetectedMod(string min, string max)
        {
            string modName       = "someModName";
            var    modDependency = new ModDependency($"{modName}>={min}<={max}");
            var    autodetected  = new AutodetectedVersion("0.0.1");

            Assert.False(modDependency.isSatisfiedBy(modName, autodetected));
        }
        public void VersionWithinBounds_vs_AutoDetectedMod(string version)
        {
            string modName       = "someModName";
            var    modDependency = new ModDependency($"{modName}>=5.6.0");
            var    autodetected  = new AutodetectedVersion("1.0");

            Assert.False(modDependency.isSatisfiedBy(modName, autodetected));
        }
        public void VersionWithinBounds_MinMax(string min, string max, string compareTo, bool expected)
        {
            string modName       = "someModName";
            var    modDependency = new ModDependency($"{modName}>={min}<={max}");
            var    version       = new ModVersion(compareTo);

            Assert.AreEqual(expected, modDependency.isSatisfiedBy(modName, version));
        }
Exemple #4
0
        /// <summary>
        /// Return the most recent release of a module with a optional ksp version to target and a RelationshipDescriptor to satisfy.
        /// </summary>
        /// <param name="ksp_version">If not null only consider mods which match this ksp version.</param>
        /// <param name="relationship">If not null only consider mods which satisfy the RelationshipDescriptor.</param>
        /// <returns></returns>
        public CfanModule Latest(FactorioVersion ksp_version = null, ModDependency relationship = null, bool hasFactorioAuth = false)
        {
            IDictionary <ModVersion, CfanJson> module_version = this.module_version;

            if (!hasFactorioAuth)
            {
                module_version = module_version.Where(p => !CfanJson.requiresFactorioComAuthorization(p.Value)).ToDictionary(p => p.Key, p => p.Value);
            }

            var      available_versions = new List <ModVersion>(module_version.Keys);
            CfanJson module;

            log.DebugFormat("Our dictionary has {0} keys", module_version.Keys.Count);
            log.DebugFormat("Choosing between {0} available versions", available_versions.Count);

            // Uh oh, nothing available. Maybe this existed once, but not any longer.
            if (available_versions.Count == 0)
            {
                return(null);
            }

            // No restrictions? Great, we can just pick the first one!
            if (ksp_version == null && relationship == null)
            {
                module = module_version[available_versions.First()];

                log.DebugFormat("No KSP version restriction, {0} is most recent", module.modInfo.version);
                return(new CfanModule(module));
            }

            // If there's no relationship to satisfy, we can just pick the first that is
            // compatible with our version of KSP.
            if (relationship == null)
            {
                // Time to check if there's anything that we can satisfy.
                var version =
                    available_versions.FirstOrDefault(v => new CfanModule(module_version[v]).IsCompatibleKSP(ksp_version));
                if (version != null)
                {
                    return(new CfanModule(module_version[version]));
                }

                log.DebugFormat("No version of {0} is compatible with KSP {1}",
                                module_version[available_versions[0]].modInfo.name, ksp_version);

                return(null);
            }

            // If we're here, then we have a relationship to satisfy, so things get more complex.
            if (ksp_version == null)
            {
                var version = available_versions.FirstOrDefault(p => relationship.isSatisfiedBy(identifier, p));
                return(version == null ? null : new CfanModule(module_version[version]));
            }
            else
            {
                var version = available_versions.FirstOrDefault(v =>
                                                                relationship.isSatisfiedBy(identifier, v) &&
                                                                new CfanModule(module_version[v]).IsCompatibleKSP(ksp_version));
                return(version == null ? null : new CfanModule(module_version[version]));
            }
        }
Exemple #5
0
        public bool IsCompatibleKSP(FactorioVersion kspVersion)
        {
            ModDependency baseGame = BaseGameDependency;

            return(baseGame == null || baseGame.isSatisfiedBy("base", kspVersion));
        }
        public void VersionWithinBounds_ExactFalse(string modDependencyString, string modName, string versionName, bool expected)
        {
            var modDependency = new ModDependency(modDependencyString);

            Assert.AreEqual(expected, modDependency.isSatisfiedBy(modName, new ModVersion(versionName)));
        }