private UrlDir(UrlDir root, ConfigDirectory rootInfo) { string path = UrlDir.CreateKSPPath(rootInfo.directory); DirectoryInfo info = Directory.CreateDirectory(path); this._name = rootInfo.urlRoot; this._type = rootInfo.type; this.Create(root, info); }
private UrlConfig GetConfig(UrlIdentifier id, int index) { if (index == id.UrlDepth) { int count = this._files.Count; for (int i = 0; i < count; i++) { UrlFile urlFile = this._files[i]; if (urlFile.Type == UrlFile.FileType.Config) { if (urlFile.ContainsConfig(id[index])) { return(urlFile.GetConfig(id[index])); } } } } else { int count2 = this._children.Count; for (int j = 0; j < count2; j++) { UrlDir urlDir = this._children[j]; if (urlDir.Name != string.Empty) { if (id[index] == urlDir.Name) { return(urlDir.GetConfig(id, index + 1)); } } else { UrlConfig config = urlDir.GetConfig(id, index); if (config != null) { return(config); } } } int count3 = this._files.Count; for (int k = 0; k < count3; k++) { UrlFile urlFile2 = this._files[k]; if (urlFile2.Type == UrlFile.FileType.Config) { if (id[index] == urlFile2.Name) { return(urlFile2.GetConfig(id[index + 1])); } } } } return(null); }
public ConfigNode[] GetConfigNodes(string baseUrl, string typeName) { List <ConfigNode> list = new List <ConfigNode>(); UrlDir directory = this._root.GetDirectory(baseUrl); if (directory == null) { return(list.ToArray()); } foreach (UrlConfig urlConfig in directory.GetConfigs(typeName, true)) { list.Add(urlConfig.Config); } return(list.ToArray()); }
public static List <UrlConfig> CreateNodeList(UrlDir parentDir, UrlFile parent) { ConfigNode configNode = ConfigNode.Load(parent.FullPath); if (configNode == null) { Debug.LogWarning("Cannot create config from file '" + parent.FullPath + "'."); return(new List <UrlConfig>()); } if (!configNode.HasData()) { Debug.LogWarning("Config in file '" + parent.FullPath + "' contains no data."); return(new List <UrlConfig>()); } List <UrlConfig> list = new List <UrlConfig>(); if (configNode.HasValue()) { if (parentDir.Type == UrlDir.DirectoryType.Parts) { configNode.name = "PART"; list.Add(new UrlConfig(parent, configNode)); return(list); } } int count = configNode.Nodes.Count; for (int i = 0; i < count; i++) { ConfigNode configNode2 = configNode.Nodes[i]; if (configNode2.name == string.Empty) { if (parentDir.Type == UrlDir.DirectoryType.Parts) { configNode2.name = "PARTS"; } else { Debug.LogWarning("Config in file '" + parent.FullPath + "' contains an unnamed node. Skipping."); continue; } } list.Add(new UrlConfig(parent, configNode2)); } return(list); }
public UrlDir(ConfigDirectory[] dirConfig, ConfigFileType[] fileConfig) { this._files = new List <UrlFile>(); this._children = new List <UrlDir>(); this._parent = null; this._root = this; this._name = "root"; int num = dirConfig.Length; for (int i = 0; i < num; i++) { this._children.Add(new UrlDir(this, dirConfig[i])); } foreach (UrlFile file in this.GetFiles()) { file.ConfigureFile(fileConfig); } }
public UrlFile(UrlDir parent, FileInfo info) { this._name = Path.GetFileNameWithoutExtension(info.Name); this._fullPath = info.FullName; this._extension = Path.GetExtension(info.Name); this._fileTime = info.LastWriteTime; if (this._extension.Length > 1) { this._extension = this._extension.Substring(1); } this._parent = parent; this._root = parent.Root; if (this._extension == "cfg") { this._type = UrlFile.FileType.Config; this._configs = UrlConfig.CreateNodeList(parent, this); } else { this._type = UrlFile.FileType.Unknown; this._configs = new List <UrlConfig>(); } }
public void LoadGameDatabase(string kspPath) { if (!UrlDir.IsValidKSPPath(kspPath)) { Debug.LogError("Invalid KSP root path! Abording game database load."); return; } GameDatabase._KSPRootPath = kspPath; this.Reset(); this._root = new UrlDir(this._configDirectories.ToArray(), new ConfigFileType[0]); UrlDir data = this._root.GetDirectory("data"); foreach (UrlDir dir in data.GetDirectories(false)) { Debug.Log(string.Concat(new object[] { "Mod '", dir.Name, "' found with ", dir.GetConfigFiles().Length, " config files" })); } }
private UrlDir(UrlDir parent, DirectoryInfo info) { this._name = info.Name; this._type = parent.Type; this.Create(parent, info); }