mirror of
https://github.com/greenshot/greenshot
synced 2025-07-14 09:03:44 -07:00
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
This commit is contained in:
parent
f006718d2a
commit
396455875f
2 changed files with 57 additions and 2 deletions
|
@ -358,7 +358,10 @@ namespace Greenshot {
|
||||||
// Remove runUser if we already have a run under all
|
// Remove runUser if we already have a run under all
|
||||||
StartupHelper.deleteRunUser();
|
StartupHelper.deleteRunUser();
|
||||||
checkbox_autostartshortcut.Enabled = StartupHelper.canWriteRunAll();
|
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 {
|
} else {
|
||||||
// No run for all, enable the checkbox and set it to true if the current user has a key
|
// No run for all, enable the checkbox and set it to true if the current user has a key
|
||||||
checkbox_autostartshortcut.Enabled = StartupHelper.canWriteRunUser();
|
checkbox_autostartshortcut.Enabled = StartupHelper.canWriteRunUser();
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using Microsoft.Win32;
|
using Microsoft.Win32;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace Greenshot.Helpers {
|
namespace Greenshot.Helpers {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -38,6 +39,10 @@ namespace Greenshot.Helpers {
|
||||||
return "\"" + Application.ExecutablePath + "\"";
|
return "\"" + Application.ExecutablePath + "\"";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Return true if the current user can write the RUN key of the local machine.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>true if Greenshot can write key</returns>
|
||||||
public static bool canWriteRunAll() {
|
public static bool canWriteRunAll() {
|
||||||
try {
|
try {
|
||||||
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(RUNKEY, true)) {
|
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(RUNKEY, true)) {
|
||||||
|
@ -48,6 +53,10 @@ namespace Greenshot.Helpers {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Return true if the current user can write the RUN key of the current user.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>true if Greenshot can write key</returns>
|
||||||
public static bool canWriteRunUser() {
|
public static bool canWriteRunUser() {
|
||||||
try {
|
try {
|
||||||
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(RUNKEY, true)) {
|
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(RUNKEY, true)) {
|
||||||
|
@ -58,6 +67,10 @@ namespace Greenshot.Helpers {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Return the RUN key value of the local machine
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>the RUN key value of the local machine</returns>
|
||||||
public static Object getRunAllValue() {
|
public static Object getRunAllValue() {
|
||||||
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(RUNKEY, false)) {
|
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(RUNKEY, false)) {
|
||||||
if (key != null) {
|
if (key != null) {
|
||||||
|
@ -81,6 +94,10 @@ namespace Greenshot.Helpers {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Return the RUN key value of the current user
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>the RUN key value of the current user</returns>
|
||||||
public static Object getRunUserValue() {
|
public static Object getRunUserValue() {
|
||||||
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(RUNKEY, false)) {
|
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(RUNKEY, false)) {
|
||||||
if (key != null) {
|
if (key != null) {
|
||||||
|
@ -103,7 +120,11 @@ namespace Greenshot.Helpers {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Return true if the local machine has a RUN entry for Greenshot
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>true if there is a run key</returns>
|
||||||
public static bool hasRunAll() {
|
public static bool hasRunAll() {
|
||||||
try {
|
try {
|
||||||
return getRunAllValue() != null;
|
return getRunAllValue() != null;
|
||||||
|
@ -113,6 +134,10 @@ namespace Greenshot.Helpers {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Return true if the current user has a RUN entry for Greenshot
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>true if there is a run key</returns>
|
||||||
public static bool hasRunUser() {
|
public static bool hasRunUser() {
|
||||||
Object runValue = null;
|
Object runValue = null;
|
||||||
try {
|
try {
|
||||||
|
@ -123,6 +148,9 @@ namespace Greenshot.Helpers {
|
||||||
return runValue != null;
|
return runValue != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Delete the RUN key for the localmachine ("ALL")
|
||||||
|
/// </summary>
|
||||||
public static void deleteRunAll() {
|
public static void deleteRunAll() {
|
||||||
if (hasRunAll()) {
|
if (hasRunAll()) {
|
||||||
try {
|
try {
|
||||||
|
@ -145,6 +173,9 @@ namespace Greenshot.Helpers {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Delete the RUN key for the current user
|
||||||
|
/// </summary>
|
||||||
public static void deleteRunUser() {
|
public static void deleteRunUser() {
|
||||||
if (hasRunUser()) {
|
if (hasRunUser()) {
|
||||||
try {
|
try {
|
||||||
|
@ -167,6 +198,9 @@ namespace Greenshot.Helpers {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Set the RUN key for the current user
|
||||||
|
/// </summary>
|
||||||
public static void setRunUser() {
|
public static void setRunUser() {
|
||||||
try {
|
try {
|
||||||
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(RUNKEY, true)) {
|
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(RUNKEY, true)) {
|
||||||
|
@ -176,5 +210,23 @@ namespace Greenshot.Helpers {
|
||||||
LOG.Error("Error in setRunUser.", e);
|
LOG.Error("Error in setRunUser.", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test if there is a link in the Statup folder
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue