diff options
| author | John T <[email protected]> | 2017-11-11 08:53:55 -0500 |
|---|---|---|
| committer | John T <[email protected]> | 2017-11-11 08:53:55 -0500 |
| commit | 97722fbe9d474adffbba0b92e9727c48a8205234 (patch) | |
| tree | 65dfe45bbfd194ddb534cc80107ab8e6d80cf5bc /ShiftOS.Engine/ShiftFS/ShiftDirectory.cs | |
| parent | a10440a45c40652b13e883aec832a0c8ded685e8 (diff) | |
| download | shiftos-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/ShiftDirectory.cs')
| -rw-r--r-- | ShiftOS.Engine/ShiftFS/ShiftDirectory.cs | 89 |
1 files changed, 64 insertions, 25 deletions
diff --git a/ShiftOS.Engine/ShiftFS/ShiftDirectory.cs b/ShiftOS.Engine/ShiftFS/ShiftDirectory.cs index 64ac4f2..249738f 100644 --- a/ShiftOS.Engine/ShiftFS/ShiftDirectory.cs +++ b/ShiftOS.Engine/ShiftFS/ShiftDirectory.cs @@ -1,50 +1,89 @@ -using System.Collections.ObjectModel; +using System; +using System.Collections.Generic; using System.IO; using System.Linq; +using Whoa; namespace ShiftOS.Engine.ShiftFS { - public class ShiftDirectory : ShiftFsObject + [Serializable] + public class ShiftDirectory : List<IShiftNode>, IShiftNode { - public ShiftDirectory(string path) : base(path) + public ShiftDirectory(string name) => Name = name; + public ShiftDirectory(string name, ShiftDirectory parent) { - 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) => { }; + Name = name; + Parent = parent; } - 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 IShiftNode this[string name] => this.First(n => string.Equals(n.Name, name, StringComparison.Ordinal)); + + + public string Name { get; set; } - public ObservableCollection<ShiftFsObject> Children + public IEnumerable<ShiftFile> Flatten() { - get + foreach (var item in this) { - var collection = new ObservableCollection<ShiftFsObject>(); - - foreach (var dir in new DirectoryInfo(Path.Combine(ShiftFs.SavePath, FullName)).EnumerateDirectories()) + switch (item) { - collection.Add(new ShiftDirectory(dir.FullName)); + case ShiftFile file: + yield return file; + break; + case ShiftDirectory dir: + foreach (var shiftNode in dir.Flatten()) + { + yield return shiftNode; + } + break; } + } + } - foreach (var file in new DirectoryInfo(Path.Combine(ShiftFs.SavePath, FullName)).EnumerateFiles()) + public IEnumerable<ShiftDirectory> FlattenFolders() + { + foreach (var item in this) + { + if (!(item is ShiftDirectory dir)) continue; + yield return dir; + + foreach (var subdir in dir.FlattenFolders()) + { + yield return subdir; + } + } + } + + public string FullName + { + get + { + var list = new List<string> { Name }; + var currentNode = Parent; + while (currentNode?.Parent != null ) { - collection.Add(new ShiftFile(file.FullName.Replace(ShiftFs.SavePath, ""))); + list.Add(currentNode.Name); + currentNode = currentNode.Parent; } + + return Path.Combine(list.Reverse<string>().ToArray()); + } + } - return collection; + public ShiftDirectory Parent + { + get => Drive.FlattenFolders().FirstOrDefault(x => x.Contains(this)); + set + { + value.Add(this); + Parent?.Remove(this); } } - public ObservableCollection<ShiftFile> Files => new ObservableCollection<ShiftFile>(Children.OfType<ShiftFile>()); + public ShiftTree Drive => ShiftFS.Drives.First(d => d.FlattenFolders().Contains(this)); - public ObservableCollection<ShiftDirectory> Directories - => new ObservableCollection<ShiftDirectory>(Children.OfType<ShiftDirectory>()); + + public Guid Guid { get; } = Guid.NewGuid(); } }
\ No newline at end of file |
