public FileHandle Add(SafeOpenMode mode, SRCCompatibilityMode srcCompatibilityMode, Stream stream) { var h = new FileHandle(++_currentHandle, stream, mode, srcCompatibilityMode); _handles.Add(h.Handle, h); return(h); }
public FileHandle(int handle, Stream stream, SafeOpenMode mode, SRCCompatibilityMode srcCompatibilityMode) { Handle = handle; Stream = stream; if (mode == SafeOpenMode.Read) { Reader = new StreamReader(stream.ToTextStream(srcCompatibilityMode)); } else { Writer = new StreamWriter(stream, srcCompatibilityMode.HasFlag(SRCCompatibilityMode.Write) ? Encoding.GetEncoding(932) : Encoding.UTF8); } }
public Stream OpenSafe(SafeOpenMode mode, params string[] paths) { var path = PathCombine(paths); var entry = safeEntrySets.FirstOrDefault(x => x.Exists(path)); if (entry == null) { if (mode == SafeOpenMode.Read) { return(null); } entry = safeEntrySets.First(); } switch (mode) { case SafeOpenMode.Read: return(entry.OpenRead(path)); case SafeOpenMode.Write: return(entry.OpenWrite(path)); case SafeOpenMode.Append: return(entry.OpenAppend(path)); default: throw new NotSupportedException(); } }