Tiberian Technologies Scripts Reference Revision: 9000
Loading...
Searching...
No Matches
engine_io.h
1/* Renegade Scripts.dll
2 Copyright 2013 Tiberian Technologies
3
4 This file is part of the Renegade scripts.dll
5 The Renegade scripts.dll is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License as published by the Free
7 Software Foundation; either version 2, or (at your option) any later
8 version. See the file COPYING for more details.
9 In addition, an exemption is given to allow Run Time Dynamic Linking of this code with any closed source module that does not contain code covered by this licence.
10 Only the source code to the module(s) containing the licenced code has to be released.
11*/
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"
17#include "Crc32.h"
18class FileClass {
19public:
20 virtual ~FileClass()
21 {
22 }
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;
33 virtual int Tell()
34 {
35 return Seek(0,1);
36 }
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()
41 {
42 return 0;
43 }
44 virtual bool Set_Date_Time(unsigned long time)
45 {
46 return false;
47 }
48 virtual void Error(int a, int b, const char *c) = 0;
49 virtual HANDLE Get_File_Handle()
50 {
51 return (HANDLE)-1;
52 }
53 virtual void Bias(int start, int length) = 0;
54 virtual bool Is_Hash_Checked() = 0;
55};
56
57class FileFactoryClass {
58public:
59 virtual ~FileFactoryClass() {};
60 virtual FileClass* Get_File(const char* Filename) = 0;
61 virtual void Return_File(FileClass* File) = 0;
62}; // 0004
63
64class Straw;
65class Pipe;
66struct INIEntry : public Node<INIEntry *>
67{
68public:
69 char* Entry; // 000C
70 char* Value; // 0010
71 ~INIEntry()
72 {
73 delete[] Entry;
74 Entry = 0;
75 delete[] Value;
76 Value = 0;
77 }
78 INIEntry(char *entry, char *value) : Entry(entry), Value(value)
79 {
80 }
81 int Index_ID()
82 {
83 return CRC_String(Entry,0);
84 }
85}; // 0014
86struct INISection : public Node<INISection *>
87{
88public:
89 char* Section; // 000C
90 List<INIEntry *> EntryList; // 0010
91 IndexClass<int,INIEntry *> EntryIndex; // 002C
92 ~INISection()
93 {
94 delete[] Section;
95 EntryList.Delete();
96 }
97 INIEntry *Find_Entry(const char *entry)
98 {
99 if (entry)
100 {
101 int crc = CRC_String(entry,0);
102 if (EntryIndex.Is_Present(crc))
103 {
104 return EntryIndex[crc];
105 }
106 }
107 return 0;
108 }
109 INISection(char *section) : Section(section)
110 {
111 }
112 int Index_ID()
113 {
114 return CRC_String(Section,0);
115 }
116}; // 0040
117class SCRIPTS_API INIClass {
118 List<INISection *> *SectionList;
119 IndexClass<int,INISection *> *SectionIndex;
120 char *Filename;
121public:
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);
125 INIClass();
126 INIClass(FileClass &file);
127 void Initialize();
128 void Shutdown();
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;
148 virtual ~INIClass();
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
156 {
157 if (entry)
158 {
159 return Find_Entry(section,entry) != 0;
160 }
161 else
162 {
163 return Find_Section(section) != 0;
164 }
165 }
166 bool Section_Present(const char *section) const
167 {
168 return Find_Section(section) != 0;
169 }
170 List<INISection *> &Get_Section_List()
171 {
172 return *SectionList;
173 }
174 IndexClass<int,INISection *>&Get_Section_Index()
175 {
176 return *SectionIndex;
177 }
178};
179
180class SCRIPTS_API file_auto_ptr
181{
182
183 FileClass* _Ptr;
184 FileFactoryClass* _Fac;
185
186public:
187
188 file_auto_ptr(FileFactoryClass* fac, const char* filename);
189 ~file_auto_ptr();
190
191 FileClass* operator ->() { return _Ptr; }
192 operator FileClass *() { return _Ptr; }
193 FileClass& operator*() { return *_Ptr; }
194 FileClass* get() { return _Ptr; }
195};
196
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)
203#else
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();
208#endif
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); \
220csave.End_Chunk();
221#define WRITE_WIDESTRING_CHUNK(csave,id,string) \
222csave.Begin_Chunk(id); \
223csave.Write(string.Peek_Buffer(),(string.Get_Length() + 1) * 2); \
224csave.End_Chunk();
225#define READ_MICRO_CHUNK(cload,id,value) \
226case id: \
227cload.Read(&value,sizeof(value)); \
228break;
229#if (PARAM_EDITING_ON) || (DDBEDIT) || (W3DVIEWER)
230#define READ_SAFE_MICRO_CHUNK(csave,id,value,type) READ_MICRO_CHUNK(csave,id,value)
231#else
232#define READ_SAFE_MICRO_CHUNK(cload,id,value,type) \
233case id: \
234{ \
235type t; \
236cload.Read(&t,sizeof(t)); \
237value = t; \
238} \
239break;
240#endif
241#define READ_MICRO_CHUNK_STRING(cload,id,string,size) \
242case id: \
243cload.Read(string,cload.Cur_Micro_Chunk_Length()); \
244break;
245#define READ_MICRO_CHUNK_WWSTRING(cload,id,string) \
246case id: \
247cload.Read(string.Get_Buffer(cload.Cur_Micro_Chunk_Length()),cload.Cur_Micro_Chunk_Length()); \
248break;
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) \
252case id: \
253cload.Read(string.Get_Buffer(cload.Cur_Chunk_Length()),cload.Cur_Chunk_Length()); \
254break;
255#define LOAD_MICRO_CHUNK(cload,type) \
256cload.Read(&type,sizeof(type));
257FileClass SCRIPTS_API *Get_Data_File(const char *file); //Open a file using the mix file opening logic
258void SCRIPTS_API Close_Data_File(FileClass *file); //Close a file that was opened with Get_Data_File
259INIClass SCRIPTS_API *Get_INI(char const *filename); //Open an INI file (reading using the normal mix file opening logic) and read stuff from it
260void SCRIPTS_API Release_INI(INIClass *ini); //Close an INI file opened with Get_INI
261unsigned int SCRIPTS_API Get_Registry_Int(const char *entry,int defaultvalue); //Get an int value from the renegade registry key
262#ifndef TTLE_EXPORTS
263#ifndef WWCONFIG
264#ifndef PACKAGEEDITOR
265#ifndef EXTERNAL
266extern SCRIPTS_API REF_DECL(FileFactoryClass*, _TheFileFactory);
267#endif
268#endif
269#endif
270#endif
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);
275#endif