mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-02-23 19:49:43 +01:00
Remove package on uninstall
Install package on enable Fix launching app Cleanup
This commit is contained in:
@@ -952,7 +952,7 @@ UINT __stdcall UnRegisterContextMenuPackagesCA(MSIHANDLE hInstall)
|
||||
try
|
||||
{
|
||||
// Packages to unregister
|
||||
const std::vector<std::wstring> packagesToRemoveDisplayName{ { L"PowerRenameContextMenu" }, { L"ImageResizerContextMenu" } };
|
||||
const std::vector<std::wstring> packagesToRemoveDisplayName{ { L"PowerRenameContextMenu" }, { L"ImageResizerContextMenu" }, { L"FileLocksmithContextMenu" } };
|
||||
|
||||
PackageManager packageManager;
|
||||
|
||||
|
||||
|
Before Width: | Height: | Size: 170 KiB After Width: | Height: | Size: 170 KiB |
@@ -1,6 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build"
|
||||
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Target Name="GenerateResourceFiles" BeforeTargets="PrepareForBuild">
|
||||
<Exec Command="powershell -NonInteractive -executionpolicy Unrestricted $(SolutionDir)tools\build\convert-resx-to-rc.ps1 $(MSBuildThisFileDirectory) resource.base.h resource.h FileLocksmithContextMenu.base.rc FileLocksmithContextMenu.rc" />
|
||||
</Target>
|
||||
@@ -9,7 +8,6 @@
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<ProjectGuid>{799a50d8-de89-4ed1-8ff8-ad5a9ed8c0ca}</ProjectGuid>
|
||||
<RootNamespace>FileLocksmithContextMenu</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup>
|
||||
@@ -98,8 +96,12 @@ MakeAppx.exe pack /d . /p $(OutDir)FileLocksmithContextMenuPackage.msix /nv</Com
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
<None Include="Resources.resx" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Assets\FileLocksmith\**" CopyToOutputDirectory="PreserveNewest" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\common\SettingsAPI\SettingsAPI.vcxproj">
|
||||
<Project>{6955446d-23f7-4023-9bb3-8657f904af99}</Project>
|
||||
@@ -114,7 +116,15 @@ MakeAppx.exe pack /d . /p $(OutDir)FileLocksmithContextMenuPackage.msix /nv</Com
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="FileLocksmithContextMenu.base.rc" />
|
||||
</ItemGroup>
|
||||
<Import Project="..\..\..\..\deps\spdlog.props" />
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
<Import Project="..\..\..\..\packages\Microsoft.Windows.ImplementationLibrary.1.0.231216.1\build\native\Microsoft.Windows.ImplementationLibrary.targets" Condition="Exists('..\..\..\..\packages\Microsoft.Windows.ImplementationLibrary.1.0.231216.1\build\native\Microsoft.Windows.ImplementationLibrary.targets')" />
|
||||
</ImportGroup>
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\..\..\..\packages\Microsoft.Windows.ImplementationLibrary.1.0.231216.1\build\native\Microsoft.Windows.ImplementationLibrary.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\Microsoft.Windows.ImplementationLibrary.1.0.231216.1\build\native\Microsoft.Windows.ImplementationLibrary.targets'))" />
|
||||
</Target>
|
||||
</Project>
|
||||
@@ -1,14 +1,14 @@
|
||||
// dllmain.cpp : Defines the entry point for the DLL application.
|
||||
#include "pch.h"
|
||||
|
||||
#include "FileLocksmithLib/AppLaunch.h"
|
||||
#include <common/utils/process_path.h>
|
||||
#include <common/utils/resources.h>
|
||||
#include <common/utils/elevation.h>
|
||||
|
||||
#include "FileLocksmithLib/IPC.h"
|
||||
#include "FileLocksmithLib/Settings.h"
|
||||
#include "FileLocksmithLib/Trace.h"
|
||||
|
||||
#include <common/utils/process_path.h>
|
||||
#include <common/utils/resources.h>
|
||||
|
||||
#include <Shlwapi.h>
|
||||
#include <shobjidl_core.h>
|
||||
#include <string>
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
#include "Generated Files/resource.h"
|
||||
|
||||
|
||||
using namespace Microsoft::WRL;
|
||||
|
||||
HINSTANCE g_hInst = 0;
|
||||
@@ -54,8 +55,8 @@ public:
|
||||
IFACEMETHODIMP GetIcon(_In_opt_ IShellItemArray*, _Outptr_result_nullonfailure_ PWSTR* icon)
|
||||
{
|
||||
std::wstring iconResourcePath = get_module_folderpath(g_hInst);
|
||||
iconResourcePath += L"\\Assets\\FileLockmsith\\";
|
||||
iconResourcePath += L"FileLockmsith.ico";
|
||||
iconResourcePath += L"\\Assets\\FileLocksmith\\";
|
||||
iconResourcePath += L"FileLocksmith.ico";
|
||||
return SHStrDup(iconResourcePath.c_str(), icon);
|
||||
}
|
||||
|
||||
@@ -93,13 +94,18 @@ public:
|
||||
return result;
|
||||
}
|
||||
|
||||
if (HRESULT result = LaunchUI(g_hInst); FAILED(result))
|
||||
std::wstring path = get_module_folderpath(g_hInst);
|
||||
path = path + L"\\PowerToys.FileLocksmithUI.exe";
|
||||
|
||||
HRESULT result;
|
||||
|
||||
if (!RunNonElevatedEx(path.c_str(), L"", get_module_folderpath(g_hInst)))
|
||||
{
|
||||
result = E_FAIL;
|
||||
Trace::InvokedRet(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
HRESULT result;
|
||||
DWORD num_items;
|
||||
selection->GetCount(&num_items);
|
||||
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Microsoft.Windows.ImplementationLibrary" version="1.0.231216.1" targetFramework="native" />
|
||||
</packages>
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "dllmain.h"
|
||||
#include "Generated Files/resource.h"
|
||||
|
||||
#include "FileLocksmithLib/AppLaunch.h"
|
||||
#include "FileLocksmithLib/Constants.h"
|
||||
#include "FileLocksmithLib/Settings.h"
|
||||
#include "FileLocksmithLib/Trace.h"
|
||||
|
||||
@@ -175,7 +175,7 @@ IFACEMETHODIMP ExplorerCommand::InvokeCommand(CMINVOKECOMMANDINFO* pici)
|
||||
return result;
|
||||
}
|
||||
|
||||
if (HRESULT result = LaunchUI(globals::instance); FAILED(result))
|
||||
if (HRESULT result = LaunchUI(pici, &writer); FAILED(result))
|
||||
{
|
||||
Trace::InvokedRet(result);
|
||||
return result;
|
||||
@@ -241,3 +241,48 @@ ExplorerCommand::~ExplorerCommand()
|
||||
{
|
||||
--globals::ref_count;
|
||||
}
|
||||
|
||||
HRESULT ExplorerCommand::LaunchUI(CMINVOKECOMMANDINFO* pici, ipc::Writer* writer)
|
||||
{
|
||||
// Compute exe path
|
||||
std::wstring exe_path = get_module_folderpath(globals::instance);
|
||||
exe_path += L'\\';
|
||||
exe_path += constants::nonlocalizable::FileNameUIExe;
|
||||
|
||||
STARTUPINFO startupInfo;
|
||||
ZeroMemory(&startupInfo, sizeof(STARTUPINFO));
|
||||
startupInfo.cb = sizeof(STARTUPINFO);
|
||||
startupInfo.dwFlags = STARTF_USESHOWWINDOW;
|
||||
|
||||
if (pici)
|
||||
{
|
||||
startupInfo.wShowWindow = pici->nShow;
|
||||
}
|
||||
else
|
||||
{
|
||||
startupInfo.wShowWindow = SW_SHOWNORMAL;
|
||||
}
|
||||
|
||||
PROCESS_INFORMATION processInformation;
|
||||
std::wstring command_line = L"\"";
|
||||
command_line += exe_path;
|
||||
command_line += L"\"\0";
|
||||
|
||||
CreateProcessW(
|
||||
NULL,
|
||||
command_line.data(),
|
||||
NULL,
|
||||
NULL,
|
||||
TRUE,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
&startupInfo,
|
||||
&processInformation);
|
||||
|
||||
// Discard handles
|
||||
CloseHandle(processInformation.hProcess);
|
||||
CloseHandle(processInformation.hThread);
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
@@ -44,6 +44,9 @@ public:
|
||||
private:
|
||||
HBITMAP m_hbmpIcon = nullptr;
|
||||
|
||||
// Helpers
|
||||
HRESULT LaunchUI(CMINVOKECOMMANDINFO* pici, ipc::Writer* writer);
|
||||
|
||||
std::atomic<ULONG> m_ref_count = 1;
|
||||
IDataObject* m_data_obj = NULL;
|
||||
std::wstring context_menu_caption;
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
#include <common/logger/logger.h>
|
||||
#include <common/logger/logger_settings.h>
|
||||
#include <common/utils/logger_helper.h>
|
||||
#include <common/utils/package.h>
|
||||
#include <common/utils/process_path.h>
|
||||
#include <optional>
|
||||
|
||||
#include "FileLocksmithLib/Constants.h"
|
||||
@@ -75,6 +77,18 @@ public:
|
||||
virtual void enable() override
|
||||
{
|
||||
Logger::info(L"File Locksmith enabled");
|
||||
|
||||
if (package::IsWin11OrGreater())
|
||||
{
|
||||
std::wstring path = get_module_folderpath(globals::instance);
|
||||
std::wstring packageUri = path + L"\\FileLocksmithContextMenuPackage.msix";
|
||||
|
||||
if (!package::IsPackageRegistered(constants::nonlocalizable::ContextMenuPackageName))
|
||||
{
|
||||
package::RegisterSparsePackage(path, packageUri);
|
||||
}
|
||||
}
|
||||
|
||||
m_enabled = true;
|
||||
save_settings();
|
||||
}
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
#include "pch.h"
|
||||
#include "AppLaunch.h"
|
||||
|
||||
HRESULT LaunchUI(HMODULE module)
|
||||
{
|
||||
// Compute exe path
|
||||
std::wstring exe_path = get_module_folderpath(module);
|
||||
exe_path += L'\\';
|
||||
exe_path += constants::nonlocalizable::FileNameUIExe;
|
||||
|
||||
STARTUPINFO startupInfo;
|
||||
ZeroMemory(&startupInfo, sizeof(STARTUPINFO));
|
||||
startupInfo.cb = sizeof(STARTUPINFO);
|
||||
startupInfo.dwFlags = STARTF_USESHOWWINDOW;
|
||||
startupInfo.wShowWindow = SW_SHOWNORMAL;
|
||||
|
||||
PROCESS_INFORMATION processInformation;
|
||||
std::wstring command_line = L"\"";
|
||||
command_line += exe_path;
|
||||
command_line += L"\"\0";
|
||||
|
||||
CreateProcessW(
|
||||
NULL,
|
||||
command_line.data(),
|
||||
NULL,
|
||||
NULL,
|
||||
TRUE,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
&startupInfo,
|
||||
&processInformation);
|
||||
|
||||
// Discard handles
|
||||
CloseHandle(processInformation.hProcess);
|
||||
CloseHandle(processInformation.hThread);
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
#pragma once
|
||||
#include <ShlObj.h>
|
||||
#include <string>
|
||||
#include <common/utils/process_path.h>
|
||||
|
||||
#include "Constants.h"
|
||||
|
||||
HRESULT LaunchUI(HMODULE module);
|
||||
|
||||
@@ -28,6 +28,9 @@ namespace constants::nonlocalizable
|
||||
|
||||
// Name of the file where the list of files to checked will be stored
|
||||
constexpr WCHAR LastRunPath[] = L"\\last-run.log";
|
||||
|
||||
// Name of the tier 1 context menu package
|
||||
constexpr WCHAR ContextMenuPackageName[] = L"FileLocksmithContextMenu";
|
||||
}
|
||||
|
||||
// Macros, non-localizable
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build"
|
||||
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>17.0</VCProjectVersion>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
@@ -66,7 +65,6 @@
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Constants.h" />
|
||||
<ClInclude Include="AppLaunch.h" />
|
||||
<ClInclude Include="IPC.h" />
|
||||
<ClInclude Include="Settings.h" />
|
||||
<ClInclude Include="Trace.h" />
|
||||
@@ -74,7 +72,6 @@
|
||||
<ClInclude Include="pch.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="AppLaunch.cpp" />
|
||||
<ClCompile Include="IPC.cpp" />
|
||||
<ClCompile Include="Settings.cpp" />
|
||||
<ClCompile Include="Trace.cpp" />
|
||||
|
||||
@@ -30,9 +30,6 @@
|
||||
<ClInclude Include="IPC.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="AppLaunch.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Constants.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
@@ -53,8 +50,5 @@
|
||||
<ClCompile Include="Trace.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="AppLaunch.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user