示例#1
0
        /// <summary>
        /// Load the application config file and restore form position
        /// </summary>
        private void LoadConfigFile()
        {
            TextReader reader = null;
            Rectangle formBounds = Rectangle.Empty;
            try
            {
                string configFolder = Path.GetDirectoryName(InstallPadApp.ConfigFilePath);
                if (!Directory.Exists(configFolder))
                    Directory.CreateDirectory(configFolder);

                reader = new StreamReader(InstallPadApp.ConfigFilePath);
                RectangleConverter converter = new RectangleConverter();
                formBounds = (Rectangle)converter.ConvertFromString(reader.ReadLine());
            }
            catch (NotSupportedException)
            {
                // Error in the configure file. Ignore
            }
            catch (IOException)
            {
                // No config file found. Ignore
            }
            finally
            {
                if (reader != null)
                    reader.Close();
            }
            if (formBounds != Rectangle.Empty)
            {
                // If the bounds are outside of the screen's work area, move the form so it's not outside
                // of the work area. This can happen if the user changes their resolution 
                // and we then restore the applicationto its position -- it may be off screen and 
                // then they can't see it or move it.

                // Get the working area of the monitor that contains this rectangle (in case it's a
                // multi-display system
                Rectangle workingArea = Screen.GetWorkingArea(formBounds);
                if (formBounds.Left < workingArea.Left)
                    formBounds.Location = new Point(workingArea.Location.X, formBounds.Location.Y);
                if (formBounds.Top < workingArea.Top)
                    formBounds.Location = new Point(formBounds.Location.X, workingArea.Location.Y);
                if (formBounds.Right > workingArea.Right)
                    formBounds.Location = new Point(formBounds.X - (formBounds.Right - workingArea.Right),
                        formBounds.Location.Y);
                if (formBounds.Bottom > workingArea.Bottom)
                    formBounds.Location = new Point(formBounds.X,
                        formBounds.Y - (formBounds.Bottom - workingArea.Bottom));

                this.Bounds = formBounds;
            }

        }
