Esempio n. 1
0
        public void DifferentEpochs()
        {
            var v1 = new ModuleVersion("1:1");
            var v2 = new ModuleVersion("2:1");

            Assert.That(!v1.IsEqualTo(v2));
        }
Esempio n. 2
0
        public void AgExt()
        {
            var v1 = new ModuleVersion("1.20");
            var v2 = new ModuleVersion("1.22a");

            Assert.That(v2.IsGreaterThan(v1));
        }
Esempio n. 3
0
        public void Issue1076()
        {
            var v0 = new ModuleVersion("1.01");
            var v1 = new ModuleVersion("1.1");

            Assert.That(v1.IsEqualTo(v0));
        }
Esempio n. 4
0
        /// <summary>
        /// Look for a CKAN update and start installing it if found.
        /// Note that this will happen on a background thread!
        /// </summary>
        /// <returns>
        /// true if update found, false otherwise.
        /// </returns>
        private bool CheckForCKANUpdate()
        {
            if (configuration.CheckForUpdatesOnLaunch && AutoUpdate.CanUpdate)
            {
                try
                {
                    log.Info("Making auto-update call");
                    AutoUpdate.Instance.FetchLatestReleaseInfo();
                    var latest_version  = AutoUpdate.Instance.latestUpdate.Version;
                    var current_version = new ModuleVersion(Meta.GetVersion());

                    if (AutoUpdate.Instance.IsFetched() && latest_version.IsGreaterThan(current_version))
                    {
                        log.Debug("Found higher ckan version");
                        var release_notes = AutoUpdate.Instance.latestUpdate.ReleaseNotes;
                        var dialog        = new NewUpdateDialog(latest_version.ToString(), release_notes);
                        if (dialog.ShowDialog() == DialogResult.OK)
                        {
                            UpdateCKAN();
                            return(true);
                        }
                    }
                }
                catch (Exception exception)
                {
                    currentUser.RaiseError(Properties.Resources.MainAutoUpdateFailed, exception.Message);
                    log.Error("Error in auto-update", exception);
                }
            }
            return(false);
        }
Esempio n. 5
0
        public IEnumerable <Metadata> Transform(Metadata metadata, TransformOptions opts)
        {
            Log.Debug("Fixing version strings (if required)...");

            var json = metadata.Json();

            JToken epoch;

            if (json.TryGetValue("x_netkan_epoch", out epoch))
            {
                Log.InfoFormat("Executing epoch transformation with {0}", metadata.Kref);
                Log.DebugFormat("Input metadata:{0}{1}", Environment.NewLine, json);

                uint epochNumber;
                if (uint.TryParse(epoch.ToString(), out epochNumber))
                {
                    //Implicit if zero. No need to add
                    if (epochNumber != 0)
                    {
                        json["version"] = epochNumber + ":" + json["version"];
                    }

                    Log.DebugFormat("Transformed metadata:{0}{1}", Environment.NewLine, json);
                }
                else
                {
                    throw new BadMetadataKraken(null, "Invalid epoch: " + epoch + " In " + json["identifier"]);
                }
            }

            JToken allowOOO;

            if (json.TryGetValue("x_netkan_allow_out_of_order", out allowOOO) && (bool)allowOOO)
            {
                Log.Debug("Out of order versions enabled in netkan, skipping OOO check");
            }
            else if (opts.HighestVersion != null)
            {
                // Ensure we are greater or equal to the previous max
                ModuleVersion startV   = new ModuleVersion((string)json["version"]);
                ModuleVersion currentV = startV;
                while (currentV < opts.HighestVersion)
                {
                    Log.DebugFormat("Auto-epoching out of order version: {0} < {1}",
                                    currentV, opts.HighestVersion);
                    // Increment epoch if too small
                    currentV = currentV.IncrementEpoch();
                }
                if (!opts.HighestVersion.EpochEquals(currentV) &&
                    startV < opts.HighestVersion && opts.HighestVersion < currentV)
                {
                    // New file, tell the Indexer to be careful
                    opts.Staged        = true;
                    opts.StagingReason = $"Auto-epoching out of order version: {startV} < {opts.HighestVersion} < {currentV}";
                }
                json["version"] = currentV.ToString();
            }

            yield return(new Metadata(json));
        }
