[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

@@ -42,6 +42,36 @@ IFACEMETHODIMP CPowerRenameItem::get_path(_Outptr_ PWSTR* path)
return hr;
}
IFACEMETHODIMP CPowerRenameItem::get_date(_Outptr_ SYSTEMTIME* date)
{
CSRWSharedAutoLock lock(&m_lock);
HRESULT hr = m_isDateParsed ? S_OK : E_FAIL ;
if (!m_isDateParsed)
{
HANDLE hFile = CreateFileW(m_path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
if (hFile != INVALID_HANDLE_VALUE)
{
FILETIME CreationTime;
if (GetFileTime(hFile, &CreationTime, NULL, NULL))
{
SYSTEMTIME SystemTime, LocalTime;
if (FileTimeToSystemTime(&CreationTime, &SystemTime))
{
if (SystemTimeToTzSpecificLocalTime(NULL, &SystemTime, &LocalTime))
{
m_date = LocalTime;
m_isDateParsed = true;
hr = S_OK;
}
}
}
}
CloseHandle(hFile);
}
*date = m_date;
return hr;
}
IFACEMETHODIMP CPowerRenameItem::get_shellItem(_Outptr_ IShellItem** ppsi)
{
return SHCreateItemFromParsingName(m_path, nullptr, IID_PPV_ARGS(ppsi));