/// <summary> /// Exports the mission briefing to an HTML or image file. /// </summary> /// <param name="fileFormat">The file format to export to.</param> private void ExportBriefing(BriefingExportFileFormat fileFormat) { if (Mission == null) { return; // No mission has been generated, nothing to export. } string defaultFileName = HQTools.RemoveInvalidFileNameCharacters(Mission.BriefingName ?? ""); if (string.IsNullOrEmpty(defaultFileName)) { defaultFileName = "NewMission"; } string briefingFilePath = GUITools.ShowSaveFileDialog( fileFormat.ToString().ToLowerInvariant(), HQTools.GetDCSMissionPath(), defaultFileName, $"{fileFormat.ToString().ToUpperInvariant()} files"); if (briefingFilePath == null) { return; } bool result; using (HTMLExporter briefingExporter = new HTMLExporter()) { switch (fileFormat) { default: return; case BriefingExportFileFormat.Html: result = briefingExporter.ExportToHTML(briefingFilePath, Mission.BriefingHTML); break; case BriefingExportFileFormat.Jpg: result = briefingExporter.ExportToJPEG(briefingFilePath, Mission.BriefingHTML); break; case BriefingExportFileFormat.Png: result = briefingExporter.ExportToPNG(briefingFilePath, Mission.BriefingHTML); break; } } if (!result) { MessageBox.Show("Failed to export briefing", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// Creates all custom kneeboard images and returns them as a dictionary of byte arrays. /// </summary> /// <param name="mission">An HQ4DCS mission.</param> /// <returns>A dictionary of entries to include the .miz file. Key is the entry name, value is an array holding the bytes of the entry.</returns> public Dictionary <string, byte[]> MakeKneeboardImages(DCSMission mission) { Dictionary <string, byte[]> kneeboardImages = new Dictionary <string, byte[]>(); DebugLog.Instance.Log($"Adding kneeboard images..."); Image kneeboardImage = null; using (HTMLExporter htmlExporter = new HTMLExporter()) { kneeboardImage = htmlExporter.ExportToImage(mission.BriefingHTML); } if (kneeboardImage == null) { return(kneeboardImages); // Failed to generate an image, abort } // TODO: format is wrong - should be 768x1024 // TODO: briefing should be split in multiple pages to make sure even long briefings are readable foreach (string acType in mission.UsedPlayerAircraftTypes) { kneeboardImages.Add($"KNEEBOARD/{acType}/IMAGES/01.png", HQTools.ImageToBytes(kneeboardImage, ImageFormat.Png)); } return(kneeboardImages); }
private static int Main(string[] args) { int retValue = -1; try { SetupStaticLogger(); ChatHistory chatConversations = null; var convCounter = 0; retValue = ParseArgs(args); if (retValue != 0) { return(retValue); } var inFile = new FileInfo(jsonPath); var inDir = inFile.Directory; if (!inDir.Exists) { Log.Warning($"The directory specified does not exist. The program cannot continue: {inDir.FullName}"); return(1); } else if (!inFile.Exists) { Log.Warning($"The file specified does not exist. The program cannot continue: {inDir.FullName}"); return(1); } Log.Information($"Attempting to read {jsonPath}. This may take a few minutes."); var regex = new Regex(@"^ROOT.conversations\[\d+\].conversation$"); using (FileStream s = File.Open(jsonPath, FileMode.Open)) using (StreamReader sr = new StreamReader(s)) using (JsonReader reader = new JsonTextReader(sr)) { reader.SupportMultipleContent = true; var serializer = new JsonSerializer(); while (reader.Read()) { if (reader.TokenType == JsonToken.StartObject) { convCounter++; chatConversations = serializer.Deserialize <ChatHistory>(reader); Log.Information($"Found {chatConversations?.conversations?.Length} conversations to process"); } } } DirectoryInfo outputDir = new DirectoryInfo($".{Path.DirectorySeparatorChar}Output"); IFormatExporter exporter = new HTMLExporter(); exporter.Generate(chatConversations, outputDir); return(retValue); } catch (Exception ex) { Log.Error(ex, $"An unhandled exception has occurred. Details follow."); return(-1); } finally { Log.CloseAndFlush(); Console.WriteLine("Press any key to continue"); Console.ReadKey(); } }
public void ExportToHtml(string title, Dictionary <string, List <IExportableToHtml> > data, string outFilePath) { HTMLExporter.Export(title, data, outFilePath); }