aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.Engine/ShiftFS/ShiftFile.cs
diff options
context:
space:
mode:
Diffstat (limited to 'ShiftOS.Engine/ShiftFS/ShiftFile.cs')
-rw-r--r--ShiftOS.Engine/ShiftFS/ShiftFile.cs88
1 files changed, 88 insertions, 0 deletions
diff --git a/ShiftOS.Engine/ShiftFS/ShiftFile.cs b/ShiftOS.Engine/ShiftFS/ShiftFile.cs
new file mode 100644
index 0000000..c8a8ef4
--- /dev/null
+++ b/ShiftOS.Engine/ShiftFS/ShiftFile.cs
@@ -0,0 +1,88 @@
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.IO;
+using System.Linq;
+using Whoa;
+
+namespace ShiftOS.Engine.ShiftFS
+{
+ [Serializable]
+ public class ShiftFile<T> : ShiftFile
+ {
+ public ShiftFile(string name) => Name = name;
+ public ShiftFile(string name, ShiftDirectory directory)
+ {
+ 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 T Object { get; set; }
+ }
+
+ [Serializable]
+ public abstract class ShiftFile : IShiftNode
+ {
+ public Bitmap Icon { get; set; }
+
+ public string Name { get; set; }
+
+ public string FullName
+ {
+ get
+ {
+ 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 ShiftDirectory Parent
+ {
+ 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