Exemple #1
0
        private bool LoadRecordValue(
            ThemeFile theme, VSRecord record,
            UnmanagedMemoryAccessor data, long offset, out object value)
        {
            TPID id = GetThemePrimitiveId(record.SymbolVal, record.Type);

            if (id == TPID.Invalid)
            {
                value = null;
                return(false);
            }

            if (record.ResId == 0)
            {
                var payload = new byte[record.ByteLength];
                data.ReadArray(offset, payload, 0, payload.Length);

                switch (id)
                {
                case TPID.STRING:
                    value = data.ReadZString(offset);
                    return(true);

                case TPID.ENUM:
                    value = GetEnum(data.ReadInt32(offset), (TMT)record.SymbolVal);
                    return(true);

                case TPID.BOOL:
                    value = data.ReadInt32(offset) == 1;
                    return(true);

                case TPID.INT:
                    value = data.ReadInt32(offset);
                    return(true);

                case TPID.COLOR:
                    value = ColorUtils.ColorFromCOLORREF(data.ReadInt32(offset));
                    return(true);

                case TPID.MARGINS:
                    value = data.Read <MARGINS>(offset);
                    return(true);

                case TPID.SIZE:
                    value = data.ReadInt32(offset);
                    return(true);

                case TPID.POSITION:
                    value = data.Read <POINT>(offset);
                    return(true);

                case TPID.RECT:
                    value = data.Read <RECT>(offset);
                    return(true);

                case TPID.HIGHCONTRASTCOLORTYPE:
                    value = (HIGHCONTRASTCOLOR)data.ReadInt32(offset);
                    return(true);

                case TPID.SIMPLIFIEDIMAGETYPE:
                    if (record.SymbolVal == (int)TMT.HCSIMPLIFIEDIMAGE)
                    {
                        value = data.ReadArray <HCIMAGEPROPERTIES>(offset, record.ByteLength);
                    }
                    else
                    {
                        value = data.ReadArray <IMAGEPROPERTIES>(offset, record.ByteLength);
                    }
                    return(true);

                case TPID.INTLIST:
                    int length = data.ReadInt32(offset);
                    if (length <= 1)
                    {
                        value = new IntList(new int[0]);
                        return(true);
                    }

                    int dim = data.ReadInt32(offset + 4);
                    Debug.Assert(length - 1 == dim * dim);
                    var intList = new int[length - 1];
                    data.ReadArray(offset + 8, intList, 0, intList.Length);
                    value = new IntList(intList);
                    return(true);

                default:
                    Console.WriteLine($"Unprocessed resource property type {id}");
                    value = null;
                    return(false);
                }
            }
            else
            {
                value = null;
                switch (id)
                {
                case TPID.BITMAPIMAGE1:
                case TPID.BITMAPIMAGE2:
                case TPID.BITMAPIMAGE3:
                case TPID.BITMAPIMAGE4:
                case TPID.BITMAPIMAGE5:
                case TPID.BITMAPIMAGE6:
                case TPID.BITMAPIMAGE7:
                case TPID.STOCKBITMAPIMAGE:
                case TPID.GLYPHIMAGE:
                case TPID.COMPOSEDIMAGETYPE:
                    return(LoadImageFileRes(theme.Theme, record.ResId, out value));

                // TPID_ATLASIMAGE
                // TPID_ATLASINPUTIMAGE
                // TPID_ENUM
                case TPID.STRING:
                    return(LoadStringRes(theme.MUI, record.ResId, out value));

                // TPID_INT
                case TPID.BOOL:
                    return(LoadBoolRes(theme.MUI, record.ResId, out value));

                // TPID_COLOR
                // TPID_MARGINS
                case TPID.FILENAME:
                    if (IsImageFile((TMT)record.SymbolVal))
                    {
                        return(LoadImageFileRes(theme.Theme, record.ResId, out value));
                    }
                    return(LoadStringRes(theme.MUI, record.ResId, out value));

                // TPID_SIZE
                // TPID_POSITION
                case TPID.RECT:
                    return(LoadRectRes(theme.MUI, record.ResId, out value));

                case TPID.FONT:
                    return(LoadFontRes(theme.MUI, record.ResId, out value));

                case TPID.DISKSTREAM:
                    value = "DISKSTREAM(" + record.ResId + ", len=" + record.ByteLength + ")";
                    //var window = new Form();
                    //window.ShowDialog();
                    //var th = StyleNativeMethods.OpenThemeData(
                    //    window.Handle, "LISTVIEW");

                    //IntPtr stream;
                    //uint streamLen;
                    //HResult hr = StyleNativeMethods.GetThemeStream(
                    //    th, (int)header.Part, (int)header.State, (int)header.Property,
                    //    out stream, out streamLen, tf.hTheme);

                    //th.Dispose();

                    //GC.KeepAlive(window);
                    return(true);

                default:
                    Console.WriteLine($"Unprocessed MUI resource property type {id}");
                    return(false);
                }
            }
        }