Browse Source

#1952: Apply suggestions and fixes from code review.

pull/1984/head
Siegfried Pammer 5 years ago
parent
commit
9ebef78b51
  1. 30
      ILSpy/Options/MiscSettings.cs
  2. 13
      ILSpy/Properties/Resources.Designer.cs
  3. 7
      ILSpy/Properties/Resources.resx

30
ILSpy/Options/MiscSettings.cs

@ -67,42 +67,32 @@ namespace ICSharpCode.ILSpy.Options @@ -67,42 +67,32 @@ namespace ICSharpCode.ILSpy.Options
public ICommand AddRemoveShellIntegrationCommand { get; }
const string rootPath = @"Software\Classes\{0}\shell";
const string fullPath = @"Software\Classes\{0}\shell\Open with ILSpy\command";
private void AddRemoveShellIntegration(object obj)
{
if (!IsElevated()) {
MessageBox.Show(Properties.Resources.RestartElevatedMessage, "ILSpy", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
string commandLine = NativeMethods.ArgumentArrayToCommandLine(Assembly.GetEntryAssembly().Location, "%L");
string commandLine = NativeMethods.ArgumentArrayToCommandLine(Assembly.GetEntryAssembly().Location) + " \"%L\"";
if (RegistryEntriesExist()) {
if (MessageBox.Show(string.Format(Properties.Resources.RemoveShellIntegrationMessage, commandLine), "ILSpy", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) {
Registry.ClassesRoot.CreateSubKey(@"dllfile\shell").DeleteSubKeyTree("Open with ILSpy");
Registry.ClassesRoot.CreateSubKey(@"exefile\shell").DeleteSubKeyTree("Open with ILSpy");
Registry.CurrentUser.CreateSubKey(string.Format(rootPath, "dllfile")).DeleteSubKeyTree("Open with ILSpy");
Registry.CurrentUser.CreateSubKey(string.Format(rootPath, "exefile")).DeleteSubKeyTree("Open with ILSpy");
}
} else {
if (MessageBox.Show(string.Format(Properties.Resources.AddShellIntegrationMessage, commandLine), "ILSpy", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) {
Registry.ClassesRoot.CreateSubKey(@"dllfile\shell\Open with ILSpy\command")?
Registry.CurrentUser.CreateSubKey(string.Format(fullPath, "dllfile"))?
.SetValue("", commandLine);
Registry.ClassesRoot.CreateSubKey(@"exefile\shell\Open with ILSpy\command")?
Registry.CurrentUser.CreateSubKey(string.Format(fullPath, "exefile"))?
.SetValue("", commandLine);
}
}
OnPropertyChanged(nameof(AddRemoveShellIntegrationText));
bool IsElevated()
{
try {
return new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator);
} catch (System.Security.SecurityException) {
return false;
}
}
}
private static bool RegistryEntriesExist()
{
return Registry.ClassesRoot.OpenSubKey(@"dllfile\shell\Open with ILSpy\command") != null
&& Registry.ClassesRoot.OpenSubKey(@"exefile\shell\Open with ILSpy\command") != null;
return Registry.CurrentUser.OpenSubKey(string.Format(fullPath, "dllfile")) != null
&& Registry.CurrentUser.OpenSubKey(string.Format(fullPath, "exefile")) != null;
}
public string AddRemoveShellIntegrationText {

13
ILSpy/Properties/Resources.Designer.cs generated

@ -295,7 +295,7 @@ namespace ICSharpCode.ILSpy.Properties { @@ -295,7 +295,7 @@ namespace ICSharpCode.ILSpy.Properties {
}
/// <summary>
/// Looks up a localized string similar to This will add &quot;{0}&quot; to the registry at &quot;HKCU\dllfile\shell\Open with ILSpy\command\&quot; and &quot;HKCU\exefile\shell\Open with ILSpy\command&quot; to allow opening .dll and .exe files from the Windows Explorer context menu.
/// Looks up a localized string similar to This will add &quot;{0}&quot; to the registry at &quot;HKCU\Software\Classes\dllfile\shell\Open with ILSpy\command&quot; and &quot;HKCU\Software\Classes\exefile\shell\Open with ILSpy\command&quot; to allow opening .dll and .exe files from the Windows Explorer context menu.
///
///Do you want to continue?.
/// </summary>
@ -1696,7 +1696,7 @@ namespace ICSharpCode.ILSpy.Properties { @@ -1696,7 +1696,7 @@ namespace ICSharpCode.ILSpy.Properties {
}
/// <summary>
/// Looks up a localized string similar to This will remove &quot;{0}&quot; from the registry at &quot;HKCU\dllfile\shell\Open with ILSpy\command\&quot; and &quot;HKCU\exefile\shell\Open with ILSpy\command&quot;.
/// Looks up a localized string similar to This will remove &quot;{0}&quot; from the registry at &quot;HKCU\Software\Classes\dllfile\shell\Open with ILSpy\command&quot; and &quot;HKCU\Software\Classes\exefile\shell\Open with ILSpy\command&quot;.
///
///Do you want to continue?.
/// </summary>
@ -1733,15 +1733,6 @@ namespace ICSharpCode.ILSpy.Properties { @@ -1733,15 +1733,6 @@ namespace ICSharpCode.ILSpy.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Please restart ILSpy.exe as administrator to execute this function!.
/// </summary>
public static string RestartElevatedMessage {
get {
return ResourceManager.GetString("RestartElevatedMessage", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Save.
/// </summary>

7
ILSpy/Properties/Resources.resx

@ -840,7 +840,7 @@ Please disable all filters that might hide the item (i.e. activate "View &gt; Sh @@ -840,7 +840,7 @@ Please disable all filters that might hide the item (i.e. activate "View &gt; Sh
<value>Add shell integration</value>
</data>
<data name="AddShellIntegrationMessage" xml:space="preserve">
<value>This will add "{0}" to the registry at "HKCU\dllfile\shell\Open with ILSpy\command\" and "HKCU\exefile\shell\Open with ILSpy\command" to allow opening .dll and .exe files from the Windows Explorer context menu.
<value>This will add "{0}" to the registry at "HKCU\Software\Classes\dllfile\shell\Open with ILSpy\command" and "HKCU\Software\Classes\exefile\shell\Open with ILSpy\command" to allow opening .dll and .exe files from the Windows Explorer context menu.
Do you want to continue?</value>
</data>
@ -848,11 +848,8 @@ Do you want to continue?</value> @@ -848,11 +848,8 @@ Do you want to continue?</value>
<value>Remove shell integration</value>
</data>
<data name="RemoveShellIntegrationMessage" xml:space="preserve">
<value>This will remove "{0}" from the registry at "HKCU\dllfile\shell\Open with ILSpy\command\" and "HKCU\exefile\shell\Open with ILSpy\command".
<value>This will remove "{0}" from the registry at "HKCU\Software\Classes\dllfile\shell\Open with ILSpy\command" and "HKCU\Software\Classes\exefile\shell\Open with ILSpy\command".
Do you want to continue?</value>
</data>
<data name="RestartElevatedMessage" xml:space="preserve">
<value>Please restart ILSpy.exe as administrator to execute this function!</value>
</data>
</root>
Loading…
Cancel
Save