public void AddContent(AddonContent content) { if (this.Contents.ContainsKey(content.File)) { Diagnostic.Warning("File {0} was already in contents of addon {1}", content.File, this.Name); return; } this.Contents.Add(content.File, content); }
private static void AssembleContentRecursive(CompileContext context, AddonEntry addon, AddonContent currentContent) { foreach (AddonContent subContent in currentContent.SubContent) { AssembleContentRecursive(context, addon, subContent); } CarbonFile absoluteFile = currentContent.RootDirectory.ToFile(currentContent.File); if (!absoluteFile.Exists) { Diagnostic.Warning("Content File {0} does not exist! ({1})", absoluteFile, currentContent.File); return; } var content = new CompileContent(addon, absoluteFile, absoluteFile.ToRelative<CarbonFile>(context.Source.ToDirectory(addon.Name))); using (var stream = absoluteFile.OpenRead()) { byte[] md5 = HashUtils.GetMd5(stream); content.Md5 = HashUtils.Md5ToString(md5); } context.FullContentList.Add(content); }
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; } }