Пример #1
0
        private bool ReadFormDataFromFile()
        {
            // Read the form positions from the file.
            UTF8Encoding encoding = new UTF8Encoding();
            string       data;

            if (_userData.Length != 0)
            {
                byte[] dataToRead = new byte[_userData.Length];

                try
                {
                    // Set the read position to the start of the file and read.
                    _userData.Seek(0, SeekOrigin.Begin);
                    _userData.Read(dataToRead, 0, dataToRead.Length);
                }
                catch (IOException e)
                {
                    string errorInfo = e.ToString();
                    // An error occurred while attempt to read, return false.
                    return(false);
                }

                // Parse out the data to get the window rectangles
                data = encoding.GetString(dataToRead);

                try
                {
                    // Convert the string data to rectangles
                    RectangleConverter rectConv = new RectangleConverter();
                    string             form1pos = data.Substring(1, data.IndexOf("~", 1) - 1);

                    _form1Position = (Rectangle)rectConv.ConvertFromString(form1pos);

                    string form2pos = data.Substring(data.IndexOf("~", 1) + 1);
                    _form2Position = (Rectangle)rectConv.ConvertFromString(form2pos);

                    return(true);
                }
                catch
                {
                    // Error occurred while attempting to convert the rectangle data.
                    // Return false to use default values.
                    return(false);
                }
            }
            else
            {
                // No data in the file, return false to use default values.
                return(false);
            }
        }
Пример #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.DefaultExt = "json";
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                RectangleConverter rc       = new RectangleConverter();
                JObject            root     = JsonConvert.DeserializeObject(File.ReadAllText(ofd.FileName)) as JObject;
                JArray             patterns = root["patterns"] as JArray;
                foreach (JObject pattern in patterns)
                {
                    string identifier = pattern["identifier"].ToString();
                    JArray rectsArray = pattern["rects"] as JArray;

                    selectedRectangles[identifier] = new List <BoundRect>();
                    foreach (var rs in rectsArray)
                    {
                        JObject obj = rs as JObject;

                        Rectangle rect = (Rectangle)rc.ConvertFromString((string)rs["rect"]);
                        int       type = int.Parse((string)rs["type"]);

                        BoundRect br = new BoundRect();
                        br.Rectangle = rect;
                        br.Type      = type;

                        selectedRectangles[identifier].Add(br);
                    }

                    selectedImages[identifier] = new Bitmap(PATH + identifier + ".png");
                }
            }
        }
Пример #3
0
        internal static Rectangle ReadAttributeRectangle(XmlNode node, string attributeName)
        {
            CheckAttributeExists(node, attributeName);
            string text = node.Attributes[attributeName].Value;

            return(RectangleConverter.ConvertFromString(null, System.Globalization.CultureInfo.CurrentCulture, text));
        }
Пример #4
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);
        }
Пример #5
0
        internal Rectangle?GetSaveBounds(string id)
        {
            string settingID = string.Format("window.{0}.bounds", id);
            var    s         = Tool.Settings.GetValue <string>(settingID, "");

            if (string.IsNullOrEmpty(s))
            {
                return(null);
            }
            return((Rectangle)converter.ConvertFromString(s));
        }
Пример #6
0
        public static void Load()
        {
            RectangleConverter rc       = new RectangleConverter();
            JObject            root     = JsonConvert.DeserializeObject(File.ReadAllText(Runner.PATH + "configurer\\config.json")) as JObject;
            JArray             patterns = root["patterns"] as JArray;

            foreach (JObject pattern in patterns)
            {
                string identifier = pattern["identifier"].ToString();

                JArray rects = pattern["rects"] as JArray;

                Rectangle?coordRect  = null;
                Rectangle?clickRect  = null;
                Rectangle?optionRect = null;
                foreach (var jo in rects)
                {
                    Rectangle rect = (Rectangle)rc.ConvertFromString((string)jo["rect"]);
                    int       type = int.Parse((string)jo["type"]);
                    if (type == 2)
                    {
                        clickRect = rect;
                    }
                    else if (type == 3)
                    {
                        optionRect = rect;
                    }
                    else
                    {
                        coordRect = rect;
                    }
                }

                Create(identifier, new Bitmap(Runner.PATH + "configurer\\" + identifier + ".png"), (Rectangle)coordRect, clickRect, optionRect);
            }
        }
