// ------------------------------------------------------------------- // Protected // ------------------------------------------------------------------- protected override void DoProcess(CarbonFile source) { string relativeRootPath = source.GetDirectory().GetPath().Replace(this.GetContext<JavaScriptBuildingContext>().Root.GetPath(), string.Empty); string fileName = source.FileName; string fileNameId = this.BuildPathId(relativeRootPath + source.FileNameWithoutExtension); string rootPathId = this.BuildPathId(relativeRootPath, true); this.GetContext<JavaScriptBuildingContext>().Cache.RegisterImage(fileNameId, $@"staticData.imageRoot{rootPathId} + ""{fileName}"""); }
public override Stream BeginWrite(CarbonFile file) { CarbonFile fullFile = this.Root.ToFile(file); fullFile.GetDirectory().Create(); var stream = fullFile.OpenCreate(); this.openStreams.Add(stream); return(stream); }
// ------------------------------------------------------------------- // Constructor // ------------------------------------------------------------------- public DBFileProvider(CarbonFile file) { if (!file.Exists) { // Ensure the directory exists file.GetDirectory().Create(); } this.database = new LiteDatabase(file.GetPath()); this.openStreams = new List <LiteFileStream>(); }
// ------------------------------------------------------------------- // Constructor // ------------------------------------------------------------------- public AddonEntry(CarbonFile tocFile) { this.Name = tocFile.FileNameWithoutExtension; this.TocFile = tocFile; this.RootDirectory = tocFile.GetDirectory(); this.Meta = new Dictionary<string, string>(); this.Contents = new Dictionary<CarbonFile, AddonContent>(); this.Resources = new List<CarbonFile>(); this.Dependencies = new List<AddonEntry>(); }
private static bool WriteXmlContentToTarget(CarbonFile source, CarbonFile target) { bool isEmpty = true; XmlDocument document = AddonXmlUtils.ReadAddonXml(source); XmlNode root = document.DocumentElement; IList<XmlNode> deleteList = new List<XmlNode>(); foreach (XmlNode childNode in root.ChildNodes) { if (childNode.Name.Equals(Constants.XmlNodeScript, StringComparison.OrdinalIgnoreCase) || childNode.Name.Equals(Constants.XmlNodeInclude, StringComparison.OrdinalIgnoreCase) || childNode.NodeType == XmlNodeType.Comment) { deleteList.Add(childNode); continue; } isEmpty = false; } if (isEmpty) { return false; } foreach (XmlNode node in deleteList) { root.RemoveChild(node); } target.GetDirectory().Create(); document.Save(target.GetPath()); return true; }
// ------------------------------------------------------------------- // Private // ------------------------------------------------------------------- private void TranslateFile(TempProject project, CarbonFile sourceFile, CarbonFile targetFile) { Diagnostic.RegisterThread("Translate." + sourceFile.FileName); CarbonDirectory targetRelativeSubDir = targetFile.GetDirectory() ?? new CarbonDirectory(string.Empty); CarbonDirectory fullTargetPath = this.targetDirectory.ToDirectory(this.config.Current.IntermediateSubDirectory, targetRelativeSubDir); CarbonFile fullTargetFile = fullTargetPath.ToFile(targetFile.FileName + TempExtension); CarbonFile relativeTargetFile = this.config.Current.IntermediateSubDirectory.ToDirectory(targetRelativeSubDir).ToFile(targetFile.FileName + TempExtension); if (this.config.Current.Verbose) { System.Diagnostics.Trace.TraceInformation("Translating {0} -> {1}", sourceFile, fullTargetFile); } IList<Token> tokens = this.TokenizeFile(sourceFile); if (tokens == null) { throw new InvalidDataException(); } project.AddStat(TempProjectStat.Files); project.AddStat(TempProjectStat.Tokens, tokens.Count); var fileEntry = new TempProjectFileEntry { IsCompressed = this.config.Current.CompressIntermediate, RelativeFile = new CarbonFile(targetFile.FileName), RelativePath = targetFile.GetDirectory(), File = relativeTargetFile, }; var data = new TranslationData(tokens) { ProjectData = project, SourceFile = sourceFile, TargetFile = fullTargetFile, FileEntry = fileEntry }; // Register the file entry into the project project.AddFile(fileEntry); try { TempFileFull file = this.TranslateToTempFile(data); this.SaveTempFile(data, file); } catch (Exception e) { System.Diagnostics.Trace.TraceError("Failed to translate {0}: {1}", fileEntry.File, e); this.SaveTempFile(data, new TempFileFull() { Name = data.TargetFile.FileName }); } Diagnostic.UnregisterThread(); }
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; } }