MCPcopy Create free account
hub / github.com/diasurgical/devilution / SFileFlushArchive

Function SFileFlushArchive

3rdParty/StormLib/src/SFileOpenArchive.cpp:501–586  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

499//
500
501bool STORMAPI SFileFlushArchive(HANDLE hMpq)
502{
503 TMPQArchive * ha;
504 int nResultError = ERROR_SUCCESS;
505 int nError;
506
507 // Do nothing if 'hMpq' is bad parameter
508 if((ha = IsValidMpqHandle(hMpq)) == NULL)
509 {
510 SetLastError(ERROR_INVALID_HANDLE);
511 return false;
512 }
513
514 // Only if the MPQ was changed
515 if(ha->dwFlags & MPQ_FLAG_CHANGED)
516 {
517 // Indicate that we are saving MPQ internal structures
518 ha->dwFlags |= MPQ_FLAG_SAVING_TABLES;
519
520 // Defragment the file table. This will allow us to put the internal files to the end
521 DefragmentFileTable(ha);
522
523 //
524 // Create each internal file
525 // Note that the (signature) file is usually before (listfile) in the file table
526 //
527
528 if(ha->dwFlags & MPQ_FLAG_SIGNATURE_NEW)
529 {
530#ifdef FULL
531 nError = SSignFileCreate(ha);
532 if(nError != ERROR_SUCCESS)
533 nResultError = nError;
534#else
535 assert(0);
536#endif
537 }
538
539 if(ha->dwFlags & MPQ_FLAG_LISTFILE_NEW)
540 {
541 nError = SListFileSaveToMpq(ha);
542 if(nError != ERROR_SUCCESS)
543 nResultError = nError;
544 }
545
546 if(ha->dwFlags & MPQ_FLAG_ATTRIBUTES_NEW)
547 {
548 nError = SAttrFileSaveToMpq(ha);
549 if(nError != ERROR_SUCCESS)
550 nResultError = nError;
551 }
552
553 // Save HET table, BET table, hash table, block table, hi-block table
554 if(ha->dwFlags & MPQ_FLAG_CHANGED)
555 {
556 // Rebuild the HET table
557 if(ha->pHetTable != NULL)
558 RebuildHetTable(ha);

Callers 1

SFileCloseArchiveFunction · 0.85

Calls 5

IsValidMpqHandleFunction · 0.85
SetLastErrorFunction · 0.85
DefragmentFileTableFunction · 0.85
RebuildHetTableFunction · 0.85
SaveMPQTablesFunction · 0.85

Tested by

no test coverage detected