Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
IsolatedStorageFileStream.cs
Go to the documentation of this file.
5
7
9{
10 private struct InitialiationData
11 {
13
15
16 public string FullPath;
17 }
18
19 private readonly FileStream _fs;
20
21 private readonly IsolatedStorageFile _isf;
22
23 private readonly string _givenPath;
24
25 private readonly string _fullPath;
26
27 public override bool CanRead => _fs.CanRead;
28
29 public override bool CanWrite => _fs.CanWrite;
30
31 public override bool CanSeek => _fs.CanSeek;
32
33 public override long Length => _fs.Length;
34
35 public override long Position
36 {
37 get
38 {
39 return _fs.Position;
40 }
41 set
42 {
43 _fs.Position = value;
44 }
45 }
46
47 public override bool IsAsync => _fs.IsAsync;
48
49 [Obsolete("IsolatedStorageFileStream.Handle has been deprecated. Use IsolatedStorageFileStream's SafeFileHandle property instead.")]
50 public override IntPtr Handle => _fs.Handle;
51
53 {
54 get
55 {
57 }
58 }
59
60 public IsolatedStorageFileStream(string path, FileMode mode)
61 : this(path, mode, (mode == FileMode.Append) ? FileAccess.Write : FileAccess.ReadWrite, FileShare.None, null)
62 {
63 }
64
66 : this(path, mode, (mode == FileMode.Append) ? FileAccess.Write : FileAccess.ReadWrite, FileShare.None, isf)
67 {
68 }
69
70 public IsolatedStorageFileStream(string path, FileMode mode, FileAccess access)
71 : this(path, mode, access, (access == FileAccess.Read) ? FileShare.Read : FileShare.None, 1024, null)
72 {
73 }
74
75 public IsolatedStorageFileStream(string path, FileMode mode, FileAccess access, IsolatedStorageFile? isf)
76 : this(path, mode, access, (access == FileAccess.Read) ? FileShare.Read : FileShare.None, 1024, isf)
77 {
78 }
79
80 public IsolatedStorageFileStream(string path, FileMode mode, FileAccess access, FileShare share)
81 : this(path, mode, access, share, 1024, null)
82 {
83 }
84
85 public IsolatedStorageFileStream(string path, FileMode mode, FileAccess access, FileShare share, IsolatedStorageFile? isf)
86 : this(path, mode, access, share, 1024, isf)
87 {
88 }
89
90 public IsolatedStorageFileStream(string path, FileMode mode, FileAccess access, FileShare share, int bufferSize)
91 : this(path, mode, access, share, bufferSize, null)
92 {
93 }
94
95 public IsolatedStorageFileStream(string path, FileMode mode, FileAccess access, FileShare share, int bufferSize, IsolatedStorageFile? isf)
96 : this(path, mode, access, share, bufferSize, InitializeFileStream(path, mode, access, share, bufferSize, isf))
97 {
98 }
99
100 private IsolatedStorageFileStream(string path, FileMode mode, FileAccess access, FileShare share, int bufferSize, InitialiationData initializationData)
101 : base(new SafeFileHandle(initializationData.NestedStream.SafeFileHandle.DangerousGetHandle(), ownsHandle: false), access, bufferSize)
102 {
103 _isf = initializationData.StorageFile;
104 _givenPath = path;
105 _fullPath = initializationData.FullPath;
106 _fs = initializationData.NestedStream;
107 }
108
109 private static InitialiationData InitializeFileStream(string path, FileMode mode, FileAccess access, FileShare share, int bufferSize, IsolatedStorageFile isf)
110 {
111 if (path == null)
112 {
113 throw new ArgumentNullException("path");
114 }
115 if (path.Length == 0 || path.Equals("\\"))
116 {
118 }
119 bool flag = false;
120 if (isf == null)
121 {
123 flag = true;
124 }
125 if (isf.Disposed)
126 {
128 }
129 if ((uint)(mode - 1) > 5u)
130 {
132 }
133 InitialiationData initialiationData = default(InitialiationData);
134 initialiationData.FullPath = isf.GetFullPath(path);
135 initialiationData.StorageFile = isf;
136 InitialiationData result = initialiationData;
137 try
138 {
139 result.NestedStream = new FileStream(result.FullPath, mode, access, share, bufferSize, FileOptions.None);
140 return result;
141 }
142 catch (Exception rootCause)
143 {
144 try
145 {
146 if (flag)
147 {
148 result.StorageFile?.Dispose();
149 }
150 }
151 catch
152 {
153 }
155 }
156 }
157
158 protected override void Dispose(bool disposing)
159 {
160 try
161 {
162 if (disposing && _fs != null)
163 {
164 _fs.Dispose();
165 }
166 }
167 finally
168 {
169 base.Dispose(disposing);
170 }
171 }
172
173 public override ValueTask DisposeAsync()
174 {
175 if (!(GetType() != typeof(IsolatedStorageFileStream)))
176 {
177 if (_fs == null)
178 {
179 return default(ValueTask);
180 }
181 return _fs.DisposeAsync();
182 }
183 return base.DisposeAsync();
184 }
185
186 public override void Flush()
187 {
188 _fs.Flush();
189 }
190
191 public override void Flush(bool flushToDisk)
192 {
193 _fs.Flush(flushToDisk);
194 }
195
200
201 public override void SetLength(long value)
202 {
204 }
205
206 public override int Read(byte[] buffer, int offset, int count)
207 {
208 return _fs.Read(buffer, offset, count);
209 }
210
211 public override int Read(Span<byte> buffer)
212 {
213 return _fs.Read(buffer);
214 }
215
220
225
226 public override int ReadByte()
227 {
228 return _fs.ReadByte();
229 }
230
231 public override long Seek(long offset, SeekOrigin origin)
232 {
233 return _fs.Seek(offset, origin);
234 }
235
236 public override void Write(byte[] buffer, int offset, int count)
237 {
239 }
240
241 public override void Write(ReadOnlySpan<byte> buffer)
242 {
244 }
245
250
255
256 public override void WriteByte(byte value)
257 {
259 }
260
261 public override IAsyncResult BeginRead(byte[] array, int offset, int numBytes, AsyncCallback? userCallback, object? stateObject)
262 {
263 return _fs.BeginRead(array, offset, numBytes, userCallback, stateObject);
264 }
265
266 public override IAsyncResult BeginWrite(byte[] array, int offset, int numBytes, AsyncCallback? userCallback, object? stateObject)
267 {
268 return _fs.BeginWrite(array, offset, numBytes, userCallback, stateObject);
269 }
270
271 public override int EndRead(IAsyncResult asyncResult)
272 {
273 return _fs.EndRead(asyncResult);
274 }
275
276 public override void EndWrite(IAsyncResult asyncResult)
277 {
279 }
280
281 [UnsupportedOSPlatform("macos")]
282 public override void Unlock(long position, long length)
283 {
284 _fs.Unlock(position, length);
285 }
286
287 [UnsupportedOSPlatform("macos")]
288 public override void Lock(long position, long length)
289 {
290 _fs.Lock(position, length);
291 }
292}
override long Length
Definition FileStream.cs:28
override bool CanRead
Definition FileStream.cs:17
override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state)
virtual bool IsAsync
Definition FileStream.cs:25
override bool CanWrite
Definition FileStream.cs:19
override Task< int > ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
override void EndWrite(IAsyncResult asyncResult)
override void Flush()
override bool CanSeek
Definition FileStream.cs:67
virtual void Unlock(long position, long length)
override void Dispose(bool disposing)
override long Position
Definition FileStream.cs:44
override void SetLength(long value)
override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
override void WriteByte(byte value)
override int EndRead(IAsyncResult asyncResult)
override ValueTask DisposeAsync()
override long Seek(long offset, SeekOrigin origin)
override Task FlushAsync(CancellationToken cancellationToken)
override int ReadByte()
FileStream(IntPtr handle, FileAccess access)
Definition FileStream.cs:71
override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state)
override void Write(byte[] buffer, int offset, int count)
virtual IntPtr Handle
Definition FileStream.cs:15
override int Read(byte[] buffer, int offset, int count)
virtual void Lock(long position, long length)
IsolatedStorageFileStream(string path, FileMode mode, IsolatedStorageFile? isf)
IsolatedStorageFileStream(string path, FileMode mode, FileAccess access, FileShare share, int bufferSize, IsolatedStorageFile? isf)
IsolatedStorageFileStream(string path, FileMode mode, FileAccess access, FileShare share)
override ValueTask< int > ReadAsync(Memory< byte > buffer, CancellationToken cancellationToken)
IsolatedStorageFileStream(string path, FileMode mode, FileAccess access, FileShare share, int bufferSize)
override int Read(byte[] buffer, int offset, int count)
override ValueTask WriteAsync(ReadOnlyMemory< byte > buffer, CancellationToken cancellationToken)
override IAsyncResult BeginRead(byte[] array, int offset, int numBytes, AsyncCallback? userCallback, object? stateObject)
IsolatedStorageFileStream(string path, FileMode mode, FileAccess access)
override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
override Task FlushAsync(CancellationToken cancellationToken)
override IAsyncResult BeginWrite(byte[] array, int offset, int numBytes, AsyncCallback? userCallback, object? stateObject)
IsolatedStorageFileStream(string path, FileMode mode, FileAccess access, IsolatedStorageFile? isf)
IsolatedStorageFileStream(string path, FileMode mode, FileAccess access, FileShare share, IsolatedStorageFile? isf)
static InitialiationData InitializeFileStream(string path, FileMode mode, FileAccess access, FileShare share, int bufferSize, IsolatedStorageFile isf)
IsolatedStorageFileStream(string path, FileMode mode, FileAccess access, FileShare share, int bufferSize, InitialiationData initializationData)
override void Write(byte[] buffer, int offset, int count)
override long Seek(long offset, SeekOrigin origin)
override Task< int > ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
static Exception GetIsolatedStorageException(string exceptionMsg, Exception rootCause)
static string IsolatedStorage_Path
Definition SR.cs:18
static string IsolatedStorage_StoreNotOpen
Definition SR.cs:14
static string IsolatedStorage_Operation_ISFS
Definition SR.cs:16
static string IsolatedStorage_FileOpenMode
Definition SR.cs:20
Definition SR.cs:7