Example #1
0
        public void WriteToRegistry(RegistryKey key)
        {
            Modified = false;
            //	save the standard color values that all schemes have
            key.SetValue("BorderColor", unchecked ((Int32)BorderColor.ToArgb()), RegistryValueKind.DWord);
            key.SetValue("HighlightColor", unchecked ((Int32)HighlightColor.ToArgb()), RegistryValueKind.DWord);
            key.SetValue("TextColor", unchecked ((Int32)TextColor.ToArgb()), RegistryValueKind.DWord);
            //	save out all square colors/textures counting the number of
            //	square colors in the scheme as we go
            int nSquareColors = 0;

            while (true)
            {
                if (SquareTextures != null && SquareTextures.ContainsKey(nSquareColors))
                {
                    key.SetValue("SquareTexture" + (nSquareColors + 1).ToString(), SquareTextures[nSquareColors].Name, RegistryValueKind.String);
                }
                else if (SquareColors.ContainsKey(nSquareColors))
                {
                    key.SetValue("SquareColor" + (nSquareColors + 1).ToString(), unchecked ((Int32)SquareColors[nSquareColors].ToArgb()), RegistryValueKind.DWord);
                    //	if there's a specified texture already, remove it or else
                    //	it will override the color when we load this scheme again
                    if (key.GetValue("SquareTexture" + (nSquareColors + 1).ToString()) != null)
                    {
                        key.DeleteValue("SquareTexture" + (nSquareColors + 1).ToString());
                    }
                }
                else
                {
                    break;
                }
                nSquareColors++;
            }
            //	clear out any additional colors/textures specified in
            //	the registry that we no longer have
            while (true)
            {
                bool found           = false;
                int  extraColorCount = nSquareColors + 1;
                if (key.GetValue("SquareTexture" + extraColorCount.ToString()) != null)
                {
                    key.DeleteValue("SquareTexture" + extraColorCount.ToString());
                    found = true;
                }
                if (key.GetValue("SquareColor" + extraColorCount.ToString()) != null)
                {
                    key.DeleteValue("SquareColor" + extraColorCount.ToString());
                    found = true;
                }
                extraColorCount++;
                if (!found)
                {
                    break;
                }
            }
            //	write out the player colors
            foreach (KeyValuePair <int, Color> pair in PlayerColors)
            {
                key.SetValue("PlayerColor" + (pair.Key + 1).ToString(), unchecked ((Int32)pair.Value.ToArgb()), RegistryValueKind.DWord);
            }
        }