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

Function LoadFileToMemory

src/External/CascLib/src/CascFiles.cpp:1789–1839  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1787}
1788
1789DWORD LoadFileToMemory(LPCTSTR szFileName, CASC_BLOB & FileData)
1790{
1791 TFileStream * pStream;
1792 ULONGLONG FileSize = 0;
1793 DWORD dwErrCode = ERROR_SUCCESS;
1794
1795 // Open the stream for read-only access and read the file
1796 pStream = FileStream_OpenFile(szFileName, STREAM_FLAG_READ_ONLY | STREAM_FLAG_WRITE_SHARE | STREAM_PROVIDER_FLAT | BASE_PROVIDER_FILE);
1797 if(pStream != NULL)
1798 {
1799 // Retrieve the file size
1800 FileStream_GetSize(pStream, &FileSize);
1801
1802 // Do not load zero files or too large files
1803 if(0 < FileSize && FileSize <= 0x2000000)
1804 {
1805 // Allocate file data buffer. Make it 1 byte longer
1806 // so string functions can put '\0' there
1807 dwErrCode = FileData.SetSize((size_t)(FileSize));
1808 if(dwErrCode == ERROR_SUCCESS)
1809 {
1810 if(FileStream_Read(pStream, NULL, FileData.pbData, (DWORD)(FileData.cbData)))
1811 {
1812 // Terminate the data with zero so various string-based functions can process it
1813 FileData.pbData[FileData.cbData] = 0;
1814 }
1815 else
1816 {
1817 dwErrCode = GetCascError();
1818 }
1819 }
1820 else
1821 {
1822 dwErrCode = ERROR_NOT_ENOUGH_MEMORY;
1823 }
1824 }
1825 else
1826 {
1827 dwErrCode = ERROR_BAD_FORMAT;
1828 }
1829
1830 // Close the file stream
1831 FileStream_Close(pStream);
1832 }
1833 else
1834 {
1835 dwErrCode = GetCascError();
1836 }
1837
1838 return dwErrCode;
1839}
1840
1841//-----------------------------------------------------------------------------
1842// Public CDN functions

Callers 7

LoadCsvFileFunction · 0.85
RibbitDownloadFileFunction · 0.85
CreateMapOfRealNamesMethod · 0.85
LoadLocalIndexFilesFunction · 0.85
LoadArchiveIndexFilesFunction · 0.85
LoadMethod · 0.85

Calls 6

FileStream_OpenFileFunction · 0.85
FileStream_GetSizeFunction · 0.85
FileStream_ReadFunction · 0.85
GetCascErrorFunction · 0.85
FileStream_CloseFunction · 0.85
SetSizeMethod · 0.80

Tested by

no test coverage detected