From 988dda89c2a406c1c6418d313685beefcf8548ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Sto=C5=A1i=C4=87?= Date: Mon, 19 Sep 2022 10:41:19 +0200 Subject: [PATCH] Add Ext and GUI projects to solution --- PowerToys.sln | 30 +- .../FileLocksmithExt/ClassFactory.cpp | 80 +++++ .../FileLocksmithExt/ClassFactory.h | 22 ++ .../FileLocksmithExt/Constants.h | 28 ++ .../FileLocksmithExt/ExplorerCommand.cpp | 275 ++++++++++++++++++ .../FileLocksmithExt/ExplorerCommand.h | 48 +++ .../FileLocksmithExt/FileLocksmithExt.vcxproj | 172 +++++++++++ .../FileLocksmithExt.vcxproj.filters | 59 ++++ .../FileLocksmithExt/Registry.cpp | 114 ++++++++ .../FileLocksmith/FileLocksmithExt/Registry.h | 6 + .../FileLocksmith/FileLocksmithExt/dll.def | 5 + .../FileLocksmithExt/dllmain.cpp | 80 +++++ .../FileLocksmith/FileLocksmithExt/dllmain.h | 9 + .../FileLocksmith/FileLocksmithExt/pch.cpp | 5 + .../FileLocksmith/FileLocksmithExt/pch.h | 12 + .../FileLocksmith/FileLocksmithGUI/App.idl | 3 + .../FileLocksmith/FileLocksmithGUI/App.xaml | 15 + .../FileLocksmithGUI/App.xaml.cpp | 46 +++ .../FileLocksmith/FileLocksmithGUI/App.xaml.h | 16 + .../Assets/LockScreenLogo.scale-200.png | Bin 0 -> 432 bytes .../Assets/SplashScreen.scale-200.png | Bin 0 -> 5372 bytes .../Assets/Square150x150Logo.scale-200.png | Bin 0 -> 1755 bytes .../Assets/Square44x44Logo.scale-200.png | Bin 0 -> 637 bytes ...x44Logo.targetsize-24_altform-unplated.png | Bin 0 -> 283 bytes .../FileLocksmithGUI/Assets/StoreLogo.png | Bin 0 -> 456 bytes .../Assets/Wide310x150Logo.scale-200.png | Bin 0 -> 2097 bytes .../FileLocksmithGUI/FileLocksmithGUI.vcxproj | 219 ++++++++++++++ .../FileLocksmithGUI.vcxproj.filters | 58 ++++ .../FileLocksmithGUI/MainWindow.idl | 8 + .../FileLocksmithGUI/MainWindow.xaml | 13 + .../FileLocksmithGUI/MainWindow.xaml.cpp | 84 ++++++ .../FileLocksmithGUI/MainWindow.xaml.h | 24 ++ .../FileLocksmithGUI/Package.appxmanifest | 48 +++ .../FileLocksmithGUI/ProcessEntry.idl | 8 + .../FileLocksmithGUI/ProcessEntry.xaml | 26 ++ .../FileLocksmithGUI/ProcessEntry.xaml.cpp | 46 +++ .../FileLocksmithGUI/ProcessEntry.xaml.h | 24 ++ .../FileLocksmithGUI/app.manifest | 15 + .../FileLocksmithGUI/packages.config | 7 + .../FileLocksmith/FileLocksmithGUI/pch.cpp | 1 + .../FileLocksmith/FileLocksmithGUI/pch.h | 29 ++ .../FileLocksmith/FileLocksmithGUI/readme.txt | 27 ++ 42 files changed, 1660 insertions(+), 2 deletions(-) create mode 100644 src/modules/FileLocksmith/FileLocksmithExt/ClassFactory.cpp create mode 100644 src/modules/FileLocksmith/FileLocksmithExt/ClassFactory.h create mode 100644 src/modules/FileLocksmith/FileLocksmithExt/Constants.h create mode 100644 src/modules/FileLocksmith/FileLocksmithExt/ExplorerCommand.cpp create mode 100644 src/modules/FileLocksmith/FileLocksmithExt/ExplorerCommand.h create mode 100644 src/modules/FileLocksmith/FileLocksmithExt/FileLocksmithExt.vcxproj create mode 100644 src/modules/FileLocksmith/FileLocksmithExt/FileLocksmithExt.vcxproj.filters create mode 100644 src/modules/FileLocksmith/FileLocksmithExt/Registry.cpp create mode 100644 src/modules/FileLocksmith/FileLocksmithExt/Registry.h create mode 100644 src/modules/FileLocksmith/FileLocksmithExt/dll.def create mode 100644 src/modules/FileLocksmith/FileLocksmithExt/dllmain.cpp create mode 100644 src/modules/FileLocksmith/FileLocksmithExt/dllmain.h create mode 100644 src/modules/FileLocksmith/FileLocksmithExt/pch.cpp create mode 100644 src/modules/FileLocksmith/FileLocksmithExt/pch.h create mode 100644 src/modules/FileLocksmith/FileLocksmithGUI/App.idl create mode 100644 src/modules/FileLocksmith/FileLocksmithGUI/App.xaml create mode 100644 src/modules/FileLocksmith/FileLocksmithGUI/App.xaml.cpp create mode 100644 src/modules/FileLocksmith/FileLocksmithGUI/App.xaml.h create mode 100644 src/modules/FileLocksmith/FileLocksmithGUI/Assets/LockScreenLogo.scale-200.png create mode 100644 src/modules/FileLocksmith/FileLocksmithGUI/Assets/SplashScreen.scale-200.png create mode 100644 src/modules/FileLocksmith/FileLocksmithGUI/Assets/Square150x150Logo.scale-200.png create mode 100644 src/modules/FileLocksmith/FileLocksmithGUI/Assets/Square44x44Logo.scale-200.png create mode 100644 src/modules/FileLocksmith/FileLocksmithGUI/Assets/Square44x44Logo.targetsize-24_altform-unplated.png create mode 100644 src/modules/FileLocksmith/FileLocksmithGUI/Assets/StoreLogo.png create mode 100644 src/modules/FileLocksmith/FileLocksmithGUI/Assets/Wide310x150Logo.scale-200.png create mode 100644 src/modules/FileLocksmith/FileLocksmithGUI/FileLocksmithGUI.vcxproj create mode 100644 src/modules/FileLocksmith/FileLocksmithGUI/FileLocksmithGUI.vcxproj.filters create mode 100644 src/modules/FileLocksmith/FileLocksmithGUI/MainWindow.idl create mode 100644 src/modules/FileLocksmith/FileLocksmithGUI/MainWindow.xaml create mode 100644 src/modules/FileLocksmith/FileLocksmithGUI/MainWindow.xaml.cpp create mode 100644 src/modules/FileLocksmith/FileLocksmithGUI/MainWindow.xaml.h create mode 100644 src/modules/FileLocksmith/FileLocksmithGUI/Package.appxmanifest create mode 100644 src/modules/FileLocksmith/FileLocksmithGUI/ProcessEntry.idl create mode 100644 src/modules/FileLocksmith/FileLocksmithGUI/ProcessEntry.xaml create mode 100644 src/modules/FileLocksmith/FileLocksmithGUI/ProcessEntry.xaml.cpp create mode 100644 src/modules/FileLocksmith/FileLocksmithGUI/ProcessEntry.xaml.h create mode 100644 src/modules/FileLocksmith/FileLocksmithGUI/app.manifest create mode 100644 src/modules/FileLocksmith/FileLocksmithGUI/packages.config create mode 100644 src/modules/FileLocksmith/FileLocksmithGUI/pch.cpp create mode 100644 src/modules/FileLocksmith/FileLocksmithGUI/pch.h create mode 100644 src/modules/FileLocksmith/FileLocksmithGUI/readme.txt diff --git a/PowerToys.sln b/PowerToys.sln index 741db7203e..1a35177492 100644 --- a/PowerToys.sln +++ b/PowerToys.sln @@ -461,6 +461,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "FileLocksmith", "FileLocksm EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FileLocksmithLib", "src\modules\FileLocksmith\FileLocksmithLib\FileLocksmithLib.vcxproj", "{8290CF58-0E97-45C4-AB41-F3C7C3128AEC}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FileLocksmithExt", "src\modules\FileLocksmith\FileLocksmithExt\FileLocksmithExt.vcxproj", "{57175EC7-92A5-4C1E-8244-E3FBCA2A81DE}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FileLocksmithGUI", "src\modules\FileLocksmith\FileLocksmithGUI\FileLocksmithGUI.vcxproj", "{BBD45704-F220-4774-9C92-D55D822C9E75}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|ARM64 = Debug|ARM64 @@ -1546,8 +1550,8 @@ Global {04B193D7-3E21-46B8-A958-89B63A8A69DE}.Release|ARM64.Build.0 = Release|ARM64 {04B193D7-3E21-46B8-A958-89B63A8A69DE}.Release|x64.ActiveCfg = Release|x64 {04B193D7-3E21-46B8-A958-89B63A8A69DE}.Release|x64.Build.0 = Release|x64 - {04B193D7-3E21-46B8-A958-89B63A8A69DE}.Release|x86.ActiveCfg = Release|Any CPU - {04B193D7-3E21-46B8-A958-89B63A8A69DE}.Release|x86.Build.0 = Release|Any CPU + {04B193D7-3E21-46B8-A958-89B63A8A69DE}.Release|x86.ActiveCfg = Release|x64 + {04B193D7-3E21-46B8-A958-89B63A8A69DE}.Release|x86.Build.0 = Release|x64 {F44934A8-36F3-49B0-9465-3831BE041CDE}.Debug|ARM64.ActiveCfg = Debug|ARM64 {F44934A8-36F3-49B0-9465-3831BE041CDE}.Debug|ARM64.Build.0 = Debug|ARM64 {F44934A8-36F3-49B0-9465-3831BE041CDE}.Debug|x64.ActiveCfg = Debug|x64 @@ -1862,6 +1866,26 @@ Global {8290CF58-0E97-45C4-AB41-F3C7C3128AEC}.Release|x64.ActiveCfg = Release|x64 {8290CF58-0E97-45C4-AB41-F3C7C3128AEC}.Release|x64.Build.0 = Release|x64 {8290CF58-0E97-45C4-AB41-F3C7C3128AEC}.Release|x86.ActiveCfg = Release|x64 + {57175EC7-92A5-4C1E-8244-E3FBCA2A81DE}.Debug|ARM64.ActiveCfg = Debug|x64 + {57175EC7-92A5-4C1E-8244-E3FBCA2A81DE}.Debug|ARM64.Build.0 = Debug|x64 + {57175EC7-92A5-4C1E-8244-E3FBCA2A81DE}.Debug|x64.ActiveCfg = Debug|x64 + {57175EC7-92A5-4C1E-8244-E3FBCA2A81DE}.Debug|x64.Build.0 = Debug|x64 + {57175EC7-92A5-4C1E-8244-E3FBCA2A81DE}.Debug|x86.ActiveCfg = Debug|x64 + {57175EC7-92A5-4C1E-8244-E3FBCA2A81DE}.Release|ARM64.ActiveCfg = Release|x64 + {57175EC7-92A5-4C1E-8244-E3FBCA2A81DE}.Release|ARM64.Build.0 = Release|x64 + {57175EC7-92A5-4C1E-8244-E3FBCA2A81DE}.Release|x64.ActiveCfg = Release|x64 + {57175EC7-92A5-4C1E-8244-E3FBCA2A81DE}.Release|x64.Build.0 = Release|x64 + {57175EC7-92A5-4C1E-8244-E3FBCA2A81DE}.Release|x86.ActiveCfg = Release|x64 + {BBD45704-F220-4774-9C92-D55D822C9E75}.Debug|ARM64.ActiveCfg = Debug|arm64 + {BBD45704-F220-4774-9C92-D55D822C9E75}.Debug|ARM64.Build.0 = Debug|arm64 + {BBD45704-F220-4774-9C92-D55D822C9E75}.Debug|x64.ActiveCfg = Debug|x64 + {BBD45704-F220-4774-9C92-D55D822C9E75}.Debug|x64.Build.0 = Debug|x64 + {BBD45704-F220-4774-9C92-D55D822C9E75}.Debug|x86.ActiveCfg = Debug|x64 + {BBD45704-F220-4774-9C92-D55D822C9E75}.Release|ARM64.ActiveCfg = Release|arm64 + {BBD45704-F220-4774-9C92-D55D822C9E75}.Release|ARM64.Build.0 = Release|arm64 + {BBD45704-F220-4774-9C92-D55D822C9E75}.Release|x64.ActiveCfg = Release|x64 + {BBD45704-F220-4774-9C92-D55D822C9E75}.Release|x64.Build.0 = Release|x64 + {BBD45704-F220-4774-9C92-D55D822C9E75}.Release|x86.ActiveCfg = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -2020,6 +2044,8 @@ Global {B41B888C-7DB8-4747-B262-4062E05A230D} = {F05E590D-AD46-42BE-9C25-6A63ADD2E3EA} {AB82E5DD-C32D-4F28-9746-2C780846188E} = {4574FDD0-F61D-4376-98BF-E5A1262C11EC} {8290CF58-0E97-45C4-AB41-F3C7C3128AEC} = {AB82E5DD-C32D-4F28-9746-2C780846188E} + {57175EC7-92A5-4C1E-8244-E3FBCA2A81DE} = {AB82E5DD-C32D-4F28-9746-2C780846188E} + {BBD45704-F220-4774-9C92-D55D822C9E75} = {AB82E5DD-C32D-4F28-9746-2C780846188E} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {C3A2F9D1-7930-4EF4-A6FC-7EE0A99821D0} diff --git a/src/modules/FileLocksmith/FileLocksmithExt/ClassFactory.cpp b/src/modules/FileLocksmith/FileLocksmithExt/ClassFactory.cpp new file mode 100644 index 0000000000..de9492161b --- /dev/null +++ b/src/modules/FileLocksmith/FileLocksmithExt/ClassFactory.cpp @@ -0,0 +1,80 @@ +#include "pch.h" + +#include "ClassFactory.h" +#include "ExplorerCommand.h" +#include "dllmain.h" + +// Class ctor/dtors + +ClassFactory::ClassFactory(_In_ REFCLSID clsid) : + m_ref_count(1), + m_clsid(clsid) +{ + ++globals::ref_count; +} + +ClassFactory::~ClassFactory() +{ + --globals::ref_count; +} + +// Implementations of inherited IUnknown methods + +IFACEMETHODIMP ClassFactory::QueryInterface(REFIID riid, void** ppv) +{ + static const QITAB qit[] = { + QITABENT(ClassFactory, IClassFactory), + { 0, 0 }, + }; + return QISearch(this, qit, riid, ppv); +} + +IFACEMETHODIMP_(ULONG) ClassFactory::AddRef() +{ + return ++m_ref_count; +} + +IFACEMETHODIMP_(ULONG) ClassFactory::Release() +{ + auto result = --m_ref_count; + if (result == 0) + { + delete this; + } + return result; +} + +// Implementations of inherited IClassFactory methods + +IFACEMETHODIMP ClassFactory::CreateInstance(IUnknown* pUnkOuter, REFIID riid, void** ppvObject) +{ + *ppvObject = NULL; + HRESULT hr; + if (pUnkOuter) + { + hr = CLASS_E_NOAGGREGATION; + } + else if (m_clsid == __uuidof(ExplorerCommand)) + { + hr = ExplorerCommand::s_CreateInstance(pUnkOuter, riid, ppvObject); + } + else + { + hr = CLASS_E_CLASSNOTAVAILABLE; + } + return hr; +} + +IFACEMETHODIMP ClassFactory::LockServer(BOOL fLock) +{ + if (fLock) + { + ++globals::ref_count; + } + else + { + --globals::ref_count; + } + + return S_OK; +} diff --git a/src/modules/FileLocksmith/FileLocksmithExt/ClassFactory.h b/src/modules/FileLocksmith/FileLocksmithExt/ClassFactory.h new file mode 100644 index 0000000000..5b2f8c9e32 --- /dev/null +++ b/src/modules/FileLocksmith/FileLocksmithExt/ClassFactory.h @@ -0,0 +1,22 @@ +#pragma once + +#include "pch.h" + +class ClassFactory : public IClassFactory +{ +public: + ClassFactory(_In_ REFCLSID clsid); + ~ClassFactory(); + + // IUnknown + IFACEMETHODIMP QueryInterface(REFIID riid, void** ppv) override; + IFACEMETHODIMP_(ULONG) AddRef() override; + IFACEMETHODIMP_(ULONG) Release() override; + + // IClassFactory + IFACEMETHODIMP CreateInstance(IUnknown* pUnkOuter, REFIID riid, void** ppvObject) override; + IFACEMETHODIMP LockServer(BOOL fLock) override; +private: + std::atomic m_ref_count; + IID m_clsid; +}; diff --git a/src/modules/FileLocksmith/FileLocksmithExt/Constants.h b/src/modules/FileLocksmith/FileLocksmithExt/Constants.h new file mode 100644 index 0000000000..11d172f961 --- /dev/null +++ b/src/modules/FileLocksmith/FileLocksmithExt/Constants.h @@ -0,0 +1,28 @@ +#pragma once + +#include "pch.h" + +// Localizable constants, these should be converted to resources +namespace constants::localizable +{ + // Text shown in the context menu + constexpr WCHAR CommandTitle[] = L"What's using this file?"; +} + +// Non-localizable constants +namespace constants::nonlocalizable +{ + // Description of the registry key + constexpr WCHAR RegistryKeyDescription[] = L"File Locksmith Shell Extension"; + + // File name of the DLL + constexpr WCHAR FileNameDLL[] = L"ContextMenuEntry.dll"; + + // File name of the UI executable + constexpr WCHAR FileNameUIExe[] = L"FileLocksmithGUI\\FileLocksmithGUI.exe"; +} + +// Macros, non-localizable + +// Description of the registry key +#define REGISTRY_CONTEXT_MENU_KEY L"FileLocksmithExt" diff --git a/src/modules/FileLocksmith/FileLocksmithExt/ExplorerCommand.cpp b/src/modules/FileLocksmith/FileLocksmithExt/ExplorerCommand.cpp new file mode 100644 index 0000000000..f621083d1a --- /dev/null +++ b/src/modules/FileLocksmith/FileLocksmithExt/ExplorerCommand.cpp @@ -0,0 +1,275 @@ +#include "pch.h" + +#include "ExplorerCommand.h" +#include "Constants.h" +#include "dllmain.h" + +// Implementations of inherited IUnknown methods + +IFACEMETHODIMP ExplorerCommand::QueryInterface(REFIID riid, void** ppv) +{ + static const QITAB qit[] = { + QITABENT(ExplorerCommand, IExplorerCommand), + QITABENT(ExplorerCommand, IShellExtInit), + QITABENT(ExplorerCommand, IContextMenu), + { 0, 0 }, + }; + return QISearch(this, qit, riid, ppv); +} + +IFACEMETHODIMP_(ULONG) ExplorerCommand::AddRef() +{ + return ++m_ref_count; +} + +IFACEMETHODIMP_(ULONG) ExplorerCommand::Release() +{ + auto result = --m_ref_count; + if (result == 0) + { + delete this; + } + return result; +} + +// Implementations of inherited IExplorerCommand methods + +IFACEMETHODIMP ExplorerCommand::GetTitle(IShellItemArray* psiItemArray, LPWSTR* ppszName) +{ + return SHStrDup(constants::localizable::CommandTitle, ppszName); +} + +IFACEMETHODIMP ExplorerCommand::GetIcon(IShellItemArray* psiItemArray, LPWSTR* ppszIcon) +{ + // Path to the icon should be computed relative to the path of this module + ppszIcon = NULL; + return E_NOTIMPL; +} + +IFACEMETHODIMP ExplorerCommand::GetToolTip(IShellItemArray* psiItemArray, LPWSTR* ppszInfotip) +{ + // No tooltip for now + return E_NOTIMPL; +} + +IFACEMETHODIMP ExplorerCommand::GetCanonicalName(GUID* pguidCommandName) +{ + *pguidCommandName = __uuidof(this); + return S_OK; +} + +IFACEMETHODIMP ExplorerCommand::GetState(IShellItemArray* psiItemArray, BOOL fOkToBeSlow, EXPCMDSTATE* pCmdState) +{ + // This should depend on the settings + // For now we'll just keep it always enabled. + *pCmdState = ECS_ENABLED; + return S_OK; +} + +IFACEMETHODIMP ExplorerCommand::Invoke(IShellItemArray* psiItemArray, IBindCtx* pbc) +{ + // This should call the main exe. + // For now we'll just show a message box. + MessageBoxW(NULL, L"OK", L"OK", MB_OK); + return S_OK; +} + +IFACEMETHODIMP ExplorerCommand::GetFlags(EXPCMDFLAGS* pFlags) +{ + *pFlags = ECF_DEFAULT; + return S_OK; +} + +IFACEMETHODIMP ExplorerCommand::EnumSubCommands(IEnumExplorerCommand** ppEnum) +{ + *ppEnum = NULL; + return E_NOTIMPL; +} + +// Implementations of inherited IShellExtInit methods + +IFACEMETHODIMP ExplorerCommand::Initialize(PCIDLIST_ABSOLUTE pidlFolder, IDataObject* pdtobj, HKEY hkeyProgID) +{ + m_data_obj = pdtobj; + m_data_obj->AddRef(); + return S_OK; +} + +// Implementations of inherited IContextMenu methods + +IFACEMETHODIMP ExplorerCommand::QueryContextMenu(HMENU hmenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags) +{ + HRESULT hr = E_UNEXPECTED; + if (m_data_obj && !(uFlags & (CMF_DEFAULTONLY | CMF_VERBSONLY | CMF_OPTIMIZEFORINVOKE))) + { + MENUITEMINFO mii; + mii.cbSize = sizeof(MENUITEMINFO); + mii.fMask = MIIM_STRING | MIIM_FTYPE | MIIM_ID | MIIM_STATE; + mii.wID = idCmdFirst++; + mii.fType = MFT_STRING; + + hr = SHStrDupW(constants::localizable::CommandTitle, &mii.dwTypeData); + if (FAILED(hr)) + { + return hr; + } + + mii.fState = MFS_ENABLED; + + // TODO icon from file + + if (!InsertMenuItem(hmenu, indexMenu, TRUE, &mii)) + { + hr = HRESULT_FROM_WIN32(GetLastError()); + } + else + { + hr = MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_NULL, 1); + } + } + + return hr; +} + +IFACEMETHODIMP ExplorerCommand::InvokeCommand(CMINVOKECOMMANDINFO* pici) +{ + ipc::Writer writer; + + if (HRESULT result = writer.start(); FAILED(result)) + { + return result; + } + + if (HRESULT result = LaunchUI(pici, &writer); FAILED(result)) + { + return result; + } + + IShellItemArray* shell_item_array; + HRESULT result = SHCreateShellItemArrayFromDataObject(m_data_obj, __uuidof(IShellItemArray), reinterpret_cast(&shell_item_array)); + if (SUCCEEDED(result)) + { + DWORD num_items; + shell_item_array->GetCount(&num_items); + for (DWORD i = 0; i < num_items; i++) + { + IShellItem* item; + result = shell_item_array->GetItemAt(i, &item); + if (SUCCEEDED(result)) + { + LPWSTR file_path; + result = item->GetDisplayName(SIGDN_FILESYSPATH, &file_path); + if (SUCCEEDED(result)) + { + // TODO Aggregate items and send to UI + writer.add_path(file_path); + CoTaskMemFree(file_path); + } + + item->Release(); + } + } + + shell_item_array->Release(); + } + + return S_OK; +} + +IFACEMETHODIMP ExplorerCommand::GetCommandString(UINT_PTR idCmd, UINT uType, UINT* pReserved, CHAR* pszName, UINT cchMax) +{ + return E_NOTIMPL; +} + +HRESULT ExplorerCommand::s_CreateInstance(IUnknown* pUnkOuter, REFIID riid, void** ppvObject) +{ + *ppvObject = NULL; + HRESULT hr = E_OUTOFMEMORY; + ExplorerCommand* pNew = new (std::nothrow) ExplorerCommand; + if (pNew) + { + hr = pNew->QueryInterface(riid, ppvObject); + pNew->Release(); + } + return hr; +} + +ExplorerCommand::~ExplorerCommand() +{ + if (m_data_obj) + { + m_data_obj->Release(); + } +} + +// Implementation taken from src/common/utils +// TODO reference that function +inline std::wstring get_module_folderpath(HMODULE mod = nullptr, const bool removeFilename = true) +{ + wchar_t buffer[MAX_PATH + 1]; + DWORD actual_length = GetModuleFileNameW(mod, buffer, MAX_PATH); + if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) + { + const DWORD long_path_length = 0xFFFF; // should be always enough + std::wstring long_filename(long_path_length, L'\0'); + actual_length = GetModuleFileNameW(mod, long_filename.data(), long_path_length); + PathRemoveFileSpecW(long_filename.data()); + long_filename.resize(std::wcslen(long_filename.data())); + long_filename.shrink_to_fit(); + return long_filename; + } + + if (removeFilename) + { + PathRemoveFileSpecW(buffer); + } + return { buffer, (UINT)lstrlenW(buffer) }; +} + +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; + + HANDLE read_handle = writer->get_read_handle(); + + STARTUPINFO startupInfo; + ZeroMemory(&startupInfo, sizeof(STARTUPINFO)); + startupInfo.cb = sizeof(STARTUPINFO); + startupInfo.hStdInput = read_handle; + startupInfo.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES; + + 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; +} diff --git a/src/modules/FileLocksmith/FileLocksmithExt/ExplorerCommand.h b/src/modules/FileLocksmith/FileLocksmithExt/ExplorerCommand.h new file mode 100644 index 0000000000..4539669d88 --- /dev/null +++ b/src/modules/FileLocksmith/FileLocksmithExt/ExplorerCommand.h @@ -0,0 +1,48 @@ +#pragma once + +#include "pch.h" + +// File Locksmith library +#include "../FileLocksmithLib/IPC.h" + +#define EXPLORER_COMMAND_UUID_STR "84d68575-e186-46ad-b0cb-baeb45ee29c0" + +class __declspec(uuid(EXPLORER_COMMAND_UUID_STR)) ExplorerCommand : public IExplorerCommand, public IShellExtInit, public IContextMenu +{ +public: + // IUnknown + IFACEMETHODIMP QueryInterface(REFIID riid, void** ppv) override; + IFACEMETHODIMP_(ULONG) AddRef() override; + IFACEMETHODIMP_(ULONG) Release() override; + + // IExplorerCommand + IFACEMETHODIMP GetTitle(IShellItemArray* psiItemArray, LPWSTR* ppszName) override; + IFACEMETHODIMP GetIcon(IShellItemArray* psiItemArray, LPWSTR* ppszIcon) override; + IFACEMETHODIMP GetToolTip(IShellItemArray* psiItemArray, LPWSTR* ppszInfotip) override; + IFACEMETHODIMP GetCanonicalName(GUID* pguidCommandName) override; + IFACEMETHODIMP GetState(IShellItemArray* psiItemArray, BOOL fOkToBeSlow, EXPCMDSTATE* pCmdState) override; + IFACEMETHODIMP Invoke(IShellItemArray* psiItemArray, IBindCtx* pbc) override; + IFACEMETHODIMP GetFlags(EXPCMDFLAGS* pFlags) override; + IFACEMETHODIMP EnumSubCommands(IEnumExplorerCommand** ppEnum) override; + + // IShellExtInit + IFACEMETHODIMP Initialize(PCIDLIST_ABSOLUTE pidlFolder, IDataObject* pdtobj, HKEY hkeyProgID) override; + + // IContextMenu + IFACEMETHODIMP QueryContextMenu(HMENU hmenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags) override; + IFACEMETHODIMP InvokeCommand(CMINVOKECOMMANDINFO* pici) override; + IFACEMETHODIMP GetCommandString(UINT_PTR idCmd, UINT uType, UINT* pReserved, CHAR* pszName, UINT cchMax) override; + + // Static member to create an instance + static HRESULT s_CreateInstance(IUnknown* pUnkOuter, REFIID riid, void** ppvObject); + + // Destructor + ~ExplorerCommand(); + +private: + // Helpers + HRESULT LaunchUI(CMINVOKECOMMANDINFO* pici, ipc::Writer* writer); + + std::atomic m_ref_count = 1; + IDataObject* m_data_obj = NULL; +}; diff --git a/src/modules/FileLocksmith/FileLocksmithExt/FileLocksmithExt.vcxproj b/src/modules/FileLocksmith/FileLocksmithExt/FileLocksmithExt.vcxproj new file mode 100644 index 0000000000..ea636bfe1d --- /dev/null +++ b/src/modules/FileLocksmith/FileLocksmithExt/FileLocksmithExt.vcxproj @@ -0,0 +1,172 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {57175ec7-92a5-4c1e-8244-e3fbca2a81de} + FileLocksmithExt + 10.0 + + + + DynamicLibrary + true + v143 + Unicode + + + DynamicLibrary + false + v143 + true + Unicode + + + DynamicLibrary + true + v143 + Unicode + + + DynamicLibrary + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;FILELOCKSMITHEXT_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + Use + + + Windows + true + false + dll.def + + + + + Level3 + true + true + true + WIN32;NDEBUG;FILELOCKSMITHEXT_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + Use + + + Windows + true + true + true + false + dll.def + + + + + Level3 + true + _DEBUG;FILELOCKSMITHEXT_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + Use + + + Windows + true + false + dll.def + + + + + Level3 + true + true + true + NDEBUG;FILELOCKSMITHLIB_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + Use + + + Windows + true + true + true + false + dll.def + + + + + + + + + + + + + + + + Create + Create + Create + Create + + + + + + + + + {8290cf58-0e97-45c4-ab41-f3c7c3128aec} + + + + + + \ No newline at end of file diff --git a/src/modules/FileLocksmith/FileLocksmithExt/FileLocksmithExt.vcxproj.filters b/src/modules/FileLocksmith/FileLocksmithExt/FileLocksmithExt.vcxproj.filters new file mode 100644 index 0000000000..df303c7691 --- /dev/null +++ b/src/modules/FileLocksmith/FileLocksmithExt/FileLocksmithExt.vcxproj.filters @@ -0,0 +1,59 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + + + Source Files + + + \ No newline at end of file diff --git a/src/modules/FileLocksmith/FileLocksmithExt/Registry.cpp b/src/modules/FileLocksmith/FileLocksmithExt/Registry.cpp new file mode 100644 index 0000000000..9117e6c3dc --- /dev/null +++ b/src/modules/FileLocksmith/FileLocksmithExt/Registry.cpp @@ -0,0 +1,114 @@ +#include "pch.h" + +#include "Registry.h" +#include "ExplorerCommand.h" +#include "Constants.h" +#include "dllmain.h" + +#define HKEY_ROOT HKEY_CURRENT_USER + +bool registry_write_string(LPCWSTR path, LPCWSTR property, LPCWSTR value) +{ + HKEY key; + LSTATUS result = RegCreateKeyExW( + HKEY_ROOT, + path, + 0, + NULL, + REG_OPTION_NON_VOLATILE, + KEY_ALL_ACCESS, + NULL, + &key, + NULL + ); + + if (result != ERROR_SUCCESS) + { + return false; + } + + if (value != NULL) + { + result = RegSetValueExW(key, property, 0, REG_SZ, reinterpret_cast(value), sizeof(WCHAR) * (1ull + lstrlenW(value))); + } + + RegCloseKey(key); + return result == ERROR_SUCCESS; +} + +bool registry_delete_tree(LPCWSTR path) +{ + LSTATUS result = RegDeleteTreeW(HKEY_ROOT, path); + return result == ERROR_SUCCESS; +} + +bool add_registry_keys() +{ + if (!registry_write_string( + L"Software\\Classes\\CLSID\\{" EXPLORER_COMMAND_UUID_STR L"}", + NULL, + constants::nonlocalizable::RegistryKeyDescription + )) + { + return false; + } + + if (!registry_write_string( + L"Software\\Classes\\CLSID\\{" EXPLORER_COMMAND_UUID_STR L"}", + L"ContextMenuOptIn", + L"" + )) + { + return false; + } + + static WCHAR module_file_name[MAX_PATH]; + DWORD result = GetModuleFileNameW(globals::instance, module_file_name, ARRAYSIZE(module_file_name)); + if (result == 0) + { + return false; + } + + if (!registry_write_string( + L"Software\\Classes\\CLSID\\{" EXPLORER_COMMAND_UUID_STR L"}\\InprocServer32", + NULL, + module_file_name + )) + { + return false; + } + + if (!registry_write_string( + L"Software\\Classes\\CLSID\\{" EXPLORER_COMMAND_UUID_STR L"}\\InprocServer32", + L"ThreadingModel", + L"Apartment" + )) + { + return false; + } + + if (!registry_write_string( + L"Software\\Classes\\AllFileSystemObjects\\ShellEx\\ContextMenuHandlers\\" REGISTRY_CONTEXT_MENU_KEY, + L"", + L"{" EXPLORER_COMMAND_UUID_STR L"}" + )) + { + return false; + } + + return true; +} + +bool delete_registry_keys() +{ + bool ok = true; + ok &= registry_delete_tree( + L"Software\\Classes\\CLSID\\{" EXPLORER_COMMAND_UUID_STR "}" + ); + + ok &= registry_delete_tree( + L"Software\\Classes\\AllFileSystemObjects\\ShellEx\\ContextMenuHandlers\\" REGISTRY_CONTEXT_MENU_KEY + ); + + return ok; +} diff --git a/src/modules/FileLocksmith/FileLocksmithExt/Registry.h b/src/modules/FileLocksmith/FileLocksmithExt/Registry.h new file mode 100644 index 0000000000..1657c2ce11 --- /dev/null +++ b/src/modules/FileLocksmith/FileLocksmithExt/Registry.h @@ -0,0 +1,6 @@ +#pragma once + +#include "pch.h" + +bool add_registry_keys(); +bool delete_registry_keys(); diff --git a/src/modules/FileLocksmith/FileLocksmithExt/dll.def b/src/modules/FileLocksmith/FileLocksmithExt/dll.def new file mode 100644 index 0000000000..450007ee91 --- /dev/null +++ b/src/modules/FileLocksmith/FileLocksmithExt/dll.def @@ -0,0 +1,5 @@ +EXPORTS + DllRegisterServer PRIVATE + DllUnregisterServer PRIVATE + DllGetClassObject PRIVATE + DllCanUnloadNow PRIVATE diff --git a/src/modules/FileLocksmith/FileLocksmithExt/dllmain.cpp b/src/modules/FileLocksmith/FileLocksmithExt/dllmain.cpp new file mode 100644 index 0000000000..a173e350b1 --- /dev/null +++ b/src/modules/FileLocksmith/FileLocksmithExt/dllmain.cpp @@ -0,0 +1,80 @@ +// dllmain.cpp : Defines the entry point for the DLL application. +#include "pch.h" + +// Additional libraries to link +#pragma comment(lib, "shlwapi") + +#include "Registry.h" +#include "ClassFactory.h" + +namespace globals +{ + HMODULE instance; + std::atomic ref_count; +} + +BOOL APIENTRY DllMain( HMODULE hModule, + DWORD ul_reason_for_call, + LPVOID lpReserved + ) +{ + switch (ul_reason_for_call) + { + case DLL_PROCESS_ATTACH: + globals::instance = hModule; + break; + case DLL_THREAD_ATTACH: + case DLL_THREAD_DETACH: + case DLL_PROCESS_DETACH: + break; + } + return TRUE; +} + + +STDAPI DllRegisterServer() +{ + if (!add_registry_keys()) + { + // Best effort here + delete_registry_keys(); + return E_FAIL; + } + + return S_OK; +} + +STDAPI DllUnregisterServer() +{ + return delete_registry_keys() ? S_OK : E_FAIL; +} + +STDAPI DllGetClassObject(REFCLSID clsid, REFIID riid, void** ppv) +{ + HRESULT result = E_FAIL; + *ppv = NULL; + ClassFactory* class_factory = new (std::nothrow) ClassFactory(clsid); + if (class_factory) + { + result = class_factory->QueryInterface(riid, ppv); + class_factory->Release(); + } + + return result; +} + +STDAPI DllCanUnloadNow(void) +{ + return globals::ref_count == 0 ? S_OK : S_FALSE; +} + +// Things to implement: +// 1. (DONE) A class which implements IExplorerCommand +// 2. (DONE) A class which implements IClassFactory +// 3. (DONE) DLL register/unregister functions which will create registry entries +// 4. (DONE) Other DLL exported functions +// 5. (DONE) Implement IShellExtInit in ExplorerCommand +// 6. (DONE) Implement IContextMenu in ExplorerCommand +// 7. (DONE) Extract useful functions from HandlesExperiment to a static library +// 8. (DONE) Implement IPC in Lib - to be used between UI and DLL +// 9. Implement UI diff --git a/src/modules/FileLocksmith/FileLocksmithExt/dllmain.h b/src/modules/FileLocksmith/FileLocksmithExt/dllmain.h new file mode 100644 index 0000000000..274acb5e11 --- /dev/null +++ b/src/modules/FileLocksmith/FileLocksmithExt/dllmain.h @@ -0,0 +1,9 @@ +#pragma once + +#include "pch.h" + +namespace globals +{ + extern HMODULE instance; + extern std::atomic ref_count; +} diff --git a/src/modules/FileLocksmith/FileLocksmithExt/pch.cpp b/src/modules/FileLocksmith/FileLocksmithExt/pch.cpp new file mode 100644 index 0000000000..64b7eef6d6 --- /dev/null +++ b/src/modules/FileLocksmith/FileLocksmithExt/pch.cpp @@ -0,0 +1,5 @@ +// pch.cpp: source file corresponding to the pre-compiled header + +#include "pch.h" + +// When you are using pre-compiled headers, this source file is necessary for compilation to succeed. diff --git a/src/modules/FileLocksmith/FileLocksmithExt/pch.h b/src/modules/FileLocksmith/FileLocksmithExt/pch.h new file mode 100644 index 0000000000..77a6a16d7b --- /dev/null +++ b/src/modules/FileLocksmith/FileLocksmithExt/pch.h @@ -0,0 +1,12 @@ +#pragma once + +// add headers that you want to pre-compile here +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +// Windows Header Files +#include +#include +#include + +// C++ Standard library +#include +#include diff --git a/src/modules/FileLocksmith/FileLocksmithGUI/App.idl b/src/modules/FileLocksmith/FileLocksmithGUI/App.idl new file mode 100644 index 0000000000..7c5fc804ad --- /dev/null +++ b/src/modules/FileLocksmith/FileLocksmithGUI/App.idl @@ -0,0 +1,3 @@ +namespace FileLocksmithGUI +{ +} diff --git a/src/modules/FileLocksmith/FileLocksmithGUI/App.xaml b/src/modules/FileLocksmith/FileLocksmithGUI/App.xaml new file mode 100644 index 0000000000..8600e69122 --- /dev/null +++ b/src/modules/FileLocksmith/FileLocksmithGUI/App.xaml @@ -0,0 +1,15 @@ + + + + + + + + + + + diff --git a/src/modules/FileLocksmith/FileLocksmithGUI/App.xaml.cpp b/src/modules/FileLocksmith/FileLocksmithGUI/App.xaml.cpp new file mode 100644 index 0000000000..a7d9624ab5 --- /dev/null +++ b/src/modules/FileLocksmith/FileLocksmithGUI/App.xaml.cpp @@ -0,0 +1,46 @@ +#include "pch.h" + +#include "App.xaml.h" +#include "MainWindow.xaml.h" + +using namespace winrt; +using namespace Windows::Foundation; +using namespace Microsoft::UI::Xaml; +using namespace Microsoft::UI::Xaml::Controls; +using namespace Microsoft::UI::Xaml::Navigation; +using namespace FileLocksmithGUI; +using namespace FileLocksmithGUI::implementation; + +// To learn more about WinUI, the WinUI project structure, +// and more about our project templates, see: http://aka.ms/winui-project-info. + +/// +/// Initializes the singleton application object. This is the first line of authored code +/// executed, and as such is the logical equivalent of main() or WinMain(). +/// +App::App() +{ + InitializeComponent(); + +#if defined _DEBUG && !defined DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION + UnhandledException([this](IInspectable const&, UnhandledExceptionEventArgs const& e) + { + if (IsDebuggerPresent()) + { + auto errorMessage = e.Message(); + __debugbreak(); + } + }); +#endif +} + +/// +/// Invoked when the application is launched normally by the end user. Other entry points +/// will be used such as when the application is launched to open a specific file. +/// +/// Details about the launch request and process. +void App::OnLaunched(LaunchActivatedEventArgs const&) +{ + window = make(); + window.Activate(); +} \ No newline at end of file diff --git a/src/modules/FileLocksmith/FileLocksmithGUI/App.xaml.h b/src/modules/FileLocksmith/FileLocksmithGUI/App.xaml.h new file mode 100644 index 0000000000..918c8a3e9b --- /dev/null +++ b/src/modules/FileLocksmith/FileLocksmithGUI/App.xaml.h @@ -0,0 +1,16 @@ +#pragma once + +#include "App.xaml.g.h" + +namespace winrt::FileLocksmithGUI::implementation +{ + struct App : AppT + { + App(); + + void OnLaunched(Microsoft::UI::Xaml::LaunchActivatedEventArgs const&); + + private: + winrt::Microsoft::UI::Xaml::Window window{ nullptr }; + }; +} diff --git a/src/modules/FileLocksmith/FileLocksmithGUI/Assets/LockScreenLogo.scale-200.png b/src/modules/FileLocksmith/FileLocksmithGUI/Assets/LockScreenLogo.scale-200.png new file mode 100644 index 0000000000000000000000000000000000000000..7440f0d4bf7c7e26e4e36328738c68e624ee851e GIT binary patch literal 432 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA1|-9oezr3(FqV6|IEGZ*x-#9g>~Mkr+x6^F zy~CDX2QIMs&Gcs3RnRBoxBA!*(Mfw0KTCYuYk0WlEIV>qBmPl! zq4ukrvfADX@#p8fbLY(H47N+k`FZ(FZh?cDro7>{8mkBO3>^oaIx`3!Jl)Qq)HI!+ z(S=1{o~eT)&W^=Ea8C`-17(Jv5(nHFJ{dOjGdxLVkY_y6&S1whfuFI4MM0kF0f&cO zPDVpV%nz;Id$>+0Ga5e9625-JcI)oq=#Pa3p^>8BB}21BUw@eN!-6@w%X+^`+Vn?! zryu|3T>kVWNBYyBc=7Y6H#s1Ah!OI_nezW zXTqOdkv2Az6KKBV=$yHdF^R3Fqw(TZEoNSZX>reXJ#bwX42%f|Pgg&ebxsLQ010xn AssI20 literal 0 HcmV?d00001 diff --git a/src/modules/FileLocksmith/FileLocksmithGUI/Assets/SplashScreen.scale-200.png b/src/modules/FileLocksmith/FileLocksmithGUI/Assets/SplashScreen.scale-200.png new file mode 100644 index 0000000000000000000000000000000000000000..32f486a86792a5e34cd9a8261b394c49b48f86be GIT binary patch literal 5372 zcmd5=Z){Ul6u)iv53sCbIJKLzl(EF%0tzcEY@|pLrfgF~2Dk$KFtU+$kbYqDN5W%7 z>?DBo!@y06eh{Oux>brrNT^{MO(tkiC@nH(2}}G_1|uvcMD(0{?|W^Gxo!tG~h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png new file mode 100644 index 0000000000000000000000000000000000000000..f713bba67f551ef91020b75716a4dc8ebd744b1c GIT binary patch literal 637 zcmeAS@N?(olHy`uVBq!ia0vp^5g^RL1|$oo8kjIJFu8cTIEGZ*dUI*J;2{SImxtDO zm%3!R$UazoY}x{$j0P5ABYXWr(l=jxJ6ps1W{tV=^>{Dl><3nv3A}sm=EZ)#l3`NR zpZda3^rNox*D1%NC98Z~L*6zipLw~Gxn&(Y-;KmJ+aR6eLabU-L#y8HW%7P-E_-VlLqIabbHPHKT*)fT@9iWJ7iWgOT9%0}Lrj>lztPxWq6sPw3pi z#-<=#$jjrP_DD*i!RLsn0mIA=>4~N)IMYWIf=j%-zuKCdMG%tHYot70D1| zvWa0wMhauW#S>1CnI_;>!1Q3zMA17@DOVq{MQ+{U7^a&yA+%dMCG;WNPV0i;w$tu; zX^b}UKziPM)(<;)ruW;-`)bBN+rQNM*Zs_>?n$|FVFo-e*PZb*@U7VAd+tHb4e?=Blc~}S6K)wL}r*Gf`BM#QB z+y>N$mCswb4d{^{S9v_!eQj4fTRMOwOCi?lSk9%<=vAz}jM-*PQtH@Odn1LZcd^j#o> hW$4xn+CT+ep9lJ{OAO?njobhL002ovPDHLkV1nYebbkN< literal 0 HcmV?d00001 diff --git a/src/modules/FileLocksmith/FileLocksmithGUI/Assets/StoreLogo.png b/src/modules/FileLocksmith/FileLocksmithGUI/Assets/StoreLogo.png new file mode 100644 index 0000000000000000000000000000000000000000..a4586f26bdf7841cad10f39cdffe2aca3af252c1 GIT binary patch literal 456 zcmeAS@N?(olHy`uVBq!ia0vp^Mj*_=1|;R|J2o;fF!p=8IEGZ*dUM0H=rDtTTVkd2 z(%lbKn@VS_lUaADVB&;Z6F#LM+mPsa?e>FnHo;HND^!P`-lX%BH~FOg%y&x+t*x!? zg$#_1A1kgsSvO(fw`bOmo;lrJX8byO1j^gf7qohR%mmt z@L)WX;>gqgK|tWJvQ5j;4;=gt4HXVKSMYRv5RhY5vS~TqfK_NAP*r{h!!g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WITGI!`$c< gARL?UBrYYkwoDw4eo*CrzXGTrZ@;GF>596)00d&n@&Et; literal 0 HcmV?d00001 diff --git a/src/modules/FileLocksmith/FileLocksmithGUI/FileLocksmithGUI.vcxproj b/src/modules/FileLocksmith/FileLocksmithGUI/FileLocksmithGUI.vcxproj new file mode 100644 index 0000000000..0178d6e9c8 --- /dev/null +++ b/src/modules/FileLocksmith/FileLocksmithGUI/FileLocksmithGUI.vcxproj @@ -0,0 +1,219 @@ + + + + + + + true + true + true + {bbd45704-f220-4774-9c92-d55d822c9e75} + FileLocksmithGUI + FileLocksmithGUI + + $(RootNamespace) + en-US + 16.0 + false + false + Windows Store + 10.0 + 10.0 + 10.0.17763.0 + true + true + None + true + + + + + Debug + Win32 + + + Debug + x64 + + + Debug + arm64 + + + Release + Win32 + + + Release + x64 + + + Release + arm64 + + + + Application + v143 + v142 + Unicode + true + + + true + true + + + false + true + false + + + + + + + + + + + Use + pch.h + $(IntDir)pch.pch + Level4 + %(AdditionalOptions) /bigobj + + + + + _DEBUG;%(PreprocessorDefinitions) + + + + + NDEBUG;%(PreprocessorDefinitions) + + + true + true + + + + + Designer + + + + + + + + + App.xaml + + + MainWindow.xaml + + + ProcessEntry.xaml + Code + + + + + + + Designer + + + + + Create + + + App.xaml + + + MainWindow.xaml + + + + ProcessEntry.xaml + Code + + + + + Code + App.xaml + + + Code + MainWindow.xaml + + + ProcessEntry.xaml + Code + + + + + false + + + + + + + + + + + + + + + + + + + + + {8290cf58-0e97-45c4-ab41-f3c7c3128aec} + + + + + true + + + + + + + + + + + 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}. + + + + + + + + + + \ No newline at end of file diff --git a/src/modules/FileLocksmith/FileLocksmithGUI/FileLocksmithGUI.vcxproj.filters b/src/modules/FileLocksmith/FileLocksmithGUI/FileLocksmithGUI.vcxproj.filters new file mode 100644 index 0000000000..4a14833aba --- /dev/null +++ b/src/modules/FileLocksmith/FileLocksmithGUI/FileLocksmithGUI.vcxproj.filters @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + Assets + + + Assets + + + Assets + + + Assets + + + Assets + + + Assets + + + Assets + + + + + {bbd45704-f220-4774-9c92-d55d822c9e75} + + + + + + + + + + + + \ No newline at end of file diff --git a/src/modules/FileLocksmith/FileLocksmithGUI/MainWindow.idl b/src/modules/FileLocksmith/FileLocksmithGUI/MainWindow.idl new file mode 100644 index 0000000000..c0cdbfce3b --- /dev/null +++ b/src/modules/FileLocksmith/FileLocksmithGUI/MainWindow.idl @@ -0,0 +1,8 @@ +namespace FileLocksmithGUI +{ + [default_interface] + runtimeclass MainWindow : Microsoft.UI.Xaml.Window + { + MainWindow(); + } +} diff --git a/src/modules/FileLocksmith/FileLocksmithGUI/MainWindow.xaml b/src/modules/FileLocksmith/FileLocksmithGUI/MainWindow.xaml new file mode 100644 index 0000000000..155b84b508 --- /dev/null +++ b/src/modules/FileLocksmith/FileLocksmithGUI/MainWindow.xaml @@ -0,0 +1,13 @@ + + + + + + diff --git a/src/modules/FileLocksmith/FileLocksmithGUI/MainWindow.xaml.cpp b/src/modules/FileLocksmith/FileLocksmithGUI/MainWindow.xaml.cpp new file mode 100644 index 0000000000..1e0ba2784f --- /dev/null +++ b/src/modules/FileLocksmith/FileLocksmithGUI/MainWindow.xaml.cpp @@ -0,0 +1,84 @@ +#include "pch.h" +#include "MainWindow.xaml.h" +#if __has_include("MainWindow.g.cpp") +#include "MainWindow.g.cpp" +#endif + +#include "../FileLocksmithLib/IPC.h" +#include "../FileLocksmithLib/FileLocksmith.h" + +#pragma comment(lib, "shcore") // GetDpiForMonitor + +using namespace winrt; +using namespace Microsoft::UI; +using namespace Microsoft::UI::Xaml; + +// To learn more about WinUI, the WinUI project structure, +// and more about our project templates, see: http://aka.ms/winui-project-info. + +namespace winrt::FileLocksmithGUI::implementation +{ + MainWindow::MainWindow() + { + place_and_resize(); + InitializeComponent(); + find_processes(); + } + + void MainWindow::find_processes() + { + auto paths = ipc::read_paths_from_stdin(); + m_process_info = find_processes_recursive(paths); + + // TODO move to another thread + stackPanel().Children().Clear(); + for (const auto& process : m_process_info) + { + ProcessEntry entry(process.name, process.pid, process.num_files); + stackPanel().Children().Append(entry); + } + } + + void MainWindow::place_and_resize() + { + // Get native handle + auto windowNative{ this->try_as<::IWindowNative>() }; + winrt::check_bool(windowNative); + HWND hwnd{ 0 }; + windowNative->get_WindowHandle(&hwnd); + + // Get mouse cursor position + POINT cursorPosition{0, 0}; + GetCursorPos(&cursorPosition); + ::Windows::Graphics::PointInt32 point{ cursorPosition.x, cursorPosition.y }; + + // Get monitor area for mouse position + auto display_area = Windowing::DisplayArea::GetFromPoint(point, Windowing::DisplayAreaFallback::Nearest); + HMONITOR monitor = MonitorFromPoint(cursorPosition, MONITOR_DEFAULTTOPRIMARY); + MONITORINFOEXW monitor_info; + monitor_info.cbSize = sizeof(MONITORINFOEX); + GetMonitorInfoW(monitor, &monitor_info); + UINT dpi_x, dpi_y; + GetDpiForMonitor(monitor, MONITOR_DPI_TYPE::MDT_EFFECTIVE_DPI, &dpi_x, &dpi_y); + UINT window_dpi = GetDpiForWindow(hwnd); + + int width = 720; + int height = 405; + + winrt::Windows::Graphics::RectInt32 rect; + + // Scale window size + rect.Width = (int32_t)(width * (float)window_dpi / dpi_x); + rect.Height = (int32_t)(height * (float)window_dpi / dpi_y); + + // Center to screen + rect.X = display_area.WorkArea().X + display_area.WorkArea().Width / 2 - width / 2; + rect.Y = display_area.WorkArea().Y + display_area.WorkArea().Height / 2 - height / 2; + + // Get app window + auto window_id = GetWindowIdFromWindow(hwnd); + auto app_window = Windowing::AppWindow::GetFromWindowId(window_id); + + app_window.MoveAndResize(rect); + } +} diff --git a/src/modules/FileLocksmith/FileLocksmithGUI/MainWindow.xaml.h b/src/modules/FileLocksmith/FileLocksmithGUI/MainWindow.xaml.h new file mode 100644 index 0000000000..a4329f4d16 --- /dev/null +++ b/src/modules/FileLocksmith/FileLocksmithGUI/MainWindow.xaml.h @@ -0,0 +1,24 @@ +#pragma once + +#include "MainWindow.g.h" +#include "../FileLocksmithLib/FileLocksmith.h" + +namespace winrt::FileLocksmithGUI::implementation +{ + struct MainWindow : MainWindowT + { + MainWindow(); + + private: + std::vector m_process_info; + void find_processes(); + void place_and_resize(); + }; +} + +namespace winrt::FileLocksmithGUI::factory_implementation +{ + struct MainWindow : MainWindowT + { + }; +} diff --git a/src/modules/FileLocksmith/FileLocksmithGUI/Package.appxmanifest b/src/modules/FileLocksmith/FileLocksmithGUI/Package.appxmanifest new file mode 100644 index 0000000000..273cf36352 --- /dev/null +++ b/src/modules/FileLocksmith/FileLocksmithGUI/Package.appxmanifest @@ -0,0 +1,48 @@ + + + + + + + + FileLocksmithGUI + Admin + Assets\StoreLogo.png + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/modules/FileLocksmith/FileLocksmithGUI/ProcessEntry.idl b/src/modules/FileLocksmith/FileLocksmithGUI/ProcessEntry.idl new file mode 100644 index 0000000000..fbc8effec9 --- /dev/null +++ b/src/modules/FileLocksmith/FileLocksmithGUI/ProcessEntry.idl @@ -0,0 +1,8 @@ +namespace FileLocksmithGUI +{ + [default_interface] + runtimeclass ProcessEntry : Microsoft.UI.Xaml.Controls.UserControl + { + ProcessEntry(String process, UInt32 pid, UInt64 num_files); + } +} diff --git a/src/modules/FileLocksmith/FileLocksmithGUI/ProcessEntry.xaml b/src/modules/FileLocksmith/FileLocksmithGUI/ProcessEntry.xaml new file mode 100644 index 0000000000..de7bfabd06 --- /dev/null +++ b/src/modules/FileLocksmith/FileLocksmithGUI/ProcessEntry.xaml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + diff --git a/src/modules/FileLocksmith/FileLocksmithGUI/ProcessEntry.xaml.cpp b/src/modules/FileLocksmith/FileLocksmithGUI/ProcessEntry.xaml.cpp new file mode 100644 index 0000000000..2747d2f00c --- /dev/null +++ b/src/modules/FileLocksmith/FileLocksmithGUI/ProcessEntry.xaml.cpp @@ -0,0 +1,46 @@ +#include "pch.h" +#include "ProcessEntry.xaml.h" +#if __has_include("ProcessEntry.g.cpp") +#include "ProcessEntry.g.cpp" +#endif + +using namespace winrt; +using namespace Microsoft::UI::Xaml; + +// To learn more about WinUI, the WinUI project structure, +// and more about our project templates, see: http://aka.ms/winui-project-info. + +namespace winrt::FileLocksmithGUI::implementation +{ + ProcessEntry::ProcessEntry(const winrt::hstring& process, DWORD pid, uint64_t num_files) + { + InitializeComponent(); + processName().Text(process); + + auto processPidStr = L"Process ID: " + std::to_wstring(pid); + auto processFileCountStr = L"Files used: " + std::to_wstring(num_files); + + processPid().Text(processPidStr); + processFileCount().Text(processFileCountStr); + + m_pid = pid; + } + + void ProcessEntry::killProcessClick(Windows::Foundation::IInspectable const&, RoutedEventArgs const&) + { + HANDLE process = OpenProcess(PROCESS_TERMINATE, FALSE, m_pid); + if (!process || !TerminateProcess(process, 1)) + { + MessageBoxW(NULL, L"Failed to kill process.", L"Error", MB_OK); + return; + } + + CloseHandle(process); + + auto siblings = Parent().as().Children(); + if (uint32_t index; siblings.IndexOf(*this, index)) + { + siblings.RemoveAt(index); + } + } +} diff --git a/src/modules/FileLocksmith/FileLocksmithGUI/ProcessEntry.xaml.h b/src/modules/FileLocksmith/FileLocksmithGUI/ProcessEntry.xaml.h new file mode 100644 index 0000000000..9303840b3e --- /dev/null +++ b/src/modules/FileLocksmith/FileLocksmithGUI/ProcessEntry.xaml.h @@ -0,0 +1,24 @@ +#pragma once + +#include "winrt/Microsoft.UI.Xaml.h" +#include "winrt/Microsoft.UI.Xaml.Markup.h" +#include "winrt/Microsoft.UI.Xaml.Controls.Primitives.h" +#include "ProcessEntry.g.h" + +namespace winrt::FileLocksmithGUI::implementation +{ + struct ProcessEntry : ProcessEntryT + { + ProcessEntry(const winrt::hstring& process, DWORD pid, uint64_t num_files); + void killProcessClick(winrt::Windows::Foundation::IInspectable const& sender, winrt::Microsoft::UI::Xaml::RoutedEventArgs const& e); + private: + DWORD m_pid; + }; +} + +namespace winrt::FileLocksmithGUI::factory_implementation +{ + struct ProcessEntry : ProcessEntryT + { + }; +} diff --git a/src/modules/FileLocksmith/FileLocksmithGUI/app.manifest b/src/modules/FileLocksmith/FileLocksmithGUI/app.manifest new file mode 100644 index 0000000000..ead078aa74 --- /dev/null +++ b/src/modules/FileLocksmith/FileLocksmithGUI/app.manifest @@ -0,0 +1,15 @@ + + + + + + + + true/PM + PerMonitorV2, PerMonitor + + + diff --git a/src/modules/FileLocksmith/FileLocksmithGUI/packages.config b/src/modules/FileLocksmith/FileLocksmithGUI/packages.config new file mode 100644 index 0000000000..54436116b2 --- /dev/null +++ b/src/modules/FileLocksmith/FileLocksmithGUI/packages.config @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/src/modules/FileLocksmith/FileLocksmithGUI/pch.cpp b/src/modules/FileLocksmith/FileLocksmithGUI/pch.cpp new file mode 100644 index 0000000000..bcb5590be1 --- /dev/null +++ b/src/modules/FileLocksmith/FileLocksmithGUI/pch.cpp @@ -0,0 +1 @@ +#include "pch.h" diff --git a/src/modules/FileLocksmith/FileLocksmithGUI/pch.h b/src/modules/FileLocksmith/FileLocksmithGUI/pch.h new file mode 100644 index 0000000000..60c8a485c3 --- /dev/null +++ b/src/modules/FileLocksmith/FileLocksmithGUI/pch.h @@ -0,0 +1,29 @@ +#pragma once +#include +#include +#include +#include +#include + +// Undefine GetCurrentTime macro to prevent +// conflict with Storyboard::GetCurrentTime +#undef GetCurrentTime + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include diff --git a/src/modules/FileLocksmith/FileLocksmithGUI/readme.txt b/src/modules/FileLocksmith/FileLocksmithGUI/readme.txt new file mode 100644 index 0000000000..72d2dca6c3 --- /dev/null +++ b/src/modules/FileLocksmith/FileLocksmithGUI/readme.txt @@ -0,0 +1,27 @@ +======================================================================== + FileLocksmithGUI Project Overview +======================================================================== + +This project demonstrates how to get started writing WinUI3 apps directly +with standard C++, using the Windows App SDK and C++/WinRT packages and +XAML compiler support to generate implementation headers from interface +(IDL) files. These headers can then be used to implement the local +Windows Runtime classes referenced in the app's XAML pages. + +Steps: +1. Create an interface (IDL) file to define any local Windows Runtime + classes referenced in the app's XAML pages. +2. Build the project once to generate implementation templates under + the "Generated Files" folder, as well as skeleton class definitions + under "Generated Files\sources". +3. Use the skeleton class definitions for reference to implement your + Windows Runtime classes. + +======================================================================== +Learn more about Windows App SDK here: +https://docs.microsoft.com/windows/apps/windows-app-sdk/ +Learn more about WinUI3 here: +https://docs.microsoft.com/windows/apps/winui/winui3/ +Learn more about C++/WinRT here: +http://aka.ms/cppwinrt/ +========================================================================