Beispiel #1
0
 public override int GetHashCode()
 {
     return(Identifier?.GetHashCode() ?? 0);
 }
Beispiel #2
0
        /// <summary>
        /// Create a CkanModule object that represents the currently installed
        /// mod list as a metapackage.
        /// </summary>
        /// <param name="recommends">If true, put the mods in the recommends relationship, otherwise use depends</param>
        /// <param name="with_versions">If true, set the installed mod versions in the relationships</param>
        /// <returns>
        /// The CkanModule object
        /// </returns>
        public CkanModule GenerateModpack(bool recommends = false, bool with_versions = true)
        {
            string kspInstanceName = ksp.Name;
            string name            = $"installed-{kspInstanceName}";
            var    module          = new CkanModule(
                // v1.18 to allow Unlicense
                new ModuleVersion("v1.18"),
                Identifier.Sanitize(name),
                name,
                $"A list of modules installed on the {kspInstanceName} KSP instance",
                null,
                new List <string>()
            {
                System.Environment.UserName
            },
                new List <License>()
            {
                new License("unknown")
            },
                new ModuleVersion(DateTime.UtcNow.ToString("yyyy.MM.dd.hh.mm.ss")),
                null,
                "metapackage"
                )
            {
                download_content_type = "application/zip",
                release_date          = DateTime.Now,
            };

            List <RelationshipDescriptor> mods = registry.Installed(false, false)
                                                 .Where(kvp => {
                // Skip unavailable modules (custom .ckan files)
                try
                {
                    var avail = registry.LatestAvailable(kvp.Key, null, null);
                    return(!avail.IsDLC);
                }
                catch
                {
                    return(false);
                }
            })
                                                 // Case insensitive sort by identifier
                                                 .OrderBy(kvp => kvp.Key, StringComparer.OrdinalIgnoreCase)
                                                 .Select(kvp => (RelationshipDescriptor) new ModuleRelationshipDescriptor()
            {
                name    = kvp.Key,
                version = with_versions ? kvp.Value : null
            })
                                                 .ToList();

            if (recommends)
            {
                module.recommends = mods;
            }
            else
            {
                module.depends = mods;
            }

            return(module);
        }