using System; using System.Collections.Generic; using System.IO; using System.Xml; namespace EDPlayerJournal; public class HumanReadableMissionName { private static Dictionary? humanreadable = null; private static void LoadMissions() { try { string dir = AppDomain.CurrentDomain.BaseDirectory; string file = Path.Combine(dir, "MissionNames.xml"); XmlDocument document = new XmlDocument(); using (FileStream stream = new FileStream(file, FileMode.Open)) { document.Load(stream); XmlNode? missions = document.DocumentElement; if (missions == null || missions.Name != "Missions" || missions.ChildNodes == null) { throw new ApplicationException("Invalid XML"); } humanreadable = new Dictionary(); foreach (XmlNode mission in missions.ChildNodes) { if (mission.Attributes == null) { continue; } string? mission_key = mission.Attributes["Name"]?.Value; string? mission_name = mission.InnerText; if (mission_key == null || mission_name == null) { continue; } humanreadable.Add(mission_key, mission_name); } } } catch (Exception) { humanreadable = null; } } public static string? MakeHumanReadableName(string name) { LoadMissions(); if (humanreadable == null || name == null) { return null; } if (humanreadable.ContainsKey(name)) { return humanreadable[name]; } return null; } }