From f711c473000a2d32764c452ecbcbb4b0405e8d56 Mon Sep 17 00:00:00 2001 From: Arjun Balgovind Date: Wed, 8 Jan 2020 11:07:02 -0800 Subject: [PATCH 1/8] Updated vcxproj file with common project references and cpp version flags --- .../ShellExtensions/ShellExtensions.vcxproj | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/modules/imageresizer/ShellExtensions/ShellExtensions.vcxproj b/src/modules/imageresizer/ShellExtensions/ShellExtensions.vcxproj index 548f691606c..4351654acd9 100644 --- a/src/modules/imageresizer/ShellExtensions/ShellExtensions.vcxproj +++ b/src/modules/imageresizer/ShellExtensions/ShellExtensions.vcxproj @@ -71,18 +71,22 @@ true true + $(SolutionDir)$(Platform)\$(Configuration)\modules\ true true + $(SolutionDir)$(Platform)\$(Configuration)\modules\ true false + $(SolutionDir)$(Platform)\$(Configuration)\modules\ true false + $(SolutionDir)$(Platform)\$(Configuration)\modules\ @@ -92,6 +96,8 @@ WIN32;_WINDOWS;_DEBUG;_USRDLL;%(PreprocessorDefinitions) true MultiThreadedDebug + ..\..\..\common\inc;..\..\..\common\Telemetry;..\..\;..\..\..\;%(AdditionalIncludeDirectories) + stdcpplatest false @@ -126,6 +132,8 @@ _WINDOWS;_DEBUG;_USRDLL;%(PreprocessorDefinitions) true MultiThreadedDebug + ..\..\..\common\inc;..\..\..\common\Telemetry;..\..\;..\..\..\;..\..\..\..\deps\cpprestsdk\include;%(AdditionalIncludeDirectories) + stdcpplatest false @@ -159,6 +167,8 @@ WIN32;_WINDOWS;NDEBUG;_USRDLL;%(PreprocessorDefinitions) true MultiThreaded + ..\..\..\common\inc;..\..\..\common\Telemetry;..\..\;..\..\..\;%(AdditionalIncludeDirectories) + stdcpplatest false @@ -195,6 +205,8 @@ _WINDOWS;NDEBUG;_USRDLL;%(PreprocessorDefinitions) true MultiThreaded + ..\..\..\common\inc;..\..\..\common\Telemetry;..\..\;..\..\..\;..\..\..\..\deps\cpprestsdk\include;%(AdditionalIncludeDirectories) + stdcpplatest false @@ -281,6 +293,11 @@ + + + {74485049-c722-400f-abe5-86ac52d929b3} + + From 7bc1df18e5ff55074c1f60b4ce1f1771d9b03027 Mon Sep 17 00:00:00 2001 From: Arjun Balgovind Date: Wed, 8 Jan 2020 13:35:13 -0800 Subject: [PATCH 2/8] Added module template code to dllmain and updated headers for successful build --- .../imageresizer/ShellExtensions/dllmain.cpp | 162 ++++++++++++++++++ .../imageresizer/ShellExtensions/stdafx.cpp | 1 + .../imageresizer/ShellExtensions/targetver.h | 3 - 3 files changed, 163 insertions(+), 3 deletions(-) diff --git a/src/modules/imageresizer/ShellExtensions/dllmain.cpp b/src/modules/imageresizer/ShellExtensions/dllmain.cpp index 9c9903e8d25..aaec33cdf85 100644 --- a/src/modules/imageresizer/ShellExtensions/dllmain.cpp +++ b/src/modules/imageresizer/ShellExtensions/dllmain.cpp @@ -2,6 +2,9 @@ #include "resource.h" #include "ShellExtensions_i.h" #include "dllmain.h" +#include +#include +#include CShellExtensionsModule _AtlModule; @@ -9,3 +12,162 @@ extern "C" BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpRes { return _AtlModule.DllMain(dwReason, lpReserved); } + +// The PowerToy name that will be shown in the settings. +const static wchar_t* MODULE_NAME = L"ImageResizer"; +// Add a description that will we shown in the module settings page. +const static wchar_t* MODULE_DESC = L""; + +// These are the properties shown in the Settings page. +struct ModuleSettings +{ + // Add the PowerToy module properties with default values. + // Currently available types: + // - int + // - bool + // - string + + //bool bool_prop = true; + //int int_prop = 10; + //std::wstring string_prop = L"The quick brown fox jumps over the lazy dog"; + //std::wstring color_prop = L"#1212FF"; + +} g_settings; + +class ImageResizerModule : public PowertoyModuleIface +{ +private: + // The PowerToy state. + bool m_enabled = false; + + // Load initial settings from the persisted values. + void init_settings(); + +public: + // Constructor + ImageResizerModule() + { + init_settings(); + }; + + // Destroy the powertoy and free memory + virtual void destroy() override + { + delete this; + } + + // Return the display name of the powertoy, this will be cached by the runner + virtual const wchar_t* get_name() override + { + return MODULE_NAME; + } + + // Return array of the names of all events that this powertoy listens for, with + // nullptr as the last element of the array. Nullptr can also be retured for empty + // list. + virtual const wchar_t** get_events() override + { + static const wchar_t* events[] = { nullptr }; + // Available events: + // - ll_keyboard + // - win_hook_event + // + // static const wchar_t* events[] = { ll_keyboard, + // win_hook_event, + // nullptr }; + + return events; + } + + // Return JSON with the configuration options. + virtual bool get_config(wchar_t* buffer, int* buffer_size) override + { + HINSTANCE hinstance = reinterpret_cast(&__ImageBase); + + // Create a Settings object. + PowerToysSettings::Settings settings(hinstance, get_name()); + settings.set_description(MODULE_DESC); + return settings.serialize_to_buffer(buffer, buffer_size); + } + + // Signal from the Settings editor to call a custom action. + // This can be used to spawn more complex editors. + virtual void call_custom_action(const wchar_t* action) override + { + static UINT custom_action_num_calls = 0; + try + { + // Parse the action values, including name. + PowerToysSettings::CustomActionObject action_object = + PowerToysSettings::CustomActionObject::from_json_string(action); + + /* + if (action_object.get_name() == L"custom_action_id") { + // Execute your custom action + } + */ + } + catch (std::exception ex) + { + // Improper JSON. + } + } + + // Called by the runner to pass the updated settings values as a serialized JSON. + virtual void set_config(const wchar_t* config) override + { + try + { + // Parse the input JSON string. + PowerToysSettings::PowerToyValues values = PowerToysSettings::PowerToyValues::from_json_string(config); + // If you don't need to do any custom processing of the settings, proceed + // to persists the values calling: + values.save_to_settings_file(); + } + catch (std::exception ex) + { + // Improper JSON. + } + } + + // Enable the powertoy + virtual void enable() + { + m_enabled = true; + } + + // Disable the powertoy + virtual void disable() + { + m_enabled = false; + } + + // Returns if the powertoys is enabled + virtual bool is_enabled() override + { + return m_enabled; + } + + // Handle incoming event, data is event-specific + virtual intptr_t signal_event(const wchar_t* name, intptr_t data) override + { + return 0; + } + + virtual void register_system_menu_helper(PowertoySystemMenuIface* helper) override {} + virtual void signal_system_menu_action(const wchar_t* name) override {} +}; + +// Load the settings file. +void ImageResizerModule::init_settings() +{ + try + { + // Load and parse the settings file for this PowerToy. + PowerToysSettings::PowerToyValues settings = PowerToysSettings::PowerToyValues::load_from_settings_file(get_name()); + } + catch (std::exception ex) + { + // Error while loading from the settings file. Let default values stay as they are. + } +} \ No newline at end of file diff --git a/src/modules/imageresizer/ShellExtensions/stdafx.cpp b/src/modules/imageresizer/ShellExtensions/stdafx.cpp index fd4f341c7b2..a8b5e27d405 100644 --- a/src/modules/imageresizer/ShellExtensions/stdafx.cpp +++ b/src/modules/imageresizer/ShellExtensions/stdafx.cpp @@ -1 +1,2 @@ #include "stdafx.h" +#pragma comment(lib, "windowsapp") \ No newline at end of file diff --git a/src/modules/imageresizer/ShellExtensions/targetver.h b/src/modules/imageresizer/ShellExtensions/targetver.h index 895f499ce39..1530e99ea64 100644 --- a/src/modules/imageresizer/ShellExtensions/targetver.h +++ b/src/modules/imageresizer/ShellExtensions/targetver.h @@ -1,7 +1,4 @@ #pragma once -#define _WIN32_WINNT _WIN32_WINNT_WINXP -#define _WIN32_IE _WIN32_IE_XPSP2 - #include #include From dd9435286a9d947109e48ea45edbe8072ca5b250 Mon Sep 17 00:00:00 2001 From: Arjun Balgovind Date: Wed, 8 Jan 2020 13:38:21 -0800 Subject: [PATCH 3/8] Removed unnecessary include --- src/modules/imageresizer/ShellExtensions/dllmain.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/modules/imageresizer/ShellExtensions/dllmain.cpp b/src/modules/imageresizer/ShellExtensions/dllmain.cpp index aaec33cdf85..af86061c181 100644 --- a/src/modules/imageresizer/ShellExtensions/dllmain.cpp +++ b/src/modules/imageresizer/ShellExtensions/dllmain.cpp @@ -2,7 +2,6 @@ #include "resource.h" #include "ShellExtensions_i.h" #include "dllmain.h" -#include #include #include From 1846be55d2154a4aedecbeb139deec4858c45543 Mon Sep 17 00:00:00 2001 From: Arjun Balgovind Date: Wed, 8 Jan 2020 14:30:53 -0800 Subject: [PATCH 4/8] Added dll to runner and add fixes to show up in PT Settings --- src/modules/imageresizer/ShellExtensions/dllmain.cpp | 5 +++++ src/runner/main.cpp | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/modules/imageresizer/ShellExtensions/dllmain.cpp b/src/modules/imageresizer/ShellExtensions/dllmain.cpp index af86061c181..ac407ec09c6 100644 --- a/src/modules/imageresizer/ShellExtensions/dllmain.cpp +++ b/src/modules/imageresizer/ShellExtensions/dllmain.cpp @@ -169,4 +169,9 @@ void ImageResizerModule::init_settings() { // Error while loading from the settings file. Let default values stay as they are. } +} + +extern "C" __declspec(dllexport) PowertoyModuleIface* __cdecl powertoy_create() +{ + return new ImageResizerModule(); } \ No newline at end of file diff --git a/src/runner/main.cpp b/src/runner/main.cpp index d39bcad1281..b800b5cb26c 100644 --- a/src/runner/main.cpp +++ b/src/runner/main.cpp @@ -52,7 +52,8 @@ int runner() std::unordered_set known_dlls = { L"shortcut_guide.dll", L"fancyzones.dll", - L"PowerRenameExt.dll" + L"PowerRenameExt.dll", + L"ShellExtensions.dll" }; for (auto& file : std::filesystem::directory_iterator(L"modules/")) { From 3665f1b78186b05a37038af3bdcf40816ff16568 Mon Sep 17 00:00:00 2001 From: Arjun Balgovind Date: Fri, 10 Jan 2020 09:38:21 -0800 Subject: [PATCH 5/8] Added settings file --- .../imageresizer/ShellExtensions/Settings.cpp | 3 + .../imageresizer/ShellExtensions/Settings.h | 9 + .../ShellExtensions/ShellExtensions.vcxproj | 608 +++++++++--------- .../ShellExtensions.vcxproj.filters | 174 ++--- .../imageresizer/ShellExtensions/dllmain.cpp | 16 - 5 files changed, 407 insertions(+), 403 deletions(-) create mode 100644 src/modules/imageresizer/ShellExtensions/Settings.cpp create mode 100644 src/modules/imageresizer/ShellExtensions/Settings.h diff --git a/src/modules/imageresizer/ShellExtensions/Settings.cpp b/src/modules/imageresizer/ShellExtensions/Settings.cpp new file mode 100644 index 00000000000..e7cb4b84251 --- /dev/null +++ b/src/modules/imageresizer/ShellExtensions/Settings.cpp @@ -0,0 +1,3 @@ +#include "stdafx.h" +#include "Settings.h" + diff --git a/src/modules/imageresizer/ShellExtensions/Settings.h b/src/modules/imageresizer/ShellExtensions/Settings.h new file mode 100644 index 00000000000..4e158064a38 --- /dev/null +++ b/src/modules/imageresizer/ShellExtensions/Settings.h @@ -0,0 +1,9 @@ +#pragma once + +class Settings +{ +public: + bool GetEnabled(); +private: + bool enabled; +}; \ No newline at end of file diff --git a/src/modules/imageresizer/ShellExtensions/ShellExtensions.vcxproj b/src/modules/imageresizer/ShellExtensions/ShellExtensions.vcxproj index 4351654acd9..1c554447ef3 100644 --- a/src/modules/imageresizer/ShellExtensions/ShellExtensions.vcxproj +++ b/src/modules/imageresizer/ShellExtensions/ShellExtensions.vcxproj @@ -1,304 +1,306 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - {0B43679E-EDFA-4DA0-AD30-F4628B308B1B} - 10.0 - AtlProj - - - - DynamicLibrary - true - Static - v142 - Unicode - - - DynamicLibrary - false - Static - v142 - Unicode - - - DynamicLibrary - true - Static - v142 - Unicode - - - DynamicLibrary - false - Static - v142 - Unicode - - - - - - - - - - - - - - - - - - - true - true - $(SolutionDir)$(Platform)\$(Configuration)\modules\ - - - true - true - $(SolutionDir)$(Platform)\$(Configuration)\modules\ - - - true - false - $(SolutionDir)$(Platform)\$(Configuration)\modules\ - - - true - false - $(SolutionDir)$(Platform)\$(Configuration)\modules\ - - - - Use - Level3 - Disabled - WIN32;_WINDOWS;_DEBUG;_USRDLL;%(PreprocessorDefinitions) - true - MultiThreadedDebug - ..\..\..\common\inc;..\..\..\common\Telemetry;..\..\;..\..\..\;%(AdditionalIncludeDirectories) - stdcpplatest - - - false - Win32 - _DEBUG;%(PreprocessorDefinitions) - ShellExtensions_i.h - ShellExtensions_i.c - ShellExtensions_p.c - true - $(IntDir)ShellExtensions.tlb - - true - - - 0x0409 - $(IntDir);%(AdditionalIncludeDirectories) - _DEBUG;%(PreprocessorDefinitions) - - - Windows - .\ShellExtensions.def - true - true - true - - - - - Use - Level3 - Disabled - _WINDOWS;_DEBUG;_USRDLL;%(PreprocessorDefinitions) - true - MultiThreadedDebug - ..\..\..\common\inc;..\..\..\common\Telemetry;..\..\;..\..\..\;..\..\..\..\deps\cpprestsdk\include;%(AdditionalIncludeDirectories) - stdcpplatest - - - false - _DEBUG;%(PreprocessorDefinitions) - ShellExtensions_i.h - ShellExtensions_i.c - ShellExtensions_p.c - true - $(IntDir)ShellExtensions.tlb - - true - - - 0x0409 - $(IntDir);%(AdditionalIncludeDirectories) - _DEBUG;%(PreprocessorDefinitions) - - - Windows - .\ShellExtensions.def - true - true - true - - - - - Use - Level3 - MaxSpeed - WIN32;_WINDOWS;NDEBUG;_USRDLL;%(PreprocessorDefinitions) - true - MultiThreaded - ..\..\..\common\inc;..\..\..\common\Telemetry;..\..\;..\..\..\;%(AdditionalIncludeDirectories) - stdcpplatest - - - false - Win32 - NDEBUG;%(PreprocessorDefinitions) - ShellExtensions_i.h - ShellExtensions_i.c - ShellExtensions_p.c - true - $(IntDir)ShellExtensions.tlb - - true - - - 0x0409 - $(IntDir);%(AdditionalIncludeDirectories) - NDEBUG;%(PreprocessorDefinitions) - - - Windows - .\ShellExtensions.def - true - true - true - true - true - - - - - Use - Level3 - MaxSpeed - _WINDOWS;NDEBUG;_USRDLL;%(PreprocessorDefinitions) - true - MultiThreaded - ..\..\..\common\inc;..\..\..\common\Telemetry;..\..\;..\..\..\;..\..\..\..\deps\cpprestsdk\include;%(AdditionalIncludeDirectories) - stdcpplatest - - - false - NDEBUG;%(PreprocessorDefinitions) - ShellExtensions_i.h - ShellExtensions_i.c - ShellExtensions_p.c - true - $(IntDir)ShellExtensions.tlb - - true - - - 0x0409 - $(IntDir);%(AdditionalIncludeDirectories) - NDEBUG;%(PreprocessorDefinitions) - - - Windows - .\ShellExtensions.def - true - true - true - true - true - - - - - - - false - - - false - - - false - - - false - - - - - - false - - - false - - - false - - - false - - - - - Create - Create - Create - Create - - - - - - - - - - - - - - - - - - - - - - - - - {74485049-c722-400f-abe5-86ac52d929b3} - - - - - + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + {0B43679E-EDFA-4DA0-AD30-F4628B308B1B} + 10.0 + AtlProj + + + + DynamicLibrary + true + Static + v142 + Unicode + + + DynamicLibrary + false + Static + v142 + Unicode + + + DynamicLibrary + true + Static + v142 + Unicode + + + DynamicLibrary + false + Static + v142 + Unicode + + + + + + + + + + + + + + + + + + + true + true + $(SolutionDir)$(Platform)\$(Configuration)\modules\ + + + true + true + $(SolutionDir)$(Platform)\$(Configuration)\modules\ + + + true + false + $(SolutionDir)$(Platform)\$(Configuration)\modules\ + + + true + false + $(SolutionDir)$(Platform)\$(Configuration)\modules\ + + + + Use + Level3 + Disabled + WIN32;_WINDOWS;_DEBUG;_USRDLL;%(PreprocessorDefinitions) + true + MultiThreadedDebug + ..\..\..\common\inc;..\..\..\common\Telemetry;..\..\;..\..\..\;%(AdditionalIncludeDirectories) + stdcpplatest + + + false + Win32 + _DEBUG;%(PreprocessorDefinitions) + ShellExtensions_i.h + ShellExtensions_i.c + ShellExtensions_p.c + true + $(IntDir)ShellExtensions.tlb + + true + + + 0x0409 + $(IntDir);%(AdditionalIncludeDirectories) + _DEBUG;%(PreprocessorDefinitions) + + + Windows + .\ShellExtensions.def + true + true + true + + + + + Use + Level3 + Disabled + _WINDOWS;_DEBUG;_USRDLL;%(PreprocessorDefinitions) + true + MultiThreadedDebug + ..\..\..\common\inc;..\..\..\common\Telemetry;..\..\;..\..\..\;..\..\..\..\deps\cpprestsdk\include;%(AdditionalIncludeDirectories) + stdcpplatest + + + false + _DEBUG;%(PreprocessorDefinitions) + ShellExtensions_i.h + ShellExtensions_i.c + ShellExtensions_p.c + true + $(IntDir)ShellExtensions.tlb + + true + + + 0x0409 + $(IntDir);%(AdditionalIncludeDirectories) + _DEBUG;%(PreprocessorDefinitions) + + + Windows + .\ShellExtensions.def + true + true + true + + + + + Use + Level3 + MaxSpeed + WIN32;_WINDOWS;NDEBUG;_USRDLL;%(PreprocessorDefinitions) + true + MultiThreaded + ..\..\..\common\inc;..\..\..\common\Telemetry;..\..\;..\..\..\;%(AdditionalIncludeDirectories) + stdcpplatest + + + false + Win32 + NDEBUG;%(PreprocessorDefinitions) + ShellExtensions_i.h + ShellExtensions_i.c + ShellExtensions_p.c + true + $(IntDir)ShellExtensions.tlb + + true + + + 0x0409 + $(IntDir);%(AdditionalIncludeDirectories) + NDEBUG;%(PreprocessorDefinitions) + + + Windows + .\ShellExtensions.def + true + true + true + true + true + + + + + Use + Level3 + MaxSpeed + _WINDOWS;NDEBUG;_USRDLL;%(PreprocessorDefinitions) + true + MultiThreaded + ..\..\..\common\inc;..\..\..\common\Telemetry;..\..\;..\..\..\;..\..\..\..\deps\cpprestsdk\include;%(AdditionalIncludeDirectories) + stdcpplatest + + + false + NDEBUG;%(PreprocessorDefinitions) + ShellExtensions_i.h + ShellExtensions_i.c + ShellExtensions_p.c + true + $(IntDir)ShellExtensions.tlb + + true + + + 0x0409 + $(IntDir);%(AdditionalIncludeDirectories) + NDEBUG;%(PreprocessorDefinitions) + + + Windows + .\ShellExtensions.def + true + true + true + true + true + + + + + + + false + + + false + + + false + + + false + + + + + + false + + + false + + + false + + + false + + + + + + Create + Create + Create + Create + + + + + + + + + + + + + + + + + + + + + + + + + + {74485049-c722-400f-abe5-86ac52d929b3} + + + + + \ No newline at end of file diff --git a/src/modules/imageresizer/ShellExtensions/ShellExtensions.vcxproj.filters b/src/modules/imageresizer/ShellExtensions/ShellExtensions.vcxproj.filters index f6ced56a9d6..dbf5c78b470 100644 --- a/src/modules/imageresizer/ShellExtensions/ShellExtensions.vcxproj.filters +++ b/src/modules/imageresizer/ShellExtensions/ShellExtensions.vcxproj.filters @@ -1,85 +1,91 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;hm;inl;inc;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 - - - {87bc9b81-f7fa-45d9-87cc-c99e55473868} - False - - - - - Source Files - - - Source Files - - - Source Files - - - Generated Files - - - Source Files - - - Source Files - - - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Generated Files - - - Header Files - - - Header Files - - - - - Resource Files - - - - - Resource Files - - - Source Files - - - Resource Files - - - - - Source Files - - + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;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 + + + {87bc9b81-f7fa-45d9-87cc-c99e55473868} + False + + + + + Source Files + + + Source Files + + + Source Files + + + Generated Files + + + Source Files + + + Source Files + + + Source Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Generated Files + + + Header Files + + + Header Files + + + Header Files + + + + + Resource Files + + + + + Resource Files + + + Source Files + + + Resource Files + + + + + Source Files + + \ No newline at end of file diff --git a/src/modules/imageresizer/ShellExtensions/dllmain.cpp b/src/modules/imageresizer/ShellExtensions/dllmain.cpp index ac407ec09c6..e8256ec94ab 100644 --- a/src/modules/imageresizer/ShellExtensions/dllmain.cpp +++ b/src/modules/imageresizer/ShellExtensions/dllmain.cpp @@ -17,22 +17,6 @@ const static wchar_t* MODULE_NAME = L"ImageResizer"; // Add a description that will we shown in the module settings page. const static wchar_t* MODULE_DESC = L""; -// These are the properties shown in the Settings page. -struct ModuleSettings -{ - // Add the PowerToy module properties with default values. - // Currently available types: - // - int - // - bool - // - string - - //bool bool_prop = true; - //int int_prop = 10; - //std::wstring string_prop = L"The quick brown fox jumps over the lazy dog"; - //std::wstring color_prop = L"#1212FF"; - -} g_settings; - class ImageResizerModule : public PowertoyModuleIface { private: From ed2abe46a1e7c83f9be944aa3fabc67e1971a30f Mon Sep 17 00:00:00 2001 From: Arjun Balgovind Date: Fri, 10 Jan 2020 14:28:39 -0800 Subject: [PATCH 6/8] Added support for enabling/disabling based on PowerRename codebase --- .../ShellExtensions/ContextMenuHandler.cpp | 4 +- .../imageresizer/ShellExtensions/Settings.cpp | 63 +++++++++++++++++++ .../imageresizer/ShellExtensions/Settings.h | 13 +++- .../imageresizer/ShellExtensions/dllmain.cpp | 3 + 4 files changed, 79 insertions(+), 4 deletions(-) diff --git a/src/modules/imageresizer/ShellExtensions/ContextMenuHandler.cpp b/src/modules/imageresizer/ShellExtensions/ContextMenuHandler.cpp index 55d1ac3a68b..53fb06d5d64 100644 --- a/src/modules/imageresizer/ShellExtensions/ContextMenuHandler.cpp +++ b/src/modules/imageresizer/ShellExtensions/ContextMenuHandler.cpp @@ -3,6 +3,7 @@ #include "stdafx.h" #include "ContextMenuHandler.h" #include "HDropIterator.h" +#include "Settings.h" CContextMenuHandler::CContextMenuHandler() { @@ -51,7 +52,8 @@ HRESULT CContextMenuHandler::QueryContextMenu(_In_ HMENU hmenu, UINT indexMenu, { return S_OK; } - + if (!CSettings::GetEnabled()) + return E_FAIL; // NB: We just check the first item. We could iterate through more if the first one doesn't meet the criteria HDropIterator i(m_pdtobj); i.First(); diff --git a/src/modules/imageresizer/ShellExtensions/Settings.cpp b/src/modules/imageresizer/ShellExtensions/Settings.cpp index e7cb4b84251..f8b446c43d2 100644 --- a/src/modules/imageresizer/ShellExtensions/Settings.cpp +++ b/src/modules/imageresizer/ShellExtensions/Settings.cpp @@ -1,3 +1,66 @@ #include "stdafx.h" +#include #include "Settings.h" +const wchar_t c_rootRegPath[] = L"Software\\Microsoft\\ImageResizer"; +const wchar_t c_enabled[] = L"Enabled"; +const bool c_enabledDefault = true; + +bool CSettings::GetEnabled() +{ + return GetRegBoolValue(c_enabled, c_enabledDefault); +} + +bool CSettings::SetEnabled(_In_ bool enabled) +{ + return SetRegBoolValue(c_enabled, enabled); +} + +bool CSettings::SetRegBoolValue(_In_ PCWSTR valueName, _In_ bool value) +{ + DWORD dwValue = value ? 1 : 0; + return SetRegDWORDValue(valueName, dwValue); +} + +bool CSettings::GetRegBoolValue(_In_ PCWSTR valueName, _In_ bool defaultValue) +{ + DWORD value = GetRegDWORDValue(valueName, (defaultValue == 0) ? false : true); + return (value == 0) ? false : true; +} + +bool CSettings::SetRegDWORDValue(_In_ PCWSTR valueName, _In_ DWORD value) +{ + return (SUCCEEDED(HRESULT_FROM_WIN32(SHSetValue(HKEY_CURRENT_USER, c_rootRegPath, valueName, REG_DWORD, &value, sizeof(value))))); +} + +DWORD CSettings::GetRegDWORDValue(_In_ PCWSTR valueName, _In_ DWORD defaultValue) +{ + DWORD retVal = defaultValue; + DWORD type = REG_DWORD; + DWORD dwEnabled = 0; + DWORD cb = sizeof(dwEnabled); + if (SHGetValue(HKEY_CURRENT_USER, c_rootRegPath, valueName, &type, &dwEnabled, &cb) == ERROR_SUCCESS) + { + retVal = dwEnabled; + } + + return retVal; +} + +bool CSettings::SetRegStringValue(_In_ PCWSTR valueName, _In_ PCWSTR value) +{ + ULONG cb = (DWORD)((wcslen(value) + 1) * sizeof(*value)); + return (SUCCEEDED(HRESULT_FROM_WIN32(SHSetValue(HKEY_CURRENT_USER, c_rootRegPath, valueName, REG_SZ, (const BYTE*)value, cb)))); +} + +bool CSettings::GetRegStringValue(_In_ PCWSTR valueName, __out_ecount(cchBuf) PWSTR value, DWORD cchBuf) +{ + if (cchBuf > 0) + { + value[0] = L'\0'; + } + + DWORD type = REG_SZ; + ULONG cb = cchBuf * sizeof(*value); + return (SUCCEEDED(HRESULT_FROM_WIN32(SHGetValue(HKEY_CURRENT_USER, c_rootRegPath, valueName, &type, value, &cb) == ERROR_SUCCESS))); +} \ No newline at end of file diff --git a/src/modules/imageresizer/ShellExtensions/Settings.h b/src/modules/imageresizer/ShellExtensions/Settings.h index 4e158064a38..aa00f9b30d3 100644 --- a/src/modules/imageresizer/ShellExtensions/Settings.h +++ b/src/modules/imageresizer/ShellExtensions/Settings.h @@ -1,9 +1,16 @@ #pragma once -class Settings +class CSettings { public: - bool GetEnabled(); + static bool GetEnabled(); + static bool SetEnabled(_In_ bool enabled); + private: - bool enabled; + static bool GetRegBoolValue(_In_ PCWSTR valueName, _In_ bool defaultValue); + static bool SetRegBoolValue(_In_ PCWSTR valueName, _In_ bool value); + static bool SetRegDWORDValue(_In_ PCWSTR valueName, _In_ DWORD value); + static DWORD GetRegDWORDValue(_In_ PCWSTR valueName, _In_ DWORD defaultValue); + static bool SetRegStringValue(_In_ PCWSTR valueName, _In_ PCWSTR value); + static bool GetRegStringValue(_In_ PCWSTR valueName, __out_ecount(cchBuf) PWSTR value, DWORD cchBuf); }; \ No newline at end of file diff --git a/src/modules/imageresizer/ShellExtensions/dllmain.cpp b/src/modules/imageresizer/ShellExtensions/dllmain.cpp index e8256ec94ab..b070afbebdb 100644 --- a/src/modules/imageresizer/ShellExtensions/dllmain.cpp +++ b/src/modules/imageresizer/ShellExtensions/dllmain.cpp @@ -4,6 +4,7 @@ #include "dllmain.h" #include #include +#include "Settings.h" CShellExtensionsModule _AtlModule; @@ -117,12 +118,14 @@ class ImageResizerModule : public PowertoyModuleIface virtual void enable() { m_enabled = true; + CSettings::SetEnabled(m_enabled); } // Disable the powertoy virtual void disable() { m_enabled = false; + CSettings::SetEnabled(m_enabled); } // Returns if the powertoys is enabled From 53ea78dc684f7ccb1f3c17231ab7a6653e4a7bb7 Mon Sep 17 00:00:00 2001 From: Arjun Balgovind Date: Tue, 14 Jan 2020 11:01:45 -0800 Subject: [PATCH 7/8] Fixed missing braces --- src/modules/imageresizer/ShellExtensions/ContextMenuHandler.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/modules/imageresizer/ShellExtensions/ContextMenuHandler.cpp b/src/modules/imageresizer/ShellExtensions/ContextMenuHandler.cpp index 53fb06d5d64..8a849016f24 100644 --- a/src/modules/imageresizer/ShellExtensions/ContextMenuHandler.cpp +++ b/src/modules/imageresizer/ShellExtensions/ContextMenuHandler.cpp @@ -53,7 +53,9 @@ HRESULT CContextMenuHandler::QueryContextMenu(_In_ HMENU hmenu, UINT indexMenu, return S_OK; } if (!CSettings::GetEnabled()) + { return E_FAIL; + } // NB: We just check the first item. We could iterate through more if the first one doesn't meet the criteria HDropIterator i(m_pdtobj); i.First(); From 35a0cad378a163ea15e768af549bb38bdc83029e Mon Sep 17 00:00:00 2001 From: Arjun Balgovind Date: Tue, 14 Jan 2020 11:38:54 -0800 Subject: [PATCH 8/8] Fixed call_custom_action --- .../imageresizer/ShellExtensions/dllmain.cpp | 21 +------------------ 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/src/modules/imageresizer/ShellExtensions/dllmain.cpp b/src/modules/imageresizer/ShellExtensions/dllmain.cpp index b070afbebdb..654ce197c4c 100644 --- a/src/modules/imageresizer/ShellExtensions/dllmain.cpp +++ b/src/modules/imageresizer/ShellExtensions/dllmain.cpp @@ -76,26 +76,7 @@ class ImageResizerModule : public PowertoyModuleIface // Signal from the Settings editor to call a custom action. // This can be used to spawn more complex editors. - virtual void call_custom_action(const wchar_t* action) override - { - static UINT custom_action_num_calls = 0; - try - { - // Parse the action values, including name. - PowerToysSettings::CustomActionObject action_object = - PowerToysSettings::CustomActionObject::from_json_string(action); - - /* - if (action_object.get_name() == L"custom_action_id") { - // Execute your custom action - } - */ - } - catch (std::exception ex) - { - // Improper JSON. - } - } + virtual void call_custom_action(const wchar_t* action) override {} // Called by the runner to pass the updated settings values as a serialized JSON. virtual void set_config(const wchar_t* config) override