public override List <byte> ReadBytes(string path) { if (!this.fileBytes.ContainsKey(path)) { if (!this.rawFileMetadata.ContainsKey(path)) { return(null); } FileOutput file = this.rawFileMetadata[path]; this.fileBytes[path] = new List <byte>(file.GetFinalBinaryContent()); } return(this.fileBytes[path]); }
public override void ExportProject( Dictionary <string, FileOutput> output, BuildData buildData, ExportProperties exportProperties) { List <string> jsExtraHead = new List <string>() { exportProperties.JsHeadExtras ?? "" }; if (exportProperties.JsFullPage) { jsExtraHead.Add( "<script type=\"text/javascript\">" + "C$common$globalOptions['fullscreen'] = true;" + "</script>"); } if (buildData.UsesU3) { Dictionary <string, FileOutput> u3Files = new Dictionary <string, FileOutput>(); foreach (string file in noriFiles) { this.CopyResourceAsText(u3Files, file, "ResourcesU3/" + file, new Dictionary <string, string>()); } List <string> newFile = new List <string>(); foreach (string file in noriFiles) { newFile.Add("// From " + file); newFile.Add(u3Files[file].TextContent.Trim()); } output["u3.js"] = new FileOutput() { Type = FileOutputType.Text, TextContent = string.Join("\n", newFile), }; jsExtraHead.Add("<script src=\"u3.js\"></script>"); } exportProperties.JsHeadExtras = string.Join("\n", jsExtraHead); ResourceDatabase resDb = buildData.CbxBundle.ResourceDB; Dictionary <string, string> replacements = this.GenerateReplacementDictionary(exportProperties, buildData); TemplateReader templateReader = new TemplateReader(new PkgAwareFileUtil(), this, null); TemplateSet vmTemplates = templateReader.GetVmTemplates(); output["vm.js"] = new FileOutput() { Type = FileOutputType.Text, TextContent = vmTemplates.GetText("vm.js"), }; Dictionary <string, string> htmlReplacements = new Dictionary <string, string>(replacements); this.CopyResourceAsText(output, "index.html", "Resources/HostHtml.txt", replacements); this.CopyResourceAsText(output, "test_server.py", "Resources/TestServerPy.txt", replacements); this.CopyResourceAsText(output, "common.js", "Resources/Common.txt", replacements); System.Text.StringBuilder resourcesJs = new System.Text.StringBuilder(); string[] fileNames = resDb.FlatFileNames; FileOutput[] files = resDb.FlatFiles; for (int i = 0; i < files.Length; i++) { FileOutput file = files[i]; string name = fileNames[i]; if (file.Type == FileOutputType.Text) { resourcesJs.Append("C$common$addTextRes("); resourcesJs.Append(ConvertStringValueToCode(name)); resourcesJs.Append(", "); resourcesJs.Append(ConvertStringValueToCode(file.TextContent)); resourcesJs.Append(");\n"); } else if (name.EndsWith(".png") || name.EndsWith(".jpg")) { output["resources/" + name] = file; } else if (name.EndsWith(".wav") || name.EndsWith(".ogg") || name.EndsWith(".mp3")) { output["resources/" + name] = file; } else { resourcesJs.Append("C$common$addBinaryRes("); resourcesJs.Append(ConvertStringValueToCode(name)); resourcesJs.Append(", '"); resourcesJs.Append(System.Convert.ToBase64String(file.GetFinalBinaryContent())); resourcesJs.Append("');\n"); } } resourcesJs.Append("C$common$resourceManifest = "); resourcesJs.Append(ConvertStringValueToCode(resDb.ResourceManifestFile.TextContent)); resourcesJs.Append(";\n"); string filePrefix = exportProperties.JsFilePrefix; if (filePrefix != null) { resourcesJs.Append("C$common$jsFilePrefix = "); resourcesJs.Append(ConvertStringValueToCode(filePrefix)); resourcesJs.Append(";\n"); } string imageManifest = resDb.ImageResourceManifestFile.TextContent; imageManifest = ConvertStringValueToCode(imageManifest); resourcesJs.Append("C$common$imageManifest = " + imageManifest + ";\n"); output["resources.js"] = new FileOutput() { Type = FileOutputType.Text, TextContent = resourcesJs.ToString(), }; output["bytecode.js"] = new FileOutput() { Type = FileOutputType.Text, TextContent = "C$bytecode = " + ConvertStringValueToCode(buildData.CbxBundle.ByteCode) + ";", }; if (exportProperties.HasIcon) { this.GenerateIconFile(output, "favicon.ico", exportProperties); } // TODO: minify JavaScript across all of output dictionary }