示例#1
0
        public SettingsForm()
        {
            InitializeComponent();

            var backEnd = new AutomaticUpdaterBackend
            {
                GUID = "Fireball AutoUpdater",
                UpdateType = UpdateType.Automatic
            };

            backEnd.Initialize();
            backEnd.AppLoaded();

            backEnd.ReadyToBeInstalled += (s, e) =>
            {
                if (backEnd.UpdateStepOn != UpdateStepOn.UpdateReadyToInstall)
                    return;

                backEnd.InstallNow();
                Application.Exit();
            };

            if (backEnd.ClosingForInstall)
                return;

            backEnd.ForceCheckForUpdate(true);

            Icon = tray.Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath);

            var builder = new StringBuilder();
            {
                builder.Append("Image Files (*.png;*.gif;*.jpg;*.jpeg;*.bmp)|*.png;*.gif;*.jpg;*.jpeg;*.bmp|");
                builder.Append("PNG|*.png|");
                builder.Append("GIF|*.gif|");
                builder.Append("JPG|*.jpg|");
                builder.Append("JPEG|*.jpeg|");
                builder.Append("BMP|*.bmp");
            }

            imageFilter = builder.ToString();

            PopulateCombos();
            Settings.Instance = SettingsManager.Load();
            settings = Settings.Instance;
            PopulateSettings();

            PluginManager.Load();

            foreach (IPlugin plugin in PluginManager.Plugins)
            {
                PluginItem item = new PluginItem(plugin);
                cPlugins.Items.Add(item);

                if (settings.ActivePlugin.Equals(plugin.Name))
                    cPlugins.SelectedItem = item;
            }

            if (cPlugins.SelectedItem == null && cPlugins.Items.Count > 0)
                cPlugins.SelectedIndex = 0;

            #region :: Register Hotkeys ::
            /*StringBuilder hotkeyRegisterErrorBuilder = new StringBuilder();

            if (settings.CaptureScreenHotey.GetCanRegister(this))
            {
                settings.CaptureScreenHotey.Register(this);
                settings.CaptureScreenHotey.Pressed += CaptureScreenHotkeyPressed;
            }
            else
            {
                if (settings.CaptureScreenHotey.KeyCode != Keys.None)
                    hotkeyRegisterErrorBuilder.AppendFormat(" - Can't register capture screen hotkey ({0})\n", settings.CaptureScreenHotey);
            }

            if (settings.CaptureAreaHotkey.GetCanRegister(this))
            {
                settings.CaptureAreaHotkey.Register(this);
                settings.CaptureAreaHotkey.Pressed += CaptureAreaHotkeyPressed;
            }
            else
            {
                if (settings.CaptureScreenHotey.KeyCode != Keys.None)
                    hotkeyRegisterErrorBuilder.AppendFormat(" - Can't register capture area hotkey ({0})\n", settings.CaptureAreaHotkey);
            }

            if (hotkeyRegisterErrorBuilder.Length > 0)
            {
                Helper.InfoBoxShow(String.Format("Failed to register hotkeys!\n{0}", hotkeyRegisterErrorBuilder));
            }*/
            #endregion

            SaveSettings();

            Application.ApplicationExit += (s, e) => SettingsManager.Save();
        }
