|
24 | 24 | // added option for editing filenames (long paths) |
25 | 25 | // Version 1.7.0 (c) 2022 thomas694 |
26 | 26 | // added direct implementations for extra functionality except slideshow |
| 27 | +// Version 1.7.1 (c) 2022 thomas694 |
| 28 | +// fixed SetDateTime for folders |
27 | 29 | // |
28 | 30 | // DFTContextMenuHandler is free software: you can redistribute it and/or modify |
29 | 31 | // it under the terms of the GNU General Public License as published by |
@@ -1064,6 +1066,14 @@ int CCmdLineContextMenu::RemoveFromFilename() |
1064 | 1066 | return 1; |
1065 | 1067 | } |
1066 | 1068 |
|
| 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 | + |
1067 | 1077 | int CCmdLineContextMenu::SetDateTime() { |
1068 | 1078 |
|
1069 | 1079 | //get new date/time |
@@ -1101,12 +1111,28 @@ int CCmdLineContextMenu::SetDateTime() { |
1101 | 1111 | times.actime = time; |
1102 | 1112 | times.modtime = time; |
1103 | 1113 |
|
| 1114 | + FILETIME modifiedTime; |
| 1115 | + TimetToFileTime(time, &modifiedTime); |
| 1116 | + |
1104 | 1117 | //set all files to new date/time |
1105 | 1118 | size_t lFiles; |
1106 | 1119 | lFiles = m_strFilenames.size(); |
1107 | 1120 | int i; |
1108 | 1121 | for (i=0; i<lFiles; i++) { |
1109 | | - _tutime(m_strFilenames[i].data(), ×); |
| 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(), ×); |
| 1135 | + } |
1110 | 1136 | } |
1111 | 1137 |
|
1112 | 1138 | return 1; |
@@ -1434,7 +1460,7 @@ void CCmdLineContextMenu::FlattenTree(string baseFolder, bool useFolderNames) |
1434 | 1460 | } |
1435 | 1461 |
|
1436 | 1462 | string oldName = folder + _T("\\") + fd.cFileName; |
1437 | | - _trename(oldName.c_str(), fn.c_str()); |
| 1463 | + int ret = _trename(oldName.c_str(), fn.c_str()); |
1438 | 1464 |
|
1439 | 1465 | } while (::FindNextFile(hFind, &fd)); |
1440 | 1466 | ::FindClose(hFind); |
|
0 commit comments