Etterna
0.74.4
Loading...
Searching...
No Matches
src
RageUtil
File
RageFile.h
1
/* RageFile - High-level file access. */
2
3
#ifndef RAGE_FILE_H
4
#define RAGE_FILE_H
5
6
#include "RageFileBasic.h"
7
8
struct
lua_State;
9
15
class
RageFile
:
public
RageFileBasic
16
{
17
public
:
18
enum
19
{
20
READ = 0x1,
21
WRITE = 0x2,
22
23
/* Always write directly to the destination file; don't do a safe write.
24
(for logs) */
25
STREAMED = 0x4,
26
27
/* Flush the file to disk on close. Combined with not streaming, this
28
* results in very safe writes, but is slow. */
29
SLOW_FLUSH = 0x8
30
};
31
32
RageFile
();
33
~RageFile
()
override
{ Close(); }
34
RageFile
(
const
RageFile
& cpy);
35
RageFile
* Copy()
const override
;
36
37
/*
38
* Use GetRealPath to get the path this file was opened with; use that if
39
* you want a path that will probably get you the same file again.
40
*
41
* GetPath can be overridden by drivers. Use it to get a path for display;
42
* it may give more information, such as the name of the archive the file
43
* is in. It has no parsable meaning.
44
*/
45
const
std::string& GetRealPath()
const
{
return
m_Path; }
46
std::string GetPath()
const
;
47
48
bool
Open(
const
std::string& path,
int
mode = READ);
49
void
Close();
50
bool
IsOpen()
const
{
return
m_File != NULL; }
51
int
GetMode()
const
{
return
m_Mode; }
52
53
bool
AtEOF()
const override
;
54
std::string GetError()
const override
;
55
void
ClearError()
override
;
56
57
int
Tell()
const override
;
58
int
Seek(
int
offset)
override
;
59
int
GetFileSize()
const override
;
60
int
GetFD()
override
;
61
62
/* Raw I/O: */
63
int
Read(
void
* buffer,
size_t
bytes)
override
;
64
int
Read(std::string& buffer,
int
bytes = -1)
override
;
65
int
Write(
const
void
* buffer,
size_t
bytes)
override
;
66
int
Write(
const
std::string&
string
)
override
67
{
68
return
Write(
string
.data(),
string
.size());
69
}
70
int
Flush()
override
;
71
72
/* These are just here to make wrappers (eg. vorbisfile, SDL_rwops) easier.
73
*/
74
int
Write(
const
void
* buffer,
size_t
bytes,
int
nmemb)
override
;
75
int
Read(
void
* buffer,
size_t
bytes,
int
nmemb)
override
;
76
int
Seek(
int
offset,
int
whence)
override
;
77
78
/* Line-based I/O: */
79
int
GetLine(std::string& out)
override
;
80
int
PutLine(
const
std::string& str)
override
;
81
82
void
EnableCRC32(
bool
on =
true
)
override
;
83
bool
GetCRC32(uint32_t* iRet)
override
;
84
85
// Lua
86
virtual
void
PushSelf(lua_State* L);
87
88
private
:
89
void
SetError(
const
std::string& err);
90
91
RageFileBasic
* m_File;
92
std::string m_Path;
93
std::string m_sError;
94
int
m_Mode;
95
96
// Swallow up warnings. If they must be used, define them.
97
RageFile
& operator=(
const
RageFile
& rhs);
98
};
99
101
namespace
FileReading
{
102
/* On error, these set sError to the error message. If sError is already
103
* non-empty, nothing happens. */
104
void
105
ReadBytes(
RageFileBasic
& f,
void
* buf,
int
size, std::string& sError);
106
void
107
SkipBytes(
RageFileBasic
& f,
int
size, std::string& sError);
108
void
109
Seek(
RageFileBasic
& f,
int
iOffset, std::string& sError);
110
std::string
111
ReadString(
RageFileBasic
& f,
int
size, std::string& sError);
112
uint8_t
113
read_8(
RageFileBasic
& f, std::string& sError);
114
int16_t
115
read_16_le(
RageFileBasic
& f, std::string& sError);
116
uint16_t
117
read_u16_le(
RageFileBasic
& f, std::string& sError);
118
int32_t
119
read_32_le(
RageFileBasic
& f, std::string& sError);
120
uint32_t
121
read_u32_le(
RageFileBasic
& f, std::string& sError);
122
};
123
124
#endif
RageFileBasic
Definition
RageFileBasic.h:10
RageFile
High-level file access.
Definition
RageFile.h:16
FileReading
Convenience wrappers for reading binary files.
Definition
RageFile.h:101
Generated by
1.9.8