/ src / Ryujinx.HLE / HOS / HomebrewRomFsStream.cs
HomebrewRomFsStream.cs
 1  using System;
 2  using System.IO;
 3  
 4  namespace Ryujinx.HLE.HOS
 5  {
 6      class HomebrewRomFsStream : Stream
 7      {
 8          private readonly Stream _baseStream;
 9          private readonly long _positionOffset;
10  
11          public HomebrewRomFsStream(Stream baseStream, long positionOffset)
12          {
13              _baseStream = baseStream;
14              _positionOffset = positionOffset;
15  
16              _baseStream.Position = _positionOffset;
17          }
18  
19          public override bool CanRead => _baseStream.CanRead;
20  
21          public override bool CanSeek => _baseStream.CanSeek;
22  
23          public override bool CanWrite => false;
24  
25          public override long Length => _baseStream.Length - _positionOffset;
26  
27          public override long Position
28          {
29              get
30              {
31                  return _baseStream.Position - _positionOffset;
32              }
33              set
34              {
35                  _baseStream.Position = value + _positionOffset;
36              }
37          }
38  
39          public override void Flush()
40          {
41              _baseStream.Flush();
42          }
43  
44          public override int Read(byte[] buffer, int offset, int count)
45          {
46              return _baseStream.Read(buffer, offset, count);
47          }
48  
49          public override long Seek(long offset, SeekOrigin origin)
50          {
51              if (origin == SeekOrigin.Begin)
52              {
53                  offset += _positionOffset;
54              }
55  
56              return _baseStream.Seek(offset, origin);
57          }
58  
59          public override void SetLength(long value)
60          {
61              throw new NotImplementedException();
62          }
63  
64          public override void Write(byte[] buffer, int offset, int count)
65          {
66              throw new NotImplementedException();
67          }
68  
69          protected override void Dispose(bool disposing)
70          {
71              if (disposing)
72              {
73                  _baseStream.Dispose();
74              }
75          }
76      }
77  }