[PowerRename] Using File Date Time Attributes Feature (#4722)

* Add basic using file attributes functionality

* Correctly return result

* Refactor

* Move retrieving date attribute to get function

* Cover various milliseconds patterns, retrieve file attributes only when needed

* Correctly check if date/time pattern is used. Remove wstring cast

* Use correct flags on CreateFile call to handle directories

* rebase to master

* Perform transform operation at last to make it not mess with date/time variables

* Refactor, remove extra space
This commit is contained in:
Mehmet Murat Akburak
2020-07-16 14:24:49 +03:00
committed by GitHub
parent ebe70a52d1
commit a8153dd8db
6 changed files with 135 additions and 14 deletions

View File

@@ -813,7 +813,35 @@ DWORD WINAPI CPowerRenameManager::s_regexWorkerThread(_In_ void* pv)
newNameToUse = trimmedName;
}
bool isDateAttributeUsed = false;
wchar_t datedName[MAX_PATH] = { 0 };
std::wstring patterns[] = { L"$YYYY", L"$SSS", L"$MMM", L"$mmm", L"$FFF", L"$fff",
L"$MM", L"$DD", L"$hh", L"$mm", L"$ss" };
size_t patternsLength = ARRAYSIZE(patterns);
SYSTEMTIME LocalTime;
if (newNameToUse != nullptr)
{
for (size_t i = 0; !isDateAttributeUsed && i < patternsLength; i++)
{
std::wstring source(newNameToUse);
if (source.find(patterns[i]) != std::string::npos)
{
isDateAttributeUsed = true;
}
}
if (isDateAttributeUsed)
{
if (SUCCEEDED(spItem->get_date(&LocalTime)))
{
if (SUCCEEDED(GetDatedFileName(datedName, ARRAYSIZE(datedName), newNameToUse, LocalTime)))
{
newNameToUse = datedName;
}
}
}
}
wchar_t transformedName[MAX_PATH] = { 0 };
if (newNameToUse != nullptr && (flags & Uppercase || flags & Lowercase || flags & Titlecase))
{
@@ -822,7 +850,7 @@ DWORD WINAPI CPowerRenameManager::s_regexWorkerThread(_In_ void* pv)
newNameToUse = transformedName;
}
}
// No change from originalName so set newName to
// null so we clear it from our UI as well.
if (lstrcmp(originalName, newNameToUse) == 0)