Exemple #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 (var stream = new MemoryStream(rawData))
            {
                using (var 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(CultureInfo.InvariantCulture) + "'"
                                  );
                    }

                    var ret = new MenuResourceData(lang, rawData)
                    {
                        Menu = menu
                    };

                    return(ret);
                }
            }
        }
Exemple #2
0
 public override ResourceData FromResource(ResourceLang lang, byte[] data)
 {
     return(MenuResourceData.TryCreate(lang, data));
 }