Repository navigation
Expand file tree
/
Copy pathVirtualFile.cs
More file actions
112 lines (96 loc) · 3.4 KB
/
Copy pathVirtualFile.cs
File metadata and controls
112 lines (96 loc) · 3.4 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace Sledge.FileSystem
{
public class VirtualFile : IFile
{
public FileSystemType Type { get { return FileSystemType.Virtual; } }
public bool IsContainer { get; private set; }
public IFile Parent { get; private set; }
public string FullPathName { get; private set; }
public string Name { get; private set; }
public string NameWithoutExtension { get; private set; }
public string Extension { get; private set; }
public bool Exists { get; private set; }
public long Size { get; private set; }
public int NumChildren { get { return Children.Count(x => x.IsContainer); } }
public int NumFiles { get { return Children.Count(x => !x.IsContainer); } }
public List<IFile> Children { get; private set; }
public VirtualFile(IFile parent, string name)
{
Parent = parent;
Name = name;
IsContainer = false;
FullPathName = parent != null ? Path.Combine(parent.FullPathName, name) : name;
NameWithoutExtension = Path.GetFileNameWithoutExtension(name);
Extension = (Path.GetExtension(Name) ?? "").TrimStart('.');
Exists = true;
Size = 0;
Children = new List<IFile>();
}
public VirtualFile(IFile parent, string name, IEnumerable<IFile> children)
{
Parent = parent;
Name = name;
IsContainer = true;
FullPathName = parent == null ? name : Path.Combine(parent.FullPathName, name);
NameWithoutExtension = name;
Extension = "";
Exists = true;
Size = 0;
Children = children.ToList();
}
public Stream Open()
{
throw new NotImplementedException();
}
public byte[] ReadAll()
{
throw new NotImplementedException();
}
public byte[] Read(long offset, long count)
{
throw new NotImplementedException();
}
public IEnumerable<IFile> GetRelatedFiles()
{
return new List<IFile>();
}
public IFile GetRelatedFile(string extension)
{
return null;
}
public IFile GetChild(string name)
{
return Children.FirstOrDefault(x => x.Name == name);
}
public IEnumerable<IFile> GetChildren()
{
return Children.Where(x => x.IsContainer);
}
public IEnumerable<IFile> GetChildren(string regex)
{
return GetChildren().Where(x => Regex.IsMatch(x.Name, regex, RegexOptions.IgnoreCase));
}
public IFile GetFile(string name)
{
return GetFiles().FirstOrDefault(x => x.Name.ToLower() == name.ToLower());
}
public IEnumerable<IFile> GetFiles()
{
return Children.Where(x => !x.IsContainer);
}
public IEnumerable<IFile> GetFiles(string regex)
{
return GetFiles().Where(x => Regex.IsMatch(x.Name, regex, RegexOptions.IgnoreCase));
}
public IEnumerable<IFile> GetFilesWithExtension(string extension)
{
return GetFiles().Where(x => x.Name.EndsWith("." + extension));
}
}
}