Пример #1
0
        /// <summary>
        /// Patches the part configs so that they refer the tags for the localizable fileds, and saves the
        /// modified fiels in the export location.
        /// </summary>
        /// <remarks></remarks>
        /// <param name="parts">The parts to patch.</param>
        void GuiExportPartConfigs(IEnumerable <PartsRecord> parts)
        {
            var exportParts = parts.SelectMany(x => x.parts);
            var exportPath  = KspPaths.GetModsDataFilePath(this, "Parts/");

            foreach (var part in exportParts)
            {
                var config = ConfigStore.LoadConfigWithComments(
                    part.configFileFullName, localizeValues: false);
                if (config == null)
                {
                    Debug.LogErrorFormat(
                        "Cannot load config file for part {0}: {1}", part.name, part.configFileFullName);
                    continue;
                }
                var partNode = config.GetNode("PART");
                foreach (var fieldName in Extractor.localizablePartFields)
                {
                    var field = partNode.values.Cast <ConfigNode.Value>()
                                .FirstOrDefault(x => x.name == fieldName);
                    if (field == null)
                    {
                        Debug.LogWarningFormat("Field '{0}' is not found in the part {1} config",
                                               fieldName, part.name);
                        continue;
                    }
                    if (field.value.StartsWith("#", StringComparison.Ordinal))
                    {
                        continue; // It's already localized.
                    }
                    var locTag = Extractor.MakePartFieldLocalizationTag(part.name, fieldName);
                    field.comment = locTag + " = " + field.value;
                    field.value   = locTag;
                }

                var tgtPath = exportPath + part.name.Replace(".", "_") + ".cfg";
                Debug.LogWarningFormat("Saving patched part config into: {0}", tgtPath);
                ConfigStore.SaveConfigWithComments(config, tgtPath);
            }
            ShowCompletionDialog(
                ConfigSavedDlgTitle,
                ConfigsSavedInFolderTxt.Format(exportParts.Count(), exportPath));
        }