Fixed a bunch of improper timestamp handling, made ZIP timestamping deterministic, added default timestamp

This commit is contained in:
elasota
2020-01-23 02:47:31 -05:00
parent a73d6fe10d
commit a1475d2ee3
11 changed files with 429 additions and 136 deletions

View File

@@ -34,9 +34,9 @@ using namespace PortabilityLayer;
int main(int argc, const char **argv)
{
if (argc != 3)
if (argc != 4)
{
fprintf(stderr, "Usage: hqx2gp <input.hqx> <output>");
fprintf(stderr, "Usage: hqx2gp <input.hqx> <input.ts> <output>");
return -1;
}
@@ -54,18 +54,52 @@ int main(int argc, const char **argv)
return -1;
}
#ifdef _CRT_INSECURE_DEPRECATE
FILE *tsF = nullptr;
if (fopen_s(&tsF, argv[2], "rb"))
tsF = nullptr;
#else
FILE *tsF = fopen(argv[2], "rb");
#endif
if (!tsF)
{
fprintf(stderr, "Could not open timestamp file");
return -1;
}
int64_t timestamp = 0;
{
uint8_t encodedTimestamp[8];
if (fread(encodedTimestamp, 1, 8, tsF) != 8)
{
fprintf(stderr, "Error reading timestamp file");
return -1;
}
for (int i = 0; i < 8; i++)
timestamp |= static_cast<int64_t>(encodedTimestamp[i]) << (i * 8);
}
fclose(tsF);
CFileStream fs(f, true, false, true);
ScopedPtr<MacFileMem> memFile = BinHex4::LoadHQX(&fs);
fs.Close();
std::string fname = argv[2];
std::string fname = argv[3];
const char* extensions[] = { ".gpf", ".gpr", ".gpd", ".gpc" };
const char* extensions[] = { ".gpf", ".gpr", ".gpd", ".gpc" };
MacFileProperties mfp = memFile->FileInfo().m_properties;
mfp.m_creationDate = mfp.m_modifiedDate = timestamp;
MacFilePropertiesSerialized sp;
sp.Serialize(memFile->FileInfo().m_properties);
sp.Serialize(mfp);
for (int i = 0; i < 4; i++)
{