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