You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
3.7 KiB

  1. // Copyright (c) 2017 AlphaSierraPapa for the SharpDevelop Team
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy of this
  4. // software and associated documentation files (the "Software"), to deal in the Software
  5. // without restriction, including without limitation the rights to use, copy, modify, merge,
  6. // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
  7. // to whom the Software is furnished to do so, subject to the following conditions:
  8. //
  9. // The above copyright notice and this permission notice shall be included in all copies or
  10. // substantial portions of the Software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  13. // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  14. // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
  15. // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  16. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  17. // DEALINGS IN THE SOFTWARE.
  18. using System.Composition;
  19. using System.IO;
  20. using System.Reflection;
  21. using System.Windows;
  22. using System.Windows.Input;
  23. using System.Xml.Linq;
  24. using ICSharpCode.ILSpy.AppEnv;
  25. using ICSharpCode.ILSpyX.Settings;
  26. using Microsoft.Win32;
  27. using TomsToolbox.Wpf;
  28. namespace ICSharpCode.ILSpy.Options
  29. {
  30. [ExportOptionPage(Order = 30)]
  31. [NonShared]
  32. public class MiscSettingsViewModel : ObservableObject, IOptionPage
  33. {
  34. private MiscSettings settings;
  35. public MiscSettings Settings {
  36. get => settings;
  37. set => SetProperty(ref settings, value);
  38. }
  39. public ICommand AddRemoveShellIntegrationCommand => new DelegateCommand(() => AppEnvironment.IsWindows, AddRemoveShellIntegration);
  40. const string rootPath = @"Software\Classes\{0}\shell";
  41. const string fullPath = @"Software\Classes\{0}\shell\Open with ILSpy\command";
  42. private void AddRemoveShellIntegration()
  43. {
  44. string commandLine = CommandLineTools.ArgumentArrayToCommandLine(Path.ChangeExtension(Assembly.GetEntryAssembly()?.Location, ".exe")) + " \"%L\"";
  45. if (RegistryEntriesExist())
  46. {
  47. if (MessageBox.Show(string.Format(Properties.Resources.RemoveShellIntegrationMessage, commandLine), "ILSpy", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
  48. {
  49. Registry.CurrentUser
  50. .CreateSubKey(string.Format(rootPath, "dllfile"))?
  51. .DeleteSubKeyTree("Open with ILSpy");
  52. Registry.CurrentUser
  53. .CreateSubKey(string.Format(rootPath, "exefile"))?
  54. .DeleteSubKeyTree("Open with ILSpy");
  55. }
  56. }
  57. else
  58. {
  59. if (MessageBox.Show(string.Format(Properties.Resources.AddShellIntegrationMessage, commandLine), "ILSpy", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
  60. {
  61. Registry.CurrentUser
  62. .CreateSubKey(string.Format(fullPath, "dllfile"))?
  63. .SetValue("", commandLine);
  64. Registry.CurrentUser
  65. .CreateSubKey(string.Format(fullPath, "exefile"))?
  66. .SetValue("", commandLine);
  67. }
  68. }
  69. OnPropertyChanged(nameof(AddRemoveShellIntegrationText));
  70. }
  71. private static bool RegistryEntriesExist()
  72. {
  73. return Registry.CurrentUser.OpenSubKey(string.Format(fullPath, "dllfile")) != null
  74. && Registry.CurrentUser.OpenSubKey(string.Format(fullPath, "exefile")) != null;
  75. }
  76. public string AddRemoveShellIntegrationText {
  77. get {
  78. return RegistryEntriesExist() ? Properties.Resources.RemoveShellIntegration : Properties.Resources.AddShellIntegration;
  79. }
  80. }
  81. public string Title => Properties.Resources.Misc;
  82. public void Load(SettingsSnapshot settings)
  83. {
  84. Settings = settings.GetSettings<MiscSettings>();
  85. }
  86. public void LoadDefaults()
  87. {
  88. Settings.LoadFromXml(new XElement("dummy"));
  89. }
  90. }
  91. }