MCPcopy Create free account
hub / github.com/ZDoom/Raze / WriteZip

Function WriteZip

source/common/utility/writezip.cpp:185–241  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

183}
184
185bool WriteZip(const char* filename, const FCompressedBuffer* content, size_t contentcount)
186{
187 // try to determine local time
188 struct tm *ltime;
189 time_t ttime;
190 ttime = time(nullptr);
191 ltime = localtime(&ttime);
192 auto dostime = time_to_dos(ltime);
193
194 TArray<int> positions;
195
196 auto f = FileWriter::Open(filename);
197 if (f != nullptr)
198 {
199 for (size_t i = 0; i < contentcount; i++)
200 {
201 int pos = AppendToZip(f, content[i], dostime);
202 if (pos == -1)
203 {
204 delete f;
205 RemoveFile(filename);
206 return false;
207 }
208 positions.Push(pos);
209 }
210
211 int dirofs = (int)f->Tell();
212 for (size_t i = 0; i < contentcount; i++)
213 {
214 if (AppendCentralDirectory(f, content[i], dostime, positions[i]) < 0)
215 {
216 delete f;
217 RemoveFile(filename);
218 return false;
219 }
220 }
221
222 // Write the directory terminator.
223 FZipEndOfCentralDirectory dirend;
224 dirend.Magic = ZIP_ENDOFDIR;
225 dirend.DiskNumber = 0;
226 dirend.FirstDisk = 0;
227 dirend.NumEntriesOnAllDisks = dirend.NumEntries = LittleShort((uint16_t)contentcount);
228 dirend.DirectoryOffset = LittleLong((unsigned)dirofs);
229 dirend.DirectorySize = LittleLong((uint32_t)(f->Tell() - dirofs));
230 dirend.ZipCommentLength = 0;
231 if (f->Write(&dirend, sizeof(dirend)) != sizeof(dirend))
232 {
233 delete f;
234 RemoveFile(filename);
235 return false;
236 }
237 delete f;
238 return true;
239 }
240 return false;
241}

Callers 1

WriteSavegameFunction · 0.85

Calls 10

OpenFunction · 0.85
AppendToZipFunction · 0.85
RemoveFileFunction · 0.85
AppendCentralDirectoryFunction · 0.85
time_to_dosFunction · 0.70
LittleShortFunction · 0.70
LittleLongFunction · 0.70
PushMethod · 0.45
TellMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected