58 lines
1.8 KiB
C#
58 lines
1.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Xml;
|
|
|
|
namespace EDJournal {
|
|
public class HumanReadableMissionName {
|
|
private static Dictionary<string, string> 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") {
|
|
throw new ApplicationException("Invalid XML");
|
|
}
|
|
|
|
humanreadable = new Dictionary<string, string>();
|
|
|
|
foreach (XmlNode mission in missions.ChildNodes) {
|
|
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;
|
|
}
|
|
}
|
|
}
|