blob: 64ac4f2677fcd7a0c351476014f1191f0d99138a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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>());
}
}
|