Ejemplo n.º 1
0
        public MainWindow()
        {
            string thisprocessname = Process.GetCurrentProcess().ProcessName;

            if (Process.GetProcesses().Count(p => p.ProcessName == thisprocessname) > 1)
            {
                Main.AddLog("Duplicate process found");
                Close();
            }


            INSTANCE = this;
            main     = new Main();
            listener = new LowLevelListener(); //publisher
            try
            {
                if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\WFInfo\settings.json"))
                {
                    Settings.settingsObj = JObject.Parse(File.ReadAllText(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\WFInfo\settings.json"));
                }
                else
                {
                    Settings.settingsObj = new JObject();
                    welcomeDialogue      = new WelcomeDialogue();
                }
                InitializeSettings();

                LowLevelListener.KeyEvent   += main.OnKeyAction;
                LowLevelListener.MouseEvent += main.OnMouseAction;
                listener.Hook();
                InitializeComponent();
                Version.Content = "v" + Main.BuildVersion;

                Left = 300;
                Top  = 300;

                System.Drawing.Rectangle winBounds = new System.Drawing.Rectangle(Convert.ToInt32(Settings.mainWindowLocation.X), Convert.ToInt32(Settings.mainWindowLocation.Y), Convert.ToInt32(Width), Convert.ToInt32(Height));
                foreach (System.Windows.Forms.Screen scr in System.Windows.Forms.Screen.AllScreens)
                {
                    if (scr.Bounds.Contains(winBounds))
                    {
                        Left = Settings.mainWindowLocation.X;
                        Top  = Settings.mainWindowLocation.Y;
                        break;
                    }
                }
                Settings.settingsObj["MainWindowLocation_X"] = Left;
                Settings.settingsObj["MainWindowLocation_Y"] = Top;

                Settings.Save();

                Closing += new CancelEventHandler(LoggOut);
            }
            catch (Exception e)
            {
                Main.AddLog("An error occured while loading the main window: " + e.Message);
            }
        }
Ejemplo n.º 2
0
        public MainWindow()
        {
            string thisprocessname = Process.GetCurrentProcess().ProcessName;

            if (Process.GetProcesses().Count(p => p.ProcessName == thisprocessname) > 1)
            {
                Main.AddLog("Duplicate process found");
                Close();
            }

            INSTANCE = this;
            main     = new Main();

            listener = new LowLevelListener(); //publisher
            try
            {
                if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\WFInfo\settings.json"))
                {
                    Settings.settingsObj = JObject.Parse(File.ReadAllText(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\WFInfo\settings.json"));
                }
                else
                {
                    Settings.settingsObj = new JObject();
                    hai = new WelcomeDialogue();
                }
                if (!Settings.settingsObj.TryGetValue("Display", out _))
                {
                    Settings.settingsObj["Display"] = "Overlay";
                }
                Settings.isOverlaySelected = Settings.settingsObj.GetValue("Display").ToString() == "Overlay";

                if (!Settings.settingsObj.TryGetValue("MainWindowLocation_X", out _))
                {
                    Settings.settingsObj["MainWindowLocation_X"] = 300;
                }
                if (!Settings.settingsObj.TryGetValue("MainWindowLocation_Y", out _))
                {
                    Settings.settingsObj["MainWindowLocation_Y"] = 300;
                }
                Settings.mainWindowLocation = new Point(Settings.settingsObj.GetValue("MainWindowLocation_X").ToObject <Int32>(), Settings.settingsObj.GetValue("MainWindowLocation_Y").ToObject <Int32>());

                if (!Settings.settingsObj.TryGetValue("ActivationKey", out _))
                {
                    Settings.settingsObj["ActivationKey"] = "Snapshot";
                }
                try
                {
                    Settings.ActivationKey = (Key)Enum.Parse(typeof(Key), Settings.settingsObj.GetValue("ActivationKey").ToString());
                } catch
                {
                    try
                    {
                        Settings.ActivationMouseButton = (MouseButton)Enum.Parse(typeof(MouseButton), Settings.settingsObj.GetValue("ActivationKey").ToString());
                    } catch
                    {
                        Main.AddLog("Couldn't Parse Activation Key -- Defaulting to PrintScreen");
                        Settings.settingsObj["ActivationKey"] = "Snapshot";
                        Settings.ActivationKey = Key.Snapshot;
                    }
                }

                if (!Settings.settingsObj.TryGetValue("Debug", out _))
                {
                    Settings.settingsObj["Debug"] = false;
                }
                Settings.debug = (bool)Settings.settingsObj.GetValue("Debug");

                if (!Settings.settingsObj.TryGetValue("Clipboard", out _))
                {
                    Settings.settingsObj["Clipboard"] = false;
                }
                Settings.clipboard = (bool)Settings.settingsObj.GetValue("Clipboard");

                if (!Settings.settingsObj.TryGetValue("Auto", out _))
                {
                    Settings.settingsObj["Auto"] = false;
                }
                Settings.auto = (bool)Settings.settingsObj.GetValue("Auto");

                if (!Settings.settingsObj.TryGetValue("CuttingEdge", out _))
                {
                    Settings.settingsObj["CuttingEdge"] = false;
                }
                Settings.autoScaling = (bool)Settings.settingsObj.GetValue("CuttingEdge");

                if (!Settings.settingsObj.TryGetValue("AutoDelay", out _))
                {
                    Settings.settingsObj["AutoDelay"] = 250L;
                }
                Settings.autoDelay = (long)Settings.settingsObj.GetValue("AutoDelay");

                if (!Settings.settingsObj.TryGetValue("Scaling", out _))
                {
                    Settings.settingsObj["Scaling"] = 100.0;
                }
                Settings.scaling = Convert.ToInt32(Settings.settingsObj.GetValue("Scaling"));

                if (!Settings.settingsObj.TryGetValue("ImageRetentionTime", out _))
                {
                    Settings.settingsObj["ImageRetentionTime"] = 12;
                }
                Settings.imageRetentionTime = Convert.ToInt32(Settings.settingsObj.GetValue("ImageRetentionTime"));

                if (!Settings.settingsObj.TryGetValue("ClipboardTemplate", out _))
                {
                    Settings.settingsObj["ClipboardTemplate"] = "-- by WFInfo (smart OCR with pricecheck)";
                }
                Settings.ClipboardTemplate = Convert.ToString(Settings.settingsObj.GetValue("ClipboardTemplate"));


                Settings.Save();

                LowLevelListener.KeyEvent   += main.OnKeyAction;
                LowLevelListener.MouseEvent += main.OnMouseAction;
                listener.Hook();
                InitializeComponent();
                Version.Content = "v" + Main.BuildVersion;

                Left = 300;
                Top  = 300;

                System.Drawing.Rectangle winBounds = new System.Drawing.Rectangle(Convert.ToInt32(Settings.mainWindowLocation.X), Convert.ToInt32(Settings.mainWindowLocation.Y), Convert.ToInt32(Width), Convert.ToInt32(Height));
                foreach (System.Windows.Forms.Screen scr in System.Windows.Forms.Screen.AllScreens)
                {
                    if (scr.Bounds.Contains(winBounds))
                    {
                        Left = Settings.mainWindowLocation.X;
                        Top  = Settings.mainWindowLocation.Y;
                        break;
                    }
                }
                Settings.settingsObj["MainWindowLocation_X"] = Left;
                Settings.settingsObj["MainWindowLocation_Y"] = Top;
                Settings.Save();
            }
            catch (Exception e)
            {
                Main.AddLog("An error occured while loading the main window: " + e.Message);
            }
        }
Ejemplo n.º 3
0
        public void InitializeSettings()
        {
            if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\WFInfo\settings.json") && Settings.settingsObj == null)
            {
                Settings.settingsObj = JObject.Parse(File.ReadAllText(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\WFInfo\settings.json"));
            }
            else
            {
                if (Settings.settingsObj == null)
                {
                    Settings.settingsObj = new JObject();
                }
                welcomeDialogue = new WelcomeDialogue();
            }

            if (!Settings.settingsObj.TryGetValue("Display", out _))
            {
                Settings.settingsObj["Display"] = "Overlay";
            }
            Settings.isOverlaySelected = Settings.settingsObj.GetValue("Display").ToString() == "Overlay";
            Settings.isLightSelected   = Settings.settingsObj.GetValue("Display").ToString() == "Light";

            if (!Settings.settingsObj.TryGetValue("MainWindowLocation_X", out _))
            {
                Settings.settingsObj["MainWindowLocation_X"] = 300;
            }
            if (!Settings.settingsObj.TryGetValue("MainWindowLocation_Y", out _))
            {
                Settings.settingsObj["MainWindowLocation_Y"] = 300;
            }
            Settings.mainWindowLocation =
                new Point(Settings.settingsObj.GetValue("MainWindowLocation_X").ToObject <Int32>(),
                          Settings.settingsObj.GetValue("MainWindowLocation_Y").ToObject <Int32>());

            if (!Settings.settingsObj.TryGetValue("ActivationKey", out _))
            {
                Settings.settingsObj["ActivationKey"] = "Snapshot";
            }
            try
            {
                Settings.ActivationKey =
                    (Key)Enum.Parse(typeof(Key), Settings.settingsObj.GetValue("ActivationKey").ToString());
            }
            catch
            {
                try
                {
                    Settings.ActivationMouseButton = (MouseButton)Enum.Parse(typeof(MouseButton),
                                                                             Settings.settingsObj.GetValue("ActivationKey").ToString());
                }
                catch
                {
                    Main.AddLog("Couldn't Parse Activation Key -- Defaulting to PrintScreen");
                    Settings.settingsObj["ActivationKey"] = "Snapshot";
                    Settings.ActivationKey = Key.Snapshot;
                }
            }

            if (!Settings.settingsObj.TryGetValue("DebugModifierKey", out _))
            {
                Settings.settingsObj["DebugModifierKey"] = Key.LeftShift.ToString();
            }
            Settings.DebugModifierKey =
                (Key)Enum.Parse(typeof(Key), Settings.settingsObj.GetValue("DebugModifierKey").ToString());

            if (!Settings.settingsObj.TryGetValue("SearchItModifierKey", out _))
            {
                Settings.settingsObj["SearchItModifierKey"] = Key.OemTilde.ToString();
            }
            Settings.SearchItModifierKey = (Key)Enum.Parse(typeof(Key), Settings.settingsObj.GetValue("SearchItModifierKey").ToString());

            if (!Settings.settingsObj.TryGetValue("SnapitModifierKey", out _))
            {
                Settings.settingsObj["SnapitModifierKey"] = Key.LeftCtrl.ToString();
            }
            Settings.SnapitModifierKey = (Key)Enum.Parse(typeof(Key), Settings.settingsObj.GetValue("SnapitModifierKey").ToString());

            if (!Settings.settingsObj.TryGetValue("Debug", out _))
            {
                Settings.settingsObj["Debug"] = false;
            }
            Settings.debug = (bool)Settings.settingsObj.GetValue("Debug");

            if (!Settings.settingsObj.TryGetValue("Locale", out _))
            {
                Settings.settingsObj["Locale"] = "en";
            }
            Settings.locale = Settings.settingsObj.GetValue("Locale").ToString();

            if (!Settings.settingsObj.TryGetValue("Clipboard", out _))
            {
                Settings.settingsObj["Clipboard"] = false;
            }
            Settings.clipboard = (bool)Settings.settingsObj.GetValue("Clipboard");

            if (!Settings.settingsObj.TryGetValue("AutoDelay", out _))
            {
                Settings.settingsObj["AutoDelay"] = 250L;
            }
            Settings.autoDelay = (long)Settings.settingsObj.GetValue("AutoDelay");

            if (!Settings.settingsObj.TryGetValue("Auto", out _))
            {
                Settings.settingsObj["Auto"] = 250L;
            }
            Settings.auto = (bool)Settings.settingsObj.GetValue("Auto");

            if (!Settings.settingsObj.TryGetValue("ImageRetentionTime", out _))
            {
                Settings.settingsObj["ImageRetentionTime"] = 12;
            }
            Settings.imageRetentionTime = Convert.ToInt32(Settings.settingsObj.GetValue("ImageRetentionTime"), Main.culture);

            if (!Settings.settingsObj.TryGetValue("ClipboardTemplate", out _))
            {
                Settings.settingsObj["ClipboardTemplate"] = "-- by WFInfo (smart OCR with pricecheck)";
            }
            Settings.ClipboardTemplate = Convert.ToString(Settings.settingsObj.GetValue("ClipboardTemplate"), Main.culture);

            if (!Settings.settingsObj.TryGetValue("SnapitExport", out _))
            {
                Settings.settingsObj["SnapitExport"] = false;
            }
            Settings.SnapitExport = Convert.ToBoolean(Settings.settingsObj.GetValue("SnapitExport"), Main.culture);

            if (!Settings.settingsObj.TryGetValue("Delay", out _))
            {
                Settings.settingsObj["Delay"] = 10000;
            }
            Settings.delay = Convert.ToInt32(Settings.settingsObj.GetValue("Delay"), Main.culture);

            if (!Settings.settingsObj.TryGetValue("HighlightRewards", out _))
            {
                Settings.settingsObj["HighlightRewards"] = true;
            }
            Settings.Highlight = Convert.ToBoolean(Settings.settingsObj.GetValue("HighlightRewards"), Main.culture);

            if (!Settings.settingsObj.TryGetValue("ClipboardVaulted", out _))
            {
                Settings.settingsObj["ClipboardVaulted"] = false;
            }
            Settings.ClipboardVaulted = (bool)Settings.settingsObj.GetValue("ClipboardVaulted");

            if (!Settings.settingsObj.TryGetValue("Auto", out _))
            {
                Settings.settingsObj["Auto"] = false;
            }
            Settings.auto = (bool)Settings.settingsObj.GetValue("Auto");

            if (!Settings.settingsObj.TryGetValue("HighContrast", out _))
            {
                Settings.settingsObj["HighContrast"] = false;
            }
            Settings.highContrast = (bool)Settings.settingsObj.GetValue("HighContrast");

            if (!Settings.settingsObj.TryGetValue("OverlayXOffsetValue", out _))
            {
                Settings.settingsObj["OverlayXOffsetValue"] = 0;
            }
            Settings.overlayXOffsetValue = Convert.ToInt32(Settings.settingsObj.GetValue("OverlayXOffsetValue"), Main.culture);

            if (!Settings.settingsObj.TryGetValue("OverlayYOffsetValue", out _))
            {
                Settings.settingsObj["OverlayYOffsetValue"] = 0;
            }
            Settings.overlayYOffsetValue = Convert.ToInt32(Settings.settingsObj.GetValue("OverlayYOffsetValue"), Main.culture);

            if (!Settings.settingsObj.TryGetValue("AutoList", out _))
            {
                Settings.settingsObj["AutoList"] = false;
            }
            Settings.automaticListing = (bool)Settings.settingsObj.GetValue("AutoList");

            if (!Settings.settingsObj.TryGetValue("DoDoubleCheck", out _))
            {
                Settings.settingsObj["DoDoubleCheck"] = true;
            }
            Settings.doDoubleCheck = (bool)Settings.settingsObj.GetValue("DoDoubleCheck");

            if (!Settings.settingsObj.TryGetValue("MaximumEfficiencyValue", out _))
            {
                Settings.settingsObj["MaximumEfficiencyValue"] = 9.5;
            }
            Settings.maximumEfficiencyValue = Convert.ToDouble(Settings.settingsObj.GetValue("MaximumEfficiencyValue"), Main.culture);

            if (!Settings.settingsObj.TryGetValue("MinimumEfficiencyValue", out _))
            {
                Settings.settingsObj["MinimumEfficiencyValue"] = 4.5;
            }
            Settings.minimumEfficiencyValue = Convert.ToDouble(Settings.settingsObj.GetValue("MinimumEfficiencyValue"), Main.culture);

            if (!Settings.settingsObj.TryGetValue("DoSnapItCount", out _))
            {
                Settings.settingsObj["DoSnapItCount"] = true;
            }
            Settings.doSnapItCount = (bool)Settings.settingsObj.GetValue("DoSnapItCount");

            if (!Settings.settingsObj.TryGetValue("SnapItCountThreshold", out _))
            {
                Settings.settingsObj["SnapItCountThreshold"] = 0;
            }
            Settings.snapItCountThreshold = Convert.ToInt32(Settings.settingsObj.GetValue("SnapItCountThreshold"), Main.culture);

            if (!Settings.settingsObj.TryGetValue("SnapItEdgeWidth", out _))
            {
                Settings.settingsObj["SnapItEdgeWidth"] = 1;
            }
            Settings.snapItEdgeWidth = Convert.ToInt32(Settings.settingsObj.GetValue("SnapItEdgeWidth"), Main.culture);

            if (!Settings.settingsObj.TryGetValue("SnapItEdgeRadius", out _))
            {
                Settings.settingsObj["SnapItEdgeRadius"] = 1;
            }
            Settings.snapItEdgeRadius = Convert.ToInt32(Settings.settingsObj.GetValue("SnapItEdgeRadius"), Main.culture);

            if (!Settings.settingsObj.TryGetValue("SnapItHorizontalNameMargin", out _))
            {
                Settings.settingsObj["SnapItHorizontalNameMargin"] = 0;
            }
            Settings.snapItHorizontalNameMargin = Convert.ToDouble(Settings.settingsObj.GetValue("SnapItHorizontalNameMargin"), Main.culture);

            if (!Settings.settingsObj.TryGetValue("DoCustomNumberBoxWidth", out _))
            {
                Settings.settingsObj["DoCustomNumberBoxWidth"] = false;
            }
            Settings.doCustomNumberBoxWidth = (bool)Settings.settingsObj.GetValue("DoCustomNumberBoxWidth");

            if (!Settings.settingsObj.TryGetValue("SnapItNumberBoxWidth", out _))
            {
                Settings.settingsObj["SnapItNumberBoxWidth"] = 0.4;
            }
            Settings.snapItNumberBoxWidth = Convert.ToDouble(Settings.settingsObj.GetValue("SnapItNumberBoxWidth"), Main.culture);

            Settings.Save();

            RegistryKey key = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\WFinfo");

            if (key.GetValue("JWT") != null) // if the key exists then update it, else ignore it.
            {
                Main.dataBase.JWT = (string)key.GetValue("JWT");
                key.Close();
            }
        }