aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.Engine/ShiftFS/ShiftFile.cs
diff options
context:
space:
mode:
authorJohn T <[email protected]>2017-11-05 18:47:46 -0500
committerJohn T <[email protected]>2017-11-05 18:47:46 -0500
commita10440a45c40652b13e883aec832a0c8ded685e8 (patch)
treeab64311e47f8e59c7c46cd50c94bec424165ecc2 /ShiftOS.Engine/ShiftFS/ShiftFile.cs
parent019da5b9ebf67b758a31dd05c4b17de66fa682f2 (diff)
downloadshiftos-rewind-a10440a45c40652b13e883aec832a0c8ded685e8.tar.gz
shiftos-rewind-a10440a45c40652b13e883aec832a0c8ded685e8.tar.bz2
shiftos-rewind-a10440a45c40652b13e883aec832a0c8ded685e8.zip
Added a half-complete ShiftFS and did some code cleanup
Diffstat (limited to 'ShiftOS.Engine/ShiftFS/ShiftFile.cs')
-rw-r--r--ShiftOS.Engine/ShiftFS/ShiftFile.cs48
1 files changed, 48 insertions, 0 deletions
diff --git a/ShiftOS.Engine/ShiftFS/ShiftFile.cs b/ShiftOS.Engine/ShiftFS/ShiftFile.cs
new file mode 100644
index 0000000..1a2413c
--- /dev/null
+++ b/ShiftOS.Engine/ShiftFS/ShiftFile.cs
@@ -0,0 +1,48 @@
+using System;
+using System.IO;
+using System.Runtime.Serialization.Formatters.Binary;
+
+namespace ShiftOS.Engine.ShiftFS
+{
+ public class ShiftFile : ShiftFsObject
+ {
+ public ShiftFile(string path) : base(path)
+ {
+ path = path.Replace(ShiftFs.SavePath, "");
+
+ using (var fs = new FileStream(Path.Combine(ShiftFs.SavePath, path), FileMode.Open))
+ {
+ Bytes = new MemoryStream();
+ fs.CopyTo(Bytes);
+ }
+
+ var file = new FileInfo(Path.Combine(ShiftFs.SavePath, path));
+
+ Name = file.Name;
+ FullDiskName = file.FullName;
+ FullName = path;
+ }
+
+ public new ShiftDirectory Parent => new ShiftDirectory(new FileInfo(FullDiskName).Directory.FullName);
+
+ public MemoryStream Bytes { get; set; }
+ public long Length => Bytes.Length;
+ }
+
+ public class ShiftFile<T> : ShiftFile // please C# gods let us constrain to attributes
+ {
+ public ShiftFile(string path) : base(path)
+ {
+ if (!typeof(T).IsSerializable)
+ {
+ throw new InvalidOperationException("Non-serializable types are not supported");
+ }
+ }
+
+ public T Object
+ {
+ get => (T) new BinaryFormatter().Deserialize(Bytes);
+ set => new BinaryFormatter().Serialize(Bytes, value);
+ }
+ }
+} \ No newline at end of file