示例#2
0
        public void LoadConfig(bool def = false)
        {
            if (def)
            {
                tabletOffset = new Point(0, 0);
                overrideBounds = new Rectangle(0, 0, 0, 0);
                smoothingStrength = 30;
                smoothingInterpolation = 4;
                overlayScreen = 0;
                tolerance = 300;
                manualInterpolation = false;
                stayOnTop = false;
                disableOverlay = false;
                allScreens = false;
                manualOverlayOverride = false;
                disableCatchUp = false;
                snapToCursor = false;
                smoothOnDraw = false;
                tabletOffsetOverride = false;
                disableAutoDetection = false;
                hotkeys[0] = "None";
                hotkeys[1] = "None";
                hotkeys[2] = "None";
                hotkeys[3] = "None";
                hotkeys[4] = "None";
                hotkeys[5] = "None";

                // Main window resetting
                mainForm.checkBox_smoothOnDraw.Checked = false;
                mainForm.checkBox_stayOnTop.Checked = false;
                mainForm.checkBox_tabletMode.Checked = false;
                mainForm.checkBox_tabletMode.Enabled = false;
                mainForm.checkBox_manualInterpolation.Checked = false;
                mainForm.trackBar_smoothingInterpolation.Enabled = false;
                mainForm.textBox_smoothingInterpolation.Enabled = false;
                mainForm.textBox_smoothingInterpolation.Text = smoothingInterpolation.ToString();
                mainForm.textBox_smoothingStrength.Text = smoothingStrength.ToString();
                mainForm.checkBox_smoothOnDraw.Checked = false;
                mainForm.TopMost = false;

                // Cursor and overlay resetting
                overlayForm.cursorColor = Color.FromArgb(128, 128, 128);
                overlayForm.cursorFillColor = Color.FromArgb(255, 255, 254);
                overlayForm.cursorType = Overlay.CursorType.Bullseye;
                overlayForm.Show();
                overlayForm.Bounds = Screen.PrimaryScreen.Bounds;
                mainForm.button_colorDialog.BackColor = overlayForm.cursorColor;

                // Hotkey resetting
                for (int i = 0; i < mainForm.hotKeyHandling.Count(); i++)
                {
                    try
                    {
                        mainForm.hotKeyHandling[i].Dispose();
                    }
                    catch
                    {
                        // Nothing to dispose!
                    }
                }
            }
            else
            {
                try
                {
                    Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                    // Main window loading
                    smoothingStrength = int.Parse(config.AppSettings.Settings["Strength"].Value);
                    smoothingInterpolation = int.Parse(config.AppSettings.Settings["Interpolation"].Value);
                    manualInterpolation = bool.Parse(config.AppSettings.Settings["Manual Interpolation"].Value);
                    smoothOnDraw = bool.Parse(config.AppSettings.Settings["Smooth On Draw"].Value);
                    stayOnTop = bool.Parse(config.AppSettings.Settings["Stay On Top"].Value);
                    disableAutoDetection = bool.Parse(config.AppSettings.Settings["Disable Auto Detection"].Value);
                    mainForm.tabletMode = bool.Parse(config.AppSettings.Settings["Tablet Mode"].Value);
                    mainForm.checkBox_tabletMode.Enabled = disableAutoDetection;
                    mainForm.checkBox_tabletMode.Checked = mainForm.tabletMode;
                    mainForm.checkBox_smoothOnDraw.Checked = smoothOnDraw;
                    if (manualInterpolation)
                    {
                        mainForm.checkBox_manualInterpolation.Checked = true;
                        mainForm.trackBar_smoothingInterpolation.Enabled = true;
                        mainForm.textBox_smoothingInterpolation.Enabled = true;
                    }
                    mainForm.textBox_smoothingInterpolation.Text = smoothingInterpolation.ToString();
                    mainForm.textBox_smoothingStrength.Text = smoothingStrength.ToString();
                    if (stayOnTop)
                    {
                        mainForm.checkBox_stayOnTop.Checked = true;
                        mainForm.TopMost = true;
                        overlayForm.TopMost = true;
                    }

                    // Cursor and overlay loading
                    overlayForm.cursorType = (Overlay.CursorType)Enum.Parse(typeof(Overlay.CursorType), config.AppSettings.Settings["Cursor Graphic"].Value);
                    overlayForm.cursorColor = ColorTranslator.FromHtml(config.AppSettings.Settings["Main Color"].Value);
                    overlayForm.cursorFillColor = ColorTranslator.FromHtml(config.AppSettings.Settings["Fill Color"].Value);
                    overlayScreen = int.Parse(config.AppSettings.Settings["Overlay Screen"].Value);
                    disableOverlay = bool.Parse(config.AppSettings.Settings["Disable Overlay"].Value);
                    allScreens = bool.Parse(config.AppSettings.Settings["All Screens"].Value);
                    manualOverlayOverride = bool.Parse(config.AppSettings.Settings["Manual Overlay Override"].Value);
                    RectangleConverter r = new RectangleConverter();
                    overrideBounds = (Rectangle)r.ConvertFromString(config.AppSettings.Settings["Override Bounds"].Value);
                    if (disableOverlay) overlayForm.Hide();
                    overlayForm.Bounds = Screen.AllScreens[overlayScreen].Bounds;
                    if (allScreens) overlayForm.Bounds = new Rectangle(0, 0, SystemInformation.VirtualScreen.Width, SystemInformation.VirtualScreen.Height);
                    if (manualOverlayOverride) overlayForm.Bounds = overrideBounds;
                    mainForm.button_colorDialog.BackColor = overlayForm.cursorColor;

                    // ...and everything else
                    disableCatchUp = bool.Parse(config.AppSettings.Settings["Disable Catch Up"].Value);
                    snapToCursor = bool.Parse(config.AppSettings.Settings["Snap To Cursor"].Value);
                    tolerance = int.Parse(config.AppSettings.Settings["Tolerance"].Value);
                    tabletOffsetOverride = bool.Parse(config.AppSettings.Settings["Tablet Offset Override"].Value);
                    PointConverter p = new PointConverter();
                    tabletOffset = (Point)p.ConvertFromString(config.AppSettings.Settings["Tablet Offset"].Value);
                    KeysConverter c = new KeysConverter();
                    Keys k;
                    Hotkey.KeyModifiers m;
                    hotkeys[0] = config.AppSettings.Settings["Hotkey 1"].Value;
                    if (hotkeys[0] != "None")
                    {
                        k = (Keys)c.ConvertFromString(config.AppSettings.Settings["Hotkey 1"].Value);
                        m = Hotkey.GetModifiers(k, out k);
                        if (k != Keys.None)
                        {
                            mainForm.RegisterHotkey(mainForm.Handle, 0, m, k);
                        }
                    }
                    hotkeys[1] = config.AppSettings.Settings["Hotkey 2"].Value;
                    if (hotkeys[1] != "None")
                    {
                        k = (Keys)c.ConvertFromString(config.AppSettings.Settings["Hotkey 2"].Value);
                        m = Hotkey.GetModifiers(k, out k);
                        if (k != Keys.None)
                        {
                            mainForm.RegisterHotkey(mainForm.Handle, 1, m, k);
                        }
                    }
                    hotkeys[2] = config.AppSettings.Settings["Hotkey 3"].Value;
                    if (hotkeys[2] != "None")
                    {
                        k = (Keys)c.ConvertFromString(config.AppSettings.Settings["Hotkey 3"].Value);
                        m = Hotkey.GetModifiers(k, out k);
                        if (k != Keys.None)
                        {
                            mainForm.RegisterHotkey(mainForm.Handle, 2, m, k);
                        }
                    }
                    hotkeys[3] = config.AppSettings.Settings["Hotkey 4"].Value;
                    if (hotkeys[3] != "None")
                    {
                        k = (Keys)c.ConvertFromString(config.AppSettings.Settings["Hotkey 4"].Value);
                        m = Hotkey.GetModifiers(k, out k);
                        if (k != Keys.None)
                        {
                            mainForm.RegisterHotkey(mainForm.Handle, 3, m, k);
                        }
                    }
                    hotkeys[4] = config.AppSettings.Settings["Hotkey 5"].Value;
                    if (hotkeys[4] != "None")
                    {
                        k = (Keys)c.ConvertFromString(config.AppSettings.Settings["Hotkey 5"].Value);
                        m = Hotkey.GetModifiers(k, out k);
                        if (k != Keys.None)
                        {
                            mainForm.RegisterHotkey(mainForm.Handle, 4, m, k);
                        }
                    }
                    hotkeys[5] = config.AppSettings.Settings["Hotkey 6"].Value;
                    if (hotkeys[5] != "None")
                    {
                        k = (Keys)c.ConvertFromString(config.AppSettings.Settings["Hotkey 6"].Value);
                        m = Hotkey.GetModifiers(k, out k);
                        if (k != Keys.None)
                        {
                            mainForm.RegisterHotkey(mainForm.Handle, 5, m, k);
                        }
                    }
                }
                catch
                {
                    // Quietly fail loading bad configs or no configs
                }
            }
        }
示例#3
0
        /// <summary>
        /// Creates instance of module from HTML node
        /// </summary>
        /// <param name="node">Module HTML node</param>
        /// <returns>Instance of AModule with UserSetup</returns>
        public AModule GetModuleFromNode(HtmlNode node)
        {
            if (node.Attributes["name"] == null)
            {
                return null;
            }

            AModule module = CModuleReader.Instance.GetModuleInstanceFromName(node.Attributes["name"].Value);

            // Set attributes
            foreach (HtmlAttribute attribute in node.Attributes)
            {
                try
                {
                    Object[] args = new Object[] { attribute.Value };
                    module.setup.GetType().InvokeMember(attribute.Name, BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty, null, module.setup, args);
                }
                catch (Exception)
                {
                    // Attribute not found, ignoring
                }
            }
            // And location
            RectangleConverter converter = new RectangleConverter();
            module.setup.location = (Rectangle)converter.ConvertFromString(node.Attributes["location"].Value);

            return module;
        }