/
VirtualFileManager.cs
108 lines (84 loc) · 2.34 KB
/
VirtualFileManager.cs
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
using System;
using DartSassHost;
using BundleTransformer.Core.FileSystem;
using CoreStrings = BundleTransformer.Core.Resources.Strings;
namespace BundleTransformer.SassAndScss.Internal
{
/// <summary>
/// Virtual file manager
/// </summary>
public sealed class VirtualFileManager : IFileManager
{
/// <summary>
/// Virtual file system wrapper
/// </summary>
private readonly IVirtualFileSystemWrapper _virtualFileSystemWrapper;
/// <summary>
/// Constructs an instance of virtual file manager
/// </summary>
/// <param name="virtualFileSystemWrapper">Virtual file system wrapper</param>
public VirtualFileManager(IVirtualFileSystemWrapper virtualFileSystemWrapper)
{
_virtualFileSystemWrapper = virtualFileSystemWrapper;
}
#region IFileManager implementation
public bool SupportsVirtualPaths
{
get { return true; }
}
public string GetCurrentDirectory()
{
string currentDirectory = _virtualFileSystemWrapper.ToAbsolutePath("~/");
return currentDirectory;
}
public bool FileExists(string path)
{
if (path == null)
{
throw new ArgumentNullException(
nameof(path),
string.Format(CoreStrings.Common_ArgumentIsNull, nameof(path))
);
}
bool result = _virtualFileSystemWrapper.FileExists(path);
return result;
}
public bool IsAppRelativeVirtualPath(string path)
{
if (path == null)
{
throw new ArgumentNullException(
nameof(path),
string.Format(CoreStrings.Common_ArgumentIsNull, nameof(path))
);
}
bool result = path.Length >= 2 && path[0] == '~' && (path[1] == '/' || path[1] == '\\');
return result;
}
public string ToAbsoluteVirtualPath(string path)
{
if (path == null)
{
throw new ArgumentNullException(
nameof(path),
string.Format(CoreStrings.Common_ArgumentIsNull, nameof(path))
);
}
string absolutePath = _virtualFileSystemWrapper.ToAbsolutePath(path);
return absolutePath;
}
public string ReadFile(string path)
{
if (path == null)
{
throw new ArgumentNullException(
nameof(path),
string.Format(CoreStrings.Common_ArgumentIsNull, nameof(path))
);
}
string content = _virtualFileSystemWrapper.GetFileTextContent(path);
return content;
}
#endregion
}
}