From a10440a45c40652b13e883aec832a0c8ded685e8 Mon Sep 17 00:00:00 2001 From: John T Date: Sun, 5 Nov 2017 18:47:46 -0500 Subject: Added a half-complete ShiftFS and did some code cleanup --- ShiftOS.Engine/ShiftFS/ShiftDirectory.cs | 50 ++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 ShiftOS.Engine/ShiftFS/ShiftDirectory.cs (limited to 'ShiftOS.Engine/ShiftFS/ShiftDirectory.cs') diff --git a/ShiftOS.Engine/ShiftFS/ShiftDirectory.cs b/ShiftOS.Engine/ShiftFS/ShiftDirectory.cs new file mode 100644 index 0000000..64ac4f2 --- /dev/null +++ b/ShiftOS.Engine/ShiftFS/ShiftDirectory.cs @@ -0,0 +1,50 @@ +using System.Collections.ObjectModel; +using System.IO; +using System.Linq; + +namespace ShiftOS.Engine.ShiftFS +{ + public class ShiftDirectory : ShiftFsObject + { + public ShiftDirectory(string path) : base(path) + { + path = path.Replace(ShiftFs.SavePath, ""); + var dir = new DirectoryInfo(Path.Combine(ShiftFs.SavePath, path)); + Name = dir.Name; + FullDiskName = dir.FullName; + FullName = path; + + Children.CollectionChanged += (sender, e) => { }; + } + + public ShiftFsObject this[string name] => Children.First(f => f.Name == name); + public ShiftFsObject this[int index] => Children[index]; + + public new ShiftDirectory Parent => new ShiftDirectory(new DirectoryInfo(FullDiskName).Parent.FullName); + + public ObservableCollection Children + { + get + { + var collection = new ObservableCollection(); + + foreach (var dir in new DirectoryInfo(Path.Combine(ShiftFs.SavePath, FullName)).EnumerateDirectories()) + { + collection.Add(new ShiftDirectory(dir.FullName)); + } + + foreach (var file in new DirectoryInfo(Path.Combine(ShiftFs.SavePath, FullName)).EnumerateFiles()) + { + collection.Add(new ShiftFile(file.FullName.Replace(ShiftFs.SavePath, ""))); + } + + return collection; + } + } + + public ObservableCollection Files => new ObservableCollection(Children.OfType()); + + public ObservableCollection Directories + => new ObservableCollection(Children.OfType()); + } +} \ No newline at end of file -- cgit v1.2.3