DayZ 1.27
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
JsonFileLoader.c
См. документацию.
1class JsonFileLoader<Class T>
2{
3 protected static const int READ_FILE_LENGTH = 100000000;
4
5 protected static ref JsonSerializer m_Serializer = new JsonSerializer();
6
7 static bool LoadFile(string filename, out T data, out string errorMessage)
8 {
9 if (FileExist(filename))
10 {
11 FileHandle handle = OpenFile(filename, FileMode.READ);
12 if (handle == 0)
13 {
14 errorMessage = string.Format("Cannot open file \"%1\" for reading", filename);
15 return false;
16 }
17
18 string fileContent;
19 ReadFile(handle, fileContent, READ_FILE_LENGTH);
20
21 CloseFile(handle);
22
23 if (!m_Serializer)
25
26 string error;
27 if (!m_Serializer.ReadFromString(data, fileContent, error))
28 {
29 errorMessage = string.Format("Cannot load data from \"%1\":\n%2", filename, error);
30 return false;
31 }
32
33 return true;
34 }
35 else
36 {
37 errorMessage = string.Format("File \"%1\" does not exist, check the provided path", filename, error);
38 return false;
39 }
40 }
41
42 static bool SaveFile(string filename, T data, out string errorMessage)
43 {
44 string fileContent;
45
46 if (!m_Serializer)
48
49 string makeDataError;
50 if (!MakeData(data, fileContent, makeDataError, true))
51 {
52 errorMessage = string.Format("Cannot save data to file \"%1\", %2", filename, makeDataError);
53 return false;
54 }
55
56 FileHandle handle = OpenFile(filename, FileMode.WRITE);
57 if (handle == 0)
58 {
59 errorMessage = string.Format("Cannot open file \"%1\" for writing", filename);
60 return false;
61 }
62
63 FPrint(handle, fileContent);
64 CloseFile(handle);
65
66 return true;
67 }
68
69 static bool LoadData(string string_data, out T data, out string errorMessage)
70 {
71 string error;
72
73 if (!m_Serializer)
75
76 if (!m_Serializer.ReadFromString(data, string_data, error))
77 {
78 errorMessage = string.Format("Cannot load provided JSON data (deserialization error) - check syntax: %1", error);
79 return false;
80 }
81
82 return true;
83 }
84
85 static bool MakeData(T inputData, out string outputData, out string errorMessage, bool prettyPrint = true)
86 {
87 if (!m_Serializer)
89
90 if (!m_Serializer.WriteToString(inputData, prettyPrint, outputData))
91 {
92 errorMessage = "Cannot create JSON from provided data (serialization error)";
93 return false;
94 }
95
96 return true;
97 }
98
101
103
105 static void JsonLoadFile(string filename, out T data)
106 {
107
108 if (FileExist(filename))
109 {
110 string file_content;
111 string line_content;
112 string error;
113
114 FileHandle handle = OpenFile(filename, FileMode.READ);
115 if (handle == 0)
116 return;
117
118 while (FGets(handle, line_content) >= 0)
119 {
120 file_content += line_content;
121 }
122
123 CloseFile(handle);
124
125 if (!m_Serializer)
127
128 if (!m_Serializer.ReadFromString(data, file_content, error))
129 ErrorEx(string.Format("Cannot load data from \"%1\":\n%2", filename, error));
130 }
131 }
132
134 static void JsonSaveFile(string filename, T data)
135 {
136 string file_content;
137 if (!m_Serializer)
139
140 m_Serializer.WriteToString(data, true, file_content);
141
142 FileHandle handle = OpenFile(filename, FileMode.WRITE);
143 if (handle == 0)
144 return;
145
146 FPrint(handle, file_content);
147 CloseFile(handle);
148 }
149
151 static void JsonLoadData(string string_data, out T data)
152 {
153 string error;
154 if (!m_Serializer)
156
157 if (!m_Serializer.ReadFromString(data, string_data, error))
158 ErrorEx(string.Format("Cannot load data %1", error));
159 }
160
162 static string JsonMakeData(T data)
163 {
164 string string_data;
165 if (!m_Serializer)
167
168 m_Serializer.WriteToString(data, true, string_data);
169 return string_data;
170 }
171
172 //#endif
173}
Super root of all classes in Enforce script.
Определения EnScript.c:11
static bool LoadFile(string filename, out T data, out string errorMessage)
Определения JsonFileLoader.c:7
static void JsonLoadFile(string filename, out T data)
#ifndef DIAG_DEVELOPER
Определения JsonFileLoader.c:105
static void JsonLoadData(string string_data, out T data)
use JsonFileLoader::LoadData instead
Определения JsonFileLoader.c:151
static bool SaveFile(string filename, T data, out string errorMessage)
Определения JsonFileLoader.c:42
static bool MakeData(T inputData, out string outputData, out string errorMessage, bool prettyPrint=true)
Определения JsonFileLoader.c:85
static void JsonSaveFile(string filename, T data)
use JsonFileLoader::SaveFile instead
Определения JsonFileLoader.c:134
static bool LoadData(string string_data, out T data, out string errorMessage)
Определения JsonFileLoader.c:69
static ref JsonSerializer m_Serializer
Определения JsonFileLoader.c:5
static const int READ_FILE_LENGTH
Определения JsonFileLoader.c:3
static string JsonMakeData(T data)
use JsonFileLoader::MakeData instead
Определения JsonFileLoader.c:162
Class for sending RPC over network.
Определения gameplay.c:50
enum ShapeType ErrorEx
FileMode
Определения EnSystem.c:383
proto void CloseFile(FileHandle file)
Close the File.
proto void FPrint(FileHandle file, void var)
Write to file.
proto int FGets(FileHandle file, string var)
Get line from file, every next call of this function returns next line.
proto int ReadFile(FileHandle file, void param_array, int length)
proto FileHandle OpenFile(string name, FileMode mode)
Opens File.
int[] FileHandle
Определения EnSystem.c:390
proto bool FileExist(string name)
Check existence of file.