Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
FileInfo.cs
Go to the documentation of this file.
2using System.Text;
3
4namespace System.IO;
5
6public sealed class FileInfo : FileSystemInfo
7{
8 public long Length
9 {
10 get
11 {
12 if ((base.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
13 {
15 }
16 return base.LengthCore;
17 }
18 }
19
21
23 {
24 get
25 {
26 string directoryName = DirectoryName;
27 if (directoryName == null)
28 {
29 return null;
30 }
31 return new DirectoryInfo(directoryName);
32 }
33 }
34
35 public bool IsReadOnly
36 {
37 get
38 {
39 return (base.Attributes & FileAttributes.ReadOnly) != 0;
40 }
41 set
42 {
43 if (value)
44 {
45 base.Attributes |= FileAttributes.ReadOnly;
46 }
47 else
48 {
49 base.Attributes &= ~FileAttributes.ReadOnly;
50 }
51 }
52 }
53
54 public FileInfo(string fileName)
55 : this(fileName, null, null, isNormalized: false)
56 {
57 }
58
59 internal FileInfo(string originalPath, string fullPath = null, string fileName = null, bool isNormalized = false)
60 {
61 OriginalPath = originalPath ?? throw new ArgumentNullException("fileName");
62 fullPath = fullPath ?? originalPath;
63 FullPath = (isNormalized ? (fullPath ?? originalPath) : Path.GetFullPath(fullPath));
64 _name = fileName ?? Path.GetFileName(originalPath);
65 }
66
68 {
69 return new StreamReader(base.NormalizedPath, Encoding.UTF8, detectEncodingFromByteOrderMarks: true);
70 }
71
73 {
74 return new StreamWriter(base.NormalizedPath, append: false);
75 }
76
78 {
79 return new StreamWriter(base.NormalizedPath, append: true);
80 }
81
82 public FileInfo CopyTo(string destFileName)
83 {
84 return CopyTo(destFileName, overwrite: false);
85 }
86
87 public FileInfo CopyTo(string destFileName, bool overwrite)
88 {
89 if (destFileName == null)
90 {
91 throw new ArgumentNullException("destFileName", SR.ArgumentNull_FileName);
92 }
93 if (destFileName.Length == 0)
94 {
95 throw new ArgumentException(SR.Argument_EmptyFileName, "destFileName");
96 }
97 string fullPath = Path.GetFullPath(destFileName);
98 FileSystem.CopyFile(FullPath, fullPath, overwrite);
99 return new FileInfo(fullPath, null, null, isNormalized: true);
100 }
101
103 {
104 FileStream result = File.Create(base.NormalizedPath);
105 Invalidate();
106 return result;
107 }
108
109 public override void Delete()
110 {
112 Invalidate();
113 }
114
116 {
117 return Open(mode, (mode == FileMode.Append) ? FileAccess.Write : FileAccess.ReadWrite, FileShare.None);
118 }
119
120 public FileStream Open(FileMode mode, FileAccess access)
121 {
122 return Open(mode, access, FileShare.None);
123 }
124
125 public FileStream Open(FileMode mode, FileAccess access, FileShare share)
126 {
127 return new FileStream(base.NormalizedPath, mode, access, share);
128 }
129
131 {
132 return new FileStream(base.NormalizedPath, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, useAsync: false);
133 }
134
136 {
137 return new FileStream(base.NormalizedPath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None);
138 }
139
140 public void MoveTo(string destFileName)
141 {
142 MoveTo(destFileName, overwrite: false);
143 }
144
145 public void MoveTo(string destFileName, bool overwrite)
146 {
147 if (destFileName == null)
148 {
149 throw new ArgumentNullException("destFileName");
150 }
151 if (destFileName.Length == 0)
152 {
153 throw new ArgumentException(SR.Argument_EmptyFileName, "destFileName");
154 }
155 string fullPath = Path.GetFullPath(destFileName);
157 {
159 }
160 if (!Exists)
161 {
163 }
164 FileSystem.MoveFile(FullPath, fullPath, overwrite);
165 FullPath = fullPath;
166 OriginalPath = destFileName;
167 _name = Path.GetFileName(fullPath);
168 Invalidate();
169 }
170
171 public FileInfo Replace(string destinationFileName, string? destinationBackupFileName)
172 {
173 return Replace(destinationFileName, destinationBackupFileName, ignoreMetadataErrors: false);
174 }
175
176 public FileInfo Replace(string destinationFileName, string? destinationBackupFileName, bool ignoreMetadataErrors)
177 {
178 if (destinationFileName == null)
179 {
180 throw new ArgumentNullException("destinationFileName");
181 }
182 FileSystem.ReplaceFile(FullPath, Path.GetFullPath(destinationFileName), (destinationBackupFileName != null) ? Path.GetFullPath(destinationBackupFileName) : null, ignoreMetadataErrors);
183 return new FileInfo(destinationFileName);
184 }
185
186 [SupportedOSPlatform("windows")]
187 public void Decrypt()
188 {
190 }
191
192 [SupportedOSPlatform("windows")]
193 public void Encrypt()
194 {
196 }
197
199 {
200 return File.Open(base.NormalizedPath, options);
201 }
202}
FileStream OpenWrite()
Definition FileInfo.cs:135
FileInfo(string originalPath, string fullPath=null, string fileName=null, bool isNormalized=false)
Definition FileInfo.cs:59
FileInfo Replace(string destinationFileName, string? destinationBackupFileName, bool ignoreMetadataErrors)
Definition FileInfo.cs:176
StreamReader OpenText()
Definition FileInfo.cs:67
StreamWriter CreateText()
Definition FileInfo.cs:72
FileInfo CopyTo(string destFileName, bool overwrite)
Definition FileInfo.cs:87
override void Delete()
Definition FileInfo.cs:109
FileInfo(string fileName)
Definition FileInfo.cs:54
void MoveTo(string destFileName)
Definition FileInfo.cs:140
FileStream Create()
Definition FileInfo.cs:102
FileInfo CopyTo(string destFileName)
Definition FileInfo.cs:82
string? DirectoryName
Definition FileInfo.cs:20
void MoveTo(string destFileName, bool overwrite)
Definition FileInfo.cs:145
FileInfo Replace(string destinationFileName, string? destinationBackupFileName)
Definition FileInfo.cs:171
StreamWriter AppendText()
Definition FileInfo.cs:77
FileStream OpenRead()
Definition FileInfo.cs:130
FileStream Open(FileStreamOptions options)
Definition FileInfo.cs:198
FileStream Open(FileMode mode, FileAccess access)
Definition FileInfo.cs:120
FileStream Open(FileMode mode, FileAccess access, FileShare share)
Definition FileInfo.cs:125
FileStream Open(FileMode mode)
Definition FileInfo.cs:115
static void DeleteFile(string fullPath)
static void MoveFile(string sourceFullPath, string destFullPath, bool overwrite)
static void CopyFile(string sourceFullPath, string destFullPath, bool overwrite)
static void ReplaceFile(string sourceFullPath, string destFullPath, string destBackupFullPath, bool ignoreMetadataErrors)
static FileStream Create(string path)
Definition File.cs:73
static FileStream Open(string path, FileMode mode)
Definition File.cs:128
static void Encrypt(string path)
Definition File.cs:614
static void Decrypt(string path)
Definition File.cs:620
static ? string GetFileName(string? path)
Definition Path.cs:200
static string GetFullPath(string path)
Definition Path.cs:881
static ? string GetDirectoryName(string? path)
Definition Path.cs:121
static string ArgumentNull_FileName
Definition SR.cs:948
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string IO_FileNotFound_FileName
Definition SR.cs:40
static string Argument_EmptyFileName
Definition SR.cs:582
static string IO_PathNotFound_Path
Definition SR.cs:44
Definition SR.cs:7
static Encoding UTF8
Definition Encoding.cs:526