aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.Engine/ShiftFS/ShiftDirectory.cs
diff options
context:
space:
mode:
Diffstat (limited to 'ShiftOS.Engine/ShiftFS/ShiftDirectory.cs')
-rw-r--r--ShiftOS.Engine/ShiftFS/ShiftDirectory.cs50
1 files changed, 50 insertions, 0 deletions
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<ShiftFsObject> Children
+ {
+ get
+ {
+ var collection = new ObservableCollection<ShiftFsObject>();
+
+ 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<ShiftFile> Files => new ObservableCollection<ShiftFile>(Children.OfType<ShiftFile>());
+
+ public ObservableCollection<ShiftDirectory> Directories
+ => new ObservableCollection<ShiftDirectory>(Children.OfType<ShiftDirectory>());
+ }
+} \ No newline at end of file