mirror of
https://github.com/elasota/Aerofoil.git
synced 2025-09-23 23:00:42 +00:00
Add MakeTimestamp to CMake, port to *nix
This commit is contained in:
@@ -349,5 +349,9 @@ target_include_directories(gpr2gpa PRIVATE
|
||||
)
|
||||
target_link_libraries(gpr2gpa PortabilityLayer MacRomanConversion zlib)
|
||||
|
||||
add_executable(MakeTimestamp MakeTimestamp/MakeTimestamp.cpp)
|
||||
target_include_directories(MakeTimestamp PRIVATE PortabilityLayer UnixCompat)
|
||||
target_link_libraries(MakeTimestamp PortabilityLayer)
|
||||
|
||||
|
||||
install (TARGETS ${EXECNAME})
|
||||
|
@@ -1,6 +1,16 @@
|
||||
#ifdef _WIN32
|
||||
#include <Windows.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#else
|
||||
#include <string.h>
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#include "UnixCompat.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "CombinedTimestamp.h"
|
||||
|
||||
@@ -13,6 +23,7 @@ int main(int argc, const char **argv)
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
SYSTEMTIME epochStart;
|
||||
epochStart.wYear = 1904;
|
||||
epochStart.wMonth = 1;
|
||||
@@ -34,13 +45,6 @@ int main(int argc, const char **argv)
|
||||
int64_t currentTime64 = (static_cast<int64_t>(timestampFT.dwLowDateTime) & 0xffffffff) | (static_cast<int64_t>(timestampFT.dwHighDateTime) << 32);
|
||||
int64_t timeDelta = (currentTime64 - epochStart64) / 10000000;
|
||||
|
||||
FILE *f = nullptr;
|
||||
if (fopen_s(&f, argv[1], "wb"))
|
||||
{
|
||||
fprintf(stderr, "Error opening output file");
|
||||
return -1;
|
||||
}
|
||||
|
||||
TIME_ZONE_INFORMATION tz;
|
||||
GetTimeZoneInformation(&tz);
|
||||
|
||||
@@ -60,9 +64,36 @@ int main(int argc, const char **argv)
|
||||
ts.m_localHour = localST.wHour;
|
||||
ts.m_localMinute = localST.wMinute;
|
||||
ts.m_localSecond = localST.wSecond;
|
||||
#else
|
||||
time_t currentTimeUnix = time(nullptr);
|
||||
|
||||
tm *currentTimeStruct = localtime(¤tTimeUnix);
|
||||
if (currentTimeStruct == nullptr) {
|
||||
fprintf(stderr, "Error converting system time to calendar format");
|
||||
return -1;
|
||||
}
|
||||
|
||||
PortabilityLayer::CombinedTimestamp ts;
|
||||
ts.SetMacEpochTime(currentTimeUnix + ts.kMacEpochToUTC);
|
||||
|
||||
ts.SetLocalYear(currentTimeStruct->tm_year + 1900);
|
||||
ts.m_localMonth = currentTimeStruct->tm_mon;
|
||||
ts.m_localDay = currentTimeStruct->tm_mday;
|
||||
|
||||
ts.m_localHour = currentTimeStruct->tm_hour;
|
||||
ts.m_localMinute = currentTimeStruct->tm_min;
|
||||
ts.m_localSecond = currentTimeStruct->tm_sec;
|
||||
#endif
|
||||
|
||||
memset(ts.m_padding, 0, sizeof(ts.m_padding));
|
||||
|
||||
FILE *f;
|
||||
if (fopen_s(&f, argv[1], "wb"))
|
||||
{
|
||||
fprintf(stderr, "Error opening output file");
|
||||
return -1;
|
||||
}
|
||||
|
||||
fwrite(&ts, sizeof(ts), 1, f);
|
||||
|
||||
fclose(f);
|
||||
|
Reference in New Issue
Block a user