Browse Source

Fix #1952: Add a button to the Misc settings page that adds an "Open with ILSpy" entry to the Windows Explorer context menu on exe and dll files.

pull/1984/head
Siegfried Pammer 5 years ago
parent
commit
f316838873
  1. 57
      ILSpy/Options/MiscSettings.cs
  2. 5
      ILSpy/Options/MiscSettingsPanel.xaml
  3. 49
      ILSpy/Properties/Resources.Designer.cs
  4. 19
      ILSpy/Properties/Resources.resx

57
ILSpy/Options/MiscSettings.cs

@ -16,19 +16,26 @@ @@ -16,19 +16,26 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.ComponentModel;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security.Principal;
using System.Windows;
using System.Windows.Input;
using ICSharpCode.ILSpy.Commands;
using Microsoft.Win32;
namespace ICSharpCode.ILSpy.Options
{
public class MiscSettings : INotifyPropertyChanged
{
bool allowMultipleInstances;
bool loadPreviousAssemblies;
bool loadPreviousAssemblies = true;
public MiscSettings()
{
this.loadPreviousAssemblies = true;
AddRemoveShellIntegrationCommand = new DelegateCommand<object>(AddRemoveShellIntegration);
}
/// <summary>
@ -58,6 +65,52 @@ namespace ICSharpCode.ILSpy.Options @@ -58,6 +65,52 @@ namespace ICSharpCode.ILSpy.Options
}
}
public ICommand AddRemoveShellIntegrationCommand { get; }
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");
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");
}
} 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")?
.SetValue("", commandLine);
Registry.ClassesRoot.CreateSubKey(@"exefile\shell\Open with ILSpy\command")?
.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;
}
public string AddRemoveShellIntegrationText {
get {
return RegistryEntriesExist() ? Properties.Resources.RemoveShellIntegration : Properties.Resources.AddShellIntegration;
}
}
#region INotifyPropertyChanged Implementation
public event PropertyChangedEventHandler PropertyChanged;

5
ILSpy/Options/MiscSettingsPanel.xaml

@ -7,7 +7,8 @@ @@ -7,7 +7,8 @@
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<StackPanel Margin="10">
<CheckBox IsChecked="{Binding AllowMultipleInstances}" Content="{x:Static properties:Resources.AllowMultipleInstances}"></CheckBox>
<CheckBox IsChecked="{Binding LoadPreviousAssemblies}" Content="{x:Static properties:Resources.LoadAssembliesThatWereLoadedInTheLastInstance}"></CheckBox>
<CheckBox IsChecked="{Binding AllowMultipleInstances}" Content="{x:Static properties:Resources.AllowMultipleInstances}" />
<CheckBox IsChecked="{Binding LoadPreviousAssemblies}" Content="{x:Static properties:Resources.LoadAssembliesThatWereLoadedInTheLastInstance}"/>
<Button Command="{Binding AddRemoveShellIntegrationCommand}" Content="{Binding AddRemoveShellIntegrationText}" Margin="3" />
</StackPanel>
</UserControl>

49
ILSpy/Properties/Resources.Designer.cs generated

@ -285,6 +285,26 @@ namespace ICSharpCode.ILSpy.Properties { @@ -285,6 +285,26 @@ namespace ICSharpCode.ILSpy.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Add shell integration.
/// </summary>
public static string AddShellIntegration {
get {
return ResourceManager.GetString("AddShellIntegration", resourceCulture);
}
}
/// <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.
///
///Do you want to continue?.
/// </summary>
public static string AddShellIntegrationMessage {
get {
return ResourceManager.GetString("AddShellIntegrationMessage", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to |All Files|*.*.
/// </summary>
@ -1666,6 +1686,26 @@ namespace ICSharpCode.ILSpy.Properties { @@ -1666,6 +1686,26 @@ namespace ICSharpCode.ILSpy.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Remove shell integration.
/// </summary>
public static string RemoveShellIntegration {
get {
return ResourceManager.GetString("RemoveShellIntegration", resourceCulture);
}
}
/// <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;.
///
///Do you want to continue?.
/// </summary>
public static string RemoveShellIntegrationMessage {
get {
return ResourceManager.GetString("RemoveShellIntegrationMessage", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Reset to defaults.
/// </summary>
@ -1693,6 +1733,15 @@ namespace ICSharpCode.ILSpy.Properties { @@ -1693,6 +1733,15 @@ 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>

19
ILSpy/Properties/Resources.resx

@ -836,4 +836,23 @@ Are you sure you want to continue?</value> @@ -836,4 +836,23 @@ Are you sure you want to continue?</value>
<value>Navigation failed because the target is hidden or a compiler-generated class.\n
Please disable all filters that might hide the item (i.e. activate "View &gt; Show internal types and members") and try again.</value>
</data>
<data name="AddShellIntegration" xml:space="preserve">
<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.
Do you want to continue?</value>
</data>
<data name="RemoveShellIntegration" xml:space="preserve">
<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".
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