📄 cpi_stream_localfile.c
字号:
#include "stdafx.h"
#include "globals.h"
#include "CPI_Stream.h"
typedef struct _CPs_InStream_File
{
HANDLE m_hFile;
} CPs_InStream_File;
//
void CPSLOCAL_Uninitialise(CPs_InStream* pStream);
BOOL CPSLOCAL_Read(CPs_InStream* pStream, void* pDestBuffer, const unsigned int iBytesToRead, unsigned int* piBytesRead);
void CPSLOCAL_Seek(CPs_InStream* pStream, const unsigned int iNewOffset);
unsigned int CPSLOCAL_GetLength(CPs_InStream* pStream);
BOOL CPSLOCAL_IsSeekable(CPs_InStream* pStream);
unsigned int CPSLOCAL_Tell(CPs_InStream* pStream);
CPs_InStream* CP_CreateInStream_LocalFile(const char* pcFlexiURL, HWND hWndOwner)
{
HANDLE hFile;
hFile = CreateFile(pcFlexiURL, GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, 0);
if(hFile == INVALID_HANDLE_VALUE)
return NULL;
{
CPs_InStream* pNewStream = (CPs_InStream*)malloc(sizeof(CPs_InStream));
CPs_InStream_File* pContext = (CPs_InStream_File*)malloc(sizeof(CPs_InStream_File));
pNewStream->Uninitialise = CPSLOCAL_Uninitialise;
pNewStream->Read = CPSLOCAL_Read;
pNewStream->Seek = CPSLOCAL_Seek;
pNewStream->Tell = CPSLOCAL_Tell;
pNewStream->GetLength = CPSLOCAL_GetLength;
pNewStream->IsSeekable = CPSLOCAL_IsSeekable;
pNewStream->m_pModuleCookie = pContext;
pContext->m_hFile = hFile;
return pNewStream;
}
}
//
void CPSLOCAL_Uninitialise(CPs_InStream* pStream)
{
CPs_InStream_File* pContext = (CPs_InStream_File*)pStream->m_pModuleCookie;
CP_CHECKOBJECT(pContext);
CloseHandle(pContext->m_hFile);
free(pContext);
free(pStream);
}
//
BOOL CPSLOCAL_Read(CPs_InStream* pStream, void* pDestBuffer, const unsigned int iBytesToRead, unsigned int* piBytesRead)
{
CPs_InStream_File* pContext = (CPs_InStream_File*)pStream->m_pModuleCookie;
CP_CHECKOBJECT(pContext);
return ReadFile(pContext->m_hFile, pDestBuffer, iBytesToRead, piBytesRead, 0);
}
//
void CPSLOCAL_Seek(CPs_InStream* pStream, const unsigned int iNewOffset)
{
CPs_InStream_File* pContext = (CPs_InStream_File*)pStream->m_pModuleCookie;
CP_CHECKOBJECT(pContext);
SetFilePointer(pContext->m_hFile, iNewOffset, 0, FILE_BEGIN);
}
//
unsigned int CPSLOCAL_GetLength(CPs_InStream* pStream)
{
CPs_InStream_File* pContext = (CPs_InStream_File*)pStream->m_pModuleCookie;
CP_CHECKOBJECT(pContext);
return GetFileSize(pContext->m_hFile, NULL);
}
//
BOOL CPSLOCAL_IsSeekable(CPs_InStream* pStream)
{
return TRUE;
}
//
#define GetFilePointer(hFile) SetFilePointer(hFile, 0, NULL, FILE_CURRENT)
unsigned int CPSLOCAL_Tell(CPs_InStream* pStream)
{
CPs_InStream_File* pContext = (CPs_InStream_File*)pStream->m_pModuleCookie;
CP_CHECKOBJECT(pContext);
return GetFilePointer(pContext->m_hFile);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -