*
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
#ifndef IFSSTREAM_H__
|
||||
#define IFSSTREAM_H__
|
||||
|
||||
#include "../../IDataStream.h"
|
||||
#include "../../LString.h"
|
||||
#include <assert.h>
|
||||
#include <windows.h>
|
||||
|
||||
namespace LifeCore
|
||||
{
|
||||
class IFSStream : public IDataStream
|
||||
{
|
||||
private:
|
||||
int openMode;
|
||||
size_t stmLength;
|
||||
HANDLE pFile;
|
||||
public:
|
||||
~IFSStream()
|
||||
{
|
||||
//printf("DESTRUCTING WIN FILE STREAM\n");
|
||||
Close();
|
||||
}
|
||||
void Close()
|
||||
{
|
||||
//printf("CLOSING WIN FILE STREAM\n");
|
||||
if(pFile)
|
||||
CloseHandle(pFile);
|
||||
pFile = (HANDLE)0;
|
||||
}
|
||||
IFSStream(String& path, int fileAccessMode, size_t size)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(size);
|
||||
this->stmLength = 0;
|
||||
openMode = fileAccessMode;
|
||||
if (fileAccessMode == FA_READ)
|
||||
{
|
||||
pFile = CreateFileA(path.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
pFile = CreateFileA(path.c_str(), GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
}
|
||||
|
||||
this->stmLength = SetFilePointer(pFile, 0, NULL, FILE_END);
|
||||
SetFilePointer(pFile, 0, NULL, FILE_BEGIN);
|
||||
}
|
||||
size_t Read(void* pBuffer, size_t countBytes)
|
||||
{
|
||||
DWORD numBytes = 0;
|
||||
|
||||
ReadFile(pFile,pBuffer,countBytes, &numBytes, NULL);
|
||||
return numBytes;
|
||||
}
|
||||
size_t Write(const void* pBuffer, size_t countBytes)
|
||||
{
|
||||
DWORD numBytes = 0;
|
||||
WriteFile(pFile,pBuffer,countBytes,&numBytes, NULL);
|
||||
return numBytes;
|
||||
}
|
||||
void Seek(size_t position)
|
||||
{
|
||||
SetFilePointer(pFile, position, NULL, FILE_BEGIN);
|
||||
}
|
||||
size_t Tell()
|
||||
{
|
||||
return SetFilePointer(pFile, 0, NULL, FILE_CURRENT);
|
||||
}
|
||||
size_t Length()
|
||||
{
|
||||
int pos = Tell();
|
||||
int length = SetFilePointer(pFile, 0, NULL, SEEK_END);
|
||||
SetFilePointer(pFile, pos, NULL, SEEK_SET);
|
||||
return length;
|
||||
}
|
||||
bool CanRead()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool CanWrite()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user