Exemple #1
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);
                }
            })
                                                 .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);
        }
Exemple #2
0
        /// <summary>
        /// Find the identifier associated with a manually installed DLL
        /// </summary>
        /// <param name="relative_path">Path of the DLL relative to game root</param>
        /// <returns>
        /// Identifier if found otherwise null
        /// </returns>
        public string DllPathToIdentifier(string relative_path)
        {
            if (!relative_path.StartsWith($"{game.PrimaryModDirectoryRelative}/", StringComparison.CurrentCultureIgnoreCase))
            {
                // DLLs only live in the primary mod directory
                return(null);
            }
            Match match = dllPattern.Match(relative_path);

            return(match.Success
                ? Identifier.Sanitize(match.Groups["identifier"].Value)
                : null);
        }
Exemple #3
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
                spec_version = new ModuleVersion("v1.18"),
                identifier   = Identifier.Sanitize(name),
                name         = name,
                @abstract    = $"A list of modules installed on the {kspInstanceName} KSP instance",
                kind         = "metapackage",
                version      = new ModuleVersion(DateTime.UtcNow.ToString("yyyy.MM.dd.hh.mm.ss")),
                license      = new List<License>() { new License("unknown") },
                download_content_type = "application/zip",
            };

            List<RelationshipDescriptor> mods = registry.Installed()
                .Where(mod => !(mod.Value is ProvidesModuleVersion || mod.Value is UnmanagedModuleVersion))
                .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;
        }