Elin Decompiled Documentation EA 23.286 Nightly Patch 1
Loading...
Searching...
No Matches
IO Class Reference

Public Types

enum  Compression { LZ4 , None }
 

Static Public Member Functions

static void OnError (object sender, Newtonsoft.Json.Serialization.ErrorEventArgs args)
 
static void PrintLog ()
 
static string GetJSON (object obj)
 
static T LoadJSON< T > (string json)
 
static void SaveFile (string path, object obj, bool compress=false, JsonSerializerSettings setting=null)
 
static void SaveText (string path, string text)
 
static void SaveTextArray (string path, string[] text)
 
static T LoadFile< T > (string path, bool compress=false, JsonSerializerSettings setting=null)
 
static T LoadStreamJson< T > (MemoryStream stream, JsonSerializerSettings setting=null)
 
static void WriteLZ4 (string _path, byte[] _bytes, Compression compression=Compression.None)
 
static byte[] ReadLZ4 (string _path, int size, Compression compression)
 
static byte[] ReadLZ4 (byte[] bytes)
 
static bool IsCompressed (string path)
 
static void Compress (string path, string text)
 
static string Decompress (string path)
 
static void CopyDir (string sourceDirectory, string targetDirectory, Func< string, bool > funcExclude=null)
 
static void _CopyDir (DirectoryInfo source, DirectoryInfo target, Func< string, bool > funcExclude=null)
 
static void Copy (string fromPath, string toPath)
 
static void CopyAs (string fromPath, string toPath)
 
static void CopyAll (string fromPath, string toPath, bool overwrite=true)
 
static void DeleteFile (string path)
 
static void DeleteFiles (string path)
 
static void CreateDirectory (string path)
 
static void DeleteDirectory (string path)
 
static T Duplicate< T > (T t)
 
static void CreateTempDirectory (string path=null)
 
static void DeleteTempDirectory (string path=null)
 
static T LoadObject< T > (FileInfo file, object option=null)
 
static T LoadObject< T > (string _path, object option=null)
 
static void SavePNG (Texture2D tex, string _path)
 
static Texture2D LoadPNG (string _path, FilterMode filter=FilterMode.Point)
 
static T DeepCopy< T > (T target)
 
static string[] LoadTextArray (string _path)
 
static string LoadText (string _path)
 

Static Public Attributes

static string log
 
static JsonSerializerSettings jsReadGeneral
 
static JsonSerializerSettings jsWriteGeneral
 
static JsonSerializerSettings jsWriteConfig
 
static Formatting formatting = Formatting.Indented
 
static TextureImportSetting.Data importSetting = new TextureImportSetting.Data()
 
static JsonSerializerSettings dpSetting
 
static Formatting dpFormat = Formatting.Indented
 

Properties

static string TempPath [get]
 

Detailed Description

Definition at line 10 of file IO.cs.

Member Enumeration Documentation

◆ Compression

Enumerator
LZ4 
None 

Definition at line 12 of file IO.cs.

13 {
14 LZ4,
15 None
16 }

Member Function Documentation

◆ _CopyDir()

static void IO._CopyDir ( DirectoryInfo  source,
DirectoryInfo  target,
Func< string, bool >  funcExclude = null 
)
inlinestatic

Definition at line 291 of file IO.cs.

292 {
293 if (funcExclude == null || !funcExclude(source.Name))
294 {
295 Directory.CreateDirectory(target.FullName);
296 FileInfo[] files = source.GetFiles();
297 foreach (FileInfo fileInfo in files)
298 {
299 fileInfo.CopyTo(Path.Combine(target.FullName, fileInfo.Name), overwrite: true);
300 }
301 DirectoryInfo[] directories = source.GetDirectories();
302 foreach (DirectoryInfo directoryInfo in directories)
303 {
304 DirectoryInfo target2 = target.CreateSubdirectory(directoryInfo.Name);
305 _CopyDir(directoryInfo, target2, funcExclude);
306 }
307 }
308 }
static void _CopyDir(DirectoryInfo source, DirectoryInfo target, Func< string, bool > funcExclude=null)
Definition: IO.cs:291

References _CopyDir().

Referenced by _CopyDir(), and CopyDir().

◆ Compress()

static void IO.Compress ( string  path,
string  text 
)
inlinestatic

Definition at line 249 of file IO.cs.

250 {
251 Debug.Log("Compressing: " + path);
252 using FileStream innerStream = new FileStream(path, FileMode.Create);
253 using LZ4Stream stream = new LZ4Stream(innerStream, LZ4StreamMode.Compress);
254 using StreamWriter streamWriter = new StreamWriter(stream);
255 streamWriter.Write(text);
256 }

References Debug.

Referenced by SaveFile().

◆ Copy()

static void IO.Copy ( string  fromPath,
string  toPath 
)
inlinestatic

Definition at line 310 of file IO.cs.

311 {
312 if (!File.Exists(fromPath))
313 {
314 Debug.Log("File does not exist:" + fromPath);
315 return;
316 }
317 FileInfo fileInfo = new FileInfo(fromPath);
318 DirectoryInfo directoryInfo = new DirectoryInfo(toPath);
319 if (!Directory.Exists(directoryInfo.FullName))
320 {
321 CreateDirectory(directoryInfo.FullName);
322 }
323 File.Copy(fileInfo.FullName, directoryInfo.FullName + "/" + fileInfo.Name, overwrite: true);
324 }
static void CreateDirectory(string path)
Definition: IO.cs:377

References CreateDirectory(), and Debug.

◆ CopyAll()

static void IO.CopyAll ( string  fromPath,
string  toPath,
bool  overwrite = true 
)
inlinestatic

Definition at line 338 of file IO.cs.

339 {
340 CreateDirectory(toPath);
341 string[] directories = Directory.GetDirectories(fromPath, "*", SearchOption.AllDirectories);
342 for (int i = 0; i < directories.Length; i++)
343 {
344 Directory.CreateDirectory(directories[i].Replace(fromPath, toPath));
345 }
346 directories = Directory.GetFiles(fromPath, "*.*", SearchOption.AllDirectories);
347 foreach (string text in directories)
348 {
349 string text2 = text.Replace(fromPath, toPath);
350 if (overwrite || !File.Exists(text2))
351 {
352 File.Copy(text, text2, overwrite: true);
353 }
354 }
355 }

References CreateDirectory().

◆ CopyAs()

static void IO.CopyAs ( string  fromPath,
string  toPath 
)
inlinestatic

Definition at line 326 of file IO.cs.

327 {
328 if (!File.Exists(fromPath))
329 {
330 Debug.LogError("File does not exist:" + fromPath);
331 }
332 else
333 {
334 File.Copy(fromPath, toPath, overwrite: true);
335 }
336 }

References Debug.

◆ CopyDir()

static void IO.CopyDir ( string  sourceDirectory,
string  targetDirectory,
Func< string, bool >  funcExclude = null 
)
inlinestatic

Definition at line 277 of file IO.cs.

278 {
279 DirectoryInfo directoryInfo = new DirectoryInfo(sourceDirectory);
280 DirectoryInfo target = new DirectoryInfo(targetDirectory);
281 if (!directoryInfo.Exists)
282 {
283 Debug.Log("Source dir doesn't exist:" + directoryInfo.FullName);
284 }
285 else
286 {
287 _CopyDir(directoryInfo, target, funcExclude);
288 }
289 }

References _CopyDir(), and Debug.

◆ CreateDirectory()

static void IO.CreateDirectory ( string  path)
inlinestatic

Definition at line 377 of file IO.cs.

378 {
379 if (!Directory.Exists(path))
380 {
381 Directory.CreateDirectory(path);
382 }
383 }

Referenced by Copy(), CopyAll(), CreateTempDirectory(), SaveFile(), SaveText(), and SaveTextArray().

◆ CreateTempDirectory()

static void IO.CreateTempDirectory ( string  path = null)
inlinestatic

Definition at line 411 of file IO.cs.

412 {
413 CreateDirectory(path ?? TempPath);
414 }

References CreateDirectory().

◆ Decompress()

static string IO.Decompress ( string  path)
inlinestatic

Definition at line 258 of file IO.cs.

259 {
260 try
261 {
262 using FileStream innerStream = new FileStream(path, FileMode.Open);
263 using LZ4Stream stream = new LZ4Stream(innerStream, LZ4StreamMode.Decompress);
264 using StreamReader streamReader = new StreamReader(stream);
265 return streamReader.ReadToEnd();
266 }
267 catch (Exception message)
268 {
269 Debug.Log(message);
270 }
271 Debug.Log("Cannot decompress:" + IsCompressed(path) + "/" + path);
272 string text = File.ReadAllText(path);
273 Debug.Log(text);
274 return text.IsEmpty("");
275 }
static bool IsCompressed(string path)
Definition: IO.cs:202

References Debug, and IsCompressed().

Referenced by LoadFile< T >().

◆ DeepCopy< T >()

static T IO.DeepCopy< T > ( target)
inlinestatic

Definition at line 470 of file IO.cs.

471 {
472 return JsonConvert.DeserializeObject<T>(JsonConvert.SerializeObject(target, dpFormat, dpSetting), dpSetting);
473 }
static JsonSerializerSettings dpSetting
Definition: IO.cs:53

◆ DeleteDirectory()

static void IO.DeleteDirectory ( string  path)
inlinestatic

Definition at line 385 of file IO.cs.

386 {
387 path = path.Replace("\\\\?\\", "");
388 if (Directory.Exists(path))
389 {
390 DirectoryInfo directoryInfo = new DirectoryInfo(path);
391 try
392 {
393 new FileIOPermission(FileIOPermissionAccess.AllAccess, path).Demand();
394 }
395 catch (SecurityException ex)
396 {
397 Debug.Log(ex.ToString());
398 }
399 if (directoryInfo.Exists)
400 {
401 directoryInfo.Delete(recursive: true);
402 }
403 }
404 }

References Debug.

Referenced by DeleteTempDirectory().

◆ DeleteFile()

static void IO.DeleteFile ( string  path)
inlinestatic

Definition at line 357 of file IO.cs.

358 {
359 if (File.Exists(path))
360 {
361 File.Delete(path);
362 }
363 }

◆ DeleteFiles()

static void IO.DeleteFiles ( string  path)
inlinestatic

Definition at line 365 of file IO.cs.

366 {
367 if (Directory.Exists(path))
368 {
369 FileInfo[] files = new DirectoryInfo(path).GetFiles();
370 for (int i = 0; i < files.Length; i++)
371 {
372 files[i].Delete();
373 }
374 }
375 }

◆ DeleteTempDirectory()

static void IO.DeleteTempDirectory ( string  path = null)
inlinestatic

Definition at line 416 of file IO.cs.

417 {
418 DeleteDirectory(path ?? TempPath);
419 }
static void DeleteDirectory(string path)
Definition: IO.cs:385

References DeleteDirectory().

◆ Duplicate< T >()

static T IO.Duplicate< T > ( t)
inlinestatic

Definition at line 406 of file IO.cs.

407 {
408 return JsonConvert.DeserializeObject<T>(JsonConvert.SerializeObject(t, formatting, jsWriteGeneral), jsReadGeneral);
409 }
static JsonSerializerSettings jsReadGeneral
Definition: IO.cs:20

◆ GetJSON()

static string IO.GetJSON ( object  obj)
inlinestatic

Definition at line 79 of file IO.cs.

80 {
81 return JsonConvert.SerializeObject(obj, formatting, jsWriteGeneral);
82 }

◆ IsCompressed()

static bool IO.IsCompressed ( string  path)
inlinestatic

Definition at line 202 of file IO.cs.

203 {
204 using FileStream fileStream = File.OpenRead(path);
205 if (fileStream.Length == 0L)
206 {
207 return false;
208 }
209 bool flag;
210 while (true)
211 {
212 switch (fileStream.ReadByte())
213 {
214 case 9:
215 case 10:
216 case 13:
217 case 32:
218 continue;
219 case -1:
220 return false;
221 case 34:
222 case 45:
223 case 48:
224 case 49:
225 case 50:
226 case 51:
227 case 52:
228 case 53:
229 case 54:
230 case 55:
231 case 56:
232 case 57:
233 case 91:
234 case 102:
235 case 110:
236 case 116:
237 case 123:
238 flag = true;
239 break;
240 default:
241 flag = false;
242 break;
243 }
244 break;
245 }
246 return !flag;
247 }

Referenced by Decompress(), and LoadFile< T >().

◆ LoadFile< T >()

static T IO.LoadFile< T > ( string  path,
bool  compress = false,
JsonSerializerSettings  setting = null 
)
inlinestatic

Definition at line 118 of file IO.cs.

119 {
120 if (!File.Exists(path))
121 {
122 Debug.Log("File does not exist:" + path);
123 return default(T);
124 }
125 string value = (IsCompressed(path) ? Decompress(path) : File.ReadAllText(path));
126 Debug.Log("#io LoadFile;" + path);
127 return JsonConvert.DeserializeObject<T>(value, setting ?? jsReadGeneral);
128 }
static string Decompress(string path)
Definition: IO.cs:258

References Debug, Decompress(), and IsCompressed().

◆ LoadJSON< T >()

static T IO.LoadJSON< T > ( string  json)
inlinestatic

Definition at line 84 of file IO.cs.

85 {
86 return JsonConvert.DeserializeObject<T>(json, jsReadGeneral);
87 }

◆ LoadObject< T >() [1/2]

static T IO.LoadObject< T > ( FileInfo  file,
object  option = null 
)
inlinestatic
Type Constraints
T :UnityEngine.Object 

Definition at line 421 of file IO.cs.

421 : UnityEngine.Object
422 {
423 return LoadObject<T>(file.FullName, option);
424 }

◆ LoadObject< T >() [2/2]

static T IO.LoadObject< T > ( string  _path,
object  option = null 
)
inlinestatic
Type Constraints
T :UnityEngine.Object 

Definition at line 426 of file IO.cs.

426 : UnityEngine.Object
427 {
428 Type typeFromHandle = typeof(T);
429 if (typeFromHandle == typeof(Sprite))
430 {
431 SpriteLoadOption spriteLoadOption = option as SpriteLoadOption;
432 Texture2D texture2D = LoadPNG(_path);
433 if (!texture2D)
434 {
435 return null;
436 }
437 return Sprite.Create(texture2D, new Rect(0f, 0f, texture2D.width, texture2D.height), spriteLoadOption?.pivot ?? new Vector2(0.5f, 0f), 100f) as T;
438 }
439 if (typeFromHandle == typeof(Texture2D))
440 {
441 return LoadPNG(_path) as T;
442 }
443 if (typeof(ExcelData).IsAssignableFrom(typeFromHandle))
444 {
445 T val = Activator.CreateInstance<T>();
446 (val as ExcelData).path = _path;
447 return val;
448 }
449 if (typeFromHandle == typeof(TextData))
450 {
451 return new TextData
452 {
453 lines = File.ReadAllLines(_path)
454 } as T;
455 }
456 return null;
457 }
static Texture2D LoadPNG(string _path, FilterMode filter=FilterMode.Point)
Definition: IO.cs:465

References LoadPNG(), and SpriteLoadOption.pivot.

◆ LoadPNG()

static Texture2D IO.LoadPNG ( string  _path,
FilterMode  filter = FilterMode::Point 
)
inlinestatic

Definition at line 465 of file IO.cs.

466 {
467 return ImageLoader.LoadPNG(_path, filter);
468 }
static Texture2D LoadPNG(string _path, FilterMode filter=FilterMode.Point)
Definition: ImageLoader.cs:6

References ImageLoader.LoadPNG().

Referenced by LoadObject< T >().

◆ LoadStreamJson< T >()

static T IO.LoadStreamJson< T > ( MemoryStream  stream,
JsonSerializerSettings  setting = null 
)
inlinestatic

Definition at line 130 of file IO.cs.

131 {
132 stream.Position = 0L;
133 string value = "";
134 using (StreamReader streamReader = new StreamReader(stream))
135 {
136 value = streamReader.ReadToEnd();
137 }
138 return JsonConvert.DeserializeObject<T>(value, setting ?? jsReadGeneral);
139 }

◆ LoadText()

static string IO.LoadText ( string  _path)
inlinestatic

Definition at line 489 of file IO.cs.

490 {
491 string[] array = LoadTextArray(_path);
492 string text = "";
493 string[] array2 = array;
494 foreach (string text2 in array2)
495 {
496 text = text + text2 + Environment.NewLine;
497 }
498 return text;
499 }
static string[] LoadTextArray(string _path)
Definition: IO.cs:475

References LoadTextArray().

◆ LoadTextArray()

static string[] IO.LoadTextArray ( string  _path)
inlinestatic

Definition at line 475 of file IO.cs.

476 {
477 if (!File.Exists(_path))
478 {
479 _path += ".txt";
480 if (!File.Exists(_path))
481 {
482 Debug.Log(_path);
483 return new string[0];
484 }
485 }
486 return File.ReadAllLines(_path);
487 }

References Debug.

Referenced by LoadText().

◆ OnError()

static void IO.OnError ( object  sender,
Newtonsoft::Json::Serialization::ErrorEventArgs  args 
)
inlinestatic

Definition at line 66 of file IO.cs.

67 {
68 }

◆ PrintLog()

static void IO.PrintLog ( )
inlinestatic

Definition at line 70 of file IO.cs.

71 {
72 if (!log.IsEmpty())
73 {
74 Debug.LogWarning(log);
75 log = null;
76 }
77 }
static string log
Definition: IO.cs:18

References Debug.

◆ ReadLZ4() [1/2]

static byte[] IO.ReadLZ4 ( byte[]  bytes)
inlinestatic

Definition at line 189 of file IO.cs.

190 {
191 try
192 {
193 return LZ4Codec.Unwrap(bytes);
194 }
195 catch
196 {
197 Debug.Log("Exception: Failed to unwrap:");
198 return bytes;
199 }
200 }

References Debug.

◆ ReadLZ4() [2/2]

static byte[] IO.ReadLZ4 ( string  _path,
int  size,
Compression  compression 
)
inlinestatic

Definition at line 159 of file IO.cs.

160 {
161 for (int i = 0; i < 5; i++)
162 {
163 string text = _path + ((i == 0) ? "" : (".b" + i));
164 if (!File.Exists(text))
165 {
166 Debug.Log("Couldn't find:" + text);
167 continue;
168 }
169 byte[] array = File.ReadAllBytes(text);
170 if (compression == Compression.LZ4)
171 {
172 try
173 {
174 return ReadLZ4(array);
175 }
176 catch (Exception message)
177 {
178 Debug.Log(message);
179 }
180 }
181 if (array.Length == size)
182 {
183 return array;
184 }
185 }
186 return null;
187 }
Compression
Definition: IO.cs:13
static byte[] ReadLZ4(string _path, int size, Compression compression)
Definition: IO.cs:159

References Debug, and ReadLZ4().

Referenced by ReadLZ4().

◆ SaveFile()

static void IO.SaveFile ( string  path,
object  obj,
bool  compress = false,
JsonSerializerSettings  setting = null 
)
inlinestatic

Definition at line 89 of file IO.cs.

90 {
91 string text = JsonConvert.SerializeObject(obj, formatting, setting ?? jsWriteGeneral);
92 CreateDirectory(Path.GetDirectoryName(path));
93 Debug.Log("#io SaveFile;" + path);
94 if (compress)
95 {
96 Compress(path, text);
97 }
98 else
99 {
100 File.WriteAllText(path, text);
101 }
102 }
static void Compress(string path, string text)
Definition: IO.cs:249

References Compress(), CreateDirectory(), and Debug.

◆ SavePNG()

static void IO.SavePNG ( Texture2D  tex,
string  _path 
)
inlinestatic

Definition at line 459 of file IO.cs.

460 {
461 byte[] bytes = tex.EncodeToPNG();
462 File.WriteAllBytes(_path, bytes);
463 }

◆ SaveText()

static void IO.SaveText ( string  path,
string  text 
)
inlinestatic

Definition at line 104 of file IO.cs.

105 {
106 CreateDirectory(Path.GetDirectoryName(path));
107 Debug.Log("#io SaveFile;" + path);
108 File.WriteAllText(path, text);
109 }

References CreateDirectory(), and Debug.

◆ SaveTextArray()

static void IO.SaveTextArray ( string  path,
string[]  text 
)
inlinestatic

Definition at line 111 of file IO.cs.

112 {
113 CreateDirectory(Path.GetDirectoryName(path));
114 Debug.Log("#io SaveFile;" + path);
115 File.WriteAllLines(path, text);
116 }

References CreateDirectory(), and Debug.

◆ WriteLZ4()

static void IO.WriteLZ4 ( string  _path,
byte[]  _bytes,
Compression  compression = Compression::None 
)
inlinestatic

Definition at line 141 of file IO.cs.

142 {
143 byte[] bytes = ((compression == Compression.LZ4) ? LZ4Codec.Wrap(_bytes, 0, _bytes.Length) : _bytes);
144 for (int i = 0; i < 5; i++)
145 {
146 string path = _path + ((i == 0) ? "" : (".b" + i));
147 try
148 {
149 File.WriteAllBytes(path, bytes);
150 break;
151 }
152 catch (Exception message)
153 {
154 Debug.Log(message);
155 }
156 }
157 }

References Debug.

Member Data Documentation

◆ dpFormat

Formatting IO.dpFormat = Formatting.Indented
static

Definition at line 62 of file IO.cs.

◆ dpSetting

JsonSerializerSettings IO.dpSetting
static
Initial value:
= new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore,
DefaultValueHandling = DefaultValueHandling.Include,
PreserveReferencesHandling = PreserveReferencesHandling.Objects,
TypeNameHandling = TypeNameHandling.Auto,
Error = OnError
}
static void OnError(object sender, Newtonsoft.Json.Serialization.ErrorEventArgs args)
Definition: IO.cs:66

Definition at line 53 of file IO.cs.

◆ formatting

Formatting IO.formatting = Formatting.Indented
static

Definition at line 49 of file IO.cs.

◆ importSetting

TextureImportSetting.Data IO.importSetting = new TextureImportSetting.Data()
static

Definition at line 51 of file IO.cs.

◆ jsReadGeneral

JsonSerializerSettings IO.jsReadGeneral
static
Initial value:
= new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore,
DefaultValueHandling = DefaultValueHandling.Ignore,
PreserveReferencesHandling = PreserveReferencesHandling.Objects,
TypeNameHandling = TypeNameHandling.Auto,
Error = OnError
}

Definition at line 20 of file IO.cs.

◆ jsWriteConfig

JsonSerializerSettings IO.jsWriteConfig
static
Initial value:
= new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore,
DefaultValueHandling = DefaultValueHandling.Populate,
PreserveReferencesHandling = PreserveReferencesHandling.Objects,
TypeNameHandling = TypeNameHandling.Auto,
Error = OnError
}
static readonly ShouldSerializeContractResolver Instance

Definition at line 39 of file IO.cs.

◆ jsWriteGeneral

JsonSerializerSettings IO.jsWriteGeneral
static
Initial value:
= new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore,
DefaultValueHandling = DefaultValueHandling.Ignore,
PreserveReferencesHandling = PreserveReferencesHandling.Objects,
TypeNameHandling = TypeNameHandling.Auto,
Error = OnError
}

Definition at line 29 of file IO.cs.

◆ log

string IO.log
static

Definition at line 18 of file IO.cs.

Property Documentation

◆ TempPath

string IO.TempPath
staticget

Definition at line 64 of file IO.cs.


The documentation for this class was generated from the following file: