public static void AddCliloc( string lang ) { StringList list = StringList.GetList( lang ); if ( list == null ) list = StringList.AddLanguage( lang ); string path = Core.FindDataFile( String.Format( "cliloc.{0}", lang ) ); if ( path == null ) { Console.WriteLine( "Warning: cliloc.{0} not found", lang ); return; } using ( BinaryReader bin = new BinaryReader( new FileStream( path, FileMode.Open, FileAccess.Read, FileShare.Read ), Encoding.ASCII ) ) { bin.ReadInt32(); bin.ReadInt16(); Encoding utf8 = Encoding.GetEncoding( "UTF-8", new EncoderReplacementFallback(""), new DecoderReplacementFallback("") ); while ( bin.PeekChar() != -1 ) { int number = bin.ReadInt32(); bin.ReadByte(); //State in Cliloc int length = bin.ReadInt16(); //Max of 65535 characters StringEntry entry = new StringEntry( number, LState.Original, StringList.FormatArguments( utf8.GetString( bin.ReadBytes( length ) ) ) ); list.Table[number] = entry; } bin.Close(); } }
public static void AddExtended( string lang ) { StringList list = StringList.GetList( lang ); if ( list == null ) list = StringList.AddLanguage( lang ); XmlDocument doc = new XmlDocument(); doc.Load( Path.Combine( Core.BaseDirectory, String.Format( "Data/Localization/{0}.xml", lang ) ) ); XmlElement root = doc["locs"]; foreach ( XmlElement loc in root.GetElementsByTagName( "loc" ) ) { int number = Utility.GetXMLInt32( Utility.GetAttribute( loc, "num", "0" ), -1 ); StringEntry entry = list[number]; if ( number > 500000 ) { string text = Utility.GetText( loc, String.Empty ); if ( entry != null ) entry.State = LState.Replaced; else entry = new StringEntry( number, LState.Extended, text ); } } }
public static void AddExtended(string lang) { StringList list = StringList.GetList(lang); if (list == null) { list = StringList.AddLanguage(lang); } XmlDocument doc = new XmlDocument(); doc.Load(Path.Combine(Core.BaseDirectory, String.Format("Data/Localization/{0}.xml", lang))); XmlElement root = doc["locs"]; foreach (XmlElement loc in root.GetElementsByTagName("loc")) { int number = Utility.GetXMLInt32(Utility.GetAttribute(loc, "num", "0"), -1); StringEntry entry = list[number]; if (number > 500000) { string text = Utility.GetText(loc, String.Empty); if (entry != null) { entry.State = LState.Replaced; } else { entry = new StringEntry(number, LState.Extended, text); } } } }
public string CombinedWithObjArguments(int number, params object[] args) { StringEntry entry = this[number]; if (entry != null) { return(entry.CombinedWithObjArguments(args)); } else { throw new Exception(String.Format("No string entry exists for {0}", number)); } }
public StringList(string language, bool format) { Language = language; Table = new Dictionary <int, string>(); string path = Core.FindDataFile(string.Format("Cliloc.{0}", language)); if (path == null) { log.Warning("Cliloc.{0} not found", language); Entries = new StringEntry[0]; return; } log.Info("Loading localization strings"); List <StringEntry> list = new List <StringEntry>(); using (BinaryReader bin = new BinaryReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))) { byte[] buffer = new byte[1024]; bin.ReadInt32(); bin.ReadInt16(); while (bin.BaseStream.Length != bin.BaseStream.Position) { int number = bin.ReadInt32(); bin.ReadByte(); int length = bin.ReadInt16(); if (length > buffer.Length) { buffer = new byte[(length + 1023) & ~1023]; } bin.Read(buffer, 0, length); string text = Encoding.UTF8.GetString(buffer, 0, length); if (format) { text = FormatArguments(text); } list.Add(new StringEntry(number, text)); Table[number] = text; } } Entries = list.ToArray(); }
public StringList(string language, bool format) { Language = language; string path = Core.FindDataFile(string.Format("Cliloc.{0}", language)); if (path == null) { Console.WriteLine("Cliloc.{0} not found", language); Entries = new List <StringEntry>(0); return; } StringTable = new Dictionary <int, string>(); EntryTable = new Dictionary <int, StringEntry>(); Entries = new List <StringEntry>(); using (BinaryReader bin = new BinaryReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))) { byte[] buffer = new byte[1024]; bin.ReadInt32(); bin.ReadInt16(); while (bin.BaseStream.Length != bin.BaseStream.Position) { int number = bin.ReadInt32(); bin.ReadByte(); // flag int length = bin.ReadInt16(); if (length > buffer.Length) { buffer = new byte[(length + 1023) & ~1023]; } bin.Read(buffer, 0, length); string text = Encoding.UTF8.GetString(buffer, 0, length); StringEntry se = new StringEntry(number, text); Entries.Add(se); StringTable[number] = text; EntryTable[number] = se; } } }
public StringList(string language, bool format) { Language = language; var path = Core.FindDataFile($"Cliloc.{language}"); if (path == null) { Console.WriteLine($"Cliloc.{language} not found"); return; } using (var bin = new BinaryReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))) { var buffer = new byte[1024]; bin.ReadInt32(); bin.ReadInt16(); while (bin.BaseStream.Length != bin.BaseStream.Position) { var number = bin.ReadInt32(); bin.ReadByte(); // flag int length = bin.ReadInt16(); if (length > buffer.Length) { buffer = new byte[(length + 1023) & ~1023]; } bin.Read(buffer, 0, length); var text = Encoding.UTF8.GetString(buffer, 0, length); var se = new StringEntry(number, text); EntryTable[number] = se; StringTable[number] = text; } } }
public static void AddCliloc(string lang) { StringList list = StringList.GetList(lang); if (list == null) { list = StringList.AddLanguage(lang); } string path = Core.FindDataFile(String.Format("cliloc.{0}", lang)); if (path == null) { Console.WriteLine("Warning: cliloc.{0} not found", lang); return; } using (BinaryReader bin = new BinaryReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read), Encoding.ASCII)) { bin.ReadInt32(); bin.ReadInt16(); Encoding utf8 = Encoding.GetEncoding("UTF-8", new EncoderReplacementFallback(""), new DecoderReplacementFallback("")); while (bin.PeekChar() != -1) { int number = bin.ReadInt32(); bin.ReadByte(); //State in Cliloc int length = bin.ReadInt16(); //Max of 65535 characters StringEntry entry = new StringEntry(number, LState.Original, StringList.FormatArguments(utf8.GetString(bin.ReadBytes(length)))); list.Table[number] = entry; } bin.Close(); } }