Ejemplo n.º 1
0
        public void AddActionKeys(string actionName, Keys[] keys)
        {
            int keyCount;

            if (string.IsNullOrEmpty(actionName))
            {
                return;
            }
            if (keys == null)
            {
                return;
            }
            if (iniFile.SectionExists(actionName))
            {
                keyCount = iniFile.Section(actionName).Count;
            }
            else
            {
                keyCount = 0;
            }

            for (int i = 0; i < keys.Length; i++)
            {
                iniFile.WriteString(actionName, "Key" + (keyCount + i + 1).ToString(), KeysToString(keys[i]));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Customs the site icon name.
        /// </summary>
        /// <param name="siteAddress">The site address.</param>
        /// <returns></returns>
        public static string CustomSiteIcon(string siteAddress)
        {
            if (File.Exists(GlobalConfig.SiteImagesFileName))
            {
                Uri        siteUri   = new Uri(siteAddress);
                string     imageName = null;
                string     siteHost  = siteUri.Host;
                string[]   parts     = siteHost.Split('.');
                MemIniFile iniFile   = new MemIniFile(GlobalConfig.SiteImagesFileName);
                try
                {
                    iniFile.Load();
                    foreach (var part in parts)
                    {
                        imageName = iniFile.ReadString("site", part);
                        if (!string.IsNullOrEmpty(imageName))
                        {
                            if (FileOperations.FileExists(imageName))
                            {
                                //return FileOperations.StripFileName(imageName);
                                return(imageName);
                            }
                        }
                    }

                    //no image for url part, return default image
                    if (iniFile.SectionExists("default"))
                    {
                        imageName = iniFile.ReadString("default", "url");
                        if (!string.IsNullOrEmpty(imageName))
                        {
                            if (FileOperations.FileExists(imageName))
                            {
                                //return FileOperations.StripFileName(imageName);
                                return(imageName);
                            }
                        }
                    }
                }
                finally
                {
                    iniFile.Dispose();
                }
            }

            return(null);
        }
Ejemplo n.º 3
0
        public bool LoadFromFile()
        {
            string iniFileName = "";
            string stoneName;
            string backgroundName;
            string skinFolder = "";

            if (!File.Exists(skinFileName))
            {
                return(false);
            }
            else
            {
                iniFileName = skinFileName;
                skinFolder  = Path.GetDirectoryName(skinFileName);
            }


            MemIniFile ini = new MemIniFile(iniFileName);

            try
            {
                ini.Load();

                MenuSkin = ini.ReadString("Menu", "Theme", null);

                ColorConverter     cc = new ColorConverter();
                RectangleConverter rc = new RectangleConverter();
                fontName = ini.ReadString("Info", "FontName", "Tahoma");
                fontSize = ini.ReadInteger("Info", "FontSize", 14);
                try
                {
                    foreColor = (Color)cc.ConvertFromInvariantString(ini.ReadString("Info", "Color", "White"));
                }
                catch
                {
                    foreColor = Color.White;
                }

                try
                {
                    HintOutlineColor = (Color)cc.ConvertFromInvariantString(ini.ReadString("Hint", "OutlineColor", "Black"));
                }
                catch
                {
                    HintOutlineColor = Color.Black;
                }

                try
                {
                    HintBorderColor = (Color)cc.ConvertFromInvariantString(ini.ReadString("Hint", "BorderColor", "Gainsboro"));
                }
                catch
                {
                    HintBorderColor = Color.Gainsboro;
                }

                try
                {
                    HintBodyColor = (Color)cc.ConvertFromInvariantString(ini.ReadString("Hint", "BodyColor", "Black"));
                }
                catch
                {
                    HintBodyColor = Color.Black;
                }

                ButtonStoneSize  = ini.ReadInteger("Hint", "ButtonSize", 26);
                ButtonStoneSpace = ini.ReadInteger("Hint", "ButtonSpace", 4);

                try
                {
                    MenuBorderColor = (Color)cc.ConvertFromInvariantString(ini.ReadString("Menu", "BorderColor", "Gainsboro"));
                }
                catch
                {
                    MenuBorderColor = Color.Gainsboro;
                }

                try
                {
                    MenuOutlineColor = (Color)cc.ConvertFromInvariantString(ini.ReadString("Menu", "OutlineColor", "Black"));
                }
                catch
                {
                    MenuOutlineColor = Color.Black;
                }

                try
                {
                    MenuBodyColor = (Color)cc.ConvertFromInvariantString(ini.ReadString("Menu", "BodyColor", "Black"));
                }
                catch
                {
                    MenuBodyColor = Color.Black;
                }

                try
                {
                    MenuNormalTextColor = (Color)cc.ConvertFromInvariantString(ini.ReadString("Menu", "NormalTextColor", "White"));
                }
                catch
                {
                    MenuNormalTextColor = Color.White;
                }

                try
                {
                    MenuDisabledTextColor = (Color)cc.ConvertFromInvariantString(ini.ReadString("Menu", "DisabledTextColor", "Gray"));
                }
                catch
                {
                    MenuDisabledTextColor = Color.Gray;
                }

                try
                {
                    MenuSelectedTextColor = (Color)cc.ConvertFromInvariantString(ini.ReadString("Menu", "SelectedTextColor", "Black"));
                }
                catch
                {
                    MenuSelectedTextColor = Color.Black;
                }

                MenuFontSize = ini.ReadInteger("Menu", "FontSize", 12);

                MenuFontName = ini.ReadString("Menu", "FontName", "Tahoma");

                try
                {
                    MenuHighlightColor = (Color)cc.ConvertFromInvariantString(ini.ReadString("Menu", "HighlightColor", "Orange"));
                }
                catch
                {
                    MenuHighlightColor = Color.Orange;
                }


                ButtonStoneAbout = ini.ReadString("Hint", "ButtonStoneAbout", string.Empty);
                if (!string.IsNullOrEmpty(ButtonStoneAbout))
                {
                    ButtonStoneAbout = Path.Combine(skinFolder, ButtonStoneAbout);
                }


                ButtonStoneSelect = ini.ReadString("Hint", "ButtonStoneSelect", string.Empty);
                if (!string.IsNullOrEmpty(ButtonStoneSelect))
                {
                    ButtonStoneSelect = Path.Combine(skinFolder, ButtonStoneSelect);
                }


                ButtonStoneEdit = ini.ReadString("Hint", "ButtonStoneEdit", string.Empty);
                if (!string.IsNullOrEmpty(ButtonStoneEdit))
                {
                    ButtonStoneEdit = Path.Combine(skinFolder, ButtonStoneEdit);
                }

                ButtonStoneDelete = ini.ReadString("Hint", "ButtonStoneDelete", string.Empty);
                if (!string.IsNullOrEmpty(ButtonStoneDelete))
                {
                    ButtonStoneDelete = Path.Combine(skinFolder, ButtonStoneDelete);
                }


                ButtonBackNormal = ini.ReadString("ButtonBack", "Normal", string.Empty);
                if (!string.IsNullOrEmpty(ButtonBackNormal))
                {
                    ButtonBackNormal = Path.Combine(skinFolder, ButtonBackNormal);
                }

                ButtonBackFocused = ini.ReadString("ButtonBack", "Focused", string.Empty);
                if (!string.IsNullOrEmpty(ButtonBackFocused))
                {
                    ButtonBackFocused = Path.Combine(skinFolder, ButtonBackFocused);
                }

                ButtonBackPressed = ini.ReadString("ButtonBack", "Pressed", string.Empty);
                if (!string.IsNullOrEmpty(ButtonBackPressed))
                {
                    ButtonBackPressed = Path.Combine(skinFolder, ButtonBackPressed);
                }


                ButtonStartMenuNormal = ini.ReadString("ButtonStartMenu", "Normal", string.Empty);
                if (!string.IsNullOrEmpty(ButtonStartMenuNormal))
                {
                    ButtonStartMenuNormal = Path.Combine(skinFolder, ButtonStartMenuNormal);
                }

                ButtonStartMenuFocused = ini.ReadString("ButtonStartMenu", "Focused", string.Empty);
                if (!string.IsNullOrEmpty(ButtonStartMenuFocused))
                {
                    ButtonStartMenuFocused = Path.Combine(skinFolder, ButtonStartMenuFocused);
                }

                ButtonStartMenuPressed = ini.ReadString("ButtonStartMenu", "Pressed", string.Empty);
                if (!string.IsNullOrEmpty(ButtonStartMenuPressed))
                {
                    ButtonStartMenuPressed = Path.Combine(skinFolder, ButtonStartMenuPressed);
                }

                ButtonForwardNormal = ini.ReadString("ButtonForward", "Normal", string.Empty);
                if (!string.IsNullOrEmpty(ButtonForwardNormal))
                {
                    ButtonForwardNormal = Path.Combine(skinFolder, ButtonForwardNormal);
                }
                else
                {
                    ButtonForwardFocused = ini.ReadString("ButtonForward", "Focused", string.Empty);
                }
                if (!string.IsNullOrEmpty(ButtonForwardFocused))
                {
                    ButtonForwardFocused = Path.Combine(skinFolder, ButtonForwardFocused);
                }

                ButtonForwardPressed = ini.ReadString("ButtonForward", "Pressed", string.Empty);
                if (!string.IsNullOrEmpty(ButtonForwardPressed))
                {
                    ButtonForwardPressed = Path.Combine(skinFolder, ButtonForwardPressed);
                }

                ButtonPowerNormal = ini.ReadString("ButtonPower", "Normal", string.Empty);
                if (!string.IsNullOrEmpty(ButtonPowerNormal))
                {
                    ButtonPowerNormal = Path.Combine(skinFolder, ButtonPowerNormal);
                }

                ButtonPowerFocused = ini.ReadString("ButtonPower", "Focused", string.Empty);
                if (!string.IsNullOrEmpty(ButtonPowerFocused))
                {
                    ButtonPowerFocused = Path.Combine(skinFolder, ButtonPowerFocused);
                }

                ButtonPowerPressed = ini.ReadString("ButtonPower", "Pressed", string.Empty);
                if (!string.IsNullOrEmpty(ButtonPowerPressed))
                {
                    ButtonPowerPressed = Path.Combine(skinFolder, ButtonPowerPressed);
                }

                ButtonHomeNormal = ini.ReadString("ButtonHome", "Normal", string.Empty);
                if (!string.IsNullOrEmpty(ButtonHomeNormal))
                {
                    ButtonHomeNormal = Path.Combine(skinFolder, ButtonHomeNormal);
                }

                ButtonHomeFocused = ini.ReadString("ButtonHome", "Focused", string.Empty);
                if (!string.IsNullOrEmpty(ButtonHomeFocused))
                {
                    ButtonHomeFocused = Path.Combine(skinFolder, ButtonHomeFocused);
                }

                ButtonHomePressed = ini.ReadString("ButtonHome", "Pressed", string.Empty);
                if (!string.IsNullOrEmpty(ButtonHomePressed))
                {
                    ButtonHomePressed = Path.Combine(skinFolder, ButtonHomePressed);
                }

                ButtonLauncherNormal = ini.ReadString("ButtonLauncher", "Normal", string.Empty);
                if (!string.IsNullOrEmpty(ButtonLauncherNormal))
                {
                    ButtonLauncherNormal = Path.Combine(skinFolder, ButtonLauncherNormal);
                }

                ButtonLauncherFocused = ini.ReadString("ButtonLauncher", "Focused", string.Empty);
                if (!string.IsNullOrEmpty(ButtonLauncherFocused))
                {
                    ButtonLauncherFocused = Path.Combine(skinFolder, ButtonLauncherFocused);
                }

                ButtonLauncherPressed = ini.ReadString("ButtonLauncher", "Pressed", string.Empty);
                if (!string.IsNullOrEmpty(ButtonLauncherPressed))
                {
                    ButtonLauncherPressed = Path.Combine(skinFolder, ButtonLauncherPressed);
                }

                ButtonSettingsNormal = ini.ReadString("ButtonSettings", "Normal", string.Empty);
                if (!string.IsNullOrEmpty(ButtonSettingsNormal))
                {
                    ButtonSettingsNormal = Path.Combine(skinFolder, ButtonSettingsNormal);
                }

                ButtonSettingsFocused = ini.ReadString("ButtonSettings", "Focused", string.Empty);
                if (!string.IsNullOrEmpty(ButtonSettingsFocused))
                {
                    ButtonSettingsFocused = Path.Combine(skinFolder, ButtonSettingsFocused);
                }

                ButtonSettingsPressed = ini.ReadString("ButtonSettings", "Pressed", string.Empty);
                if (!string.IsNullOrEmpty(ButtonSettingsPressed))
                {
                    ButtonSettingsPressed = Path.Combine(skinFolder, ButtonSettingsPressed);
                }

                ManagerWidth  = ini.ReadInteger("Background", "ManagerWidth", GlobalSettings.WindowWidth);
                ManagerHeight = ini.ReadInteger("Background", "ManagerHeight", GlobalSettings.WindowHeight);
                Radius        = ini.ReadInteger("Background", "Radius", GlobalSettings.Radius);

                string sectionName = "Background";

                if (ini.SectionExists("Background"))
                {
                    sectionName = "Background";
                }
                else
                if (ini.SectionExists("Tile"))
                {
                    sectionName = "Tile";
                }
                else
                if (ini.SectionExists("BackgroundTop"))
                {
                    sectionName = "BackgroundTop";
                }
                else
                if (ini.SectionExists("BackgroundBottom"))
                {
                    sectionName = "BackgroundBottom";
                }

                if (ini.ValueExists(sectionName, "LeftMargin"))
                {
                    leftMargin = ini.ReadInteger(sectionName, "LeftMargin", 0);
                }
                else
                {
                    leftMargin = ini.ReadInteger(sectionName, "LeftWidth", 0);
                }

                textOffset = ini.ReadInteger("Background", "TextOffset", leftMargin);

                if (ini.ValueExists(sectionName, "RightMargin"))
                {
                    rightMargin = ini.ReadInteger(sectionName, "RightMargin", 0);
                }
                else
                {
                    rightMargin = ini.ReadInteger(sectionName, "RightWidth", 0);
                }

                if (ini.ValueExists(sectionName, "TopMargin"))
                {
                    topMargin = ini.ReadInteger(sectionName, "TopMargin", 0);
                }
                else
                {
                    topMargin = ini.ReadInteger(sectionName, "TopHeight", 0);
                }

                if (ini.ValueExists(sectionName, "BottomMargin"))
                {
                    bottomMargin = ini.ReadInteger(sectionName, "BottomMargin", 0);
                }
                else
                {
                    bottomMargin = ini.ReadInteger(sectionName, "BottomHeight", 0);
                }

                if (ini.ValueExists(sectionName, "Outside-LeftMargin"))
                {
                    outsideLeftMargin = ini.ReadInteger(sectionName, "Outside-LeftMargin", 0);
                }
                else
                {
                    outsideLeftMargin = ini.ReadInteger(sectionName, "OutsideBorderLeft", 0);
                }

                if (ini.ValueExists(sectionName, "Outside-TopMargin"))
                {
                    outsideTopMargin = ini.ReadInteger(sectionName, "Outside-TopMargin", 0);
                }
                else
                {
                    outsideTopMargin = ini.ReadInteger(sectionName, "OutsideBorderTop", 0);
                }

                if (ini.ValueExists(sectionName, "Outside-BottomMargin"))
                {
                    outsideBottomMargin = ini.ReadInteger(sectionName, "Outside-BottomMargin", 0);
                }
                else
                {
                    outsideBottomMargin = ini.ReadInteger(sectionName, "OutsideBorderBottom", 0);
                }

                if (ini.ValueExists(sectionName, "Outside-RightMargin"))
                {
                    outsideRightMargin = ini.ReadInteger(sectionName, "Outside-RightMargin", 0);
                }
                else
                {
                    outsideRightMargin = ini.ReadInteger(sectionName, "OutsideBorderRight", 0);
                }

                backgroundName = ini.ReadString(sectionName, "Image", string.Empty);

                ButtonSize = ini.ReadInteger("Background", "ButtonSize", 60);


                //read stone info
                indicatorRect   = (Rectangle)rc.ConvertFromInvariantString(ini.ReadString("Stone", "Indicator-Rect", "0, 0, 100, 100"));
                IndicatorLeft   = ini.ReadInteger("Stone", "Indicator-Left", 0);
                IndicatorBottom = ini.ReadInteger("Stone", "Indicator-Bottom", 0);

                indicatorImageName = ini.ReadString("Stone", "Indicator", string.Empty);
                if (!string.IsNullOrEmpty(indicatorImageName))
                {
                    indicatorImageName = Path.Combine(skinFolder, indicatorImageName);
                }


                if (ini.SectionExists("Stone"))
                {
                    stoneMarginTop    = ini.ReadInteger("Stone", "OutsideBorderTop", 0);
                    stoneMarginBottom = ini.ReadInteger("Stone", "OutsideBorderBottom", 0);
                    stoneMarginLeft   = ini.ReadInteger("Stone", "OutsideBorderLeft", 0);
                    stoneMarginRight  = ini.ReadInteger("Stone", "OutsideBorderRight", 0);
                    stoneBorder       = ini.ReadInteger("Stone", "Border", 0);
                    stoneName         = ini.ReadString("Stone", "Image", backgroundName);
                }
                else
                {
                    stoneMarginTop    = outsideTopMargin;
                    stoneMarginBottom = outsideBottomMargin;
                    stoneMarginLeft   = outsideLeftMargin;
                    stoneMarginRight  = outsideRightMargin;
                    stoneName         = backgroundName;
                    stoneBorder       = 0;
                }

                if (string.IsNullOrEmpty(backgroundName))
                {
                    return(false);
                }
                else
                {
                    if (background != null)
                    {
                        background.Dispose();
                        background = null;
                    }
                    try
                    {
                        background = FastBitmap.FromFile(Path.Combine(skinFolder, backgroundName));
                        if (background == null)
                        {
                            return(false);
                        }
                    }
                    catch
                    {
                        return(false);
                    }
                }

                if (string.IsNullOrEmpty(stoneName))
                {
                    return(false);
                }
                else
                {
                    if (stone != null)
                    {
                        stone.Dispose();
                        stone = null;
                    }
                    try
                    {
                        stone = FastBitmap.FromFile(Path.Combine(skinFolder, stoneName));
                        if (stone == null)
                        {
                            return(false);
                        }
                    }
                    catch
                    {
                        return(false);
                    }
                }
            }
            finally
            {
                ini.Dispose();
            }
            return(true);
        }