本文整理汇总了C++中SFileReadFile函数的典型用法代码示例。如果您正苦于以下问题:C++ SFileReadFile函数的具体用法?C++ SFileReadFile怎么用?C++ SFileReadFile使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SFileReadFile函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: free
bool FileLoader::loadFile(HANDLE mpq, char* filename, bool log)
{
free();
HANDLE file;
if (!SFileOpenFileEx(mpq, filename, SFILE_OPEN_PATCHED_FILE, &file))
{
if (log)
printf("No such file %s\n", filename);
return false;
}
data_size = SFileGetFileSize(file, NULL);
data = new uint8[data_size];
if (data)
{
SFileReadFile(file, data, data_size, NULL/*bytesRead*/, NULL);
if (prepareLoadedData())
{
SFileCloseFile(file);
return true;
}
}
printf("Error loading %s\n", filename);
SFileCloseFile(file);
free();
return false;
}
示例2: eof
MPQFile::MPQFile(const char* filename):
eof(false),
buffer(0),
pointer(0),
size(0)
{
for(ArchiveSet::const_iterator i=gOpenArchives.archives.begin(); i!=gOpenArchives.archives.end();++i)
{
HANDLE hFile = "";
hMPQ = i->hMPQ;
BOOL succ = SFileOpenFileEx(hMPQ,filename,0, &hFile);
if (succ)
{
DWORD s = SFileGetFileSize(hFile, 0);
if (!s)
{
eof = true;
buffer = 0;
return;
}
size = (size_t)s;
buffer = new char[s];
SFileReadFile(hFile, buffer, s, 0, 0);
SFileCloseFile(hFile);
eof = false;
return;
}
}
eof = true;
buffer = 0;
}
示例3: getFileType
int getFileType(const char *szFileName)
{
if ( !szFileName )
return 0;
int rVal = 0;
HANDLE hMPQ;
HANDLE hFile;
// Open archive for map checking
if ( SFileOpenArchive(szFileName, 0, 0, &hMPQ) && hMPQ )
{
// Open scenario.chk file
if ( SFileOpenFileEx(hMPQ, "staredit\\scenario.chk", SFILE_FROM_MPQ, &hFile) && hFile )
{
rVal = 1;
SFileCloseFile(hFile);
}
// Close archive
SFileCloseArchive(hMPQ);
}
else if ( SFileOpenFileEx(NULL, szFileName, SFILE_FROM_ABSOLUTE, &hFile) && hFile )
{
DWORD dwRead = 0;
char tbuff[16];
DWORD dwSize = SFileGetFileSize(hFile, 0);
// Read file data to check if it's a replay
if ( dwSize > 16 && SFileReadFile(hFile, &tbuff, 16, &dwRead, 0) && dwRead == 16 && *(DWORD*)&tbuff[12] == 'SRer' )
rVal = 2;
// Close file
SFileCloseFile(hFile);
}
return rVal;
}
示例4: IsMatchingPatchFile
static bool IsMatchingPatchFile(
TMPQArchive * ha,
const char * szFileName,
LPBYTE pbFileMd5)
{
MPQ_PATCH_HEADER PatchHeader = {0};
HANDLE hFile = NULL;
DWORD dwTransferred = 0;
bool bResult = false;
// Open the file and load the patch header
if(SFileOpenFileEx((HANDLE)ha, szFileName, SFILE_OPEN_BASE_FILE, &hFile))
{
// Load the patch header
SFileReadFile(hFile, &PatchHeader, sizeof(MPQ_PATCH_HEADER), &dwTransferred, NULL);
BSWAP_ARRAY32_UNSIGNED(pPatchHeader, sizeof(DWORD) * 6);
// If the file contains an incremental patch,
// compare the "MD5 before patching" with the base file MD5
if(dwTransferred == sizeof(MPQ_PATCH_HEADER) && PatchHeader.dwSignature == PATCH_SIGNATURE_HEADER)
bResult = (!memcmp(PatchHeader.md5_before_patch, pbFileMd5, MD5_DIGEST_SIZE));
// Close the file
SFileCloseFile(hFile);
}
return bResult;
}
示例5: FileToBuffer
bool FileToBuffer(MPQHANDLE &hMpq, const std::string &fileName, buffer &buf)
{
if ( hMpq == nullptr )
CHKD_ERR("NULL MPQ file specified for opening %s", fileName.c_str());
else
{
u32 bytesRead = 0;
HANDLE openFile = NULL;
if ( SFileGetFileInfo(hMpq, SFILE_INFO_NUM_FILES) != 0xFFFFFFFF )
{
if ( SFileOpenFileEx(hMpq, fileName.c_str(), SFILE_SEARCH_CURRENT_ONLY, &openFile) )
{
u32 fileSize = (u32)SFileGetFileSize(openFile, NULL);
if ( buf.setSize(fileSize) )
{
buf.sizeUsed = fileSize;
SFileReadFile(openFile, (LPVOID)buf.data, buf.sizeUsed, (LPDWORD)(&bytesRead), NULL);
SFileCloseFile(openFile);
if ( buf.sizeUsed == bytesRead )
return true;
}
else
SFileCloseFile(openFile);
}
else
CHKD_ERR("Failed to get %s from MPQ file", fileName.c_str());
}
else
CHKD_ERR("File is already open", fileName.c_str());
}
return false;
}
示例6: IsMatchingPatchFile
static int IsMatchingPatchFile(
TMPQArchive * ha,
const char * szFileName,
unsigned char * pbFileMd5)
{
MPQ_PATCH_HEADER PatchHeader = {0};
void * hFile = NULL;
size_t dwTransferred = 0;
int bResult = 0;
/* Open the file and load the patch header */
if(SFileOpenFileEx((void *)ha, szFileName, SFILE_OPEN_BASE_FILE, &hFile))
{
/* Load the patch header */
SFileReadFile(hFile, &PatchHeader, sizeof(MPQ_PATCH_HEADER), &dwTransferred);
BSWAP_ARRAY32_UNSIGNED(pPatchHeader, sizeof(uint32_t) * 6);
/* If the file contains an incremental patch, */
/* compare the "MD5 before patching" with the base file MD5 */
if(dwTransferred == sizeof(MPQ_PATCH_HEADER) && PatchHeader.dwSignature == PATCH_SIGNATURE_HEADER)
bResult = (!memcmp(PatchHeader.md5_before_patch, pbFileMd5, MD5_DIGEST_SIZE));
/* Close the file */
SFileCloseFile(hFile);
}
return bResult;
}
示例7: FAfread
size_t FAfread(void * ptr, size_t size, size_t count, FAFile* stream)
{
switch(stream->mode)
{
case FAFile::PlainFile:
return fread(ptr, size, count, stream->data.plainFile.file);
case FAFile::MPQFile:
{
std::lock_guard<std::mutex> lock(m);
DWORD dwBytes = 1;
if(!SFileReadFile(*((HANDLE*)stream->data.mpqFile), ptr, size*count, &dwBytes, NULL))
{
int errorCode = GetLastError();
// if the error code is ERROR_HANDLE_EOF, it's not really an error,
// we just requested a read that goes over the end of the file.
// The normal fread behaviour in this case is to truncate the read to fit within
// the file, and return the actual number of bytes read, which we do,
// so there is no need to print an error message.
if(errorCode != ERROR_HANDLE_EOF)
std::cout << "Error reading from file, error code: " << errorCode << std::endl;
}
return dwBytes;
}
}
return 0;
}
示例8: LoadMpqPatch_COPY
static int LoadMpqPatch_COPY(TMPQFile * hf, TPatchHeader * pPatchHeader)
{
int nError = ERROR_SUCCESS;
// Allocate space for patch header and compressed data
hf->pPatchHeader = (TPatchHeader *)ALLOCMEM(BYTE, pPatchHeader->dwSizeOfPatchData);
if(hf->pPatchHeader == NULL)
nError = ERROR_NOT_ENOUGH_MEMORY;
// Load the patch data and decide if they are compressed or not
if(nError == ERROR_SUCCESS)
{
LPBYTE pbPatchFile = (LPBYTE)hf->pPatchHeader;
// Copy the patch header itself
memcpy(pbPatchFile, pPatchHeader, sizeof(TPatchHeader));
pbPatchFile += sizeof(TPatchHeader);
// Load the rest of the patch
if(!SFileReadFile((HANDLE)hf, pbPatchFile, pPatchHeader->dwSizeOfPatchData - sizeof(TPatchHeader)))
nError = GetLastError();
}
return nError;
}
示例9: SFileVerifyFile
BOOL WINAPI SFileVerifyFile(HANDLE hMpq, const char * szFileName, DWORD dwFlags)
{
crc32_context crc32_ctx;
md5_context md5_ctx;
TMPQFile * hf;
TMPQCRC32 Crc32;
TMPQMD5 Md5;
BYTE Buffer[0x1000];
HANDLE hFile = NULL;
DWORD dwBytesRead;
BOOL bResult = TRUE;
// Attempt to open the file
if(SFileOpenFileEx(hMpq, szFileName, 0, &hFile))
{
// Initialize the CRC32 and MD5 counters
CRC32_Init(&crc32_ctx);
MD5_Init(&md5_ctx);
hf = (TMPQFile *)hFile;
// Go through entire file and update both CRC32 and MD5
for(;;)
{
// Read data from file
SFileReadFile(hFile, Buffer, sizeof(Buffer), &dwBytesRead, NULL);
if(dwBytesRead == 0)
break;
// Update CRC32 value
if(dwFlags & MPQ_ATTRIBUTE_CRC32)
CRC32_Update(&crc32_ctx, Buffer, (int)dwBytesRead);
// Update MD5 value
if(dwFlags & MPQ_ATTRIBUTE_MD5)
MD5_Update(&md5_ctx, Buffer, (int)dwBytesRead);
}
// Check if the CRC32 matches
if((dwFlags & MPQ_ATTRIBUTE_CRC32) && hf->pCrc32 != NULL)
{
CRC32_Finish(&crc32_ctx, (unsigned long *)&Crc32.dwValue);
if(Crc32.dwValue != hf->pCrc32->dwValue)
bResult = FALSE;
}
// Check if MD5 matches
if((dwFlags & MPQ_ATTRIBUTE_MD5) && hf->pMd5 != NULL)
{
MD5_Finish(&md5_ctx, Md5.Value);
if(memcmp(Md5.Value, hf->pMd5->Value, sizeof(TMPQMD5)))
bResult = FALSE;
}
SFileCloseFile(hFile);
}
return bResult;
}
示例10: SFileExtractFile
BOOL WINAPI SFileExtractFile(HANDLE hMpq, const char * szToExtract, const char * szExtracted)
{
HANDLE hLocalFile = INVALID_HANDLE_VALUE;
HANDLE hMpqFile = NULL;
DWORD dwSearchScope = 0;
int nError = ERROR_SUCCESS;
// Open the MPQ file
if(nError == ERROR_SUCCESS)
{
if((DWORD_PTR)szToExtract <= 0x10000)
dwSearchScope = SFILE_OPEN_BY_INDEX;
if(!SFileOpenFileEx(hMpq, szToExtract, dwSearchScope, &hMpqFile))
nError = GetLastError();
}
// Create the local file
if(nError == ERROR_SUCCESS)
{
hLocalFile = CreateFile(szExtracted, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, 0, NULL);
if(hLocalFile == INVALID_HANDLE_VALUE)
nError = GetLastError();
}
// Copy the file's content
if(nError == ERROR_SUCCESS)
{
char szBuffer[0x1000];
DWORD dwTransferred;
for(;;)
{
// dwTransferred is only set to nonzero if something has been read.
// nError can be ERROR_SUCCESS or ERROR_HANDLE_EOF
if(!SFileReadFile(hMpqFile, szBuffer, sizeof(szBuffer), &dwTransferred, NULL))
nError = GetLastError();
if(nError == ERROR_HANDLE_EOF)
nError = ERROR_SUCCESS;
if(dwTransferred == 0)
break;
// If something has been actually read, write it
WriteFile(hLocalFile, szBuffer, dwTransferred, &dwTransferred, NULL);
if(dwTransferred == 0)
nError = ERROR_DISK_FULL;
}
}
// Close the files
if(hMpqFile != NULL)
SFileCloseFile(hMpqFile);
if(hLocalFile != INVALID_HANDLE_VALUE)
CloseHandle(hLocalFile);
if(nError != ERROR_SUCCESS)
SetLastError(nError);
return (BOOL)(nError == ERROR_SUCCESS);
}
示例11: LoadMpqPatch_BSD0
static int LoadMpqPatch_BSD0(TMPQFile * hf, TPatchHeader * pPatchHeader)
{
LPBYTE pbDecompressed = NULL;
LPBYTE pbCompressed = NULL;
DWORD cbDecompressed = 0;
DWORD cbCompressed = 0;
DWORD dwBytesRead = 0;
int nError = ERROR_SUCCESS;
// Allocate space for compressed data
cbCompressed = pPatchHeader->dwXfrmBlockSize - SIZE_OF_XFRM_HEADER;
pbCompressed = ALLOCMEM(BYTE, cbCompressed);
if(pbCompressed == NULL)
nError = ERROR_SUCCESS;
// Read the compressed patch data
if(nError == ERROR_SUCCESS)
{
// Load the rest of the header
SFileReadFile((HANDLE)hf, pbCompressed, cbCompressed, &dwBytesRead);
if(dwBytesRead != cbCompressed)
nError = ERROR_FILE_CORRUPT;
}
// Get the uncompressed size of the patch
if(nError == ERROR_SUCCESS)
{
cbDecompressed = pPatchHeader->dwSizeOfPatchData - sizeof(TPatchHeader);
hf->pPatchHeader = (TPatchHeader *)ALLOCMEM(BYTE, pPatchHeader->dwSizeOfPatchData);
if(hf->pPatchHeader == NULL)
nError = ERROR_NOT_ENOUGH_MEMORY;
}
// Now decompress the patch data
if(nError == ERROR_SUCCESS)
{
// Copy the patch header
memcpy(hf->pPatchHeader, pPatchHeader, sizeof(TPatchHeader));
pbDecompressed = (LPBYTE)hf->pPatchHeader + sizeof(TPatchHeader);
// Uncompress or copy the patch data
if(cbCompressed < cbDecompressed)
{
Decompress_RLE(pbDecompressed, cbDecompressed, pbCompressed, cbCompressed);
}
else
{
assert(cbCompressed == cbDecompressed);
memcpy(pbDecompressed, pbCompressed, cbCompressed);
}
}
// Free buffers and exit
if(pbCompressed != NULL)
FREEMEM(pbCompressed);
return nError;
}
示例12: LoadFilePatch_COPY
static int LoadFilePatch_COPY(TMPQFile * hf, PMPQ_PATCH_HEADER pFullPatch)
{
DWORD cbBytesToRead = pFullPatch->dwSizeOfPatchData - sizeof(MPQ_PATCH_HEADER);
DWORD cbBytesRead = 0;
// Simply load the rest of the patch
SFileReadFile((HANDLE)hf, (pFullPatch + 1), cbBytesToRead, &cbBytesRead, NULL);
return (cbBytesRead == cbBytesToRead) ? ERROR_SUCCESS : ERROR_FILE_CORRUPT;
}
示例13: SFileReadFile_stub
BOOL WINAPI SFileReadFile_stub(MPQHANDLE hFile,LPVOID lpBuffer,DWORD nNumberOfBytesToRead,LPDWORD lpNumberOfBytesRead,LPOVERLAPPED lpOverlapped)
{
LoadSFMpqDll();
if (hSFMpq) {
*(FARPROC *)&SFileReadFile = GetProcAddress(hSFMpq,"SFileReadFile");
if (SFileReadFile) return SFileReadFile(hFile,lpBuffer,nNumberOfBytesToRead,lpNumberOfBytesRead,lpOverlapped);
}
return FALSE;
}
示例14: LoadFilePatch_COPY
static int LoadFilePatch_COPY(TMPQFile * hf, PMPQ_PATCH_HEADER pFullPatch)
{
size_t cbBytesToRead = pFullPatch->dwSizeOfPatchData - sizeof(MPQ_PATCH_HEADER);
size_t cbBytesRead = 0;
/* Simply load the rest of the patch */
SFileReadFile((void *)hf, (pFullPatch + 1), cbBytesToRead, &cbBytesRead);
return (cbBytesRead == cbBytesToRead) ? ERROR_SUCCESS : ERROR_FILE_CORRUPT;
}
示例15: LoadFilePatch_BSD0
static int LoadFilePatch_BSD0(TMPQFile * hf, PMPQ_PATCH_HEADER pFullPatch)
{
unsigned char * pbDecompressed = (unsigned char *)(pFullPatch + 1);
unsigned char * pbCompressed = NULL;
size_t cbDecompressed = 0;
size_t cbCompressed = 0;
size_t dwBytesRead = 0;
int nError = ERROR_SUCCESS;
/* Calculate the size of compressed data */
cbDecompressed = pFullPatch->dwSizeOfPatchData - sizeof(MPQ_PATCH_HEADER);
cbCompressed = pFullPatch->dwXfrmBlockSize - SIZE_OF_XFRM_HEADER;
/* Is that file compressed? */
if(cbCompressed < cbDecompressed)
{
pbCompressed = STORM_ALLOC(uint8_t, cbCompressed);
if(pbCompressed == NULL)
nError = ERROR_NOT_ENOUGH_MEMORY;
/* Read the compressed patch data */
if(nError == ERROR_SUCCESS)
{
SFileReadFile((void *)hf, pbCompressed, cbCompressed, &dwBytesRead);
if(dwBytesRead != cbCompressed)
nError = ERROR_FILE_CORRUPT;
}
/* Decompress the data */
if(nError == ERROR_SUCCESS)
Decompress_RLE(pbDecompressed, cbDecompressed, pbCompressed, cbCompressed);
if(pbCompressed != NULL)
STORM_FREE(pbCompressed);
}
else
{
SFileReadFile((void *)hf, pbDecompressed, cbDecompressed, &dwBytesRead);
if(dwBytesRead != cbDecompressed)
nError = ERROR_FILE_CORRUPT;
}
return nError;
}