3737#include < mz_zip_rw.h>
3838
3939#include " millennium/zip.h"
40+ #include " millennium/logger.h"
4041
4142#include < filesystem>
4243#include < functional>
@@ -51,6 +52,7 @@ bool Util::ExtractZipArchive(const std::string& zip_path, const std::string& des
5152
5253 int32_t err = mz_zip_reader_open_file (zip_reader, zip_path.c_str ());
5354 if (err != MZ_OK) {
55+ Logger.Log (" Failed to open zip file: {} (error: {})" , zip_path, err);
5456 mz_zip_reader_delete (&zip_reader);
5557 return false ;
5658 }
@@ -68,11 +70,11 @@ bool Util::ExtractZipArchive(const std::string& zip_path, const std::string& des
6870 /* * Pre-allocate containers for better performance */
6971 std::unordered_set<std::string> created_dirs;
7072 created_dirs.reserve (file_count / 4 );
71-
7273 std::string out_path;
7374 out_path.reserve (dest_dir.length () + 256 );
7475
7576 int32_t file_index = 0 ;
77+ int32_t failed_count = 0 ;
7678 mz_zip_file* file_info = nullptr ;
7779
7880 err = mz_zip_reader_goto_first_entry (zip_reader);
@@ -94,13 +96,14 @@ bool Util::ExtractZipArchive(const std::string& zip_path, const std::string& des
9496 std::filesystem::create_directories (parent_path);
9597 }
9698
97- err = mz_zip_reader_entry_save_file (zip_reader, out_path.c_str ());
98- if (err != MZ_OK)
99- break ;
99+ int32_t extract_err = mz_zip_reader_entry_save_file (zip_reader, out_path.c_str ());
100+ if (extract_err != MZ_OK) {
101+ Logger.Warn (" Failed to extract file: {} (error code: {})" , out_path, extract_err);
102+ failed_count++;
103+ }
100104 }
101105
102106 file_index++;
103-
104107 if (progress_cb)
105108 progress_cb (file_index, file_count, file_info->filename );
106109
@@ -110,5 +113,9 @@ bool Util::ExtractZipArchive(const std::string& zip_path, const std::string& des
110113 mz_zip_reader_close (zip_reader);
111114 mz_zip_reader_delete (&zip_reader);
112115
116+ if (failed_count > 0 ) {
117+ Logger.Warn (" Extraction completed with {} failed files" , failed_count);
118+ }
119+
113120 return (err == MZ_END_OF_LIST || err == MZ_OK);
114- }
121+ }
0 commit comments