12#ifndef SCRIPTS_INCLUDE__ENGINE_IO_H
13#define SCRIPTS_INCLUDE__ENGINE_IO_H
14#include "engine_vector.h"
15#include "engine_string.h"
16#include "chunkclass.h"
23 virtual const char *File_Name() = 0;
24 virtual const char *Set_Name(
const char* name) = 0;
25 virtual bool Create() = 0;
26 virtual bool Delete() = 0;
27 virtual bool Is_Available(
int handle = 0) = 0;
28 virtual bool Is_Open() = 0;
29 virtual int Open(
const char* name,
int mode = 1) = 0;
30 virtual int Open(
int mode = 1) = 0;
31 virtual int Read(
void* buffer,
int size) = 0;
32 virtual int Seek(
int offset,
int origin) = 0;
37 virtual int Size() = 0;
38 virtual int Write(
void* buffer,
int size) = 0;
39 virtual void Close() = 0;
40 virtual unsigned long Get_Date_Time()
44 virtual bool Set_Date_Time(
unsigned long time)
48 virtual void Error(
int a,
int b,
const char *c) = 0;
49 virtual HANDLE Get_File_Handle()
53 virtual void Bias(
int start,
int length) = 0;
54 virtual bool Is_Hash_Checked() = 0;
57class FileFactoryClass {
59 virtual ~FileFactoryClass() {};
60 virtual FileClass* Get_File(
const char* Filename) = 0;
61 virtual void Return_File(FileClass* File) = 0;
66struct INIEntry :
public Node<INIEntry *>
78 INIEntry(
char *entry,
char *value) : Entry(entry), Value(value)
83 return CRC_String(Entry,0);
86struct INISection :
public Node<INISection *>
90 List<INIEntry *> EntryList;
91 IndexClass<int,INIEntry *> EntryIndex;
97 INIEntry *Find_Entry(
const char *entry)
101 int crc = CRC_String(entry,0);
102 if (EntryIndex.Is_Present(crc))
104 return EntryIndex[crc];
109 INISection(
char *section) : Section(section)
114 return CRC_String(Section,0);
117class SCRIPTS_API INIClass {
118 List<INISection *> *SectionList;
119 IndexClass<int,INISection *> *SectionIndex;
122 static void Strip_Comments(
char* buffer);
123 static int CRC(
char *
string);
124 void DuplicateCRCError(
const char *function,
const char* message,
const char* entry);
126 INIClass(FileClass &file);
129 bool Clear(
char* section,
char* entry);
130 int Get_Int(
char const *section,
char const *entry,
int defaultvalue)
const;
131 uint Get_Color_UInt(
char const *section,
char const *entry, uint defaultvalue)
const;
132 float Get_Float(
char const *section,
char const *entry,
float defaultvalue)
const;
133 bool Get_Bool(
char const *section,
char const *entry,
bool defaultvalue)
const;
134 int Get_String(
char const *section,
char const *entry,
char const *defaultvalue,
char *result,
int size)
const;
135 int Get_String_Advanced(
char const *section,
char const *entry,
char const *defaultvalue,
char *result,
int size,
bool writeIfNotFound)
const;
136 StringClass &Get_String(StringClass &str,
const char* section,
const char* entry,
const char*
default = 0)
const;
137 StringClass& Get_String_Advanced(StringClass&
string,
const char* section,
const char* entry,
const char* defaultvalue,
bool updateIfNotFound)
const;
138 WideStringClass &Get_Wide_String(WideStringClass &,
char const*,
char const*,
wchar_t const*)
const;
139 bool Put_Wide_String(
const char* section,
const char* entry,
const wchar_t*
string);
140 bool Put_String(
const char* section,
const char* entry,
const char*
string);
141 bool Put_Int(
const char* section,
const char* entry,
int value,
int format);
142 bool Put_Bool(
const char* section,
const char* entry,
bool value);
143 bool Put_Float(
const char* section,
const char* entry,
float value);
144 int Entry_Count(
char const *section)
const;
145 const char *Get_Entry(
char const *section,
int index)
const;
146 INIEntry *Find_Entry(
const char* section,
const char* entry)
const;
147 INISection *Find_Section(
const char* section)
const;
149 int Load(Straw& ffile);
150 int Load(FileClass& file);
151 int Load(
char* filename);
152 int Save(FileClass& file);
153 int Save(Pipe& pipe);
154 int Section_Count()
const;
155 bool Is_Present(
const char *section,
const char *entry)
const
159 return Find_Entry(section,entry) != 0;
163 return Find_Section(section) != 0;
166 bool Section_Present(
const char *section)
const
168 return Find_Section(section) != 0;
170 List<INISection *> &Get_Section_List()
174 IndexClass<int,INISection *>&Get_Section_Index()
176 return *SectionIndex;
180class SCRIPTS_API file_auto_ptr
184 FileFactoryClass* _Fac;
188 file_auto_ptr(FileFactoryClass* fac,
const char* filename);
191 FileClass* operator ->() {
return _Ptr; }
192 operator FileClass *() {
return _Ptr; }
193 FileClass& operator*() {
return *_Ptr; }
194 FileClass* get() {
return _Ptr; }
197#define WRITE_MICRO_CHUNK(csave,id,value) \
198csave.Begin_Micro_Chunk(id); \
199csave.Write(&value,sizeof(value)); \
200csave.End_Micro_Chunk();
201#if (PARAM_EDITING_ON) || (DDBEDIT) || (W3DVIEWER)
202#define WRITE_SAFE_MICRO_CHUNK(csave,id,value,type) WRITE_MICRO_CHUNK(csave,id,value)
204#define WRITE_SAFE_MICRO_CHUNK(csave,id,value,type) \
205csave.Begin_Micro_Chunk(id); \
206csave.Write(value.Get_Ptr(),sizeof((type)value)); \
207csave.End_Micro_Chunk();
209#define WRITE_MICRO_CHUNK_STRING(cload,id,string) \
210csave.Begin_Micro_Chunk(id); \
211csave.Write((void *)string,(int)strlen(string)+1); \
212csave.End_Micro_Chunk();
213#define WRITE_MICRO_CHUNK_WWSTRING(csave,id,string) \
214csave.Begin_Micro_Chunk(id); \
215csave.Write(string.Peek_Buffer(),sizeof(*string.Peek_Buffer())*(string.Get_Length() + 1)); \
216csave.End_Micro_Chunk();
217#define WRITE_WWSTRING_CHUNK(csave,id,string) \
218csave.Begin_Chunk(id); \
219csave.Write(string.Peek_Buffer(),string.Get_Length() + 1); \
221#define WRITE_WIDESTRING_CHUNK(csave,id,string) \
222csave.Begin_Chunk(id); \
223csave.Write(string.Peek_Buffer(),(string.Get_Length() + 1) * 2); \
225#define READ_MICRO_CHUNK(cload,id,value) \
227cload.Read(&value,sizeof(value)); \
229#if (PARAM_EDITING_ON) || (DDBEDIT) || (W3DVIEWER)
230#define READ_SAFE_MICRO_CHUNK(csave,id,value,type) READ_MICRO_CHUNK(csave,id,value)
232#define READ_SAFE_MICRO_CHUNK(cload,id,value,type) \
236cload.Read(&t,sizeof(t)); \
241#define READ_MICRO_CHUNK_STRING(cload,id,string,size) \
243cload.Read(string,cload.Cur_Micro_Chunk_Length()); \
245#define READ_MICRO_CHUNK_WWSTRING(cload,id,string) \
247cload.Read(string.Get_Buffer(cload.Cur_Micro_Chunk_Length()),cload.Cur_Micro_Chunk_Length()); \
249#define LOAD_MICRO_CHUNK_WWSTRING(cload,string) \
250cload.Read(string.Get_Buffer(cload.Cur_Micro_Chunk_Length()),cload.Cur_Micro_Chunk_Length());
251#define READ_WWSTRING_CHUNK(cload,id,string) \
253cload.Read(string.Get_Buffer(cload.Cur_Chunk_Length()),cload.Cur_Chunk_Length()); \
255#define LOAD_MICRO_CHUNK(cload,type) \
256cload.Read(&type,sizeof(type));
257FileClass SCRIPTS_API *Get_Data_File(
const char *file);
258void SCRIPTS_API Close_Data_File(FileClass *file);
259INIClass SCRIPTS_API *Get_INI(
char const *filename);
260void SCRIPTS_API Release_INI(INIClass *ini);
261unsigned int SCRIPTS_API Get_Registry_Int(
const char *entry,
int defaultvalue);
266extern SCRIPTS_API REF_DECL(FileFactoryClass*, _TheFileFactory);
271const char SCRIPTS_API *Get_File_Path();
272const char SCRIPTS_API *Get_App_Data_Path();
273const char SCRIPTS_API *Get_Registry_Path();
274void SCRIPTS_API Strip_Path_From_Filename(StringClass& target,
const char* fileName);