Skip to content

Commit

Permalink
通过BHO插件,你可以将ExplorerEx设置为默认文件管理器了!
Browse files Browse the repository at this point in the history
  • Loading branch information
DearVa committed Sep 4, 2022
1 parent 79d6259 commit c1a1004
Show file tree
Hide file tree
Showing 27 changed files with 1,949 additions and 1,470 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/dotnet-desktop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ jobs:
- name: Install .NET
uses: actions/setup-dotnet@main
with:
dotnet-version: 6.0.x
dotnet-version: |
6.0.x
4.6.2
# Execute all unit tests in the solution
- name: Execute unit tests
Expand All @@ -81,6 +83,13 @@ jobs:
- name: Create the app package
run: dotnet publish ExplorerEx -c Release -r win-x64

# Build Explorer Proxy
- name: Build Explorer Proxy
run: |
MSBuild .\ExplorerProxy\ExplorerProxy.csproj /property:Configuration=Release,Platform=x64
copy .\ExplorerProxy\bin\x64\Release\ExplorerProxy.dll .\ExplorerEx\bin\Release\net6.0-windows\win-x64\publish
copy .\ExplorerProxy\bin\x64\Release\Interop.SHDocVw.dll .\ExplorerEx\bin\Release\net6.0-windows\win-x64\publish
# Upload the MSIX package: https://github.com/marketplace/actions/upload-a-build-artifact
- name: Upload build artifacts
uses: actions/upload-artifact@main
Expand Down
10 changes: 10 additions & 0 deletions ExplorerEx.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VirtualizingWrapPanel", "Ex
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SharpSvgImage", "External\SVGImage\SharpSvgImage.csproj", "{60FE8AA1-AA35-4D97-833C-A2D420E652C5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExplorerProxy", "ExplorerProxy\ExplorerProxy.csproj", "{4263166E-01B3-44C1-891A-F6C9BA44153C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -51,6 +53,14 @@ Global
{60FE8AA1-AA35-4D97-833C-A2D420E652C5}.Release|Any CPU.Build.0 = Release|Any CPU
{60FE8AA1-AA35-4D97-833C-A2D420E652C5}.Release|x64.ActiveCfg = Release|x64
{60FE8AA1-AA35-4D97-833C-A2D420E652C5}.Release|x64.Build.0 = Release|x64
{4263166E-01B3-44C1-891A-F6C9BA44153C}.Debug|Any CPU.ActiveCfg = Debug|x64
{4263166E-01B3-44C1-891A-F6C9BA44153C}.Debug|Any CPU.Build.0 = Debug|x64
{4263166E-01B3-44C1-891A-F6C9BA44153C}.Debug|x64.ActiveCfg = Debug|x64
{4263166E-01B3-44C1-891A-F6C9BA44153C}.Debug|x64.Build.0 = Debug|x64
{4263166E-01B3-44C1-891A-F6C9BA44153C}.Release|Any CPU.ActiveCfg = Release|x64
{4263166E-01B3-44C1-891A-F6C9BA44153C}.Release|Any CPU.Build.0 = Release|x64
{4263166E-01B3-44C1-891A-F6C9BA44153C}.Release|x64.ActiveCfg = Release|x64
{4263166E-01B3-44C1-891A-F6C9BA44153C}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 1 addition & 1 deletion ExplorerEx/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ public partial class App {
notifyMmf = new NotifyMemoryMappedFile("ExplorerExIPC", 1024, false);
var command = e.Args.Length > 1 ? "Open|" + e.Args[1] : "Open";
notifyMmf.Write(Encoding.UTF8.GetBytes(command));
notifyMmf.Dispose();
Current.Shutdown();
return;
}


Container = new WindsorContainer();
Container.Register(Component.For<IBookmarkDbContext>().Instance(
new BookmarkSugarContext()
Expand Down
Binary file added ExplorerEx/Assets/DeleteExplorerExProxy.reg
Binary file not shown.
Binary file added ExplorerEx/Assets/SetExplorerExProxy.reg
Binary file not shown.
4 changes: 4 additions & 0 deletions ExplorerEx/Assets/Settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,8 @@
<item header="ShowHiddenFilesAndFolders" icon="EyeDrawingImage" type="boolean" default="false"/>
<item header="ShowProtectedSystemFilesAndFolders" icon="EyeDrawingImage" type="boolean" default="false"/>
</category>

<category header="Experimental">
<item header="SetExplorerExAsDefault" type="boolean" default="false"/>
</category>
</settings>
4 changes: 4 additions & 0 deletions ExplorerEx/ExplorerEx.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@
</ItemGroup>

<ItemGroup>
<None Remove="Assets\DeleteExplorerExProxy.reg" />
<None Remove="Assets\LogConfig.xml" />
<None Remove="Assets\Picture\Computer.png" />
<None Remove="Assets\Picture\Logo.ico" />
<None Remove="Assets\Picture\Logo.png" />
<None Remove="Assets\Picture\Network.png" />
<None Remove="Assets\Picture\RecycleBin.png" />
<None Remove="Assets\Picture\RecycleBinFull.png" />
<None Remove="Assets\SetExplorerExProxy.reg" />
<None Remove="Assets\Settings.xml" />
</ItemGroup>

Expand All @@ -55,7 +57,9 @@
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Assets\DeleteExplorerExProxy.reg" />
<EmbeddedResource Include="Assets\LogConfig.xml" />
<EmbeddedResource Include="Assets\SetExplorerExProxy.reg" />
<EmbeddedResource Include="Assets\Settings.xml" />
</ItemGroup>

Expand Down
Binary file removed ExplorerEx/Reg/Backup.reg
Binary file not shown.
Binary file removed ExplorerEx/Reg/Restore.reg
Binary file not shown.
13 changes: 0 additions & 13 deletions ExplorerEx/Reg/SetEx.reg

This file was deleted.

135 changes: 113 additions & 22 deletions ExplorerEx/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Xml;
using ExplorerEx.Command;
using ExplorerEx.Utils;
using ExplorerEx.View.Controls;
using Microsoft.Win32;

namespace ExplorerEx;
Expand Down Expand Up @@ -77,15 +78,20 @@ private class EmptySettingsItem : SettingsItem {
get => value;
set {
if (this.value != value) {
this.value = value;
OnPropertyChanged();
OnPropertyChanged(nameof(Self));
if (value != null) {
ConfigHelper.SaveToBuffer(FullName, value);
if (Changing?.Invoke(value) ?? true) {
this.value = value;
OnPropertyChanged();
OnPropertyChanged(nameof(Self));
if (value != null) {
ConfigHelper.SaveToBuffer(FullName, value);
} else {
ConfigHelper.Delete(FullName);
}
Changed?.Invoke(value);
} else {
ConfigHelper.Delete(FullName);
OnPropertyChanged();
OnPropertyChanged(nameof(Self));
}
Changed?.Invoke(value);
}
}
}
Expand All @@ -109,6 +115,11 @@ private class EmptySettingsItem : SettingsItem {

public string GetString() => Convert.ToString(Value) ?? string.Empty;

/// <summary>
/// 返回值设为false表示取消
/// </summary>
public event Func<object?, bool>? Changing;

/// <summary>
/// 与<see cref="PropertyChanged"/>不同,这个是专门用于监测值的变化
/// </summary>
Expand Down Expand Up @@ -239,6 +250,8 @@ public static class CommonSettings {

public const string ShowHiddenFilesAndFolders = "Advanced.ShowHiddenFilesAndFolders";
public const string ShowProtectedSystemFilesAndFolders = "Advanced.ShowProtectedSystemFilesAndFolders";

public const string SetExplorerExAsDefault = "Experimental.SetExplorerExAsDefault";
}

public static CultureInfo CurrentCulture { get; private set; } = CultureInfo.CurrentUICulture;
Expand Down Expand Up @@ -275,6 +288,87 @@ public static class CommonSettings {

public double BackgroundImageOpacity => this[CommonSettings.BackgroundImageOpacity].GetDouble();

private void BackgroundImage_OnChanged(object? o) {
if (o is string path && File.Exists(path)) {
try {
BackgroundImage = new BitmapImage(new Uri(path));
} catch {
BackgroundImage = null;
}
} else {
BackgroundImage = null;
}
OnPropertyChanged(nameof(BackgroundImage));
}

private static bool SetExplorerExAsDefault_OnChanging(object? o) {
if (o is true) {
var executingAsm = Assembly.GetExecutingAssembly();
var executingPath = Path.GetDirectoryName(executingAsm.Location)!;
ConfigHelper.Save("Path", Path.ChangeExtension(executingAsm.Location, ".exe"));
var proxyDllPath = Path.Combine(executingPath, "ExplorerProxy.dll");
if (!File.Exists(proxyDllPath)) {
ContentDialog.Error("#SetExplorerExAsDefaultFailProxyNotFound".L());
return false;
}
if (!File.Exists(Path.Combine(executingPath, "Interop.SHDocVw.dll"))) {
ContentDialog.Error("#SetExplorerExAsDefaultFailSHDocVwNotFound".L());
return false;
}
if (ContentDialog.Ask("#SetExplorerExAsDefaultInstructions0".L(), "PleaseReadCarefully".L()) != ContentDialog.ContentDialogResult.Primary) {
return false;
}
try {
using var stream = executingAsm.GetManifestResourceStream("ExplorerEx.Assets.DeleteExplorerExProxy.reg");
if (stream == null) {
ContentDialog.Error("#SetExplorerExAsDefaultFailReg".L());
return false;
}
var regFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Delete ExplorerEx Proxy.reg");
using var fs = new FileStream(regFilePath, FileMode.Create);
stream.CopyTo(fs);
} catch {
ContentDialog.Error("#SetExplorerExAsDefaultFailReg".L());
return false;
}
if (ContentDialog.Ask("#SetExplorerExAsDefaultInstructions1".L(), "PleaseReadCarefully".L()) != ContentDialog.ContentDialogResult.Primary) {
return false;
}
if (ContentDialog.Ask("#SetExplorerExAsDefaultInstructions2".L(), "PleaseReadCarefully".L()) != ContentDialog.ContentDialogResult.Primary) {
return false;
}
try {
using var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("ExplorerEx.Assets.SetExplorerExProxy.reg");
if (stream == null) {
ContentDialog.Error("#SetExplorerExAsDefaultFailReg".L());
return false;
}
var setRegString = new StreamReader(stream).ReadToEnd().Replace("REPLACE_HERE", proxyDllPath.Replace('\\', '/'));
var regFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Set ExplorerEx Proxy.reg");
File.WriteAllText(regFilePath, setRegString);
} catch {
ContentDialog.Error("#SetExplorerExAsDefaultFailReg".L());
}
} else {
if (ContentDialog.Ask("#UnsetExplorerExAsDefaultInstructions".L(), "PleaseReadCarefully".L()) != ContentDialog.ContentDialogResult.Primary) {
return true;
}
try {
using var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("ExplorerEx.Assets.DeleteExplorerExProxy.reg");
if (stream == null) {
ContentDialog.Error("#UnsetExplorerExAsDefaultFailReg".L());
return false;
}
var regFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Delete ExplorerEx Proxy.reg");
using var fs = new FileStream(regFilePath, FileMode.Create);
stream.CopyTo(fs);
} catch {
ContentDialog.Error("#UnsetExplorerExAsDefaultFailReg".L());
}
}
return true;
}

private void RegisterEvents() {
ThemeChanged = null;

Expand All @@ -290,24 +384,13 @@ public static class CommonSettings {
};
settings[CommonSettings.WindowBackdrop].Changed += _ => ThemeChanged?.Invoke();

void UpdateBackgroundImage(object? o) {
if (o is string path && File.Exists(path)) {
try {
BackgroundImage = new BitmapImage(new Uri(path));
} catch {
BackgroundImage = null;
}
} else {
BackgroundImage = null;
}
OnPropertyChanged(nameof(BackgroundImage));
}

settings[CommonSettings.BackgroundImage].Changed += UpdateBackgroundImage;
UpdateBackgroundImage(settings[CommonSettings.BackgroundImage].Value);
settings[CommonSettings.BackgroundImage].Changed += BackgroundImage_OnChanged;
BackgroundImage_OnChanged(settings[CommonSettings.BackgroundImage].Value);

settings[CommonSettings.BackgroundImageOpacity].Changed += _ => OnPropertyChanged(nameof(BackgroundImageOpacity));
settings[CommonSettings.ColorMode].Changed += _ => ThemeChanged?.Invoke(); // 更改颜色

settings[CommonSettings.SetExplorerExAsDefault].Changing += SetExplorerExAsDefault_OnChanging;
}

#endregion
Expand Down Expand Up @@ -430,6 +513,14 @@ public static class CommonSettings {
this[CommonSettings.WindowBackdrop].Value = 1; // Acrylic
}
}
// 设置是否为默认文件管理器的值
var registryKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Browser Helper Objects\{11451400-8700-480c-a27f-000001919810}");
if (registryKey != null) {
this[CommonSettings.SetExplorerExAsDefault].Value = true;
registryKey.Dispose();
} else {
this[CommonSettings.SetExplorerExAsDefault].Value = false;
}

RegisterEvents();
}
Expand Down

0 comments on commit c1a1004

Please sign in to comment.