Пример #7
0
        /// <summary>
        /// 폴더 폼 생성
        /// </summary>
        private void showFormFolder()
        {
            if (mainFolder == null)
            {
                mainFolder = new Form_Folder();

                // mainFolder 폼이 닫힐때 실행될 이벤트 할당
                mainFolder.FormClosed += delegate(Object tmp_sender, FormClosedEventArgs tmp_e)
                {
                    mainFolder.Dispose();
                    mainFolder    = null;
                    trayIcon.Text = DEFINE.TRAY_NAME;
                };

                // mainFolder 폼의 설정값이 변경될때 실행될 이벤트 할당
                mainFolder.throw_Environment_SettingChanged += mainFolder_throw_Environment_SettingChanged;


                // mainFolder TopMost 여부 지정
                mainFolder.TopMost = configDoc.SelectSingleNode("//SETTING/" + DEFINE.CONFIG_SETTING_TOPMOST).InnerText == "TRUE" ? true : false;


                // mainFolder 크기 지정(기존에 저장된 위치값 있는지)
                #region
                String str_mainFolder_rect = configDoc.SelectSingleNode("//SETTING/" + DEFINE.CONFIG_SETTING_CLOSERECT).InnerText;
                if (!String.IsNullOrEmpty(str_mainFolder_rect))
                {
                    RectangleConverter rc      = new RectangleConverter();
                    Rectangle          tmpRect = (Rectangle)rc.ConvertFromString(str_mainFolder_rect);

                    Screen[] sc = Screen.AllScreens;
                    for (int i = 0; i < sc.Length; i++)
                    {
                        if (sc[i].WorkingArea.Contains(tmpRect)) //맞는 화면 존재 시
                        {
                            mainFolder.Location = tmpRect.Location;
                            mainFolder.Size     = tmpRect.Size;
                            break;
                        }
                        else if (sc[i].WorkingArea.IntersectsWith(tmpRect)) //교차하는 화면 존재 시
                        {
                            // 넓이, 높이 체크, x,y조정
                            Rectangle scRect = sc[i].Bounds;
                            if (scRect.Width < tmpRect.Width)
                            {
                                tmpRect.Width = scRect.Width;
                            }
                            if (scRect.Height < tmpRect.Height)
                            {
                                tmpRect.Height = scRect.Height;
                            }

                            if (scRect.Left > tmpRect.Left)
                            {
                                tmpRect.X = scRect.Left;
                            }
                            if (scRect.Right < tmpRect.Right)
                            {
                                tmpRect.X = scRect.Right - tmpRect.Width;
                            }
                            if (scRect.Top > tmpRect.Top)
                            {
                                tmpRect.Y = scRect.Top;
                            }
                            if (scRect.Bottom < tmpRect.Bottom)
                            {
                                tmpRect.Y = scRect.Bottom - tmpRect.Height;
                            }

                            mainFolder.Location = tmpRect.Location;
                            mainFolder.Size     = tmpRect.Size;
                            break;
                        }
                        else
                        {
                            //mainFolder.Size = tmpRect.Size;
                            Rectangle primaryScreen_bounds = Screen.PrimaryScreen.Bounds;
                            Size      mainFolder_size      = DEFINE.DEFAULT_FOLDER_SIZE;
                            mainFolder.DesktopBounds = new Rectangle((primaryScreen_bounds.Width - mainFolder_size.Width) - 3, 3, mainFolder_size.Width, mainFolder_size.Height);
                        }
                    }
                }
                else
                {
                    Rectangle primaryScreen_bounds = Screen.PrimaryScreen.Bounds;
                    Size      mainFolder_size      = DEFINE.DEFAULT_FOLDER_SIZE;
                    mainFolder.DesktopBounds = new Rectangle((primaryScreen_bounds.Width - mainFolder_size.Width) - 3, 3, mainFolder_size.Width, mainFolder_size.Height);
                }
                mainFolder.MinimumSize = DEFINE.DEFAULT_FOLDER_SIZE;
                #endregion

                mainFolder.occurred_event += mainFolder_occurred_event;

                mainFolder.Text          = DEFINE.TRAY_NAME;
                mainFolder.ShowInTaskbar = false;
                mainFolder.Show(this);

                //trayIcon.Text = DEFINE.TRAY_NAME + " (RUNNING...)";
            }
            else
            {
                mainFolder.Activate();
            }
        }
Пример #8
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;
            }
        }
        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           = true;
                mainForm.checkBox_stayOnTop.Checked              = true;
                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
                }
            }
        }