From cb0cbf4cb7cc2df8a8fb0e7bb305638e04676c9d Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Wed, 26 Jan 2022 11:40:21 +1100 Subject: [PATCH] Fix files from default.zip when extracted with windows built-in zip decompressor causing a 'File not found or no read permission' when attempting to later add back into a .zip file using windows built-in zip compressor Previously, only the Central Diretory Records for files had their modification dates set to the current date, while the Local File Records for files had their modification dates left as 0. Hence when extracting default.zip using windows' built-in zip decompressor, the resulting files would have a modification and creation date of '0'. (aka 10th March 1601) Unfortunately, attempting to later put these files back into a .zip using windows' built-in zip compressor would fail with an obscure 'File not found or no read permission' error, which was actually due to the modification/creation date of these files being '0'. This commit changes Local File Records for files to also have their modification set to the current date, which results in files extracted using windows' built-in zip decompressor now having valid modifcation and creation dates, thus bypassing the 'File not found or no read permission' error --- src/Resources.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/Resources.c b/src/Resources.c index 2d770f0bf..558e6a080 100644 --- a/src/Resources.c +++ b/src/Resources.c @@ -211,18 +211,29 @@ void Resources_CheckExistence(void) { /*########################################################################################################################* *---------------------------------------------------------Zip writer------------------------------------------------------* *#########################################################################################################################*/ +static void GetCurrentZipDate(int* modTime, int* modDate) { + struct DateTime now; + DateTime_CurrentLocal(&now); + + *modTime = (now.second / 2) | (now.minute << 5) | (now.hour << 11); + *modDate = (now.day) | (now.month << 5) | ((now.year - 1980) << 9); +} + static cc_result ZipPatcher_LocalFile(struct Stream* s, struct ResourceTexture* e) { int filenameLen = String_Length(e->filename); cc_uint8 header[30 + STRING_SIZE]; cc_result res; + int modTime, modDate; + + GetCurrentZipDate(&modTime, &modDate); if ((res = s->Position(s, &e->offset))) return res; Stream_SetU32_LE(header + 0, 0x04034b50); /* signature */ Stream_SetU16_LE(header + 4, 20); /* version needed */ Stream_SetU16_LE(header + 6, 0); /* bitflags */ Stream_SetU16_LE(header + 8, 0); /* compression method */ - Stream_SetU16_LE(header + 10, 0); /* last modified */ - Stream_SetU16_LE(header + 12, 0); /* last modified */ + Stream_SetU16_LE(header + 10, modTime); /* last modified */ + Stream_SetU16_LE(header + 12, modDate); /* last modified */ Stream_SetU32_LE(header + 14, e->crc32); /* CRC32 */ Stream_SetU32_LE(header + 18, e->size); /* Compressed size */ @@ -238,12 +249,8 @@ static cc_result ZipPatcher_LocalFile(struct Stream* s, struct ResourceTexture* static cc_result ZipPatcher_CentralDir(struct Stream* s, struct ResourceTexture* e) { int filenameLen = String_Length(e->filename); cc_uint8 header[46 + STRING_SIZE]; - struct DateTime now; int modTime, modDate; - - DateTime_CurrentLocal(&now); - modTime = (now.second / 2) | (now.minute << 5) | (now.hour << 11); - modDate = (now.day) | (now.month << 5) | ((now.year - 1980) << 9); + GetCurrentZipDate(&modTime, &modDate); Stream_SetU32_LE(header + 0, 0x02014b50); /* signature */ Stream_SetU16_LE(header + 4, 20); /* version */