Esempio n. 1
0
        internal static MenuResourceData TryCreate(ResourceLang lang, Byte[] rawData)
        {
            if (rawData.Length < 12)
            {
                throw new ResourceDataException("Menus are at least 12 bytes long");
            }

            // rawData is an array of MenuTemplate instances, aligned to DWORD boundaries (fun)

            // if the first byte is '1' then it's MenuEx, otherwise its an old-style menu

            using (MemoryStream stream = new MemoryStream(rawData))
                using (BinaryReader rdr = new BinaryReader(stream, Encoding.Unicode)) {
                    DialogMenu menu;

                    switch (rawData[0])
                    {
                    case 0:
                        menu = Create(rdr);
                        break;

                    case 1:
                        menu = CreateEx(rdr);
                        break;

                    default:
                        throw new ResourceDataException("Unsupported Menu version word: '" + rawData[0].ToString(Cult.InvariantCulture) + "'");
                    }

                    MenuResourceData ret = new MenuResourceData(lang, rawData);
                    ret.Menu = menu;

                    return(ret);
                }
        }
Esempio n. 2
0
 public override ResourceData FromResource(ResourceLang lang, Byte[] data)
 {
     return(MenuResourceData.TryCreate(lang, data));
 }