Skip to content

Commit 23bdcb8

Browse files
committed
Fix SetDateTime for folders
1 parent 723a579 commit 23bdcb8

3 files changed

Lines changed: 29 additions & 3 deletions

File tree

src/CmdLineContextMenu.cpp

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
// added option for editing filenames (long paths)
2525
// Version 1.7.0 (c) 2022 thomas694
2626
// added direct implementations for extra functionality except slideshow
27+
// Version 1.7.1 (c) 2022 thomas694
28+
// fixed SetDateTime for folders
2729
//
2830
// DFTContextMenuHandler is free software: you can redistribute it and/or modify
2931
// it under the terms of the GNU General Public License as published by
@@ -1064,6 +1066,14 @@ int CCmdLineContextMenu::RemoveFromFilename()
10641066
return 1;
10651067
}
10661068

1069+
void TimetToFileTime(time_t t, LPFILETIME pft)
1070+
{
1071+
ULARGE_INTEGER time_value;
1072+
time_value.QuadPart = (t * 10000000LL) + 116444736000000000LL;
1073+
pft->dwLowDateTime = time_value.LowPart;
1074+
pft->dwHighDateTime = time_value.HighPart;
1075+
}
1076+
10671077
int CCmdLineContextMenu::SetDateTime() {
10681078

10691079
//get new date/time
@@ -1101,12 +1111,28 @@ int CCmdLineContextMenu::SetDateTime() {
11011111
times.actime = time;
11021112
times.modtime = time;
11031113

1114+
FILETIME modifiedTime;
1115+
TimetToFileTime(time, &modifiedTime);
1116+
11041117
//set all files to new date/time
11051118
size_t lFiles;
11061119
lFiles = m_strFilenames.size();
11071120
int i;
11081121
for (i=0; i<lFiles; i++) {
1109-
_tutime(m_strFilenames[i].data(), &times);
1122+
if (PathIsDirectory(m_strFilenames[i].data())) {
1123+
HANDLE hDir = CreateFile(m_strFilenames[i].data(), GENERIC_READ | GENERIC_WRITE,
1124+
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
1125+
if (hDir != INVALID_HANDLE_VALUE) {
1126+
#pragma warning(push)
1127+
#pragma warning(disable: 6001)
1128+
SetFileTime(hDir, NULL, NULL, &modifiedTime);
1129+
#pragma warning(pop)
1130+
CloseHandle(hDir);
1131+
}
1132+
}
1133+
else {
1134+
_tutime(m_strFilenames[i].data(), &times);
1135+
}
11101136
}
11111137

11121138
return 1;
@@ -1434,7 +1460,7 @@ void CCmdLineContextMenu::FlattenTree(string baseFolder, bool useFolderNames)
14341460
}
14351461

14361462
string oldName = folder + _T("\\") + fd.cFileName;
1437-
_trename(oldName.c_str(), fn.c_str());
1463+
int ret = _trename(oldName.c_str(), fn.c_str());
14381464

14391465
} while (::FindNextFile(hFind, &fd));
14401466
::FindClose(hFind);

src/CmdLineExt.rc

0 Bytes
Binary file not shown.

src/app.manifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
22
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
3-
<assemblyIdentity type='win32' name='DFTContextMenuHandler' version='1.6.0.0' processorArchitecture="amd64" />
3+
<assemblyIdentity type='win32' name='DFTContextMenuHandler' version='1.7.1.0' processorArchitecture="amd64" />
44
<asmv3:application>
55
<asmv3:windowsSettings xmlns:ws2="http://schemas.microsoft.com/SMI/2016/WindowsSettings">
66
<ws2:longPathAware>true</ws2:longPathAware>

0 commit comments

Comments
 (0)