aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.Engine/ShiftFS/ShiftFile.cs
diff options
context:
space:
mode:
authorJohn T <[email protected]>2017-11-11 08:53:55 -0500
committerJohn T <[email protected]>2017-11-11 08:53:55 -0500
commit97722fbe9d474adffbba0b92e9727c48a8205234 (patch)
tree65dfe45bbfd194ddb534cc80107ab8e6d80cf5bc /ShiftOS.Engine/ShiftFS/ShiftFile.cs
parenta10440a45c40652b13e883aec832a0c8ded685e8 (diff)
downloadshiftos-rewind-97722fbe9d474adffbba0b92e9727c48a8205234.tar.gz
shiftos-rewind-97722fbe9d474adffbba0b92e9727c48a8205234.tar.bz2
shiftos-rewind-97722fbe9d474adffbba0b92e9727c48a8205234.zip
Only 1/4 broken ShiftFS and WIP File Skimmer
Diffstat (limited to 'ShiftOS.Engine/ShiftFS/ShiftFile.cs')
-rw-r--r--ShiftOS.Engine/ShiftFS/ShiftFile.cs94
1 files changed, 67 insertions, 27 deletions
diff --git a/ShiftOS.Engine/ShiftFS/ShiftFile.cs b/ShiftOS.Engine/ShiftFS/ShiftFile.cs
index 1a2413c..c8a8ef4 100644
--- a/ShiftOS.Engine/ShiftFS/ShiftFile.cs
+++ b/ShiftOS.Engine/ShiftFS/ShiftFile.cs
@@ -1,48 +1,88 @@
using System;
+using System.Collections.Generic;
+using System.Drawing;
using System.IO;
-using System.Runtime.Serialization.Formatters.Binary;
+using System.Linq;
+using Whoa;
namespace ShiftOS.Engine.ShiftFS
{
- public class ShiftFile : ShiftFsObject
+ [Serializable]
+ public class ShiftFile<T> : ShiftFile
{
- public ShiftFile(string path) : base(path)
+ public ShiftFile(string name) => Name = name;
+ public ShiftFile(string name, ShiftDirectory directory)
{
- 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;
+ Name = name;
+ Parent = directory;
+ }
+ public ShiftFile(string name, T @object, ShiftDirectory directory)
+ {
+ Name = name;
+ Object = @object;
+ Parent = directory;
+ }
+ public ShiftFile(string name, T @object, ShiftDirectory directory, Bitmap icon)
+ {
+ Name = name;
+ Object = @object;
+ Parent = directory;
+ Icon = icon;
+ }
+ public ShiftFile(string name, T @object)
+ {
+ Name = name;
+ Object = @object;
}
+ public ShiftFile(string name, T @object, Bitmap icon)
+ {
+ Name = name;
+ Object = @object;
+ Icon = icon;
+ }
+
- public new ShiftDirectory Parent => new ShiftDirectory(new FileInfo(FullDiskName).Directory.FullName);
- public MemoryStream Bytes { get; set; }
- public long Length => Bytes.Length;
+ public T Object { get; set; }
}
- public class ShiftFile<T> : ShiftFile // please C# gods let us constrain to attributes
+ [Serializable]
+ public abstract class ShiftFile : IShiftNode
{
- public ShiftFile(string path) : base(path)
+ public Bitmap Icon { get; set; }
+
+ public string Name { get; set; }
+
+ public string FullName
{
- if (!typeof(T).IsSerializable)
+ get
{
- throw new InvalidOperationException("Non-serializable types are not supported");
+ var list = new List<string> { Name };
+ var currentNode = Parent;
+ while (currentNode?.Parent != null)
+ {
+ list.Add(currentNode.Name);
+ currentNode = currentNode.Parent;
+ }
+
+ return Path.Combine(list.Reverse<string>().ToArray()) + "\\";
}
}
-
- public T Object
+
+ public ShiftDirectory Parent
{
- get => (T) new BinaryFormatter().Deserialize(Bytes);
- set => new BinaryFormatter().Serialize(Bytes, value);
+ get => Drive.FlattenFolders().FirstOrDefault(x => x.Contains(this));
+ set
+ {
+ value.Add(this);
+ Parent?.Remove(this);
+ }
}
+
+ public ShiftTree Drive => ShiftFS.Drives.First(d => d.FlattenFolders().FirstOrDefault(f => f.Contains(this)) != null);
+
+
+ public Guid Guid { get; } = Guid.NewGuid();
+
}
} \ No newline at end of file