ManaPlus
Functions
VirtFs::FsZip Namespace Reference

Functions

FsFuncsgetFuncs ()
 
void deinit ()
 
void init ()
 
void initFuncs (FsFuncs *const ptr)
 
bool getRealDir (FsEntry *const entry, std::string filename, std::string dirName, std::string &realDir)
 
bool exists (FsEntry *const entry, std::string filename, std::string dirName)
 
void enumerate (FsEntry *const entry, std::string dirName, StringVect &names)
 
void getFiles (FsEntry *const entry, std::string dirName, StringVect &names)
 
void getFilesWithDir (FsEntry *const entry, const std::string &dirName, StringVect &names)
 
void getDirs (FsEntry *const entry, std::string dirName, StringVect &names)
 
bool isDirectory (FsEntry *const entry, std::string dirName, bool &isDirFlag)
 
void freeList (List *const handle)
 
FileopenRead (FsEntry *const entry, std::string filename)
 
FileopenWrite (FsEntry *const entry, const std::string &filename)
 
FileopenAppend (FsEntry *const entry, const std::string &filename)
 
int close (File *const file)
 
int64_t read (File *const file, void *const buffer, const uint32_t objSize, const uint32_t objCount)
 
int64_t write (File *const file, const void *const buffer, const uint32_t objSize, const uint32_t objCount)
 
int64_t fileLength (File *const file)
 
int64_t tell (File *const file)
 
int seek (File *const file, const uint64_t pos)
 
int eof (File *const file)
 
const char * loadFile (FsEntry *const entry, std::string filename, int &fileSize)
 
FileopenReadInternal (const std::string &filename)
 
int32_t rwops_seek (SDL_RWops *const rw, const int32_t offset, const int whence)
 
int rwops_read (SDL_RWops *const rw, void *const ptr, const int size, const int maxnum)
 
int rwops_write (SDL_RWops *const rw, const void *const ptr, const int size, const int num)
 
int rwops_close (SDL_RWops *const rw)
 

Function Documentation

◆ close()

int VirtFs::FsZip::close ( File *const  file)

Definition at line 583 of file fszip.cpp.

584  {
585  if (file == nullptr)
586  return 0;
587  delete file;
588  return 1;
589  }

Referenced by initFuncs().

◆ deinit()

void VirtFs::FsZip::deinit ( )

Definition at line 56 of file fszip.cpp.

57  {
58  }

Referenced by VirtFs::deinit().

◆ enumerate()

void VirtFs::FsZip::enumerate ( FsEntry *const  entry,
std::string  dirName,
StringVect names 
)

Definition at line 157 of file fszip.cpp.

160  {
161  ZipEntry *const zipEntry = static_cast<ZipEntry*>(entry);
162  const std::string subDir = zipEntry->subDir;
163  if (!subDir.empty())
164  dirName = pathJoin(subDir, dirName);
165  if (dirName == dirSeparator)
166  {
167  FOR_EACH (STD_VECTOR<ZipLocalHeader*>::const_iterator,
168  it2,
169  zipEntry->mHeaders)
170  {
171  ZipLocalHeader *const header = *it2;
172  std::string fileName = header->fileName;
173  // skip subdirs from enumeration
174  const size_t idx = fileName.find(dirSeparator);
175  if (idx != std::string::npos)
176  fileName.erase(idx);
177  bool found(false);
178  FOR_EACH (StringVectCIter, itn, names)
179  {
180  if (*itn == fileName)
181  {
182  found = true;
183  break;
184  }
185  }
186  if (found == false)
187  names.push_back(fileName);
188  }
189  }
190  else
191  {
192  FOR_EACH (STD_VECTOR<ZipLocalHeader*>::const_iterator,
193  it2,
194  zipEntry->mHeaders)
195  {
196  ZipLocalHeader *const header = *it2;
197  std::string fileName = header->fileName;
198  if (findCutFirst(fileName, dirName) == true)
199  {
200  // skip subdirs from enumeration
201  const size_t idx = fileName.find(dirSeparator);
202  if (idx != std::string::npos)
203  fileName.erase(idx);
204  bool found(false);
205  FOR_EACH (StringVectCIter, itn, names)
206  {
207  if (*itn == fileName)
208  {
209  found = true;
210  break;
211  }
212  }
213  if (found == false)
214  names.push_back(fileName);
215  }
216  }
217  }
218  }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:25
const char * dirSeparator
Definition: fs.cpp:43
bool findCutFirst(std::string &str1, const std::string &str2)
std::string pathJoin(std::string str1, const std::string &str2)
StringVect::const_iterator StringVectCIter
Definition: stringvector.h:31
std::string fileName
Definition: testmain.cpp:39

References dirSeparator, VirtFs::ZipLocalHeader::fileName, fileName, findCutFirst(), FOR_EACH, VirtFs::ZipEntry::mHeaders, pathJoin(), and VirtFs::FsEntry::subDir.

Referenced by initFuncs().

◆ eof()

int VirtFs::FsZip::eof ( File *const  file)

Definition at line 666 of file fszip.cpp.

667  {
668  if (file == nullptr)
669  return -1;
670 
671  return static_cast<int>(file->mPos >= file->mSize);
672  }

Referenced by initFuncs().

◆ exists()

bool VirtFs::FsZip::exists ( FsEntry *const  entry,
std::string  filename,
std::string  dirName 
)

Definition at line 129 of file fszip.cpp.

132  {
133  ZipEntry *const zipEntry = static_cast<ZipEntry*>(entry);
134  std::string subDir = zipEntry->subDir;
135  if (!subDir.empty())
136  {
137  filename = pathJoin(subDir, filename);
138  dirName = pathJoin(subDir, dirName);
139  }
140  FOR_EACH (STD_VECTOR<ZipLocalHeader*>::const_iterator,
141  it2,
142  zipEntry->mHeaders)
143  {
144  if ((*it2)->fileName == filename)
145  return true;
146  }
147  FOR_EACH (STD_VECTOR<std::string>::const_iterator,
148  it2,
149  zipEntry->mDirs)
150  {
151  if (*it2 == dirName)
152  return true;
153  }
154  return false;
155  }

References FOR_EACH, VirtFs::ZipEntry::mDirs, VirtFs::ZipEntry::mHeaders, pathJoin(), and VirtFs::FsEntry::subDir.

Referenced by initFuncs().

◆ fileLength()

int64_t VirtFs::FsZip::fileLength ( File *const  file)

Definition at line 638 of file fszip.cpp.

639  {
640  if (file == nullptr)
641  return -1;
642 
643  return file->mSize;
644  }

Referenced by initFuncs().

◆ freeList()

void VirtFs::FsZip::freeList ( List *const  handle)

Definition at line 538 of file fszip.cpp.

539  {
540  delete handle;
541  }

◆ getDirs()

void VirtFs::FsZip::getDirs ( FsEntry *const  entry,
std::string  dirName,
StringVect names 
)

Definition at line 419 of file fszip.cpp.

422  {
423  ZipEntry *const zipEntry = static_cast<ZipEntry*>(entry);
424  const std::string subDir = zipEntry->subDir;
425  if (!subDir.empty())
426  dirName = pathJoin(subDir, dirName);
427  if (dirName == dirSeparator)
428  {
429  FOR_EACH (STD_VECTOR<ZipLocalHeader*>::const_iterator,
430  it2,
431  zipEntry->mHeaders)
432  {
433  ZipLocalHeader *const header = *it2;
434  std::string fileName = header->fileName;
435  // skip subdirs from enumeration
436  const size_t idx = fileName.find(dirSeparator);
437  if (idx != std::string::npos)
438  fileName.erase(idx);
439  bool found(false);
440  FOR_EACH (StringVectCIter, itn, names)
441  {
442  if (*itn == fileName)
443  {
444  found = true;
445  break;
446  }
447  }
448  if (found == false)
449  {
450  std::string dirName2 = pathJoin(dirName, fileName);
451  if (findLast(dirName2, std::string(dirSeparator)) == false)
452  dirName2 += dirSeparator;
453  FOR_EACH (STD_VECTOR<std::string>::const_iterator,
454  it,
455  zipEntry->mDirs)
456  {
457  if (*it == dirName2)
458  {
459  found = true;
460  break;
461  }
462  }
463  if (found == true)
464  names.push_back(fileName);
465  }
466  }
467  }
468  else
469  {
470  FOR_EACH (STD_VECTOR<ZipLocalHeader*>::const_iterator,
471  it2,
472  zipEntry->mHeaders)
473  {
474  ZipLocalHeader *const header = *it2;
475  std::string fileName = header->fileName;
476  if (findCutFirst(fileName, dirName) == true)
477  {
478  // skip subdirs from enumeration
479  const size_t idx = fileName.find(dirSeparator);
480  if (idx != std::string::npos)
481  fileName.erase(idx);
482  bool found(false);
483  FOR_EACH (StringVectCIter, itn, names)
484  {
485  if (*itn == fileName)
486  {
487  found = true;
488  break;
489  }
490  }
491  if (found == false)
492  {
493  std::string dirName2 = pathJoin(dirName, fileName);
494  if (findLast(dirName2, std::string(dirSeparator)) ==
495  false)
496  {
497  dirName2 += dirSeparator;
498  }
499  FOR_EACH (STD_VECTOR<std::string>::const_iterator,
500  it,
501  zipEntry->mDirs)
502  {
503  if (*it == dirName2)
504  {
505  found = true;
506  break;
507  }
508  }
509  if (found == true)
510  names.push_back(fileName);
511  }
512  }
513  }
514  }
515  }
bool findLast(const std::string &str1, const std::string &str2)

References dirSeparator, VirtFs::ZipLocalHeader::fileName, fileName, findCutFirst(), findLast(), FOR_EACH, VirtFs::ZipEntry::mDirs, VirtFs::ZipEntry::mHeaders, pathJoin(), and VirtFs::FsEntry::subDir.

Referenced by initFuncs().

◆ getFiles()

void VirtFs::FsZip::getFiles ( FsEntry *const  entry,
std::string  dirName,
StringVect names 
)

Definition at line 220 of file fszip.cpp.

223  {
224  ZipEntry *const zipEntry = static_cast<ZipEntry*>(entry);
225  const std::string subDir = zipEntry->subDir;
226  if (!subDir.empty())
227  dirName = pathJoin(subDir, dirName);
228  if (dirName == dirSeparator)
229  {
230  FOR_EACH (STD_VECTOR<ZipLocalHeader*>::const_iterator,
231  it2,
232  zipEntry->mHeaders)
233  {
234  ZipLocalHeader *const header = *it2;
235  std::string fileName = header->fileName;
236  // skip subdirs from enumeration
237  const size_t idx = fileName.find(dirSeparator);
238  if (idx != std::string::npos)
239  fileName.erase(idx);
240  bool found(false);
241  FOR_EACH (StringVectCIter, itn, names)
242  {
243  if (*itn == fileName)
244  {
245  found = true;
246  break;
247  }
248  }
249  if (found == false)
250  {
251  std::string dirName2 = pathJoin(dirName, fileName);
252  if (findLast(dirName2, std::string(dirSeparator)) == false)
253  dirName2 += dirSeparator;
254  FOR_EACH (STD_VECTOR<std::string>::const_iterator,
255  it,
256  zipEntry->mDirs)
257  {
258  if (*it == dirName2)
259  {
260  found = true;
261  break;
262  }
263  }
264  if (found == false)
265  names.push_back(fileName);
266  }
267  }
268  }
269  else
270  {
271  FOR_EACH (STD_VECTOR<ZipLocalHeader*>::const_iterator,
272  it2,
273  zipEntry->mHeaders)
274  {
275  ZipLocalHeader *const header = *it2;
276  std::string fileName = header->fileName;
277  if (findCutFirst(fileName, dirName) == true)
278  {
279  // skip subdirs from enumeration
280  const size_t idx = fileName.find(dirSeparator);
281  if (idx != std::string::npos)
282  fileName.erase(idx);
283  bool found(false);
284  FOR_EACH (StringVectCIter, itn, names)
285  {
286  if (*itn == fileName)
287  {
288  found = true;
289  break;
290  }
291  }
292  if (found == false)
293  {
294  std::string dirName2 = pathJoin(dirName, fileName);
295  if (findLast(dirName2, std::string(dirSeparator)) ==
296  false)
297  {
298  dirName2 += dirSeparator;
299  }
300  FOR_EACH (STD_VECTOR<std::string>::const_iterator,
301  it,
302  zipEntry->mDirs)
303  {
304  if (*it == dirName2)
305  {
306  found = true;
307  break;
308  }
309  }
310  if (found == false)
311  names.push_back(fileName);
312  }
313  }
314  }
315  }
316  }

References dirSeparator, VirtFs::ZipLocalHeader::fileName, fileName, findCutFirst(), findLast(), FOR_EACH, VirtFs::ZipEntry::mDirs, VirtFs::ZipEntry::mHeaders, pathJoin(), and VirtFs::FsEntry::subDir.

Referenced by initFuncs().

◆ getFilesWithDir()

void VirtFs::FsZip::getFilesWithDir ( FsEntry *const  entry,
const std::string &  dirName,
StringVect names 
)

Definition at line 318 of file fszip.cpp.

321  {
322  ZipEntry *const zipEntry = static_cast<ZipEntry*>(entry);
323  const std::string subDir = zipEntry->subDir;
324  std::string dirNameFull;
325  if (!subDir.empty())
326  dirNameFull = pathJoin(subDir, dirName);
327  else
328  dirNameFull = dirName;
329  if (dirNameFull == dirSeparator)
330  {
331  FOR_EACH (STD_VECTOR<ZipLocalHeader*>::const_iterator,
332  it2,
333  zipEntry->mHeaders)
334  {
335  ZipLocalHeader *const header = *it2;
336  std::string fileName = header->fileName;
337  // skip subdirs from enumeration
338  const size_t idx = fileName.find(dirSeparator);
339  if (idx != std::string::npos)
340  fileName.erase(idx);
341  bool found(false);
342  FOR_EACH (StringVectCIter, itn, names)
343  {
344  if (*itn == fileName)
345  {
346  found = true;
347  break;
348  }
349  }
350  if (found == false)
351  {
352  std::string dirName2 = pathJoin(dirNameFull, fileName);
353  if (findLast(dirName2, std::string(dirSeparator)) == false)
354  dirName2 += dirSeparator;
355  FOR_EACH (STD_VECTOR<std::string>::const_iterator,
356  it,
357  zipEntry->mDirs)
358  {
359  if (*it == dirName2)
360  {
361  found = true;
362  break;
363  }
364  }
365  if (found == false)
366  names.push_back(pathJoin(dirName, fileName));
367  }
368  }
369  }
370  else
371  {
372  FOR_EACH (STD_VECTOR<ZipLocalHeader*>::const_iterator,
373  it2,
374  zipEntry->mHeaders)
375  {
376  ZipLocalHeader *const header = *it2;
377  std::string fileName = header->fileName;
378  if (findCutFirst(fileName, dirNameFull) == true)
379  {
380  // skip subdirs from enumeration
381  const size_t idx = fileName.find(dirSeparator);
382  if (idx != std::string::npos)
383  fileName.erase(idx);
384  bool found(false);
385  FOR_EACH (StringVectCIter, itn, names)
386  {
387  if (*itn == fileName)
388  {
389  found = true;
390  break;
391  }
392  }
393  if (found == false)
394  {
395  std::string dirName2 = pathJoin(dirNameFull, fileName);
396  if (findLast(dirName2, std::string(dirSeparator)) ==
397  false)
398  {
399  dirName2 += dirSeparator;
400  }
401  FOR_EACH (STD_VECTOR<std::string>::const_iterator,
402  it,
403  zipEntry->mDirs)
404  {
405  if (*it == dirName2)
406  {
407  found = true;
408  break;
409  }
410  }
411  if (found == false)
412  names.push_back(pathJoin(dirName, fileName));
413  }
414  }
415  }
416  }
417  }

References dirSeparator, VirtFs::ZipLocalHeader::fileName, fileName, findCutFirst(), findLast(), FOR_EACH, VirtFs::ZipEntry::mDirs, VirtFs::ZipEntry::mHeaders, pathJoin(), and VirtFs::FsEntry::subDir.

Referenced by initFuncs().

◆ getFuncs()

FsFuncs * VirtFs::FsZip::getFuncs ( )

Definition at line 51 of file fszip.cpp.

52  {
53  return &funcs;
54  }
VirtFs::FsFuncs funcs
Definition: fszip.cpp:43

References anonymous_namespace{fszip.cpp}::funcs.

Referenced by VirtFs::mountZip(), and VirtFs::mountZip2().

◆ getRealDir()

bool VirtFs::FsZip::getRealDir ( FsEntry *const  entry,
std::string  filename,
std::string  dirName,
std::string &  realDir 
)

Definition at line 94 of file fszip.cpp.

98  {
99  ZipEntry *const zipEntry = static_cast<ZipEntry*>(entry);
100  std::string subDir = zipEntry->subDir;
101  if (!subDir.empty())
102  {
103  filename = pathJoin(subDir, filename);
104  dirName = pathJoin(subDir, dirName);
105  }
106  FOR_EACH (STD_VECTOR<ZipLocalHeader*>::const_iterator,
107  it2,
108  zipEntry->mHeaders)
109  {
110  if ((*it2)->fileName == filename)
111  {
112  realDir = entry->root;
113  return true;
114  }
115  }
116  FOR_EACH (STD_VECTOR<std::string>::const_iterator,
117  it2,
118  zipEntry->mDirs)
119  {
120  if (*it2 == dirName)
121  {
122  realDir = entry->root;
123  return true;
124  }
125  }
126  return false;
127  }

References FOR_EACH, VirtFs::ZipEntry::mDirs, VirtFs::ZipEntry::mHeaders, pathJoin(), and VirtFs::FsEntry::subDir.

Referenced by initFuncs().

◆ init()

void VirtFs::FsZip::init ( )

Definition at line 60 of file fszip.cpp.

61  {
62  initFuncs(&funcs);
63  }
void initFuncs(FsFuncs *const ptr)
Definition: fszip.cpp:65

References anonymous_namespace{fszip.cpp}::funcs, and initFuncs().

Referenced by VirtFs::init().

◆ initFuncs()

void VirtFs::FsZip::initFuncs ( FsFuncs *const  ptr)

Definition at line 65 of file fszip.cpp.

66  {
67  ptr->close = &FsZip::close;
68  ptr->read = &FsZip::read;
69  ptr->write = &FsZip::write;
70  ptr->fileLength = &FsZip::fileLength;
71  ptr->tell = &FsZip::tell;
72  ptr->seek = &FsZip::seek;
73  ptr->eof = &FsZip::eof;
74  ptr->exists = &FsZip::exists;
75  ptr->getRealDir = &FsZip::getRealDir;
76  ptr->enumerate = &FsZip::enumerate;
77  ptr->isDirectory = &FsZip::isDirectory;
78  ptr->openRead = &FsZip::openRead;
79  ptr->openWrite = &FsZip::openWrite;
80  ptr->openAppend = &FsZip::openAppend;
81  ptr->loadFile = &FsZip::loadFile;
82  ptr->getFiles = &FsZip::getFiles;
83  ptr->getFilesWithDir = &FsZip::getFilesWithDir;
84  ptr->getDirs = &FsZip::getDirs;
85  ptr->rwops_seek = &FsZip::rwops_seek;
86  ptr->rwops_read = &FsZip::rwops_read;
87  ptr->rwops_write = &FsZip::rwops_write;
88  ptr->rwops_close = &FsZip::rwops_close;
89 #ifdef USE_SDL2
90  ptr->rwops_size = &FsZip::rwops_size;
91 #endif // USE_SDL2
92  }
int rwops_write(SDL_RWops *const rw, const void *const ptr, const int size, const int maxnum)
Definition: fsdirrwops.cpp:196
int32_t rwops_seek(SDL_RWops *const rw, const int32_t offset, const int whence)
Definition: fsdirrwops.cpp:41
int rwops_close(SDL_RWops *const rw)
Definition: fsdirrwops.cpp:233
int rwops_read(SDL_RWops *const rw, void *const ptr, const int size, const int maxnum)
Definition: fsdirrwops.cpp:160
File * openWrite(FsEntry *const entry, const std::string &filename)
Definition: fszip.cpp:569
bool isDirectory(FsEntry *const entry, std::string dirName, bool &isDirFlag)
Definition: fszip.cpp:517
void getDirs(FsEntry *const entry, std::string dirName, StringVect &names)
Definition: fszip.cpp:419
void enumerate(FsEntry *const entry, std::string dirName, StringVect &names)
Definition: fszip.cpp:157
void getFiles(FsEntry *const entry, std::string dirName, StringVect &names)
Definition: fszip.cpp:220
const char * loadFile(FsEntry *const entry, std::string filename, int &fileSize)
Definition: fszip.cpp:674
bool getRealDir(FsEntry *const entry, std::string filename, std::string dirName, std::string &realDir)
Definition: fszip.cpp:94
int seek(File *const file, const uint64_t pos)
Definition: fszip.cpp:654
File * openAppend(FsEntry *const entry, const std::string &filename)
Definition: fszip.cpp:576
int64_t tell(File *const file)
Definition: fszip.cpp:646
void getFilesWithDir(FsEntry *const entry, const std::string &dirName, StringVect &names)
Definition: fszip.cpp:318
bool exists(FsEntry *const entry, std::string filename, std::string dirName)
Definition: fszip.cpp:129
int64_t read(File *const file, void *const buffer, const uint32_t objSize, const uint32_t objCount)
Definition: fszip.cpp:591
int64_t write(File *const file, const void *const buffer, const uint32_t objSize, const uint32_t objCount)
Definition: fszip.cpp:630
int eof(File *const file)
Definition: fszip.cpp:666
int64_t fileLength(File *const file)
Definition: fszip.cpp:638
File * openRead(FsEntry *const entry, std::string filename)
Definition: fszip.cpp:543
int close(File *const file)
Definition: fszip.cpp:583

References close(), enumerate(), eof(), exists(), fileLength(), getDirs(), getFiles(), getFilesWithDir(), getRealDir(), isDirectory(), loadFile(), openAppend(), openRead(), openWrite(), read(), rwops_close(), rwops_read(), rwops_seek(), rwops_write(), seek(), tell(), and write().

Referenced by init().

◆ isDirectory()

bool VirtFs::FsZip::isDirectory ( FsEntry *const  entry,
std::string  dirName,
bool &  isDirFlag 
)

Definition at line 517 of file fszip.cpp.

520  {
521  ZipEntry *const zipEntry = static_cast<ZipEntry*>(entry);
522  std::string subDir = zipEntry->subDir;
523  if (!subDir.empty())
524  dirName = pathJoin(subDir, dirName);
525  FOR_EACH (STD_VECTOR<std::string>::const_iterator,
526  it2,
527  zipEntry->mDirs)
528  {
529  if (*it2 == dirName)
530  {
531  isDirFlag = true;
532  return true;
533  }
534  }
535  return false;
536  }

References FOR_EACH, VirtFs::ZipEntry::mDirs, pathJoin(), and VirtFs::FsEntry::subDir.

Referenced by initFuncs().

◆ loadFile()

const char * VirtFs::FsZip::loadFile ( FsEntry *const  entry,
std::string  filename,
int &  fileSize 
)

Definition at line 674 of file fszip.cpp.

677  {
678  ZipEntry *const zipEntry = static_cast<ZipEntry*>(entry);
679  const std::string subDir = zipEntry->subDir;
680  if (!subDir.empty())
681  filename = pathJoin(subDir, filename);
682  FOR_EACH (STD_VECTOR<ZipLocalHeader*>::const_iterator,
683  it2,
684  zipEntry->mHeaders)
685  {
686  const ZipLocalHeader *restrict const header = *it2;
687  if (header->fileName == filename)
688  {
689  const uint8_t *restrict const buf =
690  ZipReader::readFile(header);
691  if (buf == nullptr)
692  return nullptr;
693 
694  logger->log("Loaded %s/%s",
695  entry->root.c_str(),
696  filename.c_str());
697 
698  fileSize = header->uncompressSize;
699  return reinterpret_cast<const char*>(buf);
700  }
701  }
702  return nullptr;
703  }
void log(const char *const log_text,...)
Definition: logger.cpp:269
#define restrict
Definition: localconsts.h:165
Logger * logger
Definition: logger.cpp:89
uint8_t * readFile(ZipLocalHeader *header)
Definition: zipreader.cpp:276

References FOR_EACH, Logger::log(), logger, VirtFs::ZipEntry::mHeaders, pathJoin(), VirtFs::ZipReader::readFile(), restrict, and VirtFs::FsEntry::subDir.

Referenced by initFuncs().

◆ openAppend()

File * VirtFs::FsZip::openAppend ( FsEntry *const  entry,
const std::string &  filename 
)

Definition at line 576 of file fszip.cpp.

578  {
579  reportAlways("VirtFs::openAppend for zip not implemented.")
580  return nullptr;
581  }
#define reportAlways(...)
Definition: checkutils.h:253

References reportAlways.

Referenced by initFuncs().

◆ openRead()

File * VirtFs::FsZip::openRead ( FsEntry *const  entry,
std::string  filename 
)

Definition at line 543 of file fszip.cpp.

545  {
546  ZipEntry *const zipEntry = static_cast<ZipEntry*>(entry);
547  std::string subDir = zipEntry->subDir;
548  if (!subDir.empty())
549  filename = pathJoin(subDir, filename);
550  FOR_EACH (STD_VECTOR<ZipLocalHeader*>::const_iterator,
551  it2,
552  zipEntry->mHeaders)
553  {
554  const ZipLocalHeader *restrict const header = *it2;
555  if (header->fileName == filename)
556  {
557  const uint8_t *restrict const buf =
558  ZipReader::readFile(header);
559  if (buf == nullptr)
560  return nullptr;
561  return new File(&funcs,
562  buf,
563  header->uncompressSize);
564  }
565  }
566  return nullptr;
567  }

References FOR_EACH, anonymous_namespace{fszip.cpp}::funcs, VirtFs::ZipEntry::mHeaders, pathJoin(), VirtFs::ZipReader::readFile(), restrict, and VirtFs::FsEntry::subDir.

Referenced by initFuncs().

◆ openReadInternal()

File* VirtFs::FsZip::openReadInternal ( const std::string &  filename)

◆ openWrite()

File * VirtFs::FsZip::openWrite ( FsEntry *const  entry,
const std::string &  filename 
)

Definition at line 569 of file fszip.cpp.

571  {
572  reportAlways("VirtFs::openWrite for zip not implemented.")
573  return nullptr;
574  }

References reportAlways.

Referenced by initFuncs().

◆ read()

int64_t VirtFs::FsZip::read ( File *const  file,
void *const  buffer,
const uint32_t  objSize,
const uint32_t  objCount 
)

Definition at line 591 of file fszip.cpp.

595  {
596  if (file == nullptr ||
597  objSize == 0 ||
598  objCount == 0)
599  {
600  return 0;
601  }
602  if (buffer == nullptr)
603  {
604  reportAlways("FsZip::read buffer is null")
605  return 0;
606  }
607  const size_t pos = file->mPos;
608  const size_t sz = file->mSize;
609  // if outside of buffer, return
610  if (pos >= sz)
611  return 0;
612  // pointer to start for buffer ready to read
613  const uint8_t *restrict const memPtr = file->mBuf + pos;
614  // left buffer size from pos to end
615  const uint32_t memSize = CAST_U32(sz - pos);
616  // number of objects possible to read
617  uint32_t memCount = memSize / objSize;
618  if (memCount == 0)
619  return 0;
620  // limit number of possible objects to read to objCount
621  if (memCount > objCount)
622  memCount = objCount;
623  // number of bytes to read from buffer
624  const size_t memEnd = memCount * objSize;
625  memcpy(buffer, memPtr, memEnd);
626  file->mPos += memEnd;
627  return memCount;
628  }
#define CAST_U32
Definition: cast.h:31
if(!vert) return

References CAST_U32, reportAlways, and restrict.

Referenced by initFuncs().

◆ rwops_close()

int VirtFs::FsZip::rwops_close ( SDL_RWops *const  rw)

Definition at line 137 of file fsziprwops.cpp.

138  {
139  if (rw == nullptr)
140  return 0;
141  File *const handle = static_cast<File*>(
142  rw->hidden.unknown.data1);
143  delete handle;
144  SDL_FreeRW(rw);
145  return 0;
146  }

Referenced by initFuncs().

◆ rwops_read()

int VirtFs::FsZip::rwops_read ( SDL_RWops *const  rw,
void *const  ptr,
const int  size,
const int  maxnum 
)

Definition at line 112 of file fsziprwops.cpp.

116  {
117  if (rw == nullptr)
118  return 0;
119  File *const handle = static_cast<File *>(
120  rw->hidden.unknown.data1);
121 
122  const int64_t rc = handle->funcs->read(handle,
123  ptr,
124  CAST_U32(size),
125  CAST_U32(maxnum));
126  return CAST_S32(rc);
127  }
#define CAST_S32
Definition: cast.h:30
int size()
Definition: emotedb.cpp:306

References CAST_S32, CAST_U32, VirtFs::File::funcs, VirtFs::FsFuncs::read, and EmoteDB::size().

Referenced by initFuncs().

◆ rwops_seek()

int32_t VirtFs::FsZip::rwops_seek ( SDL_RWops *const  rw,
const int32_t  offset,
const int  whence 
)

Definition at line 43 of file fsziprwops.cpp.

46  {
47  if (rw == nullptr)
48  return -1;
49  File *const handle = static_cast<File *>(
50  rw->hidden.unknown.data1);
51  const size_t mPos = handle->mPos;
52  const size_t mSize = handle->mSize;
53 
54  RWOPSINT pos = 0;
55 
56  if (whence == SEEK_SET)
57  {
58  pos = offset;
59  }
60  else if (whence == SEEK_CUR)
61  {
62  const int64_t current = mPos;
63  if (current == -1)
64  {
66  "VirtFs::rwops_seek: Can't find position in file.");
67  return -1;
68  }
69 
70  pos = CAST_S32(current);
71  if (static_cast<int64_t>(pos) != current)
72  {
73  logger->assertLog("VirtFs::rwops_seek: "
74  "Can't fit current file position in an int!");
75  return -1;
76  }
77 
78  if (offset == 0) /* this is a "tell" call. We're done. */
79  return pos;
80 
81  pos += offset;
82  }
83  else if (whence == SEEK_END)
84  {
85  pos = static_cast<RWOPSINT>(mSize + offset);
86  }
87  else
88  {
90  "VirtFs::rwops_seek: Invalid 'whence' parameter.");
91  return -1;
92  }
93 
94  if (pos < 0)
95  {
96  logger->assertLog("VirtFs::rwops_seek: "
97  "Attempt to seek past start of file.");
98  return -1;
99  }
100 
101  handle->mPos = pos;
102 
103  if (pos > static_cast<RWOPSINT>(mSize))
104  {
105  logger->assertLog("VirtFs::rwops_seek: seek error.");
106  return -1;
107  }
108 
109  return pos;
110  }
void assertLog(const char *const log_text,...)
Definition: logger.cpp:316
#define RWOPSINT
Definition: rwopstypes.h:31

References Logger::assertLog(), CAST_S32, logger, VirtFs::File::mPos, anonymous_namespace{mrand.cpp}::mPos, VirtFs::File::mSize, and RWOPSINT.

Referenced by initFuncs().

◆ rwops_write()

int VirtFs::FsZip::rwops_write ( SDL_RWops *const  rw,
const void *const  ptr,
const int  size,
const int  num 
)

Definition at line 129 of file fsziprwops.cpp.

133  {
134  return 0;
135  }

Referenced by initFuncs().

◆ seek()

int VirtFs::FsZip::seek ( File *const  file,
const uint64_t  pos 
)

Definition at line 654 of file fszip.cpp.

656  {
657  if (file == nullptr)
658  return 0;
659 
660  if (pos > file->mSize)
661  return 0;
662  file->mPos = pos;
663  return 1;
664  }

Referenced by initFuncs().

◆ tell()

int64_t VirtFs::FsZip::tell ( File *const  file)

Definition at line 646 of file fszip.cpp.

647  {
648  if (file == nullptr)
649  return -1;
650 
651  return file->mPos;
652  }

Referenced by initFuncs().

◆ write()

int64_t VirtFs::FsZip::write ( File *const  file,
const void *const  buffer,
const uint32_t  objSize,
const uint32_t  objCount 
)

Definition at line 630 of file fszip.cpp.

634  {
635  return 0;
636  }

Referenced by initFuncs().