internal static StringTableResourceData Create(ResourceLang lang, byte[] rawData) { //String resourceName = lang.Name.Identifier.FriendlyName; //Int32 resourceNameInt = -1; // !Int32.TryParse( resourceName, System.Globalization.NumberStyles.Integer, Cult.InvariantCulture, out resourceNameInt ) if (lang.Name.Identifier.IntegerId == null) { throw new ResourceDataException("String Table resource names must be integers"); } var ret = new StringTableResourceData(lang, rawData) { StartId = ResourceNameToStringId(lang.Name.Identifier.IntegerId.Value) }; var underlying = new List <StringInfo>(); // FSM parser time, yay using (var ms = new MemoryStream(rawData)) { using (var rdr = new StreamReader(ms, Encoding.Unicode)) { var stringIdx = 0; int nc; while ((nc = rdr.Read()) != -1) { var c = (char)nc; if (c != (char)0) { // NULL // this char is the length of the string var length = nc; var str = new char[length]; var cnt = rdr.Read(str, 0, length); if (cnt != length) { throw new ResourceDataException("Unexpected string length"); } var info = new StringInfo(stringIdx + ret.StartId, new string(str)); underlying.Add(info); } stringIdx++; } } } ret.Strings = new StringInfoCollection(underlying); return(ret); }
public override ResourceData FromResource(ResourceLang lang, byte[] data) { return(StringTableResourceData.Create(lang, data)); }