mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-01-10 05:57:55 +08:00
da22e21a0e
* Move retrieveing file attibutes to PowerRenameRegex Move file attributes unit tests to PowerRenameRegexTests Add file time field to MockPowerRenameItem * Add file attributes unittests to PowerRenameManagerTests * Change variable name * Rearrange function arguments * Check if file attributes are used only once * Change variable name LocalTime -> fileTime, date -> time * Set fileTime as a member of PowerRenameRegEx rather than passing as an argument * Change function name isFileAttributesUsed() -> isFileTimeUsed() Check before resetting fileTime * Fix small bugs * Fix typos * Refactor for readability, move free calls to reachable places * Fix search for area empty bug searchTerm being empty is not an invalid argument rather it must return OK without any operation Tests must check if Replace() returns S_OK becuase later it checks its result * Check return values of method calls in PowerRenameManager Remove received argments checks from some methods because argument being null or empty string doesnt mean it is invalid or method fails * Fix formatting. Remove overlooked comment. Fix error message. * Change HRESULT declarations according to coding style * Fix unhandled case. Refactor.
67 lines
1.9 KiB
C++
67 lines
1.9 KiB
C++
#pragma once
|
|
#include "pch.h"
|
|
#include <vector>
|
|
#include <string>
|
|
#include "srwlock.h"
|
|
|
|
#include "PowerRenameInterfaces.h"
|
|
|
|
#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);
|
|
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);
|
|
IFACEMETHODIMP PutFileTime(_In_ SYSTEMTIME fileTime);
|
|
IFACEMETHODIMP ResetFileTime();
|
|
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();
|
|
void _OnFileTimeChanged();
|
|
|
|
size_t _Find(std::wstring data, std::wstring toSearch, bool caseInsensitive, size_t pos);
|
|
|
|
bool _useBoostLib = false;
|
|
DWORD m_flags = DEFAULT_FLAGS;
|
|
PWSTR m_searchTerm = nullptr;
|
|
PWSTR m_replaceTerm = nullptr;
|
|
|
|
SYSTEMTIME m_fileTime = {0};
|
|
bool m_useFileTime = false;
|
|
|
|
CSRWLock m_lock;
|
|
CSRWLock m_lockEvents;
|
|
|
|
DWORD m_cookie = 0;
|
|
|
|
struct RENAME_REGEX_EVENT
|
|
{
|
|
IPowerRenameRegExEvents* pEvents;
|
|
DWORD cookie;
|
|
};
|
|
|
|
_Guarded_by_(m_lockEvents) std::vector<RENAME_REGEX_EVENT> m_renameRegExEvents;
|
|
|
|
long m_refCount = 0;
|
|
}; |