diff options
| author | Alex-TIMEHACK <[email protected]> | 2017-11-18 16:29:54 +0000 |
|---|---|---|
| committer | Alex-TIMEHACK <[email protected]> | 2017-11-18 16:29:54 +0000 |
| commit | 4037be53b29a122732cfc10693e9c0027f606bb0 (patch) | |
| tree | 8533ea9ee0ac8f5f7f696b85cb039f783657ada0 /ShiftOS.Engine/ShiftFS/ShiftDirectory.cs | |
| parent | 65b7ac2b8cbc4478f6d31a21f106048aeb075078 (diff) | |
| parent | 97722fbe9d474adffbba0b92e9727c48a8205234 (diff) | |
| download | shiftos-rewind-4037be53b29a122732cfc10693e9c0027f606bb0.tar.gz shiftos-rewind-4037be53b29a122732cfc10693e9c0027f606bb0.tar.bz2 shiftos-rewind-4037be53b29a122732cfc10693e9c0027f606bb0.zip | |
Updated my fork!
Conflicts:
ShiftOS.Engine/ShiftOS.Engine.csproj
ShiftOS.Engine/Terminal/Commands/Hello.cs
ShiftOS.Engine/Terminal/TerminalBackend.cs
ShiftOS.Engine/Terminal/TerminalCommand.cs
ShiftOS.Main/ShiftOS.Main.csproj
ShiftOS.Main/ShiftOS/Apps/Terminal.cs
ShiftOS.Main/ShiftOS/Desktop.cs
Diffstat (limited to 'ShiftOS.Engine/ShiftFS/ShiftDirectory.cs')
| -rw-r--r-- | ShiftOS.Engine/ShiftFS/ShiftDirectory.cs | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/ShiftOS.Engine/ShiftFS/ShiftDirectory.cs b/ShiftOS.Engine/ShiftFS/ShiftDirectory.cs new file mode 100644 index 0000000..249738f --- /dev/null +++ b/ShiftOS.Engine/ShiftFS/ShiftDirectory.cs @@ -0,0 +1,89 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Whoa; + +namespace ShiftOS.Engine.ShiftFS +{ + [Serializable] + public class ShiftDirectory : List<IShiftNode>, IShiftNode + { + public ShiftDirectory(string name) => Name = name; + public ShiftDirectory(string name, ShiftDirectory parent) + { + Name = name; + Parent = parent; + } + + + public IShiftNode this[string name] => this.First(n => string.Equals(n.Name, name, StringComparison.Ordinal)); + + + public string Name { get; set; } + + public IEnumerable<ShiftFile> Flatten() + { + foreach (var item in this) + { + switch (item) + { + case ShiftFile file: + yield return file; + break; + case ShiftDirectory dir: + foreach (var shiftNode in dir.Flatten()) + { + yield return shiftNode; + } + break; + } + } + } + + 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 ) + { + 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().Contains(this)); + + + public Guid Guid { get; } = Guid.NewGuid(); + } +}
\ No newline at end of file |
