Пример #1
0
        /// <summary>
        /// Generate version mapping table once for all instances to share
        /// </summary>
        static KspVersion()
        {
            // Should be sorted
            List <KspVersion> versions = new KspBuildMap(new Win32Registry()).KnownVersions;

            VersionsMax[""] = versions.Last();
            foreach (var v in versions)
            {
                // Add or replace
                VersionsMax[$"{v.Major}"]           = v;
                VersionsMax[$"{v.Major}.{v.Minor}"] = v;
            }
        }
Пример #2
0
 static CompatibleVersionDialog()
 {
     options = new KspBuildMap(new Win32Registry()).KnownVersions;
     // C# won't let us foreach over an array while modifying it
     for (int i = options.Count - 1; i >= 0; --i)
     {
         KspVersion v = options[i];
         // From GUI/CompatibleKspVersionsDialog.cs
         KspVersion fullKnownVersion = v.ToVersionRange().Lower.Value;
         KspVersion toAdd            = new KspVersion(fullKnownVersion.Major, fullKnownVersion.Minor);
         if (!options.Contains(toAdd))
         {
             options.Add(toAdd);
         }
     }
 }
Пример #3
0
        /// <summary>
        /// Searches the build map if the version is a valid, known KSP version.
        /// </summary>
        /// <returns><c>true</c>, if version is in the build map, <c>false</c> otherwise.</returns>
        public bool InBuildMap()
        {
            List <KspVersion> knownVersions = new KspBuildMap(new Win32Registry()).KnownVersions;

            foreach (KspVersion ver in knownVersions)
            {
                if (ver.Major == Major && ver.Minor == Minor && ver.Patch == Patch)
                {
                    // If it found a matching maj, min and patch,
                    // test if the build numbers are the same too, but ignore if the
                    // version is NOT build defined.
                    if (ver.Build == Build || !IsBuildDefined)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Пример #4
0
        /// <summary>
        /// Raises a selection dialog for choosing a specific KSP version, if it is not fully defined yet.
        /// If a build number is specified but not known, it presents a list of all builds
        /// of the patch range.
        /// Needs at least a Major and Minor (doesn't make sense else).
        /// </summary>
        /// <returns>A complete KspVersion object</returns>
        /// <param name="user">A IUser instance, to raise the corresponding dialog.</param>
        public KspVersion RaiseVersionSelectionDialog(IUser user)
        {
            if (IsFullyDefined && InBuildMap())
            {
                // The specified version is complete and known :hooray:. Return this instance.
                return(this);
            }
            else if (!IsMajorDefined || !IsMinorDefined)
            {
                throw new IncorrectKSPVersionKraken("Needs at least Major and Minor");
            }
            else
            {
                // Get all known versions out of the build map.
                KspVersion[]      knownVersions    = new KspBuildMap(new Win32Registry()).KnownVersions.ToArray();
                List <KspVersion> possibleVersions = new List <KspVersion>();

                // Default message passed to RaiseSelectionDialog.
                string message = "The specified version is not unique, please select one:";

                // Find the versions which are part of the range.
                foreach (KspVersion ver in knownVersions)
                {
                    // If we only have Major and Minor -> compare these two.
                    if (!IsPatchDefined)
                    {
                        if (Major == ver.Major && Minor == ver.Minor)
                        {
                            possibleVersions.Add(ver);
                        }
                    }
                    // If we also have Patch -> compare it too.
                    else if (!IsBuildDefined)
                    {
                        if (Major == ver.Major && Minor == ver.Minor && Patch == ver.Patch)
                        {
                            possibleVersions.Add(ver);
                        }
                    }
                    // And if we are here, there's a build number not known in the build map.
                    // Only compare Major, Minor, Patch and adjust the message.
                    else
                    {
                        message = "The build number is not known for this patch. Please select one:";
                        if (Major == ver.Major && Minor == ver.Minor && Patch == ver.Patch)
                        {
                            possibleVersions.Add(ver);
                        }
                    }
                }

                // Now do some checks and raise the selection dialog.
                if (possibleVersions.Count == 0)
                {
                    // No version found in the map. Happens for future or other unknown versions.
                    throw new IncorrectKSPVersionKraken("The version is not known to CKAN.");
                }
                else if (possibleVersions.Count == 1)
                {
                    // Lucky, there's only one possible version. Happens f.e. if there's only one build per patch (especially the case for newer versions).
                    return(possibleVersions.ElementAt(0));
                }
                else if (user.Headless)
                {
                    return(possibleVersions.LastOrDefault());
                }
                else
                {
                    int choosen = user.RaiseSelectionDialog(message, possibleVersions.ToArray());
                    if (choosen >= 0 && choosen < possibleVersions.Count)
                    {
                        return(possibleVersions.ElementAt(choosen));
                    }
                    else
                    {
                        throw new CancelledActionKraken();
                    }
                }
            }
        }
Пример #5
0
 public MatchesKnownGameVersionsValidator()
 {
     buildMap = new KspBuildMap(new Win32Registry());
     buildMap.Refresh(BuildMapSource.Embedded);
 }
Пример #6
0
        public GUIMod(CkanModule mod, IRegistryQuerier registry, KspVersionCriteria current_ksp_version, bool incompatible = false)
        {
            IsCKAN = mod is CkanModule;
            //Currently anything which could alter these causes a full reload of the modlist
            // If this is ever changed these could be moved into the properties
            Mod              = mod;
            IsInstalled      = registry.IsInstalled(mod.identifier, false);
            IsInstallChecked = IsInstalled;
            HasUpdate        = registry.HasUpdate(mod.identifier, current_ksp_version);
            IsIncompatible   = incompatible || !mod.IsCompatibleKSP(current_ksp_version);
            IsAutodetected   = registry.IsAutodetected(mod.identifier);
            Authors          = mod.author == null ? "N/A" : String.Join(",", mod.author);

            var           installed_version = registry.InstalledVersion(mod.identifier);
            ModuleVersion latest_version    = null;
            var           ksp_version       = mod.ksp_version;

            try
            {
                var latest_available = registry.LatestAvailable(mod.identifier, current_ksp_version);
                if (latest_available != null)
                {
                    latest_version = latest_available.version;
                }
            }
            catch (ModuleNotFoundKraken)
            {
                latest_version = installed_version;
            }

            InstalledVersion = installed_version != null?installed_version.ToString() : "-";

            // 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(mod.identifier, null);
            }
            catch
            {
                // If we can't find the mod in the CKAN, but we've a CkanModule installed, then
                // use that.
                if (IsCKAN)
                {
                    latest_available_for_any_ksp = (CkanModule)mod;
                }
            }

            // If there's known information for this mod in any form, calculate the highest compatible
            // KSP.
            if (latest_available_for_any_ksp != null)
            {
                if (!VersionMaxWasGenerated)
                {
                    VersionMaxWasGenerated = true;
                    List <KspVersion> versions = new KspBuildMap(new Win32Registry()).KnownVersions;  // should be sorted

                    VersionsMax     = new Dictionary <string, KspVersion>();
                    VersionsMax[""] = versions.Last();

                    foreach (var v in versions)
                    {
                        VersionsMax[v.Major.ToString()]      = v;   // add or replace
                        VersionsMax[v.Major + "." + v.Minor] = v;
                    }
                }

                const int Undefined = -1;

                KspVersion ksp_ver = registry.LatestCompatibleKSP(mod.identifier);
                string     ver = ksp_ver?.ToString();
                int        major = ksp_ver.Major, minor = ksp_ver.Minor, patch = ksp_ver.Patch;
                KspVersion value;

                if (major == Undefined
                    //|| (major >= UptoNines(VersionsMax[""].Major))       // 9.99.99
                    || (major > VersionsMax[""].Major) ||                                                                                       // 2.0.0
                    (major == VersionsMax[""].Major && VersionsMax.TryGetValue(major.ToString(), out value) && minor >= UptoNines(value.Minor)) // 1.99.99 ?
                    )
                {
                    KSPCompatibility = "any";
                }

                else if (minor != Undefined &&
                         VersionsMax.TryGetValue(major + "." + minor, out value) &&
                         (patch == Undefined || patch >= UptoNines(value.Patch))
                         )
                {
                    KSPCompatibility = major + "." + minor + "." + UptoNines(value.Patch);
                }

                else
                {
                    KSPCompatibility = ver;
                }

                // KSPCompatibility += " | " + major + "." + minor + "." + patch;   // for testing

                // If the mod we have installed is *not* the mod we have installed, or we don't know
                // what we have installed, indicate that an upgrade would be needed.
                if (installed_version == null || !latest_available_for_any_ksp.version.IsEqualTo(installed_version))
                {
                    KSPCompatibilityLong = string.Format("{0} (using mod version {1})",
                                                         KSPCompatibility, latest_available_for_any_ksp.version);
                    //    ver, latest_available_for_any_ksp.version);   //  true values in the right tab
                }
                else
                {
                    KSPCompatibilityLong = KSPCompatibility;
                    // KSPCompatibilityLong = ver;   //  true values in the right tab
                }
            }
            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 = "-";
            }

            KSPversion = ksp_version != null?ksp_version.ToString() : "-";

            Abstract = mod.@abstract;

            // 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";
            if (mod.resources != null)
            {
                if (mod.resources.homepage != null)
                {
                    Homepage = mod.resources.homepage.ToString();
                }
                else if (mod.resources.spacedock != null)
                {
                    Homepage = mod.resources.spacedock.ToString();
                }
                else if (mod.resources.curse != null)
                {
                    Homepage = mod.resources.curse.ToString();
                }
                else if (mod.resources.repository != null)
                {
                    Homepage = mod.resources.repository.ToString();
                }
            }

            Identifier = mod.identifier;

            DownloadSize = (mod.download_size == 0)
                ? "N/A"
                : CkanModule.FmtSize(mod.download_size);

            Abbrevation = new string(mod.name.Split(' ').
                                     Where(s => s.Length > 0).Select(s => s[0]).ToArray());

            UpdateIsCached();
        }