MCPcopy Create free account
hub / github.com/Scobalula/Greyhound / LoadInternalFileToMemory

Function LoadInternalFileToMemory

src/External/CascLib/src/CascFiles.cpp:1727–1787  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1725}
1726
1727DWORD LoadInternalFileToMemory(TCascStorage * hs, PCASC_CKEY_ENTRY pCKeyEntry, CASC_BLOB & FileData)
1728{
1729 HANDLE hFile = NULL;
1730 DWORD dwFileSizeHi = 0;
1731 DWORD cbFileData = 0;
1732 DWORD dwBytesRead = 0;
1733 DWORD dwErrCode = ERROR_SUCCESS;
1734
1735 // Open the file either by CKey or by EKey
1736 if(OpenFileByCKeyEntry(hs, pCKeyEntry, CASC_STRICT_DATA_CHECK, &hFile))
1737 {
1738 // Make the file not cached. We always load the entire file to memory,
1739 // so no need to cache (and needlessly copy from one buffer to another)
1740 SetCacheStrategy(hFile, CascCacheNothing);
1741
1742 // Retrieve the size of the file. Note that the caller might specify
1743 // the real size of the file, in case the file size is not retrievable
1744 // or if the size is wrong. Example: ENCODING file has size specified in BUILD
1745 if(pCKeyEntry->ContentSize == CASC_INVALID_SIZE)
1746 {
1747 cbFileData = CascGetFileSize(hFile, &dwFileSizeHi);
1748 if(cbFileData == CASC_INVALID_SIZE || dwFileSizeHi != 0)
1749 dwErrCode = ERROR_FILE_CORRUPT;
1750 }
1751 else
1752 {
1753 cbFileData = pCKeyEntry->ContentSize;
1754 }
1755
1756 // Load the entire file to memory
1757 if(dwErrCode == ERROR_SUCCESS)
1758 {
1759 // Allocate space for the ENCODING file
1760 if((dwErrCode = FileData.SetSize(cbFileData)) == ERROR_SUCCESS)
1761 {
1762 // Read the entire file to memory
1763 CascReadFile(hFile, FileData.pbData, cbFileData, &dwBytesRead);
1764 if(dwBytesRead != cbFileData)
1765 {
1766 dwErrCode = ERROR_FILE_CORRUPT;
1767 }
1768 }
1769 else
1770 {
1771 dwErrCode = ERROR_NOT_ENOUGH_MEMORY;
1772 }
1773 }
1774
1775 // Close the file
1776 CascCloseFile(hFile);
1777 }
1778 else
1779 {
1780 dwErrCode = GetCascError();
1781 }
1782
1783 // Handle errors
1784 if(dwErrCode != ERROR_SUCCESS)

Callers 9

LoadEncodingManifestFunction · 0.85
LoadDownloadManifestFunction · 0.85
LoadInstallManifestFunction · 0.85
LoadBuildManifestFunction · 0.85
LoadFileToMemoryMethod · 0.85
LoadDirectoryFileMethod · 0.85
IsVfsSubDirectoryMethod · 0.85
LoadContentManifestFileFunction · 0.85

Calls 8

OpenFileByCKeyEntryFunction · 0.85
SetCacheStrategyFunction · 0.85
CascGetFileSizeFunction · 0.85
CascReadFileFunction · 0.85
CascCloseFileFunction · 0.85
GetCascErrorFunction · 0.85
SetSizeMethod · 0.80
FreeMethod · 0.45

Tested by

no test coverage detected