Files
korenkonder_PD_Tool/KKdMainLib/IO/File.cs
T
korenkonder 6d80dfd0c9 Release v0.4.8.0
A3DA, Aet, DataBank, DEX, VAG
2019-11-05 10:28:28 +03:00

57 lines
3.0 KiB
C#

using System;
using MSIO = System.IO;
namespace KKdMainLib.IO
{
public static class File
{
public static Stream OpenReader(byte[] Data) => new Stream(new MSIO.MemoryStream(Data));
public static Stream OpenWriter(byte[] Data) => new Stream(new MSIO.MemoryStream(Data));
public static Stream OpenWriter( ) => new Stream(new MSIO.MemoryStream( ));
public static Stream OpenReader(string file, bool ReadAllAtOnce)
{ Stream _IO = OpenReader(file); if (ReadAllAtOnce) { byte[] data =
_IO.ToArray(); _IO.Dispose(); return OpenReader(data); } return _IO; }
public static Stream OpenReader(string file)
{ Stream _IO = new Stream(new MSIO.FileStream(file, MSIO.FileMode.Open, MSIO.FileAccess.ReadWrite,
MSIO.FileShare.ReadWrite)) { File = file }; return _IO; }
public static Stream OpenWriter(string file, bool SetLength0)
{ Stream _IO = OpenWriter(file); if (SetLength0) _IO.SL(0); return _IO; }
public static Stream OpenWriter(string file, int SetLength)
{ Stream _IO = OpenWriter(file); _IO.SL(SetLength); return _IO; }
public static Stream OpenWriter(string file)
{ Stream _IO = new Stream(new MSIO.FileStream(file,
MSIO.FileMode.OpenOrCreate, MSIO.FileAccess.ReadWrite, MSIO.FileShare.ReadWrite)) { File = file };
MSIO.File. SetCreationTimeUtc(file, DateTime.UtcNow);
MSIO.File. SetLastWriteTimeUtc(file, DateTime.UtcNow);
MSIO.File.SetLastAccessTimeUtc(file, DateTime.UtcNow); return _IO; }
public static byte[] ReadAllBytes(string file, int length, int offset)
{ byte[] Data; using (Stream _IO = OpenReader(file)) Data = _IO.RBy(length, offset); return Data; }
public static byte[] ReadAllBytes(string file)
{ byte[] Data; using (Stream _IO = OpenReader(file)) Data = _IO.RBy(_IO.L); return Data; }
public static string ReadAllText (string file)
{ string Data; using (Stream _IO = OpenReader(file)) Data = _IO.RSUTF8(_IO.L);
return Data.Replace(((char)0xFEFF).ToString(), ""); }
public static string[] ReadAllLines(string file)
{ string Data; using (Stream _IO = OpenReader(file)) Data = _IO.RSUTF8(_IO.L);
return Data.Replace(((char)0xFEFF).ToString(), "").Replace("\r", "").Split('\n'); }
public static void WriteAllBytes(string file, byte[] data)
{ using (Stream _IO = OpenWriter(file, true)) _IO.W(data); }
public static void WriteAllText (string file, string data)
{ using (Stream _IO = OpenWriter(file, true)) _IO.W(data); }
public static void WriteAllLines(string file, string[] data)
{ using (Stream _IO = OpenWriter(file, true)) for (int i = 0; i < data.Length; i++)
_IO.W(data[i] + "\r\n"); }
public static bool Exists(string file) => MSIO.File.Exists(file);
public static void Delete(string file) => MSIO.File.Delete(file);
}
}