Skip to content

Commit

Permalink
Allow removing explorer context menu entry.
Browse files Browse the repository at this point in the history
Partially fixes #584
  • Loading branch information
Lolle2000la committed Oct 1, 2024
1 parent bafefd4 commit 341e0d3
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/ImageSort.Localization/Text.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/ImageSort.Localization/Text.de-DE.resx
Original file line number Diff line number Diff line change
Expand Up @@ -312,4 +312,10 @@ Wollen Sie updaten?</value>
<data name="MetadataSectionValue" xml:space="preserve">
<value>Wert</value>
</data>
<data name="WindowsIntegrationHeader" xml:space="preserve">
<value>Integration mit Windows</value>
</data>
<data name="ShowInExplorerContextMenu" xml:space="preserve">
<value>Verknüpfung zum Öffnen eines Ordners in Image Sort im Kontextmenü des Windows Explorers hinzufügen.</value>
</data>
</root>
6 changes: 6 additions & 0 deletions src/ImageSort.Localization/Text.resx
Original file line number Diff line number Diff line change
Expand Up @@ -312,4 +312,10 @@ Do you want to update?</value>
<data name="MetadataSectionValue" xml:space="preserve">
<value>Value</value>
</data>
<data name="WindowsIntegrationHeader" xml:space="preserve">
<value>Integration with Windows</value>
</data>
<data name="ShowInExplorerContextMenu" xml:space="preserve">
<value>Add a shortcut to open a folder in Image Sort directly from the context menu in Windows Explorer.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,10 @@
Margin="{adonisUi:Space 1}" />
</StackPanel>
</GroupBox>

<GroupBox Header="{x:Static text:Text.WindowsIntegrationHeader}">
<CheckBox Content="{x:Static text:Text.ShowInExplorerContextMenu}" x:Name="ShowInExplorerContextMenu"
Margin="{adonisUi:Space 1}" />
</GroupBox>
</StackPanel>
</reactiveui:ReactiveUserControl>
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ public GeneralSettingsGroupView()
vm => vm.CheckForUpdatesOnStartup,
view => view.InstallPrereleaseBuilds.IsEnabled)
.DisposeWith(disposableRegistration);

this.Bind(ViewModel,
vm => vm.ShowInExplorerContextMenu,
view => view.ShowInExplorerContextMenu.IsChecked)
.DisposeWith(disposableRegistration);
});
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using AdonisUI;
using ImageSort.Localization;
using ImageSort.SettingsManagement;
using Microsoft.Win32;
using ReactiveUI;
using System;
using System.Windows;
Expand Down Expand Up @@ -53,6 +54,18 @@ public bool AnimateGifThumbnails
set => this.RaiseAndSetIfChanged(ref _animateGifThumbnails, value);
}

private bool _showInExplorerContextMenu = CheckForExplorerContextMenu();

public bool ShowInExplorerContextMenu
{
get => _showInExplorerContextMenu;
set
{
this.RaiseAndSetIfChanged(ref _showInExplorerContextMenu, value);
UpdateExplorerContextMenu(value);
}
}

public GeneralSettingsGroupViewModel()
{
void SetDarkMode(bool darkMode)
Expand All @@ -63,4 +76,52 @@ void SetDarkMode(bool darkMode)
this.WhenAnyValue(vm => vm.DarkMode)
.Subscribe(SetDarkMode);
}

private void UpdateExplorerContextMenu(bool show)
{
string[] keys = new[]
{
@"Software\Classes\Directory\shell\ImageSort",
@"Software\Classes\Drive\shell\ImageSort",
@"Software\Classes\Folder\shell\ImageSort"
};

foreach (var key in keys)
{
if (show)
{
using (var registryKey = Registry.CurrentUser.CreateSubKey(key))
{
registryKey.SetValue("", "Open with Image Sort");
registryKey.CreateSubKey("command").SetValue("", $"\"{AppDomain.CurrentDomain.BaseDirectory}Image Sort.exe\" \"%L\"");
registryKey.SetValue("Icon", $"\"{AppDomain.CurrentDomain.BaseDirectory}Image Sort.exe\"");
}
}
else
{
Registry.CurrentUser.DeleteSubKeyTree(key, false);
}
}
}

// This is used to grandfather in users who already have the context menu enabled from using it with the installer.
private static bool CheckForExplorerContextMenu()
{
string[] keys = new[]
{
@"Software\Classes\Directory\shell\ImageSort",
@"Software\Classes\Drive\shell\ImageSort",
@"Software\Classes\Folder\shell\ImageSort"
};

foreach (var key in keys)
{
if (Registry.CurrentUser.OpenSubKey(key) != null)
{
return true;
}
}

return false;
}
}

0 comments on commit 341e0d3

Please sign in to comment.