|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifndef TFILE_H
|
|
Toshihiro Shimizu |
890ddd |
#define TFILE_H
|
|
Toshihiro Shimizu |
890ddd |
#include "tcommon.h"
|
|
Toshihiro Shimizu |
890ddd |
#include <windows.h></windows.h>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "tfilepath.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
namespace TFileConsts
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
enum SeekMode {
|
|
Toshihiro Shimizu |
890ddd |
seekStart = 0,
|
|
Toshihiro Shimizu |
890ddd |
seekCur,
|
|
Toshihiro Shimizu |
890ddd |
seekEnd
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
enum eFlags {
|
|
Toshihiro Shimizu |
890ddd |
kRead = 0x00000001,
|
|
Toshihiro Shimizu |
890ddd |
kWrite = 0x00000002,
|
|
Toshihiro Shimizu |
890ddd |
kReadWrite = kRead | kWrite,
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
kDenyNone = 0x00000000,
|
|
Toshihiro Shimizu |
890ddd |
kDenyRead = 0x00000010,
|
|
Toshihiro Shimizu |
890ddd |
kDenyWrite = 0x00000020,
|
|
Toshihiro Shimizu |
890ddd |
kDenyAll = kDenyRead | kDenyWrite,
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
kOpenExisting = 0x00000100,
|
|
Toshihiro Shimizu |
890ddd |
kOpenAlways = 0x00000200,
|
|
Toshihiro Shimizu |
890ddd |
kCreateAlways = 0x00000300,
|
|
Toshihiro Shimizu |
890ddd |
kCreateNew = 0x00000400,
|
|
Toshihiro Shimizu |
890ddd |
kTruncateExisting = 0x00000500, // not particularly useful, really
|
|
Toshihiro Shimizu |
890ddd |
kCreationMask = 0x0000FF00,
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
kSequential = 0x00010000,
|
|
Toshihiro Shimizu |
890ddd |
kRandomAccess = 0x00020000,
|
|
Toshihiro Shimizu |
890ddd |
kUnbuffered = 0x00040000, // much faster on Win32 thanks to the crappy cache, but possibly bad in Unix?
|
|
Toshihiro Shimizu |
890ddd |
kWriteThrough = 0x00080000,
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
kAllFileFlags = 0xFFFFFFFF
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
typedef __int32 uint32;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class TFile
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
HANDLE m_hFile;
|
|
Toshihiro Shimizu |
890ddd |
TINT64 m_FilePosition;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
TFile() {}
|
|
Toshihiro Shimizu |
890ddd |
TFile(const TFilePath &fname, uint32 flags = TFileConsts::kRead | TFileConsts::kDenyWrite | TFileConsts::kOpenExisting);
|
|
Toshihiro Shimizu |
890ddd |
//TFile(const wchar_t *pwszFileName, uint32 flags = TFileConsts::kRead | TFileConsts::kDenyWrite | TFileConsts::kOpenExisting);
|
|
Toshihiro Shimizu |
890ddd |
//TFile(VDFileHandle h);
|
|
Toshihiro Shimizu |
890ddd |
~TFile();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool open(const TFilePath &fname, uint32 flags = TFileConsts::kRead | TFileConsts::kDenyWrite | TFileConsts::kOpenExisting); // false if failed due to not found or already exists
|
|
Toshihiro Shimizu |
890ddd |
//bool open(const wchar_t *pwszFileName, uint32 flags = TFileConsts::kRead | TFileConsts::kDenyWrite | TFileConsts::kOpenExisting); // false if failed due to not found or already exists
|
|
Toshihiro Shimizu |
890ddd |
bool close();
|
|
Toshihiro Shimizu |
890ddd |
bool truncate();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TINT64 size();
|
|
Toshihiro Shimizu |
890ddd |
TINT32 read(void *buffer, TINT32 length);
|
|
Toshihiro Shimizu |
890ddd |
TINT32 write(const void *buffer, TINT32 length);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool seek(TINT64 newPos, TFileConsts::SeekMode mode = TFileConsts::seekStart);
|
|
Toshihiro Shimizu |
890ddd |
bool skip(TINT64 delta);
|
|
Toshihiro Shimizu |
890ddd |
TINT64 tell();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool isOpen();
|
|
Shinya Kitaoka |
3bfa54 |
std::string getLastError();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
protected:
|
|
Toshihiro Shimizu |
890ddd |
bool open_internal(const TFilePath &fname, /* const wchar_t *pwszFilename, */ uint32 flags);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
private:
|
|
Toshihiro Shimizu |
890ddd |
TFile(const TFile &);
|
|
Toshihiro Shimizu |
890ddd |
const TFile &operator=(const TFile &f);
|
|
Toshihiro Shimizu |
890ddd |
DWORD m_ec;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#endif
|