MCPcopy Create free account
hub / github.com/WolfireGames/overgrowth / AddFile

Method AddFile

Source/Internal/zip_util.cpp:80–142  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

78}
79
80void ZipFile::AddFile(const std::string& src_file_path,
81 const std::string& in_zip_file_path,
82 const std::string& password) {
83 ScopedBuffer scoped_buf(size_buf);
84
85 zip_fileinfo zi;
86 ClearZFI(zi);
87 filetime(src_file_path.c_str(), &zi.tmz_date, &zi.dosDate);
88
89 unsigned long crcFile = 0;
90 if (!password.empty()) {
91 if (getFileCrc(src_file_path.c_str(), scoped_buf.ptr, size_buf, &crcFile) != ZIP_OK) {
92 FatalError("Error", "Problem getting CRC of file: %s", src_file_path.c_str());
93 }
94 }
95
96 // The FSEEKO sometimes casuse segfault on linux debian for no reason, we never have large files anyways.
97 int zip64 = false; // isLargeFile(src_file_path.c_str());
98
99 /* The path name saved, should not include a leading slash.
100 if it did, windows/xp and dynazip couldn't read the zip file. */
101 const char* savefilenameinzip = in_zip_file_path.c_str();
102 while (savefilenameinzip[0] == '\\' || savefilenameinzip[0] == '/') {
103 savefilenameinzip++;
104 }
105
106 if (zipOpenNewFileInZip3_64(zf, savefilenameinzip, &zi,
107 NULL, 0, NULL, 0, NULL /* comment*/,
108 (opt_compress_level != 0) ? Z_DEFLATED : 0,
109 opt_compress_level, 0,
110 -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
111 password.empty() ? NULL : password.c_str(), crcFile, zip64) != ZIP_OK) {
112 FatalError("Error", "Could not open %s in zipfile", src_file_path.c_str());
113 }
114
115 {
116 FILE* file = nullptr;
117 file = FOPEN_FUNC(src_file_path.c_str(), "rb");
118 if (file == NULL) {
119 FatalError("Error", "Could not open file: %s", src_file_path.c_str());
120 return;
121 }
122
123 int size_read = 0;
124 do {
125 size_read = (int)fread(scoped_buf.ptr, 1, size_buf, file);
126 if (size_read < size_buf && feof(file) == 0) {
127 FatalError("Error", "Problem reading file: %s", src_file_path.c_str());
128 }
129 if (size_read > 0) {
130 if (zipWriteInFileInZip(zf, scoped_buf.ptr, size_read) < 0) {
131 FatalError("Error", "Problem writing \"%s\" in the zipfile.", src_file_path.c_str());
132 }
133 }
134 } while (size_read > 0);
135 if (file)
136 fclose(file);
137 }

Callers 1

ZipFunction · 0.45

Calls 9

ClearZFIFunction · 0.85
FatalErrorFunction · 0.70
filetimeFunction · 0.50
getFileCrcFunction · 0.50
zipOpenNewFileInZip3_64Function · 0.50
zipWriteInFileInZipFunction · 0.50
zipCloseFileInZipFunction · 0.50
c_strMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected