/// <summary> /// Saves the given <paramref name="stringFile"/> to an xml file formated as "strings_<paramref name="language"/>.xml" /// in the specified <paramref name="directory"/>. /// </summary> /// <param name="stringFile">The <see cref="StringFile"/> to save.</param> /// <param name="directory">The directory to save the <paramref name="stringFile"/> to.</param> /// <param name="language">The language of the <see cref="StringFile"/>.</param> /// <returns>Whether the <see cref="StringFile"/> was saved.</returns> private static bool SaveStrings(StringFile stringFile, string directory, string language) { string filename = "strings_" + language + ".xml"; string path = Path.Combine(directory, filename); /// Make a backup of the current languagefile. if (File.Exists(path + ".bak")) { File.Delete(path + ".bak"); } if (File.Exists(path)) { File.Move(path, path + ".bak"); } /// Serialize the StringFile try { XmlSerializer s = new XmlSerializer(typeof(StringFile)); XmlSerializerNamespaces ns = new XmlSerializerNamespaces(); ns.Add("", ""); using (XmlTextWriter writer = new XmlTextWriter(new StreamWriter(path))) { writer.Formatting = Formatting.Indented; s.Serialize(writer, stringFile, ns); } return(true); } catch (Exception) { return(false); } }
public static void ReadDatabase(StringFile StringFile, string ConnectionString) { SQLiteConnection Connection = new SQLiteConnection(ConnectionString); Connection.Open(); StringFile.Strings = new List <bscrString>(); using (SQLiteTransaction Transaction = Connection.BeginTransaction()) using (SQLiteCommand Command = new SQLiteCommand(Connection)) { Command.CommandText = "SELECT english, PointerRef FROM Text ORDER BY PointerRef"; SQLiteDataReader r = Command.ExecuteReader(); while (r.Read()) { String SQLText; try { SQLText = r.GetString(0).Replace("''", "'"); } catch (System.InvalidCastException) { SQLText = ""; } int PointerRef = r.GetInt32(1); bscrString b = new bscrString(); b.Position = (uint)PointerRef; b.String = SQLText; StringFile.Strings.Add(b); } Transaction.Rollback(); } return; }
public void CanInvokeFileAction() { // Arrange Resource project = GetSharedProject(); var args = new { Title = "New issue", Description = "Blah ...", Severity = 5, Attachment = new { Title = "Att", Description = "Blah blah" } }; var attachment = new StringFile { ContentType = "text/plain", Filename = "test.txt", Data = "1234" }; var files = new { attachment = attachment }; using (var resp = project.Controls[MasonTestConstants.Rels.IssueAdd].Upload <Resource>(Session, args, files)) { dynamic result = resp.Created(); Assert.AreEqual("New issue", result.Title); Assert.AreEqual(5, result.Severity); Assert.IsNotNull(result.Attachments); Assert.AreEqual(1, result.Attachments.Count); } }
private void LoadDefaultStrings() { _strings = new LocalisationStrings(_stringPath); _defaultStrings = LoadStrings(_stringPath, "en"); // Get Available language list _languageList = new List <LanguageInfo>(); foreach (CultureInfo language in _strings.GetAvailableLanguages()) { if (language.Name != "en") { LanguageInfo langInfo = new LanguageInfo(language); _languageList.Add(langInfo); } } DrawLanguageList(null); // Build section trees treeSections.Nodes.Clear(); tvSections.Nodes.Clear(); foreach (StringSection section in _defaultStrings.Sections) { treeSections.Nodes.Add(section.SectionName); tvSections.Nodes.Add(section.SectionName); } }
/// <summary> /// Tries to load all language files for the <paramref name="culture2Load"/> in the specified /// <paramref name="directory"/>. /// </summary> /// <remarks> /// The language for a culture can be split up into more than one file: We search the language for /// the parent culture (if present), then the more specific region language. /// If a language string is already present in the internal dictionary, it will be overwritten by /// the new string. /// </remarks> /// <param name="directory">Directory to load from.</param> /// <param name="culture2Load">Culture for that the language resource file will be searched.</param> protected void TryAddLanguageFile(string directory, CultureInfo culture2Load) { string fileName = string.Format("strings_{0}.xml", culture2Load.Name); string filePath = Path.Combine(directory, fileName); if (!File.Exists(filePath)) { return; } try { XmlSerializer s = new XmlSerializer(typeof(StringFile)); Encoding encoding = Encoding.UTF8; using (TextReader r = new StreamReader(filePath, encoding)) { StringFile resources = (StringFile)s.Deserialize(r); foreach (StringLocalized languageString in resources.Strings) { _languageStrings[languageString.StringName] = PrepareAndroidFormat(languageString.Text); } } } catch (Exception ex) { ServiceRegistration.Get <ILogger>().Warn("Failed to load language resource file '{0}'", ex, filePath); } }
private void btnNewStrings_Click(object sender, EventArgs e) { _defaultStrings = new StringFile(); _defaultStrings._sections = new List <StringSection>(); _defaultStrings._languageName = "en"; tabsModes.Controls[(int)Tabs.Create].Enabled = true; tabsModes.SelectedIndex = (int)Tabs.Create; }
public override bool ParseFromData() { if (!base.ParseFromData()) { return(false); } SetReadFloatForwardBy(1); STFFile = new StringFile().Deserialize(this); CustomName = ReadString(Encoding.UTF8); Volume = ReadInt32(); GuildIds = ReadList(() => ReadString(Encoding.ASCII)); return(true); }
public static void Load() { if (ResourceManager.FileExists("unityallods.cfg")) { StringFile sf = new StringFile("unityallods.cfg"); foreach (string cmd in sf.Strings) { GameConsole.Instance.ExecuteCommand(cmd); } } else { Save(); } }
private void btnNew_Click(object sender, EventArgs e) { if (CheckSave()) { NewLanguageDialog newlanguage = new NewLanguageDialog(_languageList); if (newlanguage.ShowDialog() == DialogResult.OK) { _languageList.Add(newlanguage.Selected); DrawLanguageList(newlanguage.Selected.Name); _targetStrings = new StringFile(); _targetStrings._languageName = newlanguage.Selected.Name; _targetStrings._sections = new List <StringSection>(); cbLanguages_SelectedIndexChanged(this, new EventArgs()); } } }
private static bool CheckServerConfig() { if (ResourceManager.FileExists("server.cfg")) { StringFile sf = new StringFile("server.cfg"); // execute all commands from there foreach (string cmd in sf.Strings) { Debug.Log(cmd); GameConsole.Instance.ExecuteCommand(cmd); } return(true); } return(false); }
public override Request Bind(ISession session, object args, object files) { var payload = new Dictionary <string, object>(); string jsonArgs = SerializeArgsToJson(args); payload[JsonFile] = new StringFile { ContentType = "application/json", Data = jsonArgs, Filename = "args" }; JsonFilesPropertiesVisitor v = new JsonFilesPropertiesVisitor(payload); ObjectSerializer serializer = new ObjectSerializer(files.GetType()); // FIXME: null check serializer.Serialize(files, v); return(session.Bind(HRef).Method(Method).AsMultipartFormData().Body(payload)); }
public static int Export(List <string> args) { if (args.Count < 2) { Console.WriteLine("Usage: db outfile"); return(-1); } string InDatabase = args[0]; string OutFile = args[1]; StringFile StringFile = new StringFile(); ReadDatabase(StringFile, "Data Source=" + InDatabase); StringFile.CreateFile(OutFile); return(0); }
public override bool ParseFromData() { if (!base.ParseFromData()) { return(false); } Complexity = ReadFloat(); STFFile = new StringFile().Deserialize(this); CustomName = ReadString(Encoding.UTF8); Volume = ReadInt32(); SchematicQuantity = ReadInt32(); CraftingValues = ReadList <CraftingValue>(true, true); CreatorName = ReadString(Encoding.UTF8); Complexity2 = ReadInt32(); SchematicDataSize = ReadFloat(); return(true); }
private void cbLanguages_SelectedIndexChanged(object sender, EventArgs e) { if (cbLanguages.SelectedIndex != 0 && cbLanguages.SelectedIndex != _currentLanguage) { if (CheckSave()) { LanguageInfo info = _languageList[cbLanguages.SelectedIndex - 1]; _targetStrings = LoadStrings(_stringPath, info.Name); BuildMissingList(); ColourMissingSections(); SetTargetSection(); BuildEditList(); DrawTargetList(); btnSave.Enabled = false; _modifiedSection = false; _currentLanguage = cbLanguages.SelectedIndex; } } cbLanguages.SelectedIndex = _currentLanguage; }
static void LoadStrings(IGameInstance sriv) { var results = sriv.SearchForFiles("*.le_strings"); foreach (var result in results) { string filename = result.Value.Filename.ToLowerInvariant(); filename = Path.GetFileNameWithoutExtension(filename); string[] pieces = filename.Split('_'); string languageCode = pieces.Last(); Language language = LanguageUtility.GetLanguageFromCode(languageCode); if (!languageStrings.ContainsKey(language)) { languageStrings.Add(language, new Dictionary <uint, string>()); } Dictionary <uint, string> strings = languageStrings[language]; using (Stream s = sriv.OpenPackfileFile(result.Value.Filename, result.Value.Packfile)) { StringFile file = new StringFile(s, language, sriv); foreach (var hash in file.GetHashes()) { if (strings.ContainsKey(hash)) { continue; } strings.Add(hash, file.GetString(hash)); } } } }
public static void Main(string[] args) { Options options = null; try { options = CommandLine.Parse<Options>(); } catch (CommandLineException exception) { Console.WriteLine(exception.ArgumentHelp.Message); Console.WriteLine(); Console.WriteLine(exception.ArgumentHelp.GetHelpText(Console.BufferWidth)); #if DEBUG Console.ReadLine(); #endif return; } string outputFile = options.Output != null ? options.Output : Path.ChangeExtension(options.Input, ".le_strings"); Console.WriteLine("Packing {0} and creating {1}...", options.Input, outputFile); XDocument xml = null; using (Stream s = File.OpenRead(options.Input)) { xml = XDocument.Load(s); } var stringsNode = xml.Descendants("Strings").First(); string languageString = stringsNode.Attribute("Language").Value; string gameString = stringsNode.Attribute("Game").Value; Language language = LanguageUtility.GetLanguageFromCode(languageString); IGameInstance instance = GameInstance.GetFromString(gameString); var stringNodes = stringsNode.Descendants("String"); UInt16 bucketCount = (UInt16)(stringNodes.Count() / 5); if (bucketCount < 32) bucketCount = 32; else if (bucketCount < 64) bucketCount = 64; else if (bucketCount < 128) bucketCount = 128; else if (bucketCount < 256) bucketCount = 256; else if (bucketCount < 512) bucketCount = 512; else bucketCount = 1024; StringFile stringFile = new StringFile(bucketCount, language, instance); foreach (var stringNode in stringNodes) { uint hash; var nameAttribute = stringNode.Attribute("Name"); if (nameAttribute != null) { hash = Hashes.CrcVolition(nameAttribute.Value); } else { hash = uint.Parse(stringNode.Attribute("Hash").Value, System.Globalization.NumberStyles.HexNumber); } string value = stringNode.Value; if (stringFile.ContainsKey(hash)) { Console.WriteLine("You are attempting to add a duplicate key to the strings file."); Console.WriteLine("Name: \"{0}\", Hash: {1}, Value: {2}", nameAttribute != null ? nameAttribute.Value : "", hash, value); Console.WriteLine("Other value: {0}", stringFile.GetString(hash)); return; } stringFile.AddString(hash, value); } using (Stream s = File.Create(outputFile)) { stringFile.Save(s); } Console.WriteLine("Done."); #if DEBUG Console.ReadLine(); #endif }
static void Main(string[] args) { Options options = null; try { options = CommandLine.Parse <Options>(); } catch (CommandLineException exception) { Console.WriteLine(exception.ArgumentHelp.Message); Console.WriteLine(); Console.WriteLine(exception.ArgumentHelp.GetHelpText(Console.BufferWidth)); #if DEBUG Console.ReadLine(); #endif return; } if (options.Output == null) { options.Output = options.NewName; } string outputFolder = options.Output; Directory.CreateDirectory(outputFolder); IGameInstance sriv = GameInstance.GetFromSteamId(GameSteamID.SaintsRowIV); LoadStrings(sriv); IAssetAssemblerFile newAsm; using (Stream newAsmStream = File.OpenRead(Path.Combine("templates", "template_customize_item.asm_pc"))) { newAsm = AssetAssemblerFile.FromStream(newAsmStream); } XDocument customizationItem = null; using (Stream itemsTemplateStream = File.OpenRead(Path.Combine("templates", "template_customization_items.xtbl"))) { customizationItem = XDocument.Load(itemsTemplateStream); } var customizationItemTable = customizationItem.Descendants("Table").First(); XElement itemNode = FindCustomizationItem(options.Source, sriv); if (itemNode == null) { Console.WriteLine("Couldn't find {0}.", options.Source); #if DEBUG Console.ReadLine(); #endif return; } string itemName = itemNode.Element("Name").Value; itemNode.Element("Name").Value = options.NewName; string originalDisplayName = itemNode.Element("DisplayName").Value; uint originalStringCrc = Hashes.CrcVolition(originalDisplayName); string newDisplayName = "DUPLICATED_" + options.NewName.ToUpperInvariant(); itemNode.Element("DisplayName").Value = newDisplayName; List <string> str2Names = new List <string>(); bool found = false; var dlcElement = itemNode.Element("Is_DLC"); if (dlcElement != null) { string isDLCString = dlcElement.Value; // Remove Is_DLC element so DLC items show up in SRIV dlcElement.Remove(); } var wearOptionsNode = itemNode.Element("Wear_Options"); int wearOption = 0; foreach (var wearOptionNode in wearOptionsNode.Descendants("Wear_Option")) { var meshInformationNode = wearOptionNode.Element("Mesh_Information"); var maleMeshFilenameNode = meshInformationNode.Element("Male_Mesh_Filename"); var filenameNode = maleMeshFilenameNode.Element("Filename"); string maleMeshFilename = filenameNode.Value; string newMaleMeshFilename = (wearOption == 0) ? String.Format("cm_{0}.cmeshx", options.NewName) : String.Format("cm_{0}_{1}.cmeshx", options.NewName, wearOption); filenameNode.Value = newMaleMeshFilename; var femaleMeshFilenameNode = meshInformationNode.Element("Female_Mesh_Filename"); filenameNode = femaleMeshFilenameNode.Element("Filename"); string femaleMeshFilename = filenameNode.Value; string newFemaleMeshFilename = (wearOption == 0) ? String.Format("cf_{0}.cmeshx", options.NewName) : String.Format("cf_{0}_{1}.cmeshx", options.NewName, wearOption); filenameNode.Value = newFemaleMeshFilename; Console.WriteLine("Mapping mesh {0} -> {1}", maleMeshFilename, newMaleMeshFilename); Console.WriteLine("Mapping mesh {0} -> {1}", femaleMeshFilename, newFemaleMeshFilename); string clothSimFilename = null; var clothSimFilenameNode = meshInformationNode.Element("Cloth_Sim_Filename"); if (clothSimFilenameNode != null) { filenameNode = clothSimFilenameNode.Element("Filename"); string xmlClothSimFilename = filenameNode.Value; clothSimFilename = Path.ChangeExtension(xmlClothSimFilename, ".sim_pc"); string newClothSimFilename = (wearOption == 0) ? String.Format("cm_{0}.simx", options.NewName) : String.Format("cm_{0}_{1}.simx", options.NewName, wearOption); filenameNode.Value = newClothSimFilename; Console.WriteLine("Mapping cloth sim {0} -> {1}", xmlClothSimFilename, newClothSimFilename); } var variantNodes = itemNode.Element("Variants").Descendants("Variant"); foreach (var variantNode in variantNodes) { var meshVariantInfoNode = variantNode.Element("Mesh_Variant_Info"); var variantIdNode = meshVariantInfoNode.Element("VariantID"); uint variantId = uint.Parse(variantIdNode.Value); int crc = Hashes.CustomizationItemCrc(itemName, maleMeshFilename, variantId); string maleStr2 = String.Format("custmesh_{0}.str2_pc", crc); string femaleStr2 = String.Format("custmesh_{0}f.str2_pc", crc); int newCrc = Hashes.CustomizationItemCrc(options.NewName, newMaleMeshFilename, variantId); string newMaleStr2 = String.Format("custmesh_{0}.str2_pc", newCrc); string newFemaleStr2 = String.Format("custmesh_{0}f.str2_pc", newCrc); string newMaleName = (wearOption == 0) ? String.Format("cm_{0}", options.NewName) : String.Format("cm_{0}_{1}", options.NewName, wearOption); string newFemaleName = (wearOption == 0) ? String.Format("cf_{0}", options.NewName) : String.Format("cf_{0}_{1}", options.NewName, wearOption); bool foundMale = ClonePackfile(sriv, maleStr2, clothSimFilename, options.Output, newAsm, itemName, newMaleName, Path.Combine(outputFolder, newMaleStr2)); bool foundFemale = ClonePackfile(sriv, femaleStr2, clothSimFilename, options.Output, newAsm, itemName, newFemaleName, Path.Combine(outputFolder, newFemaleStr2)); if (foundMale || foundFemale) { found = true; } } wearOption++; } if (found) { customizationItemTable.Add(itemNode); } using (Stream xtblOutStream = File.Create(Path.Combine(outputFolder, "customization_items.xtbl"))) { XmlWriterSettings settings = new XmlWriterSettings(); settings.OmitXmlDeclaration = true; settings.Encoding = new UTF8Encoding(false); settings.NewLineChars = "\r\n"; settings.Indent = true; settings.IndentChars = "\t"; using (XmlWriter writer = XmlWriter.Create(xtblOutStream, settings)) { customizationItem.Save(writer); } } using (Stream asmOutStream = File.Create(Path.Combine(outputFolder, "customize_item.asm_pc"))) { newAsm.Save(asmOutStream); } string stringXmlFolder = Path.Combine(outputFolder, "stringxml"); Directory.CreateDirectory(stringXmlFolder); foreach (var pair in languageStrings) { Language language = pair.Key; Dictionary <uint, string> strings = pair.Value; StringFile file = new StringFile(language, sriv); string newString = "CLONE: " + options.NewName; if (strings.ContainsKey(originalStringCrc)) { string originalString = strings[originalStringCrc]; newString = "CLONE: " + originalString; } else { Console.WriteLine("Warning: original language string could not be found for {0}.", language); } file.AddString(newDisplayName, newString); string newFilename = Path.Combine(outputFolder, String.Format("{0}_{1}.le_strings", options.NewName, LanguageUtility.GetLanguageCode(language))); string newXmlFilename = Path.Combine(stringXmlFolder, String.Format("{0}_{1}.xml", options.NewName, LanguageUtility.GetLanguageCode(language))); using (Stream s = File.Create(newFilename)) { file.Save(s); } XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.IndentChars = "\t"; settings.NewLineChars = "\r\n"; using (XmlWriter xml = XmlTextWriter.Create(newXmlFilename, settings)) { xml.WriteStartDocument(); xml.WriteStartElement("Strings"); xml.WriteAttributeString("Language", language.ToString()); xml.WriteAttributeString("Game", sriv.Game.ToString()); xml.WriteStartElement("String"); xml.WriteAttributeString("Name", newDisplayName); xml.WriteString(newString); xml.WriteEndElement(); // String xml.WriteEndElement(); // Strings xml.WriteEndDocument(); } } Console.WriteLine("Finished cloning customization item {0} to {1}!", options.Source, options.NewName); #if DEBUG Console.ReadLine(); #endif }
public StringExporter(StringFile stringFile) { StringFile = stringFile; }
public StringExporter(byte[] data) { using (var memoryStream = new MemoryStream(data)) StringFile = new StringFileReader().Load(data); }
public static void Main(string[] args) { Options options = null; try { options = CommandLine.Parse<Options>(); } catch (CommandLineException exception) { Console.WriteLine(exception.ArgumentHelp.Message); Console.WriteLine(); Console.WriteLine(exception.ArgumentHelp.GetHelpText(Console.BufferWidth)); #if DEBUG Console.ReadLine(); #endif return; } IGameInstance instance = GameInstance.GetFromString(options.Game); string filename = Path.GetFileNameWithoutExtension(options.Input); string languageCode = filename.Remove(0, filename.Length - 2); Language language = LanguageUtility.GetLanguageFromCode(languageCode); Console.WriteLine("Loading XTBL files..."); Dictionary<UInt32, string> hashLookup = new Dictionary<UInt32, string>(); var results = instance.SearchForFiles("*.xtbl"); foreach (var pair in results) { string xtbl = null; using (StreamReader reader = new StreamReader(pair.Value.GetStream())) { xtbl = reader.ReadToEnd(); } Regex regex = new Regex("<Name>(.*?)</Name>", RegexOptions.Compiled); foreach (Match m in regex.Matches(xtbl)) { uint hash = Hashes.CrcVolition(m.Groups[1].Value); if (!hashLookup.ContainsKey(hash)) hashLookup.Add(hash, m.Groups[1].Value); } } string outputFile = (options.Output != null) ? options.Output : Path.ChangeExtension(options.Input, ".xml"); Console.WriteLine("Extracting {0} to {1}...", options.Input, outputFile); StringFile stringFile = null; using (Stream stream = File.OpenRead(options.Input)) { stringFile = new StringFile(stream, language, instance); } XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.IndentChars = "\t"; settings.NewLineChars = "\r\n"; Dictionary<string, string> stringsWithName = new Dictionary<string, string>(); Dictionary<uint, string> stringsWithHash = new Dictionary<uint, string>(); foreach (uint hash in stringFile.GetHashes()) { string text = stringFile.GetString(hash); if (hashLookup.ContainsKey(hash)) stringsWithName.Add(hashLookup[hash], text); else stringsWithHash.Add(hash, text); } using (XmlWriter xml = XmlTextWriter.Create(outputFile, settings)) { xml.WriteStartDocument(); xml.WriteStartElement("Strings"); xml.WriteAttributeString("Language", language.ToString()); xml.WriteAttributeString("Game", instance.Game.ToString()); foreach (var pair in stringsWithName.OrderBy(x => x.Key)) { xml.WriteStartElement("String"); xml.WriteAttributeString("Name", pair.Key); xml.WriteString(pair.Value); xml.WriteEndElement(); // String } foreach (var pair in stringsWithHash) { xml.WriteStartElement("String"); xml.WriteAttributeString("Hash", pair.Key.ToString("X8")); xml.WriteString(pair.Value); xml.WriteEndElement(); // String } xml.WriteEndElement(); // Strings xml.WriteEndDocument(); } Console.WriteLine("Done."); #if DEBUG Console.ReadLine(); #endif }
public static void Main(string[] args) { Options options = null; try { options = CommandLine.Parse <Options>(); } catch (CommandLineException exception) { Console.WriteLine(exception.ArgumentHelp.Message); Console.WriteLine(); Console.WriteLine(exception.ArgumentHelp.GetHelpText(Console.BufferWidth)); #if DEBUG Console.ReadLine(); #endif return; } IGameInstance instance = GameInstance.GetFromString(options.Game); string filename = Path.GetFileNameWithoutExtension(options.Input); string languageCode = filename.Remove(0, filename.Length - 2); Language language = LanguageUtility.GetLanguageFromCode(languageCode); Dictionary <UInt32, string> hashLookup = new Dictionary <UInt32, string>(); if (options.LoadXtbls) { Console.WriteLine("Loading XTBL files..."); Dictionary <string, FileSearchResult> results = instance.SearchForFiles("*.xtbl"); int i = 0; foreach (var pair in results) { i++; Console.WriteLine("[{0}/{1}] Loading xtbl: {2}", i, results.Count, pair.Key); string xtbl = null; using (StreamReader reader = new StreamReader(pair.Value.GetStream())) { xtbl = reader.ReadToEnd(); } Regex regex = new Regex("<Name>(.*?)</Name>", RegexOptions.Compiled); foreach (Match m in regex.Matches(xtbl)) { uint hash = Hashes.CrcVolition(m.Groups[1].Value); if (!hashLookup.ContainsKey(hash)) { hashLookup.Add(hash, m.Groups[1].Value); } } } } string outputFile = (options.Output != null) ? options.Output : Path.ChangeExtension(options.Input, ".xml"); Console.WriteLine("Extracting {0} to {1}...", options.Input, outputFile); StringFile stringFile = null; using (Stream stream = File.OpenRead(options.Input)) { stringFile = new StringFile(stream, language, instance); } XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.IndentChars = "\t"; settings.NewLineChars = "\r\n"; Dictionary <string, string> stringsWithName = new Dictionary <string, string>(); Dictionary <uint, string> stringsWithHash = new Dictionary <uint, string>(); foreach (uint hash in stringFile.GetHashes()) { string text = stringFile.GetString(hash); if (hashLookup.ContainsKey(hash)) { stringsWithName.Add(hashLookup[hash], text); } else { stringsWithHash.Add(hash, text); } } using (XmlWriter xml = XmlTextWriter.Create(outputFile, settings)) { xml.WriteStartDocument(); xml.WriteStartElement("Strings"); xml.WriteAttributeString("Language", language.ToString()); xml.WriteAttributeString("Game", instance.Game.ToString()); foreach (var pair in stringsWithName.OrderBy(x => x.Key)) { xml.WriteStartElement("String"); xml.WriteAttributeString("Name", pair.Key); xml.WriteString(pair.Value); xml.WriteEndElement(); // String } foreach (var pair in stringsWithHash) { xml.WriteStartElement("String"); xml.WriteAttributeString("Hash", pair.Key.ToString("X8")); xml.WriteString(pair.Value); xml.WriteEndElement(); // String } xml.WriteEndElement(); // Strings xml.WriteEndDocument(); } Console.WriteLine("Done."); #if DEBUG Console.ReadLine(); #endif }
public static void Main(string[] args) { Options options = null; try { options = CommandLine.Parse <Options>(); } catch (CommandLineException exception) { Console.WriteLine(exception.ArgumentHelp.Message); Console.WriteLine(); Console.WriteLine(exception.ArgumentHelp.GetHelpText(Console.BufferWidth)); #if DEBUG Console.ReadLine(); #endif return; } string outputFile = options.Output != null ? options.Output : Path.ChangeExtension(options.Input, ".le_strings"); Console.WriteLine("Packing {0} and creating {1}...", options.Input, outputFile); XDocument xml = null; using (Stream s = File.OpenRead(options.Input)) { xml = XDocument.Load(s); } var stringsNode = xml.Descendants("Strings").First(); string languageString = stringsNode.Attribute("Language").Value; string gameString = stringsNode.Attribute("Game").Value; Language language = LanguageUtility.GetLanguageFromCode(languageString); IGameInstance instance = GameInstance.GetFromString(gameString); StringFile stringFile = new StringFile(language, instance); var stringNodes = stringsNode.Descendants("String"); foreach (var stringNode in stringNodes) { uint hash; var nameAttribute = stringNode.Attribute("Name"); if (nameAttribute != null) { hash = Hashes.CrcVolition(nameAttribute.Value); } else { hash = uint.Parse(stringNode.Attribute("Hash").Value, System.Globalization.NumberStyles.HexNumber); } string value = stringNode.Value; if (stringFile.ContainsKey(hash)) { Console.WriteLine("You are attempting to add a duplicate key to the strings file."); Console.WriteLine("Name: \"{0}\", Hash: {1}, Value: {2}", nameAttribute != null ? nameAttribute.Value : "", hash, value); Console.WriteLine("Other value: {0}", stringFile.GetString(hash)); return; } stringFile.AddString(hash, value); } using (Stream s = File.Create(outputFile)) { stringFile.Save(s); } Console.WriteLine("Done."); #if DEBUG Console.ReadLine(); #endif }