tweak new miniz

This commit is contained in:
Garux 2018-10-23 19:43:04 +03:00
parent 2384269177
commit d716c4d0b9
3 changed files with 34 additions and 20 deletions

View File

@ -6010,12 +6010,12 @@ static mz_bool mz_zip_writer_write_zeros(mz_zip_archive *pZip, mz_uint64 cur_fil
mz_bool mz_zip_writer_add_mem_ex(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, mz_bool mz_zip_writer_add_mem_ex(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags,
mz_uint64 uncomp_size, mz_uint32 uncomp_crc32) mz_uint64 uncomp_size, mz_uint32 uncomp_crc32)
{ {
return mz_zip_writer_add_mem_ex_v2(pZip, pArchive_name, pBuf, buf_size, pComment, comment_size, level_and_flags, uncomp_size, uncomp_crc32, NULL, NULL, 0, NULL, 0); return mz_zip_writer_add_mem_ex_v2(pZip, pArchive_name, pBuf, buf_size, pComment, comment_size, level_and_flags, uncomp_size, uncomp_crc32, NULL, NULL, 0, NULL, 0, NULL);
} }
mz_bool mz_zip_writer_add_mem_ex_v2(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_bool mz_zip_writer_add_mem_ex_v2(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size,
mz_uint level_and_flags, mz_uint64 uncomp_size, mz_uint32 uncomp_crc32, MZ_TIME_T *last_modified, mz_uint level_and_flags, mz_uint64 uncomp_size, mz_uint32 uncomp_crc32, MZ_TIME_T *last_modified,
const char *user_extra_data, mz_uint user_extra_data_len, const char *user_extra_data_central, mz_uint user_extra_data_central_len) const char *user_extra_data, mz_uint user_extra_data_len, const char *user_extra_data_central, mz_uint user_extra_data_central_len, mz_uint32* dosDate)
{ {
mz_uint16 method = 0, dos_time = 0, dos_date = 0; mz_uint16 method = 0, dos_time = 0, dos_date = 0;
mz_uint level, ext_attributes = 0, num_alignment_padding_bytes; mz_uint level, ext_attributes = 0, num_alignment_padding_bytes;
@ -6073,7 +6073,13 @@ mz_bool mz_zip_writer_add_mem_ex_v2(mz_zip_archive *pZip, const char *pArchive_n
return mz_zip_set_error(pZip, MZ_ZIP_INVALID_FILENAME); return mz_zip_set_error(pZip, MZ_ZIP_INVALID_FILENAME);
#ifndef MINIZ_NO_TIME #ifndef MINIZ_NO_TIME
if (last_modified != NULL) if( dosDate != NULL ){
dos_time = ( mz_uint16 )( *dosDate );
dos_date = ( mz_uint16 )( *dosDate >> 16 );
// MZ_TIME_T timeee = mz_zip_dos_to_time_t( *dosDate, *dosDate >> 16 );
// mz_zip_time_t_to_dos_time( timeee, &dos_time, &dos_date );
}
else if (last_modified != NULL)
{ {
mz_zip_time_t_to_dos_time(*last_modified, &dos_time, &dos_date); mz_zip_time_t_to_dos_time(*last_modified, &dos_time, &dos_date);
} }
@ -7193,12 +7199,7 @@ mz_bool mz_zip_writer_end(mz_zip_archive *pZip)
} }
#ifndef MINIZ_NO_STDIO #ifndef MINIZ_NO_STDIO
mz_bool mz_zip_add_mem_to_archive_file_in_place(const char *pZip_filename, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags) mz_bool mz_zip_add_mem_to_archive_file_in_place_implementation(const char *pZip_filename, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, mz_uint32* dosDate, mz_zip_error *pErr)
{
return mz_zip_add_mem_to_archive_file_in_place_v2(pZip_filename, pArchive_name, pBuf, buf_size, pComment, comment_size, level_and_flags, NULL);
}
mz_bool mz_zip_add_mem_to_archive_file_in_place_v2(const char *pZip_filename, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, mz_zip_error *pErr)
{ {
mz_bool status, created_new_archive = MZ_FALSE; mz_bool status, created_new_archive = MZ_FALSE;
mz_zip_archive zip_archive; mz_zip_archive zip_archive;
@ -7258,7 +7259,7 @@ mz_bool mz_zip_add_mem_to_archive_file_in_place_v2(const char *pZip_filename, co
} }
} }
status = mz_zip_writer_add_mem_ex(&zip_archive, pArchive_name, pBuf, buf_size, pComment, comment_size, level_and_flags, 0, 0); status = mz_zip_writer_add_mem_ex_v2(&zip_archive, pArchive_name, pBuf, buf_size, pComment, comment_size, level_and_flags, 0, 0, NULL, NULL, 0, NULL, 0, dosDate);
actual_err = zip_archive.m_last_error; actual_err = zip_archive.m_last_error;
/* Always finalize, even if adding failed for some reason, so we have a valid central directory. (This may not always succeed, but we can try.) */ /* Always finalize, even if adding failed for some reason, so we have a valid central directory. (This may not always succeed, but we can try.) */
@ -7291,6 +7292,21 @@ mz_bool mz_zip_add_mem_to_archive_file_in_place_v2(const char *pZip_filename, co
return status; return status;
} }
mz_bool mz_zip_add_mem_to_archive_file_in_place(const char *pZip_filename, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags)
{
return mz_zip_add_mem_to_archive_file_in_place_implementation(pZip_filename, pArchive_name, pBuf, buf_size, pComment, comment_size, level_and_flags, NULL, NULL);
}
mz_bool mz_zip_add_mem_to_archive_file_in_place_v2(const char *pZip_filename, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, mz_zip_error *pErr){
return mz_zip_add_mem_to_archive_file_in_place_implementation(pZip_filename, pArchive_name, pBuf, buf_size, pComment, comment_size, level_and_flags, NULL, pErr);
}
mz_bool mz_zip_add_mem_to_archive_file_in_place_with_time(const char *pZip_filename, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, mz_uint32 dosDate){
return mz_zip_add_mem_to_archive_file_in_place_implementation(pZip_filename, pArchive_name, pBuf, buf_size, pComment, comment_size, level_and_flags, &dosDate, NULL);
}
void *mz_zip_extract_archive_file_to_heap_v2(const char *pZip_filename, const char *pArchive_name, const char *pComment, size_t *pSize, mz_uint flags, mz_zip_error *pErr) void *mz_zip_extract_archive_file_to_heap_v2(const char *pZip_filename, const char *pArchive_name, const char *pComment, size_t *pSize, mz_uint flags, mz_zip_error *pErr)
{ {
mz_uint32 file_index; mz_uint32 file_index;

View File

@ -1267,7 +1267,7 @@ mz_bool mz_zip_writer_add_mem_ex(mz_zip_archive *pZip, const char *pArchive_name
mz_bool mz_zip_writer_add_mem_ex_v2(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, mz_bool mz_zip_writer_add_mem_ex_v2(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags,
mz_uint64 uncomp_size, mz_uint32 uncomp_crc32, MZ_TIME_T *last_modified, const char *user_extra_data_local, mz_uint user_extra_data_local_len, mz_uint64 uncomp_size, mz_uint32 uncomp_crc32, MZ_TIME_T *last_modified, const char *user_extra_data_local, mz_uint user_extra_data_local_len,
const char *user_extra_data_central, mz_uint user_extra_data_central_len); const char *user_extra_data_central, mz_uint user_extra_data_central_len, mz_uint32* dosDate);
#ifndef MINIZ_NO_STDIO #ifndef MINIZ_NO_STDIO
/* Adds the contents of a disk file to an archive. This function also records the disk file's modified time into the archive. */ /* Adds the contents of a disk file to an archive. This function also records the disk file's modified time into the archive. */
@ -1305,6 +1305,7 @@ mz_bool mz_zip_writer_end(mz_zip_archive *pZip);
/* TODO: Perhaps add an option to leave the existing central dir in place in case the add dies? We could then truncate the file (so the old central dir would be at the end) if something goes wrong. */ /* TODO: Perhaps add an option to leave the existing central dir in place in case the add dies? We could then truncate the file (so the old central dir would be at the end) if something goes wrong. */
mz_bool mz_zip_add_mem_to_archive_file_in_place(const char *pZip_filename, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags); mz_bool mz_zip_add_mem_to_archive_file_in_place(const char *pZip_filename, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags);
mz_bool mz_zip_add_mem_to_archive_file_in_place_v2(const char *pZip_filename, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, mz_zip_error *pErr); mz_bool mz_zip_add_mem_to_archive_file_in_place_v2(const char *pZip_filename, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, mz_zip_error *pErr);
mz_bool mz_zip_add_mem_to_archive_file_in_place_with_time(const char *pZip_filename, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, mz_uint32 dosDate);
/* Reads a single file from an archive into a heap block. */ /* Reads a single file from an archive into a heap block. */
/* If pComment is not NULL, only the file with the specified comment will be extracted. */ /* If pComment is not NULL, only the file with the specified comment will be extracted. */

View File

@ -557,9 +557,6 @@ qboolean vfsPackFile( const char *filename, const char *packname, const int comp
// we need to end the buffer with a 0 // we need to end the buffer with a 0
( (char*) ( bufferptr ) )[file->size] = 0; ( (char*) ( bufferptr ) )[file->size] = 0;
mz_uint16 DOS_time = (mz_uint16)(((file->zipinfo.cur_file_info.tmu_date.tm_hour) << 11) + ((file->zipinfo.cur_file_info.tmu_date.tm_min) << 5) + ((file->zipinfo.cur_file_info.tmu_date.tm_sec) >> 1));
mz_uint16 DOS_date = (mz_uint16)(((file->zipinfo.cur_file_info.tmu_date.tm_year - 1980) << 9) + ((file->zipinfo.cur_file_info.tmu_date.tm_mon + 1) << 5) + file->zipinfo.cur_file_info.tmu_date.tm_mday);
i = unzReadCurrentFile( file->zipfile, bufferptr, file->size ); i = unzReadCurrentFile( file->zipfile, bufferptr, file->size );
unzCloseCurrentFile( file->zipfile ); unzCloseCurrentFile( file->zipfile );
if ( i < 0 ) { if ( i < 0 ) {
@ -567,7 +564,7 @@ qboolean vfsPackFile( const char *filename, const char *packname, const int comp
} }
else{ else{
mz_bool success = MZ_TRUE; mz_bool success = MZ_TRUE;
success &= mz_zip_add_mem_to_archive_file_in_place_with_time( packname, filename, bufferptr, i, 0, 0, compLevel, DOS_time, DOS_date ); success &= mz_zip_add_mem_to_archive_file_in_place_with_time( packname, filename, bufferptr, i, 0, 0, compLevel, file->zipinfo.cur_file_info.dosDate );
if ( !success ){ if ( !success ){
Error( "Failed creating zip archive \"%s\"!\n", packname ); Error( "Failed creating zip archive \"%s\"!\n", packname );
} }