Esempio n. 6
0
        /// <summary>
        /// Initialize a GUIMod based on just an identifier
        /// </summary>
        /// <param name="identifier">The id of the module to represent</param>
        /// <param name="registry">CKAN registry object for current game instance</param>
        /// <param name="current_ksp_version">Current game version</param>
        /// <param name="incompatible">If true, mark this module as incompatible</param>
        public GUIMod(string identifier, IRegistryQuerier registry, KspVersionCriteria current_ksp_version, bool incompatible = false)
        {
            Identifier     = identifier;
            IsIncompatible = incompatible;
            IsAutodetected = registry.IsAutodetected(identifier);
            DownloadCount  = registry.DownloadCount(identifier);

            ModuleVersion latest_version = null;

            try
            {
                latest_version = registry.LatestAvailable(identifier, current_ksp_version)?.version;
            }
            catch (ModuleNotFoundKraken)
            {
            }

            // Let's try to find the compatibility for this mod. If it's not in the registry at
            // all (because it's a DarkKAN mod) then this might fail.

            CkanModule latest_available_for_any_ksp = null;

            try
            {
                latest_available_for_any_ksp = registry.LatestAvailable(identifier, null);
            }
            catch
            { }

            // If there's known information for this mod in any form, calculate the highest compatible
            // KSP.
            if (latest_available_for_any_ksp != null)
            {
                KSPCompatibility = registry.LatestCompatibleKSP(identifier)?.ToYalovString()
                                   ?? "Unknown";
                KSPCompatibilityLong = $"{KSPCompatibility} (using mod version {latest_available_for_any_ksp.version})";
            }
            else
            {
                // No idea what this mod is, sorry!
                KSPCompatibility = KSPCompatibilityLong = "unknown";
            }

            if (latest_version != null)
            {
                LatestVersion = latest_version.ToString();
            }
            else if (latest_available_for_any_ksp != null)
            {
                LatestVersion = latest_available_for_any_ksp.version.ToString();
            }
            else
            {
                LatestVersion = "-";
            }

            // If we have a homepage provided, use that; otherwise use the spacedock page, curse page or the github repo so that users have somewhere to get more info than just the abstract.

            Homepage = "N/A";
        }
Esempio n. 7
0
        /// <summary>
        /// Returns whether the given constraint matches the desired version
        /// for the mod we're processing.
        /// </summary>
        private static bool ConstraintPasses(string op, ModuleVersion version, ModuleVersion desiredVersion)
        {
            switch (op)
            {
            case "":
            case "=":
                return(version.IsEqualTo(desiredVersion));

            case "<":
                return(version.IsLessThan(desiredVersion));

            case ">":
                return(version.IsGreaterThan(desiredVersion));

            case "<=":
                return(version.CompareTo(desiredVersion) <= 0);

            case ">=":
                return(version.CompareTo(desiredVersion) >= 0);

            default:
                throw new Kraken(
                          string.Format("Unknown x_netkan_override comparator: {0}", op));
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Fetches all the latest release info, populating our attributes in
        /// the process.
        /// </summary>
        public void FetchLatestReleaseInfo()
        {
            var response = MakeRequest(latestCKANReleaseApiUrl);

            try
            {
                // Check whether the release includes the auto updater
                foreach (var asset in response.assets)
                {
                    string url = asset.browser_download_url.ToString();
                    if (url.EndsWith("ckan.exe"))
                    {
                        fetchedCkanUrl = new Tuple <Uri, long>(new Uri(url), (long)asset.size);
                    }
                    else if (url.EndsWith("AutoUpdater.exe"))
                    {
                        fetchedUpdaterUrl = new Tuple <Uri, long>(new Uri(url), (long)asset.size);
                    }
                }
                if (fetchedUpdaterUrl == null)
                {
                    // Older releases don't include the auto updater
                    fetchedUpdaterUrl = RetrieveUrl(MakeRequest(oldLatestUpdaterReleaseApiUrl), 0);
                }
            }
            catch (Kraken)
            {
                LatestVersion = new ModuleVersion(Meta.GetVersion());
                return;
            }

            ReleaseNotes  = ExtractReleaseNotes(response.body.ToString());
            LatestVersion = new CkanModuleVersion(response.tag_name.ToString(), response.name.ToString());
        }
Esempio n. 9
0
        /// <summary>
        /// Find installed modules that have different metadata in their equivalent available module
        /// </summary>
        /// <param name="registry">Registry to scan</param>
        /// <returns>
        /// List of CkanModules that are available and have changed metadata
        /// </returns>
        private static List <CkanModule> GetChangedInstalledModules(Registry registry)
        {
            List <CkanModule> metadataChanges = new List <CkanModule>();

            foreach (InstalledModule installedModule in registry.InstalledModules)
            {
                string identifier = installedModule.identifier;

                ModuleVersion installedVersion = registry.InstalledVersion(identifier);
                if (!(registry.available_modules.ContainsKey(identifier)))
                {
                    log.InfoFormat("UpdateRegistry, module {0}, version {1} not in registry", identifier, installedVersion);
                    continue;
                }

                if (!registry.available_modules[identifier].module_version.ContainsKey(installedVersion))
                {
                    continue;
                }

                // if the mod is installed and the metadata is different we have to reinstall it
                CkanModule metadata = registry.available_modules[identifier].module_version[installedVersion];

                CkanModule oldMetadata = registry.InstalledModule(identifier).Module;

                if (!MetadataEquals(metadata, oldMetadata))
                {
                    metadataChanges.Add(registry.available_modules[identifier].module_version[installedVersion]);
                }
            }
            return(metadataChanges);
        }
Esempio n. 10
0
File: KSP.cs Progetto: zicrog/CKAN
        public void ScanDlls()
        {
            string path     = Path.Combine(ksp.GameData(), "Example.dll");
            var    registry = CKAN.RegistryManager.Instance(ksp).registry;

            Assert.IsFalse(registry.IsInstalled("Example"), "Example should start uninstalled");

            File.WriteAllText(path, "Not really a DLL, are we?");

            ksp.ScanGameData();

            Assert.IsTrue(registry.IsInstalled("Example"), "Example installed");

            ModuleVersion version = registry.InstalledVersion("Example");

            Assert.IsInstanceOf <UnmanagedModuleVersion>(version, "DLL detected as a DLL, not full mod");

            // Now let's do the same with different case.

            string path2 = Path.Combine(ksp.GameData(), "NewMod.DLL");

            Assert.IsFalse(registry.IsInstalled("NewMod"));
            File.WriteAllText(path2, "This text is irrelevant. You will be assimilated");

            ksp.ScanGameData();

            Assert.IsTrue(registry.IsInstalled("NewMod"));
        }
Esempio n. 11
0
        /// <summary>
        /// Initialize a GUIMod based on just an identifier
        /// </summary>
        /// <param name="identifier">The id of the module to represent</param>
        /// <param name="registry">CKAN registry object for current game instance</param>
        /// <param name="current_ksp_version">Current game version</param>
        /// <param name="incompatible">If true, mark this module as incompatible</param>
        public GUIMod(string identifier, IRegistryQuerier registry, KspVersionCriteria current_ksp_version, bool?incompatible = null)
        {
            Identifier     = identifier;
            IsAutodetected = registry.IsAutodetected(identifier);
            DownloadCount  = registry.DownloadCount(identifier);
            if (IsAutodetected)
            {
                IsInstalled = true;
            }

            ModuleVersion latest_version = null;

            try
            {
                LatestCompatibleMod = registry.LatestAvailable(identifier, current_ksp_version);
                latest_version      = LatestCompatibleMod?.version;
            }
            catch (ModuleNotFoundKraken)
            {
            }

            IsIncompatible = incompatible ?? LatestCompatibleMod == null;

            // Let's try to find the compatibility for this mod. If it's not in the registry at
            // all (because it's a DarkKAN mod) then this might fail.

            CkanModule latest_available_for_any_ksp = null;

            try
            {
                latest_available_for_any_ksp = registry.LatestAvailable(identifier, null);
            }
            catch
            { }

            // If there's known information for this mod in any form, calculate the highest compatible
            // KSP.
            if (latest_available_for_any_ksp != null)
            {
                KSPCompatibilityVersion = registry.LatestCompatibleKSP(identifier);
                KSPCompatibility        = KSPCompatibilityVersion?.ToYalovString()
                                          ?? Properties.Resources.GUIModUnknown;
                KSPCompatibilityLong = string.Format(Properties.Resources.GUIModKSPCompatibilityLong, KSPCompatibility, latest_available_for_any_ksp.version);
            }

            if (latest_version != null)
            {
                LatestVersion = latest_version.ToString();
            }
            else if (latest_available_for_any_ksp != null)
            {
                LatestVersion = latest_available_for_any_ksp.version.ToString();
            }
            else
            {
                LatestVersion = "-";
            }

            SearchableIdentifier = CkanModule.nonAlphaNums.Replace(Identifier, "");
        }
Esempio n. 12
0
        /// <summary>
        /// Returns true if we support at least spec_version of the CKAN spec.
        /// </summary>
        internal static bool IsSpecSupported(ModuleVersion spec_vesion)
        {
            // This could be a read-only state variable; do we have those in C#?
            ModuleVersion release = new ModuleVersion(Meta.GetVersion(VersionFormat.Short));

            return(release == null || release.IsGreaterThan(spec_vesion));
        }
Esempio n. 13
0
        private IList <ModuleVersion> ReadModules()
        {
            string fileName = Environment.CurrentDirectory + @"\..\..\..\SuperDump\dumps\dotnetworld2\modules.txt";
            List <ModuleVersion> versions = new List <ModuleVersion>();
            StreamReader         reader   = new StreamReader(fileName);

            while (reader.Peek() >= 0)
            {
                var line   = reader.ReadLine();
                var values = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                if (values.Length > 1 && values[0].Equals("Image") && values[1].Equals("name:"))
                {
                    ModuleVersion v = new ModuleVersion();
                    v.name = values[2];
                    // go to version
                    while (reader.Peek() >= 0)
                    {
                        var line2   = reader.ReadLine();
                        var values2 = line2.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                        if (values2.Length > 1 && values2[0].Equals("File") && values2[1].Equals("version:"))
                        {
                            v.version = values2[2];
                            versions.Add(v);
                            break;
                        }
                    }
                }
            }
            return(versions);
        }
Esempio n. 14
0
        private TreeNode findDependencyShallow(IRegistryQuerier registry, string identifier, RelationshipType relationship, KspVersionCriteria crit)
        {
            try
            {
                CkanModule dependencyModule = registry.LatestAvailable(identifier, crit);
                if (dependencyModule != null)
                {
                    return(indexedNode(registry, dependencyModule, relationship, crit != null));
                }
            }
            catch (ModuleNotFoundKraken)
            {
                // Maybe it's a DLC?
                ModuleVersion installedVersion = registry.InstalledVersion(identifier, false);
                if (installedVersion != null)
                {
                    return(nonModuleNode(identifier, installedVersion, relationship));
                }

                // If we don't find a module by this name, look for other modules that provide it.
                List <CkanModule> dependencyModules = registry.LatestAvailableWithProvides(identifier, crit);
                if (dependencyModules != null && dependencyModules.Count > 0)
                {
                    List <TreeNode> children = new List <TreeNode>();
                    foreach (CkanModule dep in dependencyModules)
                    {
                        children.Add(indexedNode(registry, dep, relationship, crit != null));
                    }
                    return(providesNode(identifier, relationship, children));
                }
            }
            return(null);
        }
Esempio n. 15
0
        /// <summary>
        /// Returns if the other version satisfies this RelationshipDescriptor.
        /// If the RelationshipDescriptor has version set it compares against that.
        /// Else it uses the {min,max}_version fields treating nulls as unbounded.
        /// Note: Uses inclusive inequalities.
        /// </summary>
        /// <param name="other"></param>
        /// <returns>True if other_version is within the bounds</returns>
        public bool WithinBounds(ModuleVersion other)
        {
            // UnmanagedModuleVersions with unknown versions always satisfy the bound
            if (other is UnmanagedModuleVersion unmanagedModuleVersion && unmanagedModuleVersion.IsUnknownVersion)
            {
                return(true);
            }

            if (version == null)
            {
                if (max_version == null && min_version == null)
                {
                    return(true);
                }

                var minSat = min_version == null || min_version <= other;
                var maxSat = max_version == null || max_version >= other;

                if (minSat && maxSat)
                {
                    return(true);
                }
            }
            else
            {
                if (version.Equals(other))
                {
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 16
0
        public IEnumerable <Metadata> Transform(Metadata metadata, TransformOptions opts)
        {
            if (metadata.Kref != null && metadata.Kref.Source == KrefSource)
            {
                var json = metadata.Json();

                Log.InfoFormat("Executing MetaNetkan transformation with {0}", metadata.Kref);
                Log.DebugFormat("Input metadata:{0}{1}", Environment.NewLine, json);

                // Make sure resources exist, save metanetkan
                if (json["resources"] == null)
                {
                    json["resources"] = new JObject();
                }
                var resourcesJson = (JObject)json["resources"];
                resourcesJson.SafeAdd("metanetkan", metadata.Kref.Id);

                var uri            = new Uri(metadata.Kref.Id);
                var targetFileText = _http.DownloadText(CKAN.Net.GetRawUri(uri));

                Log.DebugFormat("Target netkan:{0}{1}", Environment.NewLine, targetFileText);

                var targetJson     = JObject.Parse(targetFileText);
                var targetMetadata = new Metadata(targetJson);

                if (targetMetadata.Kref == null || targetMetadata.Kref.Source != "netkan")
                {
                    json["spec_version"] = ModuleVersion.Max(metadata.SpecVersion, targetMetadata.SpecVersion)
                                           .ToSpecVersionJson();

                    if (targetJson["$kref"] != null)
                    {
                        json["$kref"] = targetJson["$kref"];
                    }
                    else
                    {
                        json.Remove("$kref");
                    }

                    json.SafeMerge("resources", targetJson["resources"]);

                    foreach (var property in targetJson.Properties())
                    {
                        json.SafeAdd(property.Name, property.Value);
                    }

                    Log.DebugFormat("Transformed metadata:{0}{1}", Environment.NewLine, json);

                    yield return(new Metadata(json));
                }
                else
                {
                    throw new Kraken("The target of a metanetkan may not also be a metanetkan.");
                }
            }
            else
            {
                yield return(metadata);
            }
        }
Esempio n. 17
0
        /// <summary>
        /// Returns the module with the specified version, or null if that does not exist.
        /// </summary>
        public CkanModule ByVersion(ModuleVersion v)
        {
            CkanModule module;

            module_version.TryGetValue(v, out module);
            return(module);
        }
Esempio n. 18
0
 /// <summary>
 /// Initialize a CkanModule
 /// </summary>
 /// <param name="spec_version">The version of the spec obeyed by this module</param>
 /// <param name="identifier">This module's machine-readable identifier</param>
 /// <param name="name">This module's user-visible display name</param>
 /// <param name="@abstract">Short description of this module</param>
 /// <param name="description">Long description of this module</param>
 /// <param name="author">Authors of this module</param>
 /// <param name="license">Licenses of this module</param>
 /// <param name="version">Version number of this release</param>
 /// <param name="download">Where to download this module</param>
 /// <param name="kind">package, metapackage, or dlc</param>
 /// <param name="comparator">Object used for checking compatibility of this module</param>
 public CkanModule(
     ModuleVersion spec_version,
     string identifier,
     string name,
     string @abstract,
     string description,
     List <string> author,
     List <License> license,
     ModuleVersion version,
     Uri download,
     string kind = null,
     IGameComparator comparator = null
     )
 {
     this.spec_version = spec_version;
     this.identifier   = identifier;
     this.name         = name;
     this.@abstract    = @abstract;
     this.description  = description;
     this.author       = author;
     this.license      = license;
     this.version      = version;
     this.download     = download;
     this.kind         = kind;
     this._comparator  = comparator ?? ServiceLocator.Container.Resolve <IGameComparator>();
     CheckHealth();
     CalculateSearchables();
 }
Esempio n. 19
0
        /// <summary>
        /// Gets a collections of module updates that have already been applied
        /// to the system.
        /// </summary>
        private async Task <ICollection <ModuleVersion> > GetUpdateVersionHistoryAsync()
        {
            var query = @"
                if (exists (select * 
                                 from information_schema.tables 
                                 where table_schema = 'Cofoundry' 
                                 and  table_name = 'ModuleUpdate'))
                begin
                    select Module, MAX([Version]) as Version
	                from  Cofoundry.ModuleUpdate
	                group by Module
	                order by Module
                end";

            var moduleVersions = await _db.ReadAsync(query, r =>
            {
                var moduleVersion     = new ModuleVersion();
                moduleVersion.Module  = (string)r["Module"];
                moduleVersion.Version = (int)r["Version"];

                return(moduleVersion);
            });

            return(moduleVersions);
        }
        private IEnumerable <IVersionedUpdateCommand> GetAdditionalCommands(ModuleVersion moduleVersion)
        {
            if (moduleVersion == null)
            {
                var createDirectoriesCommand = new CreateDirectoriesUpdateCommand()
                {
                    Version     = 1,
                    Description = "InitCofoundryDirectories",
                    Directories = new string[]
                    {
                        "~/App_Data/Files/Images/",
                        "~/App_Data/Files/Other/",
                        "~/App_Data/Emails/"
                    }
                };

                yield return(createDirectoriesCommand);
            }

            var importPermissionsCommand = new ImportPermissionsCommand();

            if (moduleVersion == null || moduleVersion.Version < importPermissionsCommand.Version)
            {
                yield return(new ImportPermissionsCommand());
            }
        }
Esempio n. 21
0
        private TreeNode findDependencyShallow(IRegistryQuerier registry, string identifier, RelationshipType relationship, KspVersionCriteria crit)
        {
            // Maybe it's a DLC?
            ModuleVersion installedVersion = registry.InstalledVersion(identifier, false);

            if (installedVersion != null)
            {
                return(nonModuleNode(identifier, installedVersion, relationship));
            }

            // Find modules that satisfy this dependency
            List <CkanModule> dependencyModules = registry.LatestAvailableWithProvides(identifier, crit);

            if (dependencyModules.Count == 0)
            {
                // Nothing found, don't return a node
                return(null);
            }
            else if (dependencyModules.Count == 1 && dependencyModules[0].identifier == identifier)
            {
                // Only one exact match module, return a simple node
                return(indexedNode(registry, dependencyModules[0], relationship, crit != null));
            }
            else
            {
                // Several found or not same id, return a "provides" node
                return(providesNode(identifier, relationship,
                                    dependencyModules.Select(dep => indexedNode(registry, dep, relationship, crit != null))
                                    ));
            }
        }
Esempio n. 22
0
 public GithubRelease(string author, ModuleVersion version, Uri download, DateTime?updated)
 {
     Author       = author;
     Version      = version;
     Download     = download;
     AssetUpdated = updated;
 }
Esempio n. 23
0
        public IEnumerable <Metadata> Transform(Metadata metadata, TransformOptions opts)
        {
            if (metadata.Download != null)
            {
                var json = metadata.Json();

                string file = _http.DownloadPackage(metadata.Download, metadata.Identifier, metadata.RemoteTimestamp);

                var internalJson = _moduleService.GetInternalCkan(file);

                if (internalJson != null)
                {
                    Log.InfoFormat("Executing internal CKAN transformation with {0}", metadata.Kref);
                    Log.DebugFormat("Input metadata:{0}{1}", Environment.NewLine, json);

                    foreach (var property in internalJson.Properties())
                    {
                        json.SafeAdd(property.Name, property.Value);
                    }

                    json["spec_version"] = ModuleVersion.Max(metadata.SpecVersion, new Metadata(internalJson).SpecVersion)
                                           .ToSpecVersionJson();

                    Log.DebugFormat("Transformed metadata:{0}{1}", Environment.NewLine, json);
                }

                yield return(new Metadata(json));
            }
            else
            {
                yield return(metadata);
            }
        }
Esempio n. 24
0
        /// <summary>
        /// Walks through a list of constraints, and returns true if they're all satisifed
        /// for the mod version we're examining.
        /// </summary>
        private static bool ConstraintsApply(IEnumerable <string> constraints, ModuleVersion version)
        {
            foreach (var constraint in constraints)
            {
                var match = Regex.Match(
                    constraint,
                    @"^(?<op> [<>=]*) \s* (?<version> .*)$",
                    RegexOptions.IgnorePatternWhitespace);

                if (!match.Success)
                {
                    throw new Kraken(
                              string.Format("Unable to parse x_netkan_override - {0}", constraint));
                }

                var op             = match.Groups["op"].Value;
                var desiredVersion = new ModuleVersion(match.Groups["version"].Value);

                // This contstraint failed. This stanza is not for us.
                if (!ConstraintPasses(op, version, desiredVersion))
                {
                    return(false);
                }
            }

            // All the constraints passed! We want to apply this stanza!
            return(true);
        }
Esempio n. 25
0
 /// <summary>
 /// Find the minimum and maximum mod versions and compatible game versions
 /// for a list of modules (presumably different versions of the same mod).
 /// </summary>
 /// <param name="modVersions">The modules to inspect</param>
 /// <param name="minMod">Return parameter for the lowest  mod  version</param>
 /// <param name="maxMod">Return parameter for the highest mod  version</param>
 /// <param name="minKsp">Return parameter for the lowest  game version</param>
 /// <param name="maxKsp">Return parameter for the highest game version</param>
 public static void GetMinMaxVersions(IEnumerable <CkanModule> modVersions,
                                      out ModuleVersion minMod, out ModuleVersion maxMod,
                                      out KspVersion minKsp, out KspVersion maxKsp)
 {
     minMod = maxMod = null;
     minKsp = maxKsp = null;
     foreach (CkanModule rel in modVersions.Where(v => v != null))
     {
         if (minMod == null || minMod > rel.version)
         {
             minMod = rel.version;
         }
         if (maxMod == null || maxMod < rel.version)
         {
             maxMod = rel.version;
         }
         KspVersion relMin = rel.EarliestCompatibleKSP();
         KspVersion relMax = rel.LatestCompatibleKSP();
         if (minKsp == null || !minKsp.IsAny && (minKsp > relMin || relMin.IsAny))
         {
             minKsp = relMin;
         }
         if (maxKsp == null || !maxKsp.IsAny && (maxKsp < relMax || relMax.IsAny))
         {
             maxKsp = relMax;
         }
     }
 }
Esempio n. 26
0
        public void Epoch()
        {
            var v1 = new ModuleVersion("1.2.0");
            var v2 = new ModuleVersion("1:1.2.0");

            Assert.That(v1.IsLessThan(v2));
        }
Esempio n. 27
0
        public List <ModuleVersion> GetVersionData(string moduleID, string languageID)
        {
            List <ModuleVersion> versions = new List <ModuleVersion>();

            con.Open();
            SqlCommand cmd = new SqlCommand("SELECT VersionNumber, Users.FirstName, Users.LastName, " +
                                            "VersionDescription, VersionDate, StudyYear " +
                                            "FROM ModuleVersion " +
                                            "INNER JOIN Users " +
                                            "ON AuthorID = UserID " +
                                            "WHERE ModuleID = @moduleID " +
                                            "AND LanguageID = @languageID " +
                                            "ORDER BY VersionNumber DESC", con);

            cmd.Parameters.AddWithValue("@moduleID", moduleID.Trim());
            cmd.Parameters.AddWithValue("@languageID", languageID.Trim().ToUpper());
            SqlDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                ModuleVersion version = new ModuleVersion();
                version.VersionNumber      = reader.GetDouble(0);
                version.AuthorFirstName    = reader.GetString(1);
                version.AuthorLastName     = reader.GetString(2);
                version.VersionDescription = reader.GetString(3);
                version.VersionDate        = reader.GetDateTime(4);
                version.StudyYear          = reader.GetString(5);
                versions.Add(version);
            }
            con.Close();
            return(versions);
        }
Esempio n. 28
0
        public CkanModule GeneratorRandomModule(
            GameVersion ksp_version = null,
            List <RelationshipDescriptor> conflicts = null,
            List <RelationshipDescriptor> depends   = null,
            List <RelationshipDescriptor> suggests  = null,
            List <String> provides = null,
            string identifier      = null,
            ModuleVersion version  = null)
        {
            var mod = new CkanModule
            {
                name         = Generator.Next().ToString(CultureInfo.InvariantCulture),
                @abstract    = Generator.Next().ToString(CultureInfo.InvariantCulture),
                identifier   = identifier ?? Generator.Next().ToString(CultureInfo.InvariantCulture),
                spec_version = new ModuleVersion(1.ToString(CultureInfo.InvariantCulture)),
                ksp_version  = ksp_version ?? GameVersion.Parse("0." + Generator.Next()),
                version      = version ?? new ModuleVersion(Generator.Next().ToString(CultureInfo.InvariantCulture))
            };

            mod.ksp_version_max = mod.ksp_version_min = null;
            mod.conflicts       = conflicts;
            mod.depends         = depends;
            mod.suggests        = suggests;
            mod.provides        = provides;
            return(mod);
        }
Esempio n. 29
0
        public void UnevenVersioning()
        {
            var v0 = new ModuleVersion("1.1.0.0");
            var v1 = new ModuleVersion("1.1.1");

            Assert.That(v0.IsLessThan(v1));
            Assert.That(v1.IsGreaterThan(v0));
        }
Esempio n. 30
0
        public void Alpha()
        {
            var v1 = new ModuleVersion("apple");
            var v2 = new ModuleVersion("banana");

            // alphabetical test
            Assert.That(v1.IsLessThan(v2));
        }
        private void ReadHeader(TextReader reader)
        {
            string version = ReadNextLine(reader);
            string description = ReadNextLine(reader);
            string offset = ReadNextLine(reader);
            string entryCount = ReadNextLine(reader);
            string length = ReadNextLine(reader);
            string entryList = ReadNextLine(reader);
            string tableFile = ReadNextLine(reader);

            if (version == "1")
            {
                //Will be changed to XeldZahlman if needed
                this.version = ModuleVersion.Original;
            }
            else if (version == "2")
            {
                this.version = ModuleVersion.NLight;
            }

            this.description = description;

            this.offset = offset.GetValue();
            this.entryCount = entryCount.GetValue();
            this.length = length.GetValue();

            if (entryList != "NULL")
            {
                this.entrySelectorFile = File.ReadAllLines(entryList);
            }
            if (tableFile != "NULL")
            {
                this.tableFile = new Table(tableFile);
            }
        }