Example #1
0
        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");
            }

            StringTableResourceData ret = new StringTableResourceData(lang, rawData);

            ret.StartId = ResourceNameToStringId(lang.Name.Identifier.IntegerId.Value);

            List <StringInfo> underlying = new List <StringInfo>();

            // FSM parser time, yay
            using (MemoryStream ms = new MemoryStream(rawData))
                using (StreamReader rdr = new StreamReader(ms, Encoding.Unicode)) {
                    Int32 stringIdx = 0;

                    Int32 nc; Char c;
                    while ((nc = rdr.Read()) != -1)
                    {
                        c = (Char)nc;

                        if (c != (Char)0)                  // NULL

                        // this char is the length of the string
                        {
                            Int32 length = nc;

                            Char[] str = new Char[length];
                            int    cnt = rdr.Read(str, 0, length);
                            if (cnt != length)
                            {
                                throw new ResourceDataException("Unexpected string length");
                            }

                            StringInfo info = new StringInfo(stringIdx + ret.StartId, new String(str));
                            underlying.Add(info);
                        }

                        stringIdx++;
                    }
                }

            ret.Strings = new StringInfoCollection(underlying);

            return(ret);
        }
Example #2
0
 public override ResourceData FromResource(ResourceLang lang, Byte[] data)
 {
     return(StringTableResourceData.Create(lang, data));
 }