2019-10-18 11:57:19 +08:00
|
|
|
#pragma once
|
2020-04-30 04:02:18 +08:00
|
|
|
#include "pch.h"
|
2019-10-18 11:57:19 +08:00
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
#include "srwlock.h"
|
|
|
|
|
2019-12-17 16:21:46 +08:00
|
|
|
#include "PowerRenameInterfaces.h"
|
|
|
|
|
2019-10-18 11:57:19 +08:00
|
|
|
#define DEFAULT_FLAGS MatchAllOccurences
|
|
|
|
|
|
|
|
class CPowerRenameRegEx : public IPowerRenameRegEx
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// IUnknown
|
|
|
|
IFACEMETHODIMP QueryInterface(_In_ REFIID iid, _Outptr_ void** resultInterface);
|
|
|
|
IFACEMETHODIMP_(ULONG) AddRef();
|
|
|
|
IFACEMETHODIMP_(ULONG) Release();
|
|
|
|
|
|
|
|
// IPowerRenameRegEx
|
|
|
|
IFACEMETHODIMP Advise(_In_ IPowerRenameRegExEvents* regExEvents, _Out_ DWORD* cookie);
|
|
|
|
IFACEMETHODIMP UnAdvise(_In_ DWORD cookie);
|
2020-08-25 13:22:05 +08:00
|
|
|
IFACEMETHODIMP GetSearchTerm(_Outptr_ PWSTR* searchTerm);
|
|
|
|
IFACEMETHODIMP PutSearchTerm(_In_ PCWSTR searchTerm);
|
|
|
|
IFACEMETHODIMP GetReplaceTerm(_Outptr_ PWSTR* replaceTerm);
|
|
|
|
IFACEMETHODIMP PutReplaceTerm(_In_ PCWSTR replaceTerm);
|
|
|
|
IFACEMETHODIMP GetFlags(_Out_ DWORD* flags);
|
|
|
|
IFACEMETHODIMP PutFlags(_In_ DWORD flags);
|
2019-10-18 11:57:19 +08:00
|
|
|
IFACEMETHODIMP Replace(_In_ PCWSTR source, _Outptr_ PWSTR* result);
|
|
|
|
|
|
|
|
static HRESULT s_CreateInstance(_Outptr_ IPowerRenameRegEx **renameRegEx);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
CPowerRenameRegEx();
|
|
|
|
virtual ~CPowerRenameRegEx();
|
|
|
|
|
|
|
|
void _OnSearchTermChanged();
|
|
|
|
void _OnReplaceTermChanged();
|
|
|
|
void _OnFlagsChanged();
|
|
|
|
|
|
|
|
size_t _Find(std::wstring data, std::wstring toSearch, bool caseInsensitive, size_t pos);
|
|
|
|
|
|
|
|
DWORD m_flags = DEFAULT_FLAGS;
|
|
|
|
PWSTR m_searchTerm = nullptr;
|
|
|
|
PWSTR m_replaceTerm = nullptr;
|
|
|
|
|
|
|
|
CSRWLock m_lock;
|
|
|
|
CSRWLock m_lockEvents;
|
|
|
|
|
|
|
|
DWORD m_cookie = 0;
|
|
|
|
|
2019-11-12 03:00:42 +08:00
|
|
|
struct RENAME_REGEX_EVENT
|
2019-10-18 11:57:19 +08:00
|
|
|
{
|
|
|
|
IPowerRenameRegExEvents* pEvents;
|
|
|
|
DWORD cookie;
|
|
|
|
};
|
|
|
|
|
2019-11-12 03:00:42 +08:00
|
|
|
_Guarded_by_(m_lockEvents) std::vector<RENAME_REGEX_EVENT> m_renameRegExEvents;
|
2019-10-18 11:57:19 +08:00
|
|
|
|
|
|
|
long m_refCount = 0;
|
|
|
|
};
|