-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUBinaryFile.h
74 lines (73 loc) · 2.37 KB
/
UBinaryFile.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//---------------------------------------------------------------------------
#ifndef UBinaryFileH
#define UBinaryFileH
//---------------------------------------------------------------------------
#include <windows.h>
#include <System.hpp>
#include <Classes.hpp>
#include <vcl.h>
//---------------------------------------------------------------------------
class TBinaryFile : public TObject
{
__published:
__property const unsigned __int64 Position = {read=GetPos,write=SetPos,default=0};
protected:
TMemoryStream* fs;
public:
void __fastcall SetPos(const unsigned __int64 __pos);
unsigned __int64 __fastcall GetPos();
BYTE* operator=(TBinaryFile* Source)
{
const unsigned __int64 size = Source->fs->Size;
BYTE* buffer = new BYTE[size];
Source->fs->Read(buffer, size);
return buffer;
}
void Clear() {fs->Clear();}
__fastcall TBinaryFile();
__fastcall TBinaryFile(UnicodeString File);
__fastcall TBinaryFile(TStream* S);
__fastcall TBinaryFile(const void* Buffer, const unsigned __int64 Size);
__fastcall ~TBinaryFile();
BYTE ReadByte();
short ReadShort();
float ReadFloat();
int ReadInt();
double ReadDouble();
__int64 ReadInt64();
UnicodeString ReadString();
AnsiString ReadAnsiString();
void ReadStream(TStream* Dest);
void ReadDiskFile(const UnicodeString File);
void ReadBuffer(const unsigned nSize, const PVOID pBuffer);
void ReadNullTerminatedString(char* szDest, int nMaxRead);
void WriteByte(const BYTE Value);
void WriteShort(const short Value);
void WriteFloat(const float Value);
void WriteInt(const int Value);
void WriteDouble(const double Value);
void WriteInt64(const __int64 Value);
void WriteString(const UnicodeString Value);
void WriteAnsiString(const AnsiString Value);
void WriteStream(TStream* Value);
void WriteDiskFile(const UnicodeString File);
void WriteBuffer(const unsigned nSize, const PVOID pBuffer);
virtual void SaveToFile(const UnicodeString File)
{
fs->SaveToFile(File);
}
virtual void LoadFromFile(const UnicodeString File)
{
if(FileExists(File)) fs->LoadFromFile(File);
}
virtual void SaveToStream(TStream* S)
{
fs->SaveToStream(S);
}
virtual void LoadFromStream(TStream* S)
{
if(HANDLE_VALID(S)) fs->LoadFromStream(S);
}
};
//---------------------------------------------------------------------------
#endif