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 0000000000..7440f0d4bf Binary files /dev/null and b/src/modules/FileLocksmith/FileLocksmithGUI/Assets/LockScreenLogo.scale-200.png differ 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 0000000000..32f486a867 Binary files /dev/null and b/src/modules/FileLocksmith/FileLocksmithGUI/Assets/SplashScreen.scale-200.png differ diff --git a/src/modules/FileLocksmith/FileLocksmithGUI/Assets/Square150x150Logo.scale-200.png b/src/modules/FileLocksmith/FileLocksmithGUI/Assets/Square150x150Logo.scale-200.png new file mode 100644 index 0000000000..53ee3777ea Binary files /dev/null and b/src/modules/FileLocksmith/FileLocksmithGUI/Assets/Square150x150Logo.scale-200.png differ diff --git a/src/modules/FileLocksmith/FileLocksmithGUI/Assets/Square44x44Logo.scale-200.png b/src/modules/FileLocksmith/FileLocksmithGUI/Assets/Square44x44Logo.scale-200.png new file mode 100644 index 0000000000..f713bba67f Binary files /dev/null and b/src/modules/FileLocksmith/FileLocksmithGUI/Assets/Square44x44Logo.scale-200.png differ diff --git a/src/modules/FileLocksmith/FileLocksmithGUI/Assets/Square44x44Logo.targetsize-24_altform-unplated.png b/src/modules/FileLocksmith/FileLocksmithGUI/Assets/Square44x44Logo.targetsize-24_altform-unplated.png new file mode 100644 index 0000000000..dc9f5bea0c Binary files /dev/null and b/src/modules/FileLocksmith/FileLocksmithGUI/Assets/Square44x44Logo.targetsize-24_altform-unplated.png differ diff --git a/src/modules/FileLocksmith/FileLocksmithGUI/Assets/StoreLogo.png b/src/modules/FileLocksmith/FileLocksmithGUI/Assets/StoreLogo.png new file mode 100644 index 0000000000..a4586f26bd Binary files /dev/null and b/src/modules/FileLocksmith/FileLocksmithGUI/Assets/StoreLogo.png differ diff --git a/src/modules/FileLocksmith/FileLocksmithGUI/Assets/Wide310x150Logo.scale-200.png b/src/modules/FileLocksmith/FileLocksmithGUI/Assets/Wide310x150Logo.scale-200.png new file mode 100644 index 0000000000..8b4a5d0dd5 Binary files /dev/null and b/src/modules/FileLocksmith/FileLocksmithGUI/Assets/Wide310x150Logo.scale-200.png differ 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/ +========================================================================