///// <summary> ///// Check if OneDrive is blocking hotkeys ///// </summary> ///// <returns>true if onedrive has hotkeys turned on</returns> //private static bool IsOneDriveBlockingHotkey() //{ // if (!Environment.OSVersion.IsWindows10()) // { // return false; // } // var localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); // var oneDriveSettingsPath = Path.Combine(localAppData, @"Microsoft\OneDrive\settings\Personal"); // if (!Directory.Exists(oneDriveSettingsPath)) // { // return false; // } // var oneDriveSettingsFile = Directory.GetFiles(oneDriveSettingsPath, "*_screenshot.dat").FirstOrDefault(); // if (!File.Exists(oneDriveSettingsFile)) // { // return false; // } // var screenshotSetting = File.ReadAllLines(oneDriveSettingsFile).Skip(1).Take(1).First(); // return "2".Equals(screenshotSetting); //} /// <summary> /// Displays a dialog for the user to choose how to handle hotkey registration failures: /// retry (allowing to shut down the conflicting application before), /// ignore (not registering the conflicting hotkey and resetting the respective config to "None", i.e. not trying to register it again on next startup) /// abort (do nothing about it) /// </summary> /// <param name="failedKeys">comma separated list of the hotkeys that could not be registered, for display in dialog text</param> /// <returns></returns> private static bool HandleFailedHotkeyRegistration(string failedKeys) { bool success = false; #warning todo //var warningTitle = Language.GetString(LangKey.warning); string warningTitle = "Warning"; //var message = string.Format(Language.GetString(LangKey.warning_hotkeys), failedKeys, IsOneDriveBlockingHotkey() ? " (OneDrive)" : ""); string message = Translator.GetText("Could not register the hot key."); //DialogResult dr = MessageBox.Show(Instance, message, warningTitle, MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Exclamation); DialogResult dr = MessageBox.Show(message, warningTitle, MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Exclamation); if (dr == DialogResult.Retry) { //LOG.DebugFormat("Re-trying to register hotkeys"); HotkeyControl.UnregisterHotkeys(); success = RegisterHotkeys(false); } else if (dr == DialogResult.Ignore) { //LOG.DebugFormat("Ignoring failed hotkey registration"); HotkeyControl.UnregisterHotkeys(); success = RegisterHotkeys(true); } return(success); }
private void ReloadConfiguration(object source, FileSystemEventArgs e) { lang.SetLanguage(conf.Language); this.Invoke((MethodInvoker) delegate { // Even update language when needed UpdateUI(); // Update the hotkey // Make sure the current hotkeys are disabled HotkeyControl.UnregisterHotkeys(); RegisterHotkeys(); }); }
public void Shutdown() { Log.Debug().WriteLine("Stopping hotkeys"); // Make sure hotkeys are disabled try { HotkeyControl.UnregisterHotkeys(); } catch (Exception e) { Log.Error().WriteLine(e, "Error unregistering hotkeys!"); } }
private void Settings_okayClick(object sender, EventArgs e) { if (CheckSettings()) { HotkeyControl.UnregisterHotkeys(); SaveSettings(); StoreFields(); MainForm.RegisterHotkeys(); // Make sure the current language & settings are reflected in the Main-context menu MainForm.Instance.UpdateUi(); DialogResult = DialogResult.OK; } else { tabcontrol.SelectTab(tab_output); } }
/// <summary> /// Displays a dialog for the user to choose how to handle hotkey registration failures: /// retry (allowing to shut down the conflicting application before), /// ignore (not registering the conflicting hotkey and resetting the respective config to "None", i.e. not trying to /// register it again on next startup) /// abort (do nothing about it) /// </summary> /// <param name="failedKeys">comma separated list of the hotkeys that could not be registered, for display in dialog text</param> /// <returns></returns> private bool HandleFailedHotkeyRegistration(string failedKeys) { var success = false; var warningTitle = Language.GetString(LangKey.warning); var message = string.Format(Language.GetString(LangKey.warning_hotkeys), failedKeys, IsOneDriveBlockingHotkey() ? " (OneDrive)" : ""); var dr = MessageBox.Show(MainForm.Instance, message, warningTitle, MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Exclamation); if (dr == DialogResult.Retry) { Log.Debug().WriteLine("Re-trying to register hotkeys"); HotkeyControl.UnregisterHotkeys(); success = RegisterHotkeys(false); } else if (dr == DialogResult.Ignore) { Log.Debug().WriteLine("Ignoring failed hotkey registration"); HotkeyControl.UnregisterHotkeys(); success = RegisterHotkeys(true); } return(success); }
/// <inheritdoc /> public void ReloadConfig() { Log.Info().WriteLine("Reload requested"); try { IniConfig.Current?.ReloadAsync().Wait(); _mainForm.Invoke((MethodInvoker)(() => { // Even update language when needed, this should be done automatically :) _mainForm.UpdateUi(); // Make sure the current hotkeys are disabled HotkeyControl.UnregisterHotkeys(); // and registered again (should be automated) _hotkeyHandler.RegisterHotkeys(true); })); } catch (Exception ex) { Log.Warn().WriteLine(ex, "Exception while reloading configuration: "); } }
///// <summary> ///// Check if OneDrive is blocking hotkeys ///// </summary> ///// <returns>true if onedrive has hotkeys turned on</returns> // private static bool IsOneDriveBlockingHotkey() // { // if (!Environment.OSVersion.IsWindows10()) // { // return false; // } // var localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); // var oneDriveSettingsPath = Path.Combine(localAppData, @"Microsoft\OneDrive\settings\Personal"); // if (!Directory.Exists(oneDriveSettingsPath)) // { // return false; // } // var oneDriveSettingsFile = Directory.GetFiles(oneDriveSettingsPath, "*_screenshot.dat").FirstOrDefault(); // if (!File.Exists(oneDriveSettingsFile)) // { // return false; // } // var screenshotSetting = File.ReadAllLines(oneDriveSettingsFile).Skip(1).Take(1).First(); // return "2".Equals(screenshotSetting); // } /// <summary> /// Displays a dialog for the user to choose how to handle hotkey registration failures: /// retry (allowing to shut down the conflicting application before), /// ignore (not registering the conflicting hotkey and resetting the respective config to "None", i.e. not trying to register it again on next startup) /// abort (do nothing about it). /// </summary> /// <param name="failedKeys">comma separated list of the hotkeys that could not be registered, for display in dialog text.</param> /// <returns>bool success.</returns> private static bool HandleFailedHotkeyRegistration(string failedKeys) { bool success = false; string warningTitle = Translator.GetText("Warning"); string message = Translator.GetText("Could not register the hot key.") + failedKeys; DialogResult dr = MessageBox.Show(message, warningTitle, MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Exclamation); if (dr == DialogResult.Retry) { // LOG.DebugFormat("Re-trying to register hotkeys"); HotkeyControl.UnregisterHotkeys(); success = RegisterHotkeys(false); } else if (dr == DialogResult.Ignore) { // LOG.DebugFormat("Ignoring failed hotkey registration"); HotkeyControl.UnregisterHotkeys(); success = RegisterHotkeys(true); } return(success); }
/// <summary> /// Displays a dialog for the user to choose how to handle hotkey registration failures: /// retry (allowing to shut down the conflicting application before), /// ignore (not registering the conflicting hotkey and resetting the respective config to "None", i.e. not trying to /// register it again on next startup) /// abort (do nothing about it) /// </summary> /// <param name="failedKeys">comma separated list of the hotkeys that could not be registered, for display in dialog text</param> /// <returns></returns> private bool HandleFailedHotkeyRegistration(string failedKeys) { var success = false; var warningTitle = _greenshotLanguage.Warning; var message = string.Format(_greenshotLanguage.WarningHotkeys, failedKeys, IsOneDriveBlockingHotkey() ? " (OneDrive)" : ""); var dialogResult = MessageBox.Show(MainForm.Instance, message, warningTitle, MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Exclamation); switch (dialogResult) { case DialogResult.Retry: Log.Debug().WriteLine("Re-trying to register hotkeys"); HotkeyControl.UnregisterHotkeys(); success = RegisterHotkeys(false); break; case DialogResult.Ignore: Log.Debug().WriteLine("Ignoring failed hotkey registration"); HotkeyControl.UnregisterHotkeys(); success = RegisterHotkeys(true); break; } return(success); }
private void EnterHotkeyControl(object sender, EventArgs e) { HotkeyControl.UnregisterHotkeys(); _inHotkey = true; }
private void HelperForm_FormClosing(object sender, FormClosingEventArgs e) { hotkeyControl.UnregisterHotkeys(); }
private void TextBoxHotkeyEnter(object sender, EventArgs e) { HotkeyControl.UnregisterHotkeys(); inHotkey = true; }
void SettingsFormShown(object sender, EventArgs e) { HotkeyControl.UnregisterHotkeys(); }
/// <summary> /// Shutdown / cleanup /// </summary> public void exit() { ClipboardHelper.DeregisterClipboardViewer(this.Handle); LOG.Info("Exit: " + EnvironmentInfo.EnvironmentToString(false)); // Close all open forms (except this), use a separate List to make sure we don't get a "InvalidOperationException: Collection was modified" List <Form> formsToClose = new List <Form>(); foreach (Form form in Application.OpenForms) { if (form.Handle != this.Handle && !form.GetType().Equals(typeof(Greenshot.ImageEditorForm))) { formsToClose.Add(form); } } foreach (Form form in formsToClose) { try { LOG.InfoFormat("Closing form: {0}", form.Name); this.Invoke((MethodInvoker) delegate { form.Close(); }); } catch (Exception e) { LOG.Error("Error closing form!", e); } } // Make sure hotkeys are disabled try { HotkeyControl.UnregisterHotkeys(); } catch (Exception e) { LOG.Error("Error unregistering hotkeys!", e); } // Now the sound isn't needed anymore try { SoundHelper.Deinitialize(); } catch (Exception e) { LOG.Error("Error deinitializing sound!", e); } // Inform all registed plugins try { PluginHelper.instance.Shutdown(); } catch (Exception e) { LOG.Error("Error shutting down plugins!", e); } // Gracefull shutdown try { Application.DoEvents(); Application.Exit(); } catch (Exception e) { LOG.Error("Error closing application!", e); } // Store any open configuration changes try { IniConfig.Save(); } catch (Exception e) { LOG.Error("Error storing configuration!", e); } // Remove the application mutex FreeMutex(); // make the icon invisible otherwise it stays even after exit!! if (notifyIcon != null) { notifyIcon.Visible = false; notifyIcon.Dispose(); notifyIcon = null; } }