public void Save(CarbonDirectory path) { path.Create(); CarbonFile target = path.ToFile(FileGeneric); JsonExtensions.SaveToFile(target, this.Generic, false, Formatting.Indented); foreach (D3Class @class in this.classes) { CarbonFile classTarget = path.ToFile(@class.Name + ExtensionClass); JsonExtensions.SaveToFile(classTarget, @class, false, Formatting.Indented); } }
private bool LoadFromPath(CarbonDirectory path) { this.ClearData(); this.Generic = JsonExtensions.LoadFromFile<D3Generic>(path.ToFile(FileGeneric), false); CarbonFileResult[] files = path.GetFiles("*" + ExtensionClass); foreach (CarbonFileResult file in files) { try { var @class = JsonExtensions.LoadFromFile<D3Class>(file.Absolute, false); this.classes.Add(@class); } catch (Exception e) { Diagnostic.Error("Could not load class definition from {0}: {1}", file, e); return false; } } return true; }
private static AddonContent ReadXMLContent(CarbonFile file, CarbonDirectory rootDirectory) { CarbonFile absoluteFile = rootDirectory.ToFile(file); if (!absoluteFile.Exists) { Diagnostic.Warning("Could not find content file {0}", absoluteFile); return null; } try { var result = new AddonContent(file, rootDirectory); XmlDocument document = AddonXmlUtils.ReadAddonXml(absoluteFile); XmlNode root = document.DocumentElement; foreach (XmlNode node in root.ChildNodes) { if (node.Name.Equals(Constants.XmlNodeScript, StringComparison.OrdinalIgnoreCase)) { string nestedContent = node.Attributes[Constants.XmlScriptFileAttribute].Value; CarbonDirectory nestedRoot = file.GetDirectory() == null ? rootDirectory : rootDirectory.ToDirectory(file.GetDirectory()); result.SubContent.Add(new AddonContent(new CarbonFile(nestedContent), nestedRoot)); continue; } if (node.Name.Equals(Constants.XmlNodeInclude, StringComparison.OrdinalIgnoreCase)) { string nestedContent = node.Attributes[Constants.XmlIncludeFileAttribute].Value; CarbonFile nestedContentFile = new CarbonFile(nestedContent.Trim()); if (nestedContentFile.Extension == Constants.ExtensionLua) { CarbonDirectory nestedRoot = file.GetDirectory() == null ? rootDirectory : rootDirectory.ToDirectory(file.GetDirectory()); result.SubContent.Add(new AddonContent(nestedContentFile, nestedRoot)); continue; } AddonContent nestedEntry = ReadXMLContent( new CarbonFile(nestedContent), absoluteFile.GetDirectory()); if (nestedEntry != null) { result.SubContent.Add(nestedEntry); } } } return result; } catch (Exception e) { Diagnostic.Error("Could not read content XML {0}\n{1}", file, e); return null; } }