From 45ba6ac400a8207458b99663896e697841327dc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Sto=C5=A1i=C4=87?= Date: Mon, 19 Sep 2022 16:33:13 +0200 Subject: [PATCH] Implement some parts of FileLocksmithModule --- .../FileLocksmithExt/Constants.h | 6 ++ .../FileLocksmithExt/FileLocksmithExt.vcxproj | 18 ++++ .../FileLocksmithExt.vcxproj.filters | 4 + .../FileLocksmithExt/PowerToysModule.cpp | 88 +++++++++++++++++++ .../FileLocksmithExt/packages.config | 4 + .../FileLocksmith/FileLocksmithExt/pch.h | 1 + .../interface/powertoy_module_interface.h | 1 + 7 files changed, 122 insertions(+) create mode 100644 src/modules/FileLocksmith/FileLocksmithExt/PowerToysModule.cpp create mode 100644 src/modules/FileLocksmith/FileLocksmithExt/packages.config diff --git a/src/modules/FileLocksmith/FileLocksmithExt/Constants.h b/src/modules/FileLocksmith/FileLocksmithExt/Constants.h index 11d172f961..2b0190b28b 100644 --- a/src/modules/FileLocksmith/FileLocksmithExt/Constants.h +++ b/src/modules/FileLocksmith/FileLocksmithExt/Constants.h @@ -7,6 +7,9 @@ namespace constants::localizable { // Text shown in the context menu constexpr WCHAR CommandTitle[] = L"What's using this file?"; + + // Localized name of this PowerToy + constexpr WCHAR PowerToyName[] = L"File Locksmith"; } // Non-localizable constants @@ -20,6 +23,9 @@ namespace constants::nonlocalizable // File name of the UI executable constexpr WCHAR FileNameUIExe[] = L"FileLocksmithGUI\\FileLocksmithGUI.exe"; + + // String key used by PowerToys + constexpr WCHAR PowerToyKey[] = L"FileLocksmith"; } // Macros, non-localizable diff --git a/src/modules/FileLocksmith/FileLocksmithExt/FileLocksmithExt.vcxproj b/src/modules/FileLocksmith/FileLocksmithExt/FileLocksmithExt.vcxproj index ea636bfe1d..a96213d9f4 100644 --- a/src/modules/FileLocksmith/FileLocksmithExt/FileLocksmithExt.vcxproj +++ b/src/modules/FileLocksmith/FileLocksmithExt/FileLocksmithExt.vcxproj @@ -1,5 +1,6 @@ + Debug @@ -156,17 +157,34 @@ Create Create + + + + {d9b8fc84-322a-4f9f-bbb9-20915c47ddfd} + + + {6955446d-23f7-4023-9bb3-8657f904af99} + {8290cf58-0e97-45c4-ab41-f3c7c3128aec} + + + + + 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/FileLocksmithExt/FileLocksmithExt.vcxproj.filters b/src/modules/FileLocksmith/FileLocksmithExt/FileLocksmithExt.vcxproj.filters index df303c7691..137228b40e 100644 --- a/src/modules/FileLocksmith/FileLocksmithExt/FileLocksmithExt.vcxproj.filters +++ b/src/modules/FileLocksmith/FileLocksmithExt/FileLocksmithExt.vcxproj.filters @@ -50,10 +50,14 @@ Source Files + + Source Files + Source Files + \ No newline at end of file diff --git a/src/modules/FileLocksmith/FileLocksmithExt/PowerToysModule.cpp b/src/modules/FileLocksmith/FileLocksmithExt/PowerToysModule.cpp new file mode 100644 index 0000000000..2f30c016a5 --- /dev/null +++ b/src/modules/FileLocksmith/FileLocksmithExt/PowerToysModule.cpp @@ -0,0 +1,88 @@ +#include "pch.h" + +#include "../../interface/powertoy_module_interface.h" +#include "../../../common/SettingsAPI/settings_objects.h" +#include "../../../common/logger/logger.h" + +#include "Constants.h" + +class FileLocksmithModule : public PowertoyModuleIface +{ +public: + virtual const wchar_t* get_name() override + { + return constants::localizable::PowerToyName; + } + + virtual const wchar_t* get_key() override + { + return constants::nonlocalizable::PowerToyKey; + } + + // Return JSON with the configuration options. + // These are the settings shown on the settings page along with their current values. + virtual bool get_config(_Out_ PWSTR buffer, _Out_ int* buffer_size) override + { + HINSTANCE hinstance = reinterpret_cast(&__ImageBase); + + // Create a Settings object. + PowerToysSettings::Settings settings(hinstance, get_name()); + settings.set_description(L"TODO: GET_RESOURCE_STRING(IDS_SETTINGS_DESCRIPTION"); + settings.set_icon_key(L"TODO: pt-file-locksmith"); + + // Link to the GitHub PowerRename sub-page + settings.set_overview_link(L"TODO: GET_RESOURCE_STRING(IDS_OVERVIEW_LINK)"); + + return settings.serialize_to_buffer(buffer, buffer_size); + } + + // Passes JSON with the configuration settings for the powertoy. + // This is called when the user hits Save on the settings page. + virtual void set_config(PCWSTR config) override + { + try + { + // Parse the input JSON string. + PowerToysSettings::PowerToyValues values = + PowerToysSettings::PowerToyValues::from_json_string(config, get_key()); + + // TODO: Trace + // Trace::SettingsChanged(); + } + catch (std::exception& e) + { + Logger::error("Configuration parsing failed: {}", std::string{ e.what() }); + } + } + + virtual void enable() override + { + Logger::info(L"File Locksmith enabled"); + m_enabled = true; + // TODO + // save_settings(); + } + + virtual void disable() override + { + Logger::info(L"File Locksmith disabled"); + m_enabled = false; + // TODO + // save_settings(); + } + + virtual bool is_enabled() override + { + return m_enabled; + } + + virtual void destroy() override + { + delete this; + } + + // This should be enough to create an instance + +private: + bool m_enabled; +}; diff --git a/src/modules/FileLocksmith/FileLocksmithExt/packages.config b/src/modules/FileLocksmith/FileLocksmithExt/packages.config new file mode 100644 index 0000000000..fa024c0634 --- /dev/null +++ b/src/modules/FileLocksmith/FileLocksmithExt/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/src/modules/FileLocksmith/FileLocksmithExt/pch.h b/src/modules/FileLocksmith/FileLocksmithExt/pch.h index 77a6a16d7b..cc26c583d4 100644 --- a/src/modules/FileLocksmith/FileLocksmithExt/pch.h +++ b/src/modules/FileLocksmith/FileLocksmithExt/pch.h @@ -6,6 +6,7 @@ #include #include #include +#include // C++ Standard library #include diff --git a/src/modules/interface/powertoy_module_interface.h b/src/modules/interface/powertoy_module_interface.h index 4bc44e4967..c40a28ef26 100644 --- a/src/modules/interface/powertoy_module_interface.h +++ b/src/modules/interface/powertoy_module_interface.h @@ -1,6 +1,7 @@ #pragma once #include +#include /* DLL Interface for PowerToys. The powertoy_create() (see below) must return