1class JsonFileLoader<
Class T>
7 static bool LoadFile(
string filename, out T data, out
string errorMessage)
14 errorMessage =
string.Format(
"Cannot open file \"%1\" for reading", filename);
27 if (!
m_Serializer.ReadFromString(data, fileContent, error))
29 errorMessage =
string.Format(
"Cannot load data from \"%1\":\n%2", filename, error);
37 errorMessage =
string.Format(
"File \"%1\" does not exist, check the provided path", filename, error);
42 static bool SaveFile(
string filename, T data, out
string errorMessage)
50 if (!
MakeData(data, fileContent, makeDataError,
true))
52 errorMessage =
string.Format(
"Cannot save data to file \"%1\", %2", filename, makeDataError);
59 errorMessage =
string.Format(
"Cannot open file \"%1\" for writing", filename);
63 FPrint(handle, fileContent);
69 static bool LoadData(
string string_data, out T data, out
string errorMessage)
76 if (!
m_Serializer.ReadFromString(data, string_data, error))
78 errorMessage =
string.Format(
"Cannot load provided JSON data (deserialization error) - check syntax: %1", error);
85 static bool MakeData(T inputData, out
string outputData, out
string errorMessage,
bool prettyPrint =
true)
90 if (!
m_Serializer.WriteToString(inputData, prettyPrint, outputData))
92 errorMessage =
"Cannot create JSON from provided data (serialization error)";
118 while (
FGets(handle, line_content) >= 0)
120 file_content += line_content;
128 if (!
m_Serializer.ReadFromString(data, file_content, error))
129 ErrorEx(
string.Format(
"Cannot load data from \"%1\":\n%2", filename, error));
146 FPrint(handle, file_content);
157 if (!
m_Serializer.ReadFromString(data, string_data, error))
158 ErrorEx(
string.Format(
"Cannot load data %1", error));
Super root of all classes in Enforce script.
static bool LoadFile(string filename, out T data, out string errorMessage)
static void JsonLoadFile(string filename, out T data)
#ifndef DIAG_DEVELOPER
static void JsonLoadData(string string_data, out T data)
use JsonFileLoader::LoadData instead
static bool SaveFile(string filename, T data, out string errorMessage)
static bool MakeData(T inputData, out string outputData, out string errorMessage, bool prettyPrint=true)
static void JsonSaveFile(string filename, T data)
use JsonFileLoader::SaveFile instead
static bool LoadData(string string_data, out T data, out string errorMessage)
static ref JsonSerializer m_Serializer
static const int READ_FILE_LENGTH
static string JsonMakeData(T data)
use JsonFileLoader::MakeData instead
Class for sending RPC over network.
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.
proto bool FileExist(string name)
Check existence of file.