private static void Main(string[] args) { if (args.Length != 1) { ShowUsageInfo(); return; } string path = args[0]; if (File.Exists(path) == false) { ShowUsageInfo(); return; } string extension = Path.GetExtension(path); if (String.Equals(extension, ".xml", StringComparison.OrdinalIgnoreCase)) { using (FileStream inputStream = new FileStream(path, FileMode.Open)) using (StreamReader xmlReader = new StreamReader(inputStream, Encoding.UTF8)) using (FileStream outputStream = new FileStream(path.Substring(0, path.Length - 4), FileMode.Create)) { XmlSerializer serializer = new XmlSerializer(typeof(LangFile)); LangFile file = serializer.Deserialize(xmlReader) as LangFile; if (file == null) { Console.WriteLine("XML was not not a valid LangFile"); return; } file.Write(outputStream); } } else if (String.Equals(extension, ".lng", StringComparison.OrdinalIgnoreCase) || String.Equals(extension, ".lng2", StringComparison.OrdinalIgnoreCase)) { var dictionary = GetDictionary(DefaultDictionaryPath); using (FileStream inputStream = new FileStream(path, FileMode.Open)) using (FileStream outputStream = new FileStream(path + ".xml", FileMode.Create)) using (StreamWriter xmlWriter = new StreamWriter(outputStream, Encoding.UTF8)) { LangFile file = LangFile.ReadLangFile(inputStream, dictionary); XmlSerializer serializer = new XmlSerializer(typeof(LangFile)); serializer.Serialize(xmlWriter, file); } } else { ShowUsageInfo(); } }
private static void Main(string[] args) { if (args.Length != 1) { ShowUsageInfo(); return; } string path = args[0]; if (File.Exists(path) == false) { ShowUsageInfo(); return; } string extension = Path.GetExtension(path); if (extension == ".xml") { using (FileStream inputStream = new FileStream(path, FileMode.Open)) using (StreamReader xmlReader = new StreamReader(inputStream, Encoding.UTF8)) using (FileStream outputStream = new FileStream(path.Substring(0, path.Length - 4), FileMode.Create)) { XmlSerializer serializer = new XmlSerializer(typeof(LangFile)); LangFile file = serializer.Deserialize(xmlReader) as LangFile; if (file == null) { Console.WriteLine("XML was not not a valid LangFile"); return; } file.Write(outputStream); } } else if (Regex.Match(extension, @"^\.lng#\w{3}$", RegexOptions.IgnoreCase).Success) { using (FileStream inputStream = new FileStream(path, FileMode.Open)) using (FileStream outputStream = new FileStream(path + ".xml", FileMode.Create)) using (StreamWriter xmlWriter = new StreamWriter(outputStream, Encoding.UTF8)) { LangFile file = LangFile.ReadLangFile(inputStream); XmlSerializer serializer = new XmlSerializer(typeof(LangFile)); serializer.Serialize(xmlWriter, file); } } else { ShowUsageInfo(); } }
private static void Main(string[] args) { if (args.Length == 0 || args.Length > 3) { ShowUsageInfo(); return; } string path = args[0]; bool outputHashes = false; string dictionaryPath = DefaultDictionaryPath; if (args.Length > 1) { for (int i = 1; i < args.Length; i++) { string arg = args[i]; string argL = args[i].ToLower(); if (argL == "-outputhashes" || argL == "-o") { outputHashes = true; } else { if (argL == "-dictionary" || argL == "-d") { if (i + 1 < args.Length) { dictionaryPath = args[i + 1]; } } } } } if (File.Exists(path) == false) { ShowUsageInfo(); return; } string extension = Path.GetExtension(path); if (String.Equals(extension, ".xml", StringComparison.OrdinalIgnoreCase)) { using (FileStream inputStream = new FileStream(path, FileMode.Open)) using (StreamReader xmlReader = new StreamReader(inputStream, Encoding.UTF8)) using (FileStream outputStream = new FileStream(path.Substring(0, path.Length - 4), FileMode.Create)) { XmlSerializer serializer = new XmlSerializer(typeof(LangFile)); LangFile file = serializer.Deserialize(xmlReader) as LangFile; if (file == null) { Console.WriteLine("XML was not not a valid LangFile"); return; } file.Write(outputStream); } } else if (String.Equals(extension, ".lng", StringComparison.OrdinalIgnoreCase) || String.Equals(extension, ".lng2", StringComparison.OrdinalIgnoreCase)) { var dictionary = GetDictionary(dictionaryPath); using (FileStream inputStream = new FileStream(path, FileMode.Open)) using (FileStream outputStream = new FileStream(path + ".xml", FileMode.Create)) using (StreamWriter xmlWriter = new StreamWriter(outputStream, Encoding.UTF8)) { LangFile file = LangFile.ReadLangFile(inputStream, dictionary); XmlSerializer serializer = new XmlSerializer(typeof(LangFile)); serializer.Serialize(xmlWriter, file); if (outputHashes) { HashSet <string> uniqueHashes = new HashSet <string>(); foreach (LangEntry entry in file.Entries) { ulong langIdHash = entry.Key; uniqueHashes.Add(langIdHash.ToString("x")); } List <string> hashes = uniqueHashes.ToList <string>(); hashes.Sort(); string fileDirectory = Path.GetDirectoryName(path); string hashesOutputPath = Path.Combine(fileDirectory, string.Format("{0}_langIdHashes.txt", Path.GetFileName(path))); File.WriteAllLines(hashesOutputPath, hashes.ToArray <string>()); } } } else { ShowUsageInfo(); } }