示例#2
0
        public static Settings Load()
        {
            Settings rtnSettings = new Settings();

            try
            {
                XDocument xdoc = XDocument.Load(FileManager.SettingsFile);
                XElement root = xdoc.Element("SettingsFile");

                if (root == null)
                    return rtnSettings;

                XElement languageNode = root.Element("Language");
                XElement captureScreenNode = root.Element("CaptureScreenHotkey");
                XElement captureAreaNode = root.Element("CaptureAreaHotkey");

                XElement uploadFromClipboardNode = root.Element("UploadFromClipboardHotkey");
                XElement uploadFromFileNode = root.Element("UploadFromFileHotkey");

                XElement captureModeNode = root.Element("CaptureMode");
                XElement activePluginNode = root.Element("ActivePlugin");
                XElement notificationNode = root.Element("Notification");
                XElement startWithComputerNode = root.Element("StartWithComputer");
                XElement withoutEditorNode = root.Element("WithoutEditor");

                XElement brushWidthNode = root.Element("BrushWidth");
                XElement foreColorNode = root.Element("ForeColor");
                XElement backColorNode = root.Element("BackColor");
                XElement textFontNode = root.Element("TextFont");

                XElement mruNode = root.Element("Recent");

                if (languageNode != null)
                    rtnSettings.Language = languageNode.Value;

                #region :: CaptureScreenHotkey ::
                if (captureScreenNode == null)
                    return rtnSettings;

                XAttribute winAttribute = captureScreenNode.Attribute("Win");
                XAttribute ctrlAttribute = captureScreenNode.Attribute("Ctrl");
                XAttribute shiftAttribute = captureScreenNode.Attribute("Shift");
                XAttribute altAttribute = captureScreenNode.Attribute("Alt");
                XAttribute keyAttribute = captureScreenNode.Attribute("Key");

                if (winAttribute == null || ctrlAttribute == null || shiftAttribute == null || altAttribute == null || keyAttribute == null)
                    return rtnSettings;

                rtnSettings.CaptureScreenHotey = new Hotkey(
                    Convert.ToBoolean(ctrlAttribute.Value),
                    Convert.ToBoolean(shiftAttribute.Value),
                    Convert.ToBoolean(altAttribute.Value),
                    Convert.ToBoolean(winAttribute.Value),
                    (Keys)Enum.Parse(typeof(Keys), keyAttribute.Value));
                #endregion
                #region :: CaptureAreaHotkey ::
                if (captureAreaNode == null)
                    return rtnSettings;

                winAttribute = captureAreaNode.Attribute("Win");
                ctrlAttribute = captureAreaNode.Attribute("Ctrl");
                shiftAttribute = captureAreaNode.Attribute("Shift");
                altAttribute = captureAreaNode.Attribute("Alt");
                keyAttribute = captureAreaNode.Attribute("Key");

                if (winAttribute == null || ctrlAttribute == null || shiftAttribute == null || altAttribute == null || keyAttribute == null)
                    return rtnSettings;

                rtnSettings.CaptureAreaHotkey = new Hotkey(
                    Convert.ToBoolean(ctrlAttribute.Value),
                    Convert.ToBoolean(shiftAttribute.Value),
                    Convert.ToBoolean(altAttribute.Value),
                    Convert.ToBoolean(winAttribute.Value),
                    (Keys)Enum.Parse(typeof(Keys), keyAttribute.Value));
                #endregion
                #region :: UploadFromClipboardHotkey ::
                if (uploadFromClipboardNode == null)
                    return rtnSettings;

                winAttribute = uploadFromClipboardNode.Attribute("Win");
                ctrlAttribute = uploadFromClipboardNode.Attribute("Ctrl");
                shiftAttribute = uploadFromClipboardNode.Attribute("Shift");
                altAttribute = uploadFromClipboardNode.Attribute("Alt");
                keyAttribute = uploadFromClipboardNode.Attribute("Key");

                if (winAttribute == null || ctrlAttribute == null || shiftAttribute == null || altAttribute == null || keyAttribute == null)
                    return rtnSettings;

                rtnSettings.UploadFromClipboardHotkey = new Hotkey(
                    Convert.ToBoolean(ctrlAttribute.Value),
                    Convert.ToBoolean(shiftAttribute.Value),
                    Convert.ToBoolean(altAttribute.Value),
                    Convert.ToBoolean(winAttribute.Value),
                    (Keys)Enum.Parse(typeof(Keys), keyAttribute.Value));
                #endregion
                #region :: UploadFromFileHotkey ::
                if (uploadFromFileNode == null)
                    return rtnSettings;

                winAttribute = uploadFromFileNode.Attribute("Win");
                ctrlAttribute = uploadFromFileNode.Attribute("Ctrl");
                shiftAttribute = uploadFromFileNode.Attribute("Shift");
                altAttribute = uploadFromFileNode.Attribute("Alt");
                keyAttribute = uploadFromFileNode.Attribute("Key");

                if (winAttribute == null || ctrlAttribute == null || shiftAttribute == null || altAttribute == null || keyAttribute == null)
                    return rtnSettings;

                rtnSettings.UploadFromFileHotkey = new Hotkey(
                    Convert.ToBoolean(ctrlAttribute.Value),
                    Convert.ToBoolean(shiftAttribute.Value),
                    Convert.ToBoolean(altAttribute.Value),
                    Convert.ToBoolean(winAttribute.Value),
                    (Keys)Enum.Parse(typeof(Keys), keyAttribute.Value));
                #endregion

                if (activePluginNode == null)
                    return rtnSettings;

                rtnSettings.ActivePlugin = activePluginNode.Value;

                if (startWithComputerNode == null)
                    return rtnSettings;

                if (notificationNode == null)
                {
                    rtnSettings.Notification = NotificationType.Tooltip;
                }
                else
                {
                    NotificationType type;

                    if (Enum.TryParse(notificationNode.Value, out type))
                        rtnSettings.Notification = type;
                }

                rtnSettings.StartWithComputer = Convert.ToBoolean(startWithComputerNode.Value);
                rtnSettings.WithoutEditor = Convert.ToBoolean(withoutEditorNode.Value);

                rtnSettings.BrushWidth = Byte.Parse(brushWidthNode.Value);
                rtnSettings.ForeColor = Color.FromArgb(
                    Byte.Parse(foreColorNode.Attribute("R").Value),
                    Byte.Parse(foreColorNode.Attribute("G").Value),
                    Byte.Parse(foreColorNode.Attribute("B").Value));

                rtnSettings.BackColor = Color.FromArgb(
                    Byte.Parse(backColorNode.Attribute("R").Value),
                    Byte.Parse(backColorNode.Attribute("G").Value),
                    Byte.Parse(backColorNode.Attribute("B").Value));

                rtnSettings.TextFont = new Font(
                    textFontNode.Attribute("FontFamily").Value,
                    float.Parse(textFontNode.Attribute("FontSize").Value),
                    (FontStyle)Enum.Parse(typeof(FontStyle), textFontNode.Attribute("Style").Value));

                rtnSettings.MRUList = new MRUList(
                    from link in mruNode.Descendants("Link")
                    select link.Value);
            }
            catch { }

            return rtnSettings;
        }