common: refactor common library pt2 (#8588)

- remove common lib
- split settings, remove common-md
- move ipc interop/kb_layout to interop
- rename core -> settings, settings -> old_settings
- os-detect header-only; interop -> PowerToysInterop
- split notifications, move single-use headers where they're used
- winstore lib
- rename com utils
- rename Updating and Telemetry projects
- rename core -> settings-ui and remove examples folder
- rename settings-ui folder + consisent common/version include
This commit is contained in:
Andrey Nekrasov
2020-12-15 15:16:09 +03:00
committed by GitHub
parent cddf48547d
commit 212ea2de30
588 changed files with 3304 additions and 3328 deletions

View File

@@ -1,6 +1,5 @@
#pragma once
#include <common.h>
#include <lib/PowerRenameInterfaces.h>
HRESULT GetTrimmedFileName(_Out_ PWSTR result, UINT cchMax, _In_ PCWSTR source);

View File

@@ -1,15 +1,17 @@
#include "pch.h"
#include "PowerRenameItem.h"
#include "icon_helpers.h"
#include <common/themes/icon_helpers.h>
int CPowerRenameItem::s_id = 0;
IFACEMETHODIMP_(ULONG) CPowerRenameItem::AddRef()
IFACEMETHODIMP_(ULONG)
CPowerRenameItem::AddRef()
{
return InterlockedIncrement(&m_refCount);
}
IFACEMETHODIMP_(ULONG) CPowerRenameItem::Release()
IFACEMETHODIMP_(ULONG)
CPowerRenameItem::Release()
{
long refCount = InterlockedDecrement(&m_refCount);
@@ -198,9 +200,9 @@ IFACEMETHODIMP CPowerRenameItem::IsItemVisible(_In_ DWORD filter, _In_ DWORD fla
GetSelected(isItemVisible);
break;
case PowerRenameFilters::FlagsApplicable:
*isItemVisible = !((m_isFolder && (flags & PowerRenameFlags::ExcludeFolders)) ||
(!m_isFolder && (flags & PowerRenameFlags::ExcludeFiles)) ||
(m_depth > 0 && (flags & PowerRenameFlags::ExcludeSubfolders)));
*isItemVisible = !((m_isFolder && (flags & PowerRenameFlags::ExcludeFolders)) ||
(!m_isFolder && (flags & PowerRenameFlags::ExcludeFiles)) ||
(m_depth > 0 && (flags & PowerRenameFlags::ExcludeSubfolders)));
break;
case PowerRenameFilters::ShouldRename:
ShouldRenameItem(flags, isItemVisible);

View File

@@ -31,15 +31,13 @@
<PropertyGroup>
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\modules\PowerRename\</OutDir>
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<PreprocessorDefinitions>WIN32;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(ProjectDir)..\;$(ProjectDir)..\ui;$(ProjectDir)..\dll;$(ProjectDir)..\lib;$(ProjectDir)..\..\..\common;$(ProjectDir)..\..\..\common\Telemetry;%(AdditionalIncludeDirectories);$(GeneratedFilesDir)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(ProjectDir)..\;$(ProjectDir)..\ui;$(ProjectDir)..\dll;$(ProjectDir)..\lib;$(ProjectDir)..\..\..\;$(ProjectDir)..\..\..\common\Telemetry;%(AdditionalIncludeDirectories);$(GeneratedFilesDir)</AdditionalIncludeDirectories>
</ClCompile>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="Helpers.h" />
<ClInclude Include="PowerRenameItem.h" />
@@ -66,6 +64,11 @@
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\common\SettingsAPI\SetttingsAPI.vcxproj">
<Project>{6955446d-23f7-4023-9bb3-8657f904af99}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.200729.8\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.200729.8\build\native\Microsoft.Windows.CppWinRT.targets')" />

View File

@@ -5,7 +5,6 @@
#include <shlobj.h>
#include <cstring>
#include "helpers.h"
#include "window_helpers.h"
#include <filesystem>
#include "trace.h"
#include <winrt/base.h>
@@ -14,15 +13,45 @@ namespace fs = std::filesystem;
extern HINSTANCE g_hInst;
HWND CreateMsgWindow(_In_ HINSTANCE hInst, _In_ WNDPROC pfnWndProc, _In_ void* p)
{
WNDCLASS wc = { 0 };
PCWSTR wndClassName = L"MsgWindow";
wc.lpfnWndProc = DefWindowProc;
wc.cbWndExtra = sizeof(void*);
wc.hInstance = hInst;
wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
wc.lpszClassName = wndClassName;
RegisterClass(&wc);
HWND hwnd = CreateWindowEx(
0, wndClassName, nullptr, 0, 0, 0, 0, 0, HWND_MESSAGE, 0, hInst, nullptr);
if (hwnd)
{
SetWindowLongPtr(hwnd, 0, (LONG_PTR)p);
if (pfnWndProc)
{
SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)pfnWndProc);
}
}
return hwnd;
}
// The default FOF flags to use in the rename operations
#define FOF_DEFAULTFLAGS (FOF_ALLOWUNDO | FOFX_ADDUNDORECORD | FOFX_SHOWELEVATIONPROMPT | FOF_RENAMEONCOLLISION)
IFACEMETHODIMP_(ULONG) CPowerRenameManager::AddRef()
IFACEMETHODIMP_(ULONG)
CPowerRenameManager::AddRef()
{
return InterlockedIncrement(&m_refCount);
}
IFACEMETHODIMP_(ULONG) CPowerRenameManager::Release()
IFACEMETHODIMP_(ULONG)
CPowerRenameManager::Release()
{
long refCount = InterlockedDecrement(&m_refCount);
@@ -170,7 +199,7 @@ IFACEMETHODIMP CPowerRenameManager::GetVisibleItemByIndex(_In_ UINT index, _COM_
UINT realIndex = 0, visibleIndex = 0;
for (size_t i = 0; i < m_isVisible.size(); i++)
{
if (m_isVisible[i] && visibleIndex == index)
if (m_isVisible[i] && visibleIndex == index)
{
realIndex = static_cast<UINT>(i);
break;
@@ -194,7 +223,7 @@ IFACEMETHODIMP CPowerRenameManager::GetItemById(_In_ int id, _COM_Outptr_ IPower
HRESULT hr = E_FAIL;
std::map<int, IPowerRenameItem*>::iterator it;
it = m_renameItems.find(id);
if (it != m_renameItems.end())
if (it != m_renameItems.end())
{
*ppItem = m_renameItems[id];
(*ppItem)->AddRef();
@@ -221,7 +250,7 @@ IFACEMETHODIMP CPowerRenameManager::SetVisible()
for (auto rit = m_renameItems.rbegin(); rit != m_renameItems.rend(); ++rit, --i)
{
bool isVisible = false;
if (m_filter == PowerRenameFilters::ShouldRename &&
if (m_filter == PowerRenameFilters::ShouldRename &&
(FAILED(m_spRegEx->GetSearchTerm(&searchTerm)) || searchTerm && wcslen(searchTerm) == 0))
{
isVisible = true;
@@ -239,17 +268,17 @@ IFACEMETHODIMP CPowerRenameManager::SetVisible()
{
lastVisibleDepth = itemDepth;
}
else if (lastVisibleDepth == itemDepth+1)
else if (lastVisibleDepth == itemDepth + 1)
{
isVisible = true;
lastVisibleDepth = itemDepth;
}
m_isVisible[i] = isVisible;
hr = S_OK;
}
return hr;
return hr;
}
IFACEMETHODIMP CPowerRenameManager::GetVisibleItemCount(_Out_ UINT* count)
@@ -273,7 +302,7 @@ IFACEMETHODIMP CPowerRenameManager::GetVisibleItemCount(_Out_ UINT* count)
{
GetItemCount(count);
}
return S_OK;
}
@@ -465,11 +494,11 @@ HRESULT CPowerRenameManager::_Init()
// Custom messages for worker threads
enum
{
SRM_REGEX_ITEM_UPDATED = (WM_APP + 1), // Single rename item processed by regex worker thread
SRM_REGEX_STARTED, // RegEx operation was started
SRM_REGEX_CANCELED, // Regex operation was canceled
SRM_REGEX_COMPLETE, // Regex worker thread completed
SRM_FILEOP_COMPLETE // File Operation worker thread completed
SRM_REGEX_ITEM_UPDATED = (WM_APP + 1), // Single rename item processed by regex worker thread
SRM_REGEX_STARTED, // RegEx operation was started
SRM_REGEX_CANCELED, // Regex operation was canceled
SRM_REGEX_COMPLETE, // Regex worker thread completed
SRM_FILEOP_COMPLETE // File Operation worker thread completed
};
struct WorkerThreadData
@@ -556,7 +585,6 @@ void CPowerRenameManager::_LogOperationTelemetry()
GetRenameItemCount(&renameItemCount);
GetFlags(&flags);
// Enumerate extensions used into a map
std::map<std::wstring, int> extensionsMap;
for (UINT i = 0; i < totalItemCount; i++)
@@ -748,7 +776,7 @@ DWORD WINAPI CPowerRenameManager::s_fileOpWorkerThread(_In_ void* pv)
{
spFileOp->SetOwnerWindow(pwtd->hwndParent);
}
// Perform the operation
// We don't care about the return code here. We would rather
// return control back to explorer so the user can cleanly

View File

@@ -1,13 +1,13 @@
#include "pch.h"
#include "Settings.h"
#include "PowerRenameInterfaces.h"
#include "settings_helpers.h"
#include <common/SettingsAPI/settings_helpers.h>
#include <filesystem>
#include <commctrl.h>
#include <algorithm>
#include <fstream>
#include <dll\PowerRenameConstants.h>
#include <dll/PowerRenameConstants.h>
namespace
{
@@ -61,7 +61,7 @@ namespace
SetRegNumber(valueName, value ? 1 : 0);
}
std::wstring GetRegString(const std::wstring& valueName,const std::wstring& subPath)
std::wstring GetRegString(const std::wstring& valueName, const std::wstring& subPath)
{
wchar_t value[CSettings::MAX_INPUT_STRING_LEN];
value[0] = L'\0';
@@ -123,7 +123,6 @@ private:
const std::wstring registryFilePath;
};
void MRUListHandler::Push(const std::wstring& data)
{
if (Exists(data))
@@ -265,7 +264,9 @@ void MRUListHandler::ParseJson()
}
}
}
catch (const winrt::hresult_error&) { }
catch (const winrt::hresult_error&)
{
}
}
}
@@ -280,15 +281,21 @@ class CRenameMRU :
{
public:
// IUnknown
IFACEMETHODIMP_(ULONG) AddRef();
IFACEMETHODIMP_(ULONG) Release();
IFACEMETHODIMP_(ULONG)
AddRef();
IFACEMETHODIMP_(ULONG)
Release();
IFACEMETHODIMP QueryInterface(_In_ REFIID riid, _Outptr_ void** ppv);
// IEnumString
IFACEMETHODIMP Next(__in ULONG celt, __out_ecount_part(celt, *pceltFetched) LPOLESTR* rgelt, __out_opt ULONG* pceltFetched);
IFACEMETHODIMP Skip(__in ULONG) { return E_NOTIMPL; }
IFACEMETHODIMP Reset();
IFACEMETHODIMP Clone(__deref_out IEnumString** ppenum) { *ppenum = nullptr; return E_NOTIMPL; }
IFACEMETHODIMP Clone(__deref_out IEnumString** ppenum)
{
*ppenum = nullptr;
return E_NOTIMPL;
}
// IPowerRenameMRU
IFACEMETHODIMP AddMRUString(_In_ PCWSTR entry);
@@ -328,12 +335,14 @@ HRESULT CRenameMRU::CreateInstance(_In_ const std::wstring& filePath, _In_ const
return hr;
}
IFACEMETHODIMP_(ULONG) CRenameMRU::AddRef()
IFACEMETHODIMP_(ULONG)
CRenameMRU::AddRef()
{
return InterlockedIncrement(&refCount);
}
IFACEMETHODIMP_(ULONG) CRenameMRU::Release()
IFACEMETHODIMP_(ULONG)
CRenameMRU::Release()
{
unsigned int cnt = InterlockedDecrement(&refCount);
@@ -408,15 +417,15 @@ void CSettings::Save()
{
json::JsonObject jsonData;
jsonData.SetNamedValue(c_enabled, json::value(settings.enabled));
jsonData.SetNamedValue(c_showIconOnMenu, json::value(settings.showIconOnMenu));
jsonData.SetNamedValue(c_enabled, json::value(settings.enabled));
jsonData.SetNamedValue(c_showIconOnMenu, json::value(settings.showIconOnMenu));
jsonData.SetNamedValue(c_extendedContextMenuOnly, json::value(settings.extendedContextMenuOnly));
jsonData.SetNamedValue(c_persistState, json::value(settings.persistState));
jsonData.SetNamedValue(c_mruEnabled, json::value(settings.MRUEnabled));
jsonData.SetNamedValue(c_maxMRUSize, json::value(settings.maxMRUSize));
jsonData.SetNamedValue(c_searchText, json::value(settings.searchText));
jsonData.SetNamedValue(c_replaceText, json::value(settings.replaceText));
jsonData.SetNamedValue(c_useBoostLib, json::value(settings.useBoostLib));
jsonData.SetNamedValue(c_persistState, json::value(settings.persistState));
jsonData.SetNamedValue(c_mruEnabled, json::value(settings.MRUEnabled));
jsonData.SetNamedValue(c_maxMRUSize, json::value(settings.maxMRUSize));
jsonData.SetNamedValue(c_searchText, json::value(settings.searchText));
jsonData.SetNamedValue(c_replaceText, json::value(settings.replaceText));
jsonData.SetNamedValue(c_useBoostLib, json::value(settings.useBoostLib));
json::to_file(jsonFilePath, jsonData);
GetSystemTimeAsFileTime(&lastLoadedTime);
@@ -451,16 +460,16 @@ void CSettings::Reload()
void CSettings::MigrateFromRegistry()
{
settings.enabled = GetRegBoolean(c_enabled, true);
settings.showIconOnMenu = GetRegBoolean(c_showIconOnMenu, true);
settings.enabled = GetRegBoolean(c_enabled, true);
settings.showIconOnMenu = GetRegBoolean(c_showIconOnMenu, true);
settings.extendedContextMenuOnly = GetRegBoolean(c_extendedContextMenuOnly, false); // Disabled by default.
settings.persistState = GetRegBoolean(c_persistState, true);
settings.MRUEnabled = GetRegBoolean(c_mruEnabled, true);
settings.maxMRUSize = GetRegNumber(c_maxMRUSize, 10);
settings.flags = GetRegNumber(c_flags, 0);
settings.searchText = GetRegString(c_searchText, L"");
settings.replaceText = GetRegString(c_replaceText, L"");
settings.useBoostLib = false; // Never existed in registry, disabled by default.
settings.persistState = GetRegBoolean(c_persistState, true);
settings.MRUEnabled = GetRegBoolean(c_mruEnabled, true);
settings.maxMRUSize = GetRegNumber(c_maxMRUSize, 10);
settings.flags = GetRegNumber(c_flags, 0);
settings.searchText = GetRegString(c_searchText, L"");
settings.replaceText = GetRegString(c_replaceText, L"");
settings.useBoostLib = false; // Never existed in registry, disabled by default.
}
void CSettings::ParseJson()
@@ -508,7 +517,9 @@ void CSettings::ParseJson()
settings.useBoostLib = jsonSettings.GetNamedBoolean(c_useBoostLib);
}
}
catch (const winrt::hresult_error&) { }
catch (const winrt::hresult_error&)
{
}
}
GetSystemTimeAsFileTime(&lastLoadedTime);
}

View File

@@ -1,6 +1,6 @@
#pragma once
#include "json.h"
#include <common/utils/json.h>
class CSettings
{