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); } }
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); } }