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

Function mpqapi_add_file

Source/mpqapi.cpp:451–479  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

449}
450
451_BLOCKENTRY *mpqapi_add_file(const char *pszName, _BLOCKENTRY *pBlk, int block_index)
452{
453 DWORD h1, h2, h3;
454 int i, hIdx;
455
456 h1 = Hash(pszName, 0);
457 h2 = Hash(pszName, 1);
458 h3 = Hash(pszName, 2);
459 if (mpqapi_get_hash_index(h1, h2, h3, 0) != -1)
460 app_fatal("Hash collision between \"%s\" and existing file\n", pszName);
461 hIdx = h1 & 0x7FF;
462 i = 2048;
463 while (i--) {
464 if (cur_archive.sgpHashTbl[hIdx].block == -1 || cur_archive.sgpHashTbl[hIdx].block == -2)
465 break;
466 hIdx = (hIdx + 1) & 0x7FF;
467 }
468 if (i < 0)
469 app_fatal("Out of hash space");
470 if (!pBlk)
471 pBlk = mpqapi_new_block(&block_index);
472
473 cur_archive.sgpHashTbl[hIdx].hashcheck[0] = h2;
474 cur_archive.sgpHashTbl[hIdx].hashcheck[1] = h3;
475 cur_archive.sgpHashTbl[hIdx].lcid = 0;
476 cur_archive.sgpHashTbl[hIdx].block = block_index;
477
478 return pBlk;
479}
480
481BOOL mpqapi_write_file_contents(const char *pszName, const BYTE *pbData, DWORD dwLen, _BLOCKENTRY *pBlk)
482{

Callers 2

mpqapi_write_fileFunction · 0.85
mpqapi_renameFunction · 0.85

Calls 4

HashFunction · 0.85
mpqapi_get_hash_indexFunction · 0.85
app_fatalFunction · 0.85
mpqapi_new_blockFunction · 0.85

Tested by

no test coverage detected