Set a valid timestamp on MacBinary output
This commit is contained in:
parent
e19ca07b3a
commit
f186dc1d57
|
@ -3,6 +3,8 @@
|
||||||
|
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
#include "boost/filesystem/fstream.hpp"
|
#include "boost/filesystem/fstream.hpp"
|
||||||
|
#include <chrono>
|
||||||
|
#include <ctime>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
@ -73,6 +75,13 @@ static void writeMacBinary(std::ostream& out, std::string filename,
|
||||||
|
|
||||||
const std::string& rsrcBytes = resstream.str();
|
const std::string& rsrcBytes = resstream.str();
|
||||||
|
|
||||||
|
// Calculate Mac-style timestamp (seconds since 1 January 1904 00:00:00)
|
||||||
|
std::tm mac_epoch_tm = {
|
||||||
|
0, 0, 0, // 00:00:00
|
||||||
|
1, 0, 4 // 1 January 1904
|
||||||
|
};
|
||||||
|
auto mac_epoch = std::chrono::system_clock::from_time_t(std::mktime(&mac_epoch_tm));
|
||||||
|
uint32_t mac_time = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now() - mac_epoch).count();
|
||||||
|
|
||||||
std::ostringstream header;
|
std::ostringstream header;
|
||||||
byte(header, 0);
|
byte(header, 0);
|
||||||
|
@ -91,8 +100,8 @@ static void writeMacBinary(std::ostream& out, std::string filename,
|
||||||
byte(header, 0);
|
byte(header, 0);
|
||||||
longword(header, (int)data.size());
|
longword(header, (int)data.size());
|
||||||
longword(header, (int)rsrcBytes.size());
|
longword(header, (int)rsrcBytes.size());
|
||||||
longword(header, 0); // creation date
|
longword(header, mac_time); // creation date
|
||||||
longword(header, 0); // modification date
|
longword(header, mac_time); // modification date
|
||||||
while((int)header.tellp() < 124)
|
while((int)header.tellp() < 124)
|
||||||
byte(header,0);
|
byte(header,0);
|
||||||
std::string headerData = header.str();
|
std::string headerData = header.str();
|
||||||
|
|
Loading…
Reference in New Issue