Example #1
0
        public ThemeFile LoadTheme()
        {
            var themeFile = new ThemeFile(filePath, neutralModule, muiModule);

            themeFile.Version = GetVersion();
            var classNames = ReadClassMap();
            var vmap       = ReadVariantMap();
            var bcmap      = ReadBaseClassMap();

            themeFile.VariantMap = vmap;
            themeFile.ClassNames = classNames;
            UxThemeExNativeMethods.UxOpenThemeFile(filePath, isHighContrast, out var themeFileHandle).ThrowIfFailed();
            themeFile.NativeThemeFile = themeFileHandle;

            ReadProperties(themeFile, "RMAP", "RMAP");
            ReadProperties(themeFile, "VARIANT", vmap.Name);

            foreach (var @class in themeFile.Classes)
            {
                AddKnownPartsAndStates(@class);
            }

            var classMap    = themeFile.Classes.ToDictionary(x => x.Name);
            var classNames2 = themeFile.ClassNames.Skip(4).ToList();

            foreach (var entry in bcmap.Map)
            {
                var className     = classNames2[entry.Key];
                var baseClassName = classNames2[entry.Value];

                if (classMap.TryGetValue(className, out ThemeClass @class) &&
                    classMap.TryGetValue(baseClassName, out ThemeClass baseClass))
                {
                    @class.BaseClass = baseClass;
                }
            }

            themeFile.Sort();

            return(themeFile);
        }