From 396455875fb3821e1b74e407ff7a8d82fb9a0c1c Mon Sep 17 00:00:00 2001 From: RKrom Date: Mon, 12 Nov 2012 15:25:52 +0000 Subject: [PATCH] Fixes for the Startup-Helper, if Greenshot is already in the startup-folder we check & disable the checkbox. git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2268 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4 --- Greenshot/Forms/SettingsForm.cs | 5 ++- Greenshot/Helpers/StartupHelper.cs | 54 +++++++++++++++++++++++++++++- 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/Greenshot/Forms/SettingsForm.cs b/Greenshot/Forms/SettingsForm.cs index 59ee7c7b4..3d465271c 100644 --- a/Greenshot/Forms/SettingsForm.cs +++ b/Greenshot/Forms/SettingsForm.cs @@ -358,7 +358,10 @@ namespace Greenshot { // Remove runUser if we already have a run under all StartupHelper.deleteRunUser(); checkbox_autostartshortcut.Enabled = StartupHelper.canWriteRunAll(); - checkbox_autostartshortcut.Checked = StartupHelper.hasRunAll(); + checkbox_autostartshortcut.Checked = true; // We already checked this + } else if (StartupHelper.IsInStartupFolder()) { + checkbox_autostartshortcut.Enabled = false; + checkbox_autostartshortcut.Checked = true; // We already checked this } else { // No run for all, enable the checkbox and set it to true if the current user has a key checkbox_autostartshortcut.Enabled = StartupHelper.canWriteRunUser(); diff --git a/Greenshot/Helpers/StartupHelper.cs b/Greenshot/Helpers/StartupHelper.cs index 5ce3d1889..b811976ab 100644 --- a/Greenshot/Helpers/StartupHelper.cs +++ b/Greenshot/Helpers/StartupHelper.cs @@ -21,6 +21,7 @@ using System; using System.Windows.Forms; using Microsoft.Win32; +using System.IO; namespace Greenshot.Helpers { /// @@ -38,6 +39,10 @@ namespace Greenshot.Helpers { return "\"" + Application.ExecutablePath + "\""; } + /// + /// Return true if the current user can write the RUN key of the local machine. + /// + /// true if Greenshot can write key public static bool canWriteRunAll() { try { using (RegistryKey key = Registry.LocalMachine.OpenSubKey(RUNKEY, true)) { @@ -48,6 +53,10 @@ namespace Greenshot.Helpers { return true; } + /// + /// Return true if the current user can write the RUN key of the current user. + /// + /// true if Greenshot can write key public static bool canWriteRunUser() { try { using (RegistryKey key = Registry.CurrentUser.OpenSubKey(RUNKEY, true)) { @@ -58,6 +67,10 @@ namespace Greenshot.Helpers { return true; } + /// + /// Return the RUN key value of the local machine + /// + /// the RUN key value of the local machine public static Object getRunAllValue() { using (RegistryKey key = Registry.LocalMachine.OpenSubKey(RUNKEY, false)) { if (key != null) { @@ -81,6 +94,10 @@ namespace Greenshot.Helpers { return null; } + /// + /// Return the RUN key value of the current user + /// + /// the RUN key value of the current user public static Object getRunUserValue() { using (RegistryKey key = Registry.CurrentUser.OpenSubKey(RUNKEY, false)) { if (key != null) { @@ -103,7 +120,11 @@ namespace Greenshot.Helpers { } return null; } - + + /// + /// Return true if the local machine has a RUN entry for Greenshot + /// + /// true if there is a run key public static bool hasRunAll() { try { return getRunAllValue() != null; @@ -113,6 +134,10 @@ namespace Greenshot.Helpers { return false; } + /// + /// Return true if the current user has a RUN entry for Greenshot + /// + /// true if there is a run key public static bool hasRunUser() { Object runValue = null; try { @@ -123,6 +148,9 @@ namespace Greenshot.Helpers { return runValue != null; } + /// + /// Delete the RUN key for the localmachine ("ALL") + /// public static void deleteRunAll() { if (hasRunAll()) { try { @@ -145,6 +173,9 @@ namespace Greenshot.Helpers { } } + /// + /// Delete the RUN key for the current user + /// public static void deleteRunUser() { if (hasRunUser()) { try { @@ -167,6 +198,9 @@ namespace Greenshot.Helpers { } } + /// + /// Set the RUN key for the current user + /// public static void setRunUser() { try { using (RegistryKey key = Registry.CurrentUser.OpenSubKey(RUNKEY, true)) { @@ -176,5 +210,23 @@ namespace Greenshot.Helpers { LOG.Error("Error in setRunUser.", e); } } + + /// + /// Test if there is a link in the Statup folder + /// + /// + public static bool IsInStartupFolder() { + try { + string startupPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup); + if (Directory.Exists(startupPath)) { + LOG.DebugFormat("Startup path: {0}", startupPath); + if (File.Exists(Path.Combine(startupPath, Path.GetFileNameWithoutExtension(Application.ExecutablePath) + ".lnk"))) { + return true; + } + } + } catch { + } + return false; + } } }