00001
00002
00003
00004
00005
#ifndef RAGE_FILE_H
00006
#define RAGE_FILE_H
00007
00008
#include "RageFileBasic.h"
00009
00010
00011
00012 class RageFile:
public RageFileBasic
00013 {
00014
public:
00015
enum
00016 {
00017
READ = 0x1,
00018
WRITE = 0x2,
00019
00020
00021
STREAMED = 0x4,
00022
00023
00024
00025
SLOW_FLUSH = 0x8
00026 };
00027
00028
RageFile();
00029 ~RageFile() {
Close(); }
00030
RageFile(
const RageFile &cpy );
00031
RageFileBasic *
Copy() const;
00032
00033
00034
00035
00036
00037
00038
00039 const CString &GetRealPath()
const {
return m_Path; }
00040
CString GetPath() const;
00041
00042
bool Open( const CString& path,
int mode = READ );
00043
void Close();
00044 bool IsOpen()
const {
return m_File != NULL; }
00045
00046
bool AtEOF() const;
00047 CString GetError() const;
00048
void ClearError();
00049 bool IsGood()
const {
return IsOpen() && !
AtEOF() &&
GetError().empty(); }
00050
00051
int Tell() const;
00052
int Seek(
int offset );
00053
int GetFileSize() const;
00054
00055
00056
int Read(
void *buffer, size_t bytes );
00057
int Read( CString &buffer,
int bytes = -1 );
00058
int Write( const
void *buffer, size_t bytes );
00059 int Write( const CString& string ) {
return Write( string.data(), string.size() ); }
00060
int Flush();
00061
00062
00063
int Write(
const void *buffer, size_t bytes,
int nmemb );
00064
int Read(
void *buffer, size_t bytes,
int nmemb );
00065
int Seek(
int offset,
int whence );
00066
00067
00068
int GetLine( CString &out );
00069
int PutLine(
const CString &str );
00070
00071
void EnableCRC32(
bool on=
true );
00072
bool GetCRC32( uint32_t *iRet );
00073
00074
protected:
00075
void SetError(
const CString &err );
00076
00077
private:
00078 RageFileBasic *
m_File;
00079 CString m_Path;
00080 CString m_sError;
00081 int m_Mode;
00082 };
00083
00084
00085 namespace FileReading
00086 {
00087
00088
00089
void ReadBytes(
RageFileBasic &
f,
void *buf,
int size,
CString &sError );
00090
void SkipBytes(
RageFileBasic &
f,
int size,
CString &sError );
00091
void Seek(
RageFileBasic &
f,
int iOffset,
CString &sError );
00092 uint8_t
read_8(
RageFileBasic &
f,
CString &sError );
00093 int16_t
read_16_le(
RageFileBasic &
f,
CString &sError );
00094 uint16_t
read_u16_le(
RageFileBasic &
f,
CString &sError );
00095 int32_t
read_32_le(
RageFileBasic &
f,
CString &sError );
00096 uint32_t
read_u32_le(
RageFileBasic &
f,
CString &sError );
00097 };
00098
00099
#endif