Hello to everyone,
Important: This thread is not about returning any timestamps to TC but handling them within a plugin.
The thread Wrong timestamp in RAR files modified in other time zone got me thinking about the method of retrieving the file times in my Startups plugin. Currently it uses GetFileAttributesEx() to retrieve the file times, which are then converted to local time via FileTimeToLocalFileTime(). This produces the same results as in Explorer and TC, but only on Win2k and XP (on FAT32 and NTFS). On Win7 the times are one hour off for some of the files, depending on DST, regardless of file-system.
Because of this I changed the implementation to use FileTimeToSystemTime() and SystemTimeToTzSpecificLocalTime() functions. Now the timestamps are correct (i.e. the same as in Explorer/TC) on Win7 but not anymore on Win2k and XP . So I tried GetFileTime() instead of GetFileAttributesEx(), because that's what MS suggests to use in their File Times article. The result remains the same . For now I have included an if-condition that checks the OS version and calls the functions accordingly (FileTimeToLocalFileTime up to XP, the other two functions on newer Windows versions). However, I highly doubt that's what I'm supposed to do.
What's the correct way to do it? How does TC do it?
[EDIT] Typo [/EDIT]
Regards
Dalai
Correct way to handle file times
Moderators: white, Hacker, petermad, Stefan2
Correct way to handle file times
Last edited by Dalai on 2017-11-29, 14:46 UTC, edited 1 time in total.
#101164 Personal licence
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64
Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64
Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
- ghisler(Author)
- Site Admin
- Posts: 48104
- Joined: 2003-02-04, 09:46 UTC
- Location: Switzerland
- Contact:
There is no function which works correctly in all cases.
TC uses the old FileTimeToLocalFileTime() on Windows XP and older, and the newer FileTimeToSystemTime() and SystemTimeToTzSpecificLocalTime() on all newer systems.
You can also override this with NewTimeZoneMethod flag in wincmd.ini, but I think you can neglect this - only a small minority of users will set this flag.
TC uses the old FileTimeToLocalFileTime() on Windows XP and older, and the newer FileTimeToSystemTime() and SystemTimeToTzSpecificLocalTime() on all newer systems.
You can also override this with NewTimeZoneMethod flag in wincmd.ini, but I think you can neglect this - only a small minority of users will set this flag.
Author of Total Commander
https://www.ghisler.com
https://www.ghisler.com
Thank you for your answer!
Regards
Dalai
Uh, OK. That's not what I was expecting to read, although it's rather typical for MS, I think...ghisler(Author) wrote:There is no function which works correctly in all cases.
OK, that's the same way I doubted I was supposed to be doing, and I can leave it as it is.TC uses the old FileTimeToLocalFileTime() on Windows XP and older, and the newer FileTimeToSystemTime() and SystemTimeToTzSpecificLocalTime() on all newer systems.
Well, I certainly can't expect users to set a flag in their wincmd.ini which affects timestamps shown in TC in general, so I'll stick with what I have now.You can also override this with NewTimeZoneMethod flag in wincmd.ini, but I think you can neglect this - only a small minority of users will set this flag.
Regards
Dalai
#101164 Personal licence
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64
Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64
Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror