Skip to content

Use external launcher to set Files as default explorer #8684

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Mar 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions Files.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.1.31903.286
# Visual Studio Version 16
VisualStudioVersion = 16.0.31911.196
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Files.Launcher", "src\Files.Launcher\Files.Launcher.csproj", "{533F9E86-EE0A-4FCB-B70C-F29532C1B787}"
ProjectSection(ProjectDependencies) = postProject
Expand Down Expand Up @@ -30,6 +30,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Files.UI", "Files.UI", "{A1
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Files.Backend", "src\Files.Backend\Files.Backend.csproj", "{4CFE0BBC-8D07-49A0-8B10-4EDD61ABCF57}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FilesLauncher", "src\Files.OpenDialog\FilesLauncher\FilesLauncher.vcxproj", "{25FD5045-6D4C-4DD0-B3AC-613AB59CBB07}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|arm64 = Debug|arm64
Expand Down Expand Up @@ -142,6 +144,16 @@ Global
{4CFE0BBC-8D07-49A0-8B10-4EDD61ABCF57}.Release|x64.Build.0 = Release|x64
{4CFE0BBC-8D07-49A0-8B10-4EDD61ABCF57}.Release|x86.ActiveCfg = Release|x86
{4CFE0BBC-8D07-49A0-8B10-4EDD61ABCF57}.Release|x86.Build.0 = Release|x86
{25FD5045-6D4C-4DD0-B3AC-613AB59CBB07}.Debug|arm64.ActiveCfg = Debug|Win32
{25FD5045-6D4C-4DD0-B3AC-613AB59CBB07}.Debug|x64.ActiveCfg = Debug|x64
{25FD5045-6D4C-4DD0-B3AC-613AB59CBB07}.Debug|x64.Build.0 = Debug|x64
{25FD5045-6D4C-4DD0-B3AC-613AB59CBB07}.Debug|x86.ActiveCfg = Debug|Win32
{25FD5045-6D4C-4DD0-B3AC-613AB59CBB07}.Debug|x86.Build.0 = Debug|Win32
{25FD5045-6D4C-4DD0-B3AC-613AB59CBB07}.Release|arm64.ActiveCfg = Release|Win32
{25FD5045-6D4C-4DD0-B3AC-613AB59CBB07}.Release|x64.ActiveCfg = Release|x64
{25FD5045-6D4C-4DD0-B3AC-613AB59CBB07}.Release|x64.Build.0 = Release|x64
{25FD5045-6D4C-4DD0-B3AC-613AB59CBB07}.Release|x86.ActiveCfg = Release|Win32
{25FD5045-6D4C-4DD0-B3AC-613AB59CBB07}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -157,6 +169,7 @@ Global
{B7E43D1F-AC8B-4958-95D5-A06CDD1FEACD} = {481DE2EA-E6CE-4A9C-A220-3B543B95AAA1}
{A188C26B-E731-4E0B-9D17-D21CEBD9B43F} = {A74DCE98-A744-4D71-A2B1-7EE4FED0936B}
{4CFE0BBC-8D07-49A0-8B10-4EDD61ABCF57} = {A188C26B-E731-4E0B-9D17-D21CEBD9B43F}
{25FD5045-6D4C-4DD0-B3AC-613AB59CBB07} = {0175B70C-1E29-4A3F-AA4F-C2017B040EF0}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0E62043C-A7A1-4982-9EC9-4CDB2939B776}
Expand Down
Binary file not shown.
Binary file modified src/Files.Launcher/Assets/FilesOpenDialog/SetFilesAsDefault.reg
Binary file not shown.
4 changes: 4 additions & 0 deletions src/Files.Launcher/Files.Launcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Files.Shared\Files.Shared.csproj" />
<Content Include="Assets\FilesOpenDialog\FilesLauncher.exe" />
<Content Include="Assets\FilesOpenDialog\SetFilesAsDefault.reg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
Expand All @@ -45,4 +46,7 @@
<ItemGroup>
<Compile Remove="FolderNames.cs" />
</ItemGroup>
<ItemGroup>
<None Remove="Assets\FilesOpenDialog\FilesLauncher.exe" />
</ItemGroup>
</Project>
18 changes: 17 additions & 1 deletion src/Files.Launcher/MessageHandlers/Win32MessageHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private static void DetectIsSetAsDefaultFileManager()
{
using var subkey = Registry.ClassesRoot.OpenSubKey(@"Folder\shell\open\command");
var command = (string)subkey?.GetValue(string.Empty);
ApplicationData.Current.LocalSettings.Values["IsSetAsDefaultFileManager"] = !string.IsNullOrEmpty(command) && command.Contains("files.exe");
ApplicationData.Current.LocalSettings.Values["IsSetAsDefaultFileManager"] = !string.IsNullOrEmpty(command) && command.Contains("FilesLauncher.exe");
}

private static void DetectIsSetAsOpenFileDialog()
Expand Down Expand Up @@ -159,6 +159,22 @@ public async Task ParseArgumentsAsync(PipeStream connection, Dictionary<string,
return;
}
}

var dataPath = Environment.ExpandEnvironmentVariables("%LocalAppData%\\Files");
if (enable)
{
if (!Win32API.RunPowershellCommand($"-command \"New-Item -Force -Path {dataPath} -ItemType Directory; Copy-Item -Filter *.* -Path '{destFolder}\\*' -Recurse -Force -Destination '{dataPath}'\"", false))
{
// Error copying files
DetectIsSetAsDefaultFileManager();
await Win32API.SendMessageAsync(connection, new ValueSet() { { "Success", false } }, message.Get("RequestID", (string)null));
return;
}
}
else
{
Win32API.RunPowershellCommand($"-command \"Remove-Item -Path '{dataPath}' -Recurse -Force\"", false);
}

try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<VCProjectVersion>16.0</VCProjectVersion>
<ProjectGuid>{A2FF3F3B-8EBC-4108-B99D-1476B7876656}</ProjectGuid>
<Keyword>AtlProj</Keyword>
<WindowsTargetPlatformVersion>10.0.19041.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
Expand Down
57 changes: 57 additions & 0 deletions src/Files.OpenDialog/FilesLauncher/DocumentServiceProvider.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright (C) Explorer++ Project
// SPDX-License-Identifier: GPL-3.0-only
// See LICENSE in the top level directory

#include "DocumentServiceProvider.h"

// IDispatch
// Note that none of these methods require any implementation. When attempting to find a shell
// window, the shell requests the IDispatch interface, but doesn't actually call any methods on it.
IFACEMETHODIMP DocumentServiceProvider::GetTypeInfoCount(UINT *typeInfoCount)
{
UNREFERENCED_PARAMETER(typeInfoCount);

return E_NOTIMPL;
}

IFACEMETHODIMP DocumentServiceProvider::GetTypeInfo(UINT type, LCID localeId, ITypeInfo **typeInfo)
{
UNREFERENCED_PARAMETER(type);
UNREFERENCED_PARAMETER(localeId);
UNREFERENCED_PARAMETER(typeInfo);

return E_NOTIMPL;
}

IFACEMETHODIMP DocumentServiceProvider::GetIDsOfNames(
REFIID riid, LPOLESTR *names, UINT numNames, LCID localeId, DISPID *dispId)
{
UNREFERENCED_PARAMETER(riid);
UNREFERENCED_PARAMETER(names);
UNREFERENCED_PARAMETER(numNames);
UNREFERENCED_PARAMETER(localeId);
UNREFERENCED_PARAMETER(dispId);

return E_NOTIMPL;
}

IFACEMETHODIMP DocumentServiceProvider::Invoke(DISPID dispIdMember, REFIID riid, LCID localeId,
WORD flags, DISPPARAMS *dispParams, VARIANT *varResult, EXCEPINFO *exceptionInfo, UINT *argErr)
{
UNREFERENCED_PARAMETER(dispIdMember);
UNREFERENCED_PARAMETER(riid);
UNREFERENCED_PARAMETER(localeId);
UNREFERENCED_PARAMETER(flags);
UNREFERENCED_PARAMETER(dispParams);
UNREFERENCED_PARAMETER(varResult);
UNREFERENCED_PARAMETER(exceptionInfo);
UNREFERENCED_PARAMETER(argErr);

return E_NOTIMPL;
}

// IServiceProvider
IFACEMETHODIMP DocumentServiceProvider::QueryService(REFGUID guidService, REFIID riid, void **ppv)
{
return ServiceProviderBase::QueryService(guidService, riid, ppv);
}
25 changes: 25 additions & 0 deletions src/Files.OpenDialog/FilesLauncher/DocumentServiceProvider.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (C) Explorer++ Project
// SPDX-License-Identifier: GPL-3.0-only
// See LICENSE in the top level directory

#pragma once

#include "ServiceProviderBase.h"
#include <winrt/base.h>

class DocumentServiceProvider :
public winrt::implements<DocumentServiceProvider, IDispatch, IServiceProvider>,
public ServiceProviderBase
{
public:
// IDispatch
IFACEMETHODIMP GetTypeInfoCount(UINT *typeInfoCount);
IFACEMETHODIMP GetTypeInfo(UINT type, LCID localeId, ITypeInfo **typeInfo);
IFACEMETHODIMP GetIDsOfNames(
REFIID riid, LPOLESTR *names, UINT numNames, LCID localeId, DISPID *dispId);
IFACEMETHODIMP Invoke(DISPID dispIdMember, REFIID riid, LCID localeId, WORD flags,
DISPPARAMS *dispParams, VARIANT *varResult, EXCEPINFO *exceptionInfo, UINT *argErr);

// IServiceProvider
IFACEMETHODIMP QueryService(REFGUID guidService, REFIID riid, void **ppv);
};
Loading