summaryrefslogtreecommitdiff
path: root/zen/dst_hack.h
blob: 600107bb7d63c5557dfc46ee2d3b6db1219b5aa3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#ifndef DST_HACK_H_INCLUDED
#define DST_HACK_H_INCLUDED

#include "win.h" //includes "windows.h"
#include "zstring.h"
#include <stdexcept>


namespace dst
{
/*
Solve DST +-1h and time zone shift issues on FAT drives
-------------------------------------------------------
- (local) last write time is not touched!
- all additional metadata is encoded in local create time:
   I. indicator that offset in II) is present
  II. local<->UTC time offset
 III. indicator that offset in II) corresponds to current local write time (a hash of local last write time)
*/

bool isFatDrive(const Zstring& fileName); //throw ()

//all subsequent functions may throw the std::runtime_error exception!

struct RawTime //time as retrieved by ::FindFirstFile() and ::GetFileAttributesEx()
{
    RawTime(const FILETIME& create, const FILETIME& lastWrite) : createTimeRaw(create), writeTimeRaw(lastWrite) {}
    FILETIME createTimeRaw;
    FILETIME writeTimeRaw;
};
//save UTC time resistant against DST/time zone shifts
bool fatHasUtcEncoded(const RawTime& rawTime); //throw std::runtime_error; as retrieved by ::FindFirstFile() and ::GetFileAttributesEx()

RawTime fatEncodeUtcTime(const FILETIME& writeTimeRealUtc); //throw std::runtime_error
FILETIME fatDecodeUtcTime(const RawTime& rawTime); //throw std::runtime_error; return last write time in real UTC
}

#endif // DST_HACK_H_INCLUDED
bgstack15