diff options
| author | Alkaline Thunder <[email protected]> | 2018-12-28 01:16:53 -0500 |
|---|---|---|
| committer | Alkaline Thunder <[email protected]> | 2018-12-28 01:16:53 -0500 |
| commit | 6995abe190fad72892fb621758914ea2e2ebe92d (patch) | |
| tree | 79a7aa1299cd324f9ba5df56954e9721c02132a6 /ShiftOS | |
| parent | e127819f16d7c87d12b7a76696ca4d84b2c86ddb (diff) | |
| download | shiftos-challenge-6995abe190fad72892fb621758914ea2e2ebe92d.tar.gz shiftos-challenge-6995abe190fad72892fb621758914ea2e2ebe92d.tar.bz2 shiftos-challenge-6995abe190fad72892fb621758914ea2e2ebe92d.zip | |
Filesystem can now read and write files.
Diffstat (limited to 'ShiftOS')
| -rw-r--r-- | ShiftOS/ShiftOS/FilesystemContext.cs | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/ShiftOS/ShiftOS/FilesystemContext.cs b/ShiftOS/ShiftOS/FilesystemContext.cs index 2d68794..96d3832 100644 --- a/ShiftOS/ShiftOS/FilesystemContext.cs +++ b/ShiftOS/ShiftOS/FilesystemContext.cs @@ -62,5 +62,69 @@ namespace ShiftOS { return Path.Combine(_workingDirectory, ResolveToAbsolutePath(InPath).Replace("/", Path.DirectorySeparatorChar.ToString())); } + + public Stream Open(string InPath, FileMode InFileMode) + { + return File.Open(MapToEnvironmentPath(InPath), InFileMode); + } + + public Stream OpenRead(string InPath) + { + return File.OpenRead(this.MapToEnvironmentPath(InPath)); + } + + public Stream OpenWrite(string InPath) + { + return File.OpenWrite(this.MapToEnvironmentPath(InPath)); + } + + public StreamReader OpenText(string InPath) + { + return File.OpenText(this.MapToEnvironmentPath(InPath)); + } + + public string ReadAllText(string InPath) + { + using (var sr = OpenText(InPath)) + { + return sr.ReadToEnd(); + } + } + + public string[] ReadAllLines(string InPath) + { + return ReadAllText(InPath).Split(new[] { Environment.NewLine.ToString() }, StringSplitOptions.None); + } + + public byte[] ReadAllBytes(string InPath) + { + using (var s = OpenRead(InPath)) + { + byte[] bytes = new byte[s.Length]; + s.Read(bytes, 0, bytes.Length); + return bytes; + } + } + + public void WriteAllBytes(string InPath, byte[] InBytes) + { + using (var s = OpenWrite(InPath)) + { + s.SetLength(InBytes.Length); + s.Write(InBytes, 0, InBytes.Length); + } + } + + public void WriteAllText(string InPath, string InText) + { + WriteAllBytes(InPath, Encoding.UTF8.GetBytes(InText)); + } + + public void WriteAllLines(string InPath, string[] InLines) + { + WriteAllText(InPath, string.Join(Environment.NewLine, InLines)); + } + + } } |
