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