예제 #1
0
        internal OptionsDialog(Type optionsType, KMod.Mod modSpec)
        {
            dialog           = null;
            modImage         = null;
            this.modSpec     = modSpec ?? throw new ArgumentNullException("modSpec");
            this.optionsType = optionsType ?? throw new ArgumentNullException("optionsType");
            optionCategories = OptionsEntry.BuildOptions(optionsType);
            options          = null;
            // Determine config location
            infoAttr = POptions.GetModInfoAttribute(optionsType);
            typeAttr = POptions.GetConfigFileAttribute(optionsType);
            var src = modSpec.file_source;

            if (src == null)
            {
                path = null;
            }
            else
            {
                path = Path.Combine(src.GetRoot(), typeAttr?.ConfigFileName ?? POptions.
                                    CONFIG_FILE_NAME);
            }
            // Find mod home page
            string url   = infoAttr?.URL;
            var    label = modSpec.label;

            if (string.IsNullOrEmpty(url) && label.distribution_platform == KMod.Label.
                DistributionPlatform.Steam)
            {
                // Steam mods use their workshop ID as the label
                url = "https://steamcommunity.com/sharedfiles/filedetails/?id=" + label.id;
            }
            modURL = url;
        }
예제 #2
0
        internal OptionsDialog(Type optionsType, IOptionsHandler handler)
        {
            string root = handler.ConfigPath;

            dialog           = null;
            modImage         = null;
            this.handler     = handler ?? throw new ArgumentNullException("handler");
            this.optionsType = optionsType ?? throw new ArgumentNullException("optionsType");
            optionCategories = OptionsEntry.BuildOptions(optionsType);
            options          = null;
            // Determine config location
            infoAttr = POptions.GetModInfoAttribute(optionsType);
            typeAttr = POptions.GetConfigFileAttribute(optionsType);
            path     = (root == null) ? null : Path.Combine(root, typeAttr?.ConfigFileName ??
                                                            POptions.CONFIG_FILE_NAME);
        }
예제 #3
0
        /// <summary>
        /// Retrieves the information attribute a mod config.
        /// </summary>
        /// <param name="optionsType">The type potentially containing the mod info attribute.</param>
        /// <returns>The ModInfoAttribute (in this mod's assembly) applied to that type,
        /// or null if none is present.</returns>
        internal static ModInfoAttribute GetModInfoAttribute(Type optionsType)
        {
            if (optionsType == null)
            {
                throw new ArgumentNullException("optionsType");
            }
            ModInfoAttribute newAttr = null;

            foreach (var attr in optionsType.GetCustomAttributes(true))
            {
                // Cross mod types need reflection
                if ((newAttr = ModInfoAttribute.CreateFrom(attr)) != null)
                {
                    break;
                }
            }
            return(newAttr);
        }