Use JSON data file for storing PowerRename settings instead of registry (#1909)

* Use JSON data file for storing PowerRename settings instead of registry

* Address PR comments and made several improvements

* Remove WindowsApp.lib dependencies in test app and unit tests

* Revert changes in vcxproj for unit test

* Solve linker warnings generated while linking WindowsApp.lib

* Don't migrate enabled flag. Always read / write from registry.
This commit is contained in:
vldmr11080
2020-04-08 19:12:46 +02:00
committed by GitHub
parent 17022d50d4
commit c355a2b61e
8 changed files with 314 additions and 224 deletions

View File

@@ -48,7 +48,7 @@ HRESULT CPowerRenameMenu::s_CreateInstance(_In_opt_ IUnknown*, _In_ REFIID riid,
HRESULT CPowerRenameMenu::Initialize(_In_opt_ PCIDLIST_ABSOLUTE, _In_ IDataObject* pdtobj, HKEY)
{
// Check if we have disabled ourselves
if (!CSettings::GetEnabled())
if (!CSettingsInstance().GetEnabled())
return E_FAIL;
// Cache the data object to be used later
@@ -60,11 +60,11 @@ HRESULT CPowerRenameMenu::Initialize(_In_opt_ PCIDLIST_ABSOLUTE, _In_ IDataObjec
HRESULT CPowerRenameMenu::QueryContextMenu(HMENU hMenu, UINT index, UINT uIDFirst, UINT, UINT uFlags)
{
// Check if we have disabled ourselves
if (!CSettings::GetEnabled())
if (!CSettingsInstance().GetEnabled())
return E_FAIL;
// Check if we should only be on the extended context menu
if (CSettings::GetExtendedContextMenuOnly() && (!(uFlags & CMF_EXTENDEDVERBS)))
if (CSettingsInstance().GetExtendedContextMenuOnly() && (!(uFlags & CMF_EXTENDEDVERBS)))
return E_FAIL;
HRESULT hr = E_UNEXPECTED;
@@ -81,7 +81,7 @@ HRESULT CPowerRenameMenu::QueryContextMenu(HMENU hMenu, UINT index, UINT uIDFirs
mii.dwTypeData = (PWSTR)menuName;
mii.fState = MFS_ENABLED;
if (CSettings::GetShowIconOnMenu())
if (CSettingsInstance().GetShowIconOnMenu())
{
HICON hIcon = (HICON)LoadImage(g_hInst, MAKEINTRESOURCE(IDI_RENAME), IMAGE_ICON, 16, 16, 0);
if (hIcon)
@@ -113,7 +113,7 @@ HRESULT CPowerRenameMenu::InvokeCommand(_In_ LPCMINVOKECOMMANDINFO pici)
{
HRESULT hr = E_FAIL;
if (CSettings::GetEnabled() &&
if (CSettingsInstance().GetEnabled() &&
(IS_INTRESOURCE(pici->lpVerb)) &&
(LOWORD(pici->lpVerb) == 0))
{
@@ -203,7 +203,7 @@ HRESULT __stdcall CPowerRenameMenu::GetTitle(IShellItemArray* /*psiItemArray*/,
HRESULT __stdcall CPowerRenameMenu::GetIcon(IShellItemArray* /*psiItemArray*/, LPWSTR* ppszIcon)
{
if (!CSettings::GetShowIconOnMenu())
if (!CSettingsInstance().GetShowIconOnMenu())
{
*ppszIcon = nullptr;
return E_NOTIMPL;
@@ -229,7 +229,7 @@ HRESULT __stdcall CPowerRenameMenu::GetCanonicalName(GUID* pguidCommandName)
HRESULT __stdcall CPowerRenameMenu::GetState(IShellItemArray* psiItemArray, BOOL fOkToBeSlow, EXPCMDSTATE* pCmdState)
{
*pCmdState = CSettings::GetEnabled() ? ECS_ENABLED : ECS_HIDDEN;
*pCmdState = CSettingsInstance().GetEnabled() ? ECS_ENABLED : ECS_HIDDEN;
return S_OK;
}

View File

@@ -207,17 +207,17 @@ public:
settings.add_bool_toogle(
L"bool_persist_input",
GET_RESOURCE_STRING(IDS_RESTORE_SEARCH),
CSettings::GetPersistState());
CSettingsInstance().GetPersistState());
settings.add_bool_toogle(
L"bool_mru_enabled",
GET_RESOURCE_STRING(IDS_ENABLE_AUTO),
CSettings::GetMRUEnabled());
CSettingsInstance().GetMRUEnabled());
settings.add_int_spinner(
L"int_max_mru_size",
GET_RESOURCE_STRING(IDS_MAX_ITEMS),
CSettings::GetMaxMRUSize(),
CSettingsInstance().GetMaxMRUSize(),
0,
20,
1);
@@ -225,12 +225,12 @@ public:
settings.add_bool_toogle(
L"bool_show_icon_on_menu",
GET_RESOURCE_STRING(IDS_ICON_CONTEXT_MENU),
CSettings::GetShowIconOnMenu());
CSettingsInstance().GetShowIconOnMenu());
settings.add_bool_toogle(
L"bool_show_extended_menu",
GET_RESOURCE_STRING(IDS_EXTENDED_MENU_INFO),
CSettings::GetExtendedContextMenuOnly());
CSettingsInstance().GetExtendedContextMenuOnly());
return settings.serialize_to_buffer(buffer, buffer_size);
}
@@ -245,11 +245,12 @@ public:
PowerToysSettings::PowerToyValues values =
PowerToysSettings::PowerToyValues::from_json_string(config);
CSettings::SetPersistState(values.get_bool_value(L"bool_persist_input").value());
CSettings::SetMRUEnabled(values.get_bool_value(L"bool_mru_enabled").value());
CSettings::SetMaxMRUSize(values.get_int_value(L"int_max_mru_size").value());
CSettings::SetShowIconOnMenu(values.get_bool_value(L"bool_show_icon_on_menu").value());
CSettings::SetExtendedContextMenuOnly(values.get_bool_value(L"bool_show_extended_menu").value());
CSettingsInstance().SetPersistState(values.get_bool_value(L"bool_persist_input").value());
CSettingsInstance().SetMRUEnabled(values.get_bool_value(L"bool_mru_enabled").value());
CSettingsInstance().SetMaxMRUSize(values.get_int_value(L"int_max_mru_size").value());
CSettingsInstance().SetShowIconOnMenu(values.get_bool_value(L"bool_show_icon_on_menu").value());
CSettingsInstance().SetExtendedContextMenuOnly(values.get_bool_value(L"bool_show_extended_menu").value());
CSettingsInstance().SavePowerRenameData();
Trace::SettingsChanged();
}
@@ -282,13 +283,15 @@ public:
void init_settings()
{
m_enabled = CSettings::GetEnabled();
CSettingsInstance().LoadPowerRenameData();
m_enabled = CSettingsInstance().GetEnabled();
Trace::EnablePowerRename(m_enabled);
}
void save_settings()
{
CSettings::SetEnabled(m_enabled);
CSettingsInstance().SetEnabled(m_enabled);
CSettingsInstance().SavePowerRenameData();
Trace::EnablePowerRename(m_enabled);
}