-
Notifications
You must be signed in to change notification settings - Fork 264
Expand file tree
/
Copy pathFileInfoWrapper.cs
More file actions
305 lines (261 loc) · 8.54 KB
/
FileInfoWrapper.cs
File metadata and controls
305 lines (261 loc) · 8.54 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
using System.Runtime.Versioning;
using System.Security.AccessControl;
namespace System.IO.Abstractions
{
/// <inheritdoc cref="FileInfoBase" />
#if FEATURE_SERIALIZABLE
[Serializable]
#endif
public class FileInfoWrapper : FileInfoBase, IFileSystemAclSupport
{
private readonly FileInfo instance;
/// <summary>
/// Wrapper class for calling methods of <see cref="FileInfo"/>
/// </summary>
public FileInfoWrapper(IFileSystem fileSystem, FileInfo instance) : base(fileSystem)
{
this.instance = instance ?? throw new ArgumentNullException(nameof(instance));
}
#if FEATURE_CREATE_SYMBOLIC_LINK
/// <inheritdoc />
public override void CreateAsSymbolicLink(string pathToTarget)
{
instance.CreateAsSymbolicLink(pathToTarget);
}
#endif
/// <inheritdoc />
public override void Delete()
{
instance.Delete();
}
/// <inheritdoc />
public override void Refresh()
{
instance.Refresh();
}
#if FEATURE_CREATE_SYMBOLIC_LINK
/// <inheritdoc />
public override IFileSystemInfo ResolveLinkTarget(bool returnFinalTarget)
{
return instance.ResolveLinkTarget(returnFinalTarget)
.WrapFileSystemInfo(FileSystem);
}
#endif
/// <inheritdoc />
public override FileAttributes Attributes
{
get { return instance.Attributes; }
set { instance.Attributes = value; }
}
/// <inheritdoc />
public override DateTime CreationTime
{
get { return instance.CreationTime; }
set { instance.CreationTime = value; }
}
/// <inheritdoc />
public override DateTime CreationTimeUtc
{
get { return instance.CreationTimeUtc; }
set { instance.CreationTimeUtc = value; }
}
/// <inheritdoc />
public override bool Exists
{
get { return instance.Exists; }
}
/// <inheritdoc />
public override string Extension
{
get { return instance.Extension; }
}
/// <inheritdoc />
public override string FullName
{
get { return instance.FullName; }
}
/// <inheritdoc />
public override DateTime LastAccessTime
{
get { return instance.LastAccessTime; }
set { instance.LastAccessTime = value; }
}
/// <inheritdoc />
public override DateTime LastAccessTimeUtc
{
get { return instance.LastAccessTimeUtc; }
set { instance.LastAccessTimeUtc = value; }
}
/// <inheritdoc />
public override DateTime LastWriteTime
{
get { return instance.LastWriteTime; }
set { instance.LastWriteTime = value; }
}
/// <inheritdoc />
public override DateTime LastWriteTimeUtc
{
get { return instance.LastWriteTimeUtc; }
set { instance.LastWriteTimeUtc = value; }
}
#if FEATURE_FILE_SYSTEM_INFO_LINK_TARGET
/// <inheritdoc />
public override string LinkTarget
{
get { return instance.LinkTarget; }
}
#endif
/// <inheritdoc />
public override string Name
{
get { return instance.Name; }
}
/// <inheritdoc />
public override StreamWriter AppendText()
{
return instance.AppendText();
}
/// <inheritdoc />
public override IFileInfo CopyTo(string destFileName)
{
return new FileInfoWrapper(FileSystem, instance.CopyTo(destFileName));
}
/// <inheritdoc />
public override IFileInfo CopyTo(string destFileName, bool overwrite)
{
return new FileInfoWrapper(FileSystem, instance.CopyTo(destFileName, overwrite));
}
/// <inheritdoc />
public override FileSystemStream Create()
{
return new FileStreamWrapper(instance.Create());
}
/// <inheritdoc />
public override StreamWriter CreateText()
{
return instance.CreateText();
}
/// <inheritdoc />
[SupportedOSPlatform("windows")]
public override void Decrypt()
{
instance.Decrypt();
}
/// <inheritdoc />
[SupportedOSPlatform("windows")]
public override void Encrypt()
{
instance.Encrypt();
}
/// <inheritdoc />
public override void MoveTo(string destFileName)
{
instance.MoveTo(destFileName);
}
#if FEATURE_FILE_MOVE_WITH_OVERWRITE
/// <inheritdoc />
public override void MoveTo(string destFileName, bool overwrite)
{
instance.MoveTo(destFileName, overwrite);
}
#endif
/// <inheritdoc />
public override FileSystemStream Open(FileMode mode)
{
return new FileStreamWrapper(instance.Open(mode));
}
/// <inheritdoc />
public override FileSystemStream Open(FileMode mode, FileAccess access)
{
return new FileStreamWrapper(instance.Open(mode, access));
}
/// <inheritdoc />
public override FileSystemStream Open(FileMode mode, FileAccess access, FileShare share)
{
return new FileStreamWrapper(instance.Open(mode, access, share));
}
#if FEATURE_FILESTREAM_OPTIONS
/// <inheritdoc />
public override FileSystemStream Open(FileStreamOptions options)
{
return new FileStreamWrapper(instance.Open(options));
}
#endif
/// <inheritdoc />
public override FileSystemStream OpenRead()
{
return new FileStreamWrapper(instance.OpenRead());
}
/// <inheritdoc />
public override StreamReader OpenText()
{
return instance.OpenText();
}
/// <inheritdoc />
public override FileSystemStream OpenWrite()
{
return new FileStreamWrapper(instance.OpenWrite());
}
/// <inheritdoc />
public override IFileInfo Replace(string destinationFileName, string destinationBackupFileName)
{
return new FileInfoWrapper(FileSystem, instance.Replace(destinationFileName, destinationBackupFileName));
}
/// <inheritdoc />
public override IFileInfo Replace(string destinationFileName, string destinationBackupFileName, bool ignoreMetadataErrors)
{
return new FileInfoWrapper(FileSystem, instance.Replace(destinationFileName, destinationBackupFileName, ignoreMetadataErrors));
}
/// <inheritdoc />
public override IDirectoryInfo Directory
{
get { return new DirectoryInfoWrapper(FileSystem, instance.Directory); }
}
/// <inheritdoc />
public override string DirectoryName
{
get { return instance.DirectoryName; }
}
/// <inheritdoc />
public override bool IsReadOnly
{
get { return instance.IsReadOnly; }
set { instance.IsReadOnly = value; }
}
/// <inheritdoc />
public override long Length
{
get { return instance.Length; }
}
/// <inheritdoc />
public override string ToString()
{
return instance.ToString();
}
/// <inheritdoc cref="IFileSystemAclSupport.GetAccessControl()" />
[SupportedOSPlatform("windows")]
public object GetAccessControl()
{
return instance.GetAccessControl();
}
/// <inheritdoc cref="IFileSystemAclSupport.GetAccessControl(IFileSystemAclSupport.AccessControlSections)" />
[SupportedOSPlatform("windows")]
public object GetAccessControl(IFileSystemAclSupport.AccessControlSections includeSections)
{
return instance.GetAccessControl((AccessControlSections)includeSections);
}
/// <inheritdoc cref="IFileSystemAclSupport.SetAccessControl(object)" />
[SupportedOSPlatform("windows")]
public void SetAccessControl(object value)
{
if (value is FileSecurity fileSecurity)
{
this.instance.SetAccessControl(fileSecurity);
}
else
{
throw new ArgumentException("value must be of type `FileSecurity`");
}
}
}
}