private static void SaveConfigs( string prefix, bool isPatch = true, string extension = ".cfg", bool force = false ) { var node = new ConfigNode(); var save = new SaveVisitor { IsPatch = isPatch, Node = node }; foreach (KeyValuePair <string, ReflectedConfig> pair in ConfigReflection.Instance.Configs) { if (!pair.Value.Reflection.ShouldSave) { continue; } pair.Value.Reflection.Save(save, pair.Value.Instance); if (!save.Node.HasData) { continue; } string path = PathUtil.Combine(KSPUtils.GameDataPath, $"{prefix}_{pair.Key}{extension}"); if (!pair.Value.Reflection.AllowMultiple) { Serialization.MakeTopNode(node, pair.Key, null, isPatch); } string nodeStr = node.ToString(); if (lastConfigs.TryGetValue(pair.Key, out string oldStr)) { lastConfigs[pair.Key] = nodeStr; } else { lastConfigs.Add(pair.Key, nodeStr); } // only write if requested or if the node has been modified, first time oldStr should be null so can be skipped if (force || (!string.IsNullOrEmpty(oldStr) && nodeStr != oldStr)) { FARLogger.DebugFormat("Saving {0} config to {1}:\n{2}\n\n{3}", pair.Key, path, oldStr, nodeStr); System.IO.File.WriteAllText(path, nodeStr); } else { FARLogger.DebugFormat("{0} does not require saving", pair.Key); } node.ClearData(); } }
public static string CombineGameData(string dir1, string dir2, string filename) { return(PathUtil.Combine(GameDataPath, dir1, dir2, filename)); }
public static string CombineKSPRoot(string dir1, string dir2, string filename) { return(PathUtil.Combine(KSPRootPath, dir1, dir2, filename)); }