diff --git a/DiscUtils/DiscUtils.Fat/FatFileStream.cs b/DiscUtils/DiscUtils.Fat/FatFileStream.cs index 6605928..5f1183b 100644 --- a/DiscUtils/DiscUtils.Fat/FatFileStream.cs +++ b/DiscUtils/DiscUtils.Fat/FatFileStream.cs @@ -20,20 +20,20 @@ // DEALINGS IN THE SOFTWARE. // +using System; +using System.Collections.Generic; +using System.IO; +using DiscUtils.Streams; + namespace DiscUtils.Fat { - using DiscUtils.Streams; - using System; - using System.Collections.Generic; - using System.IO; - internal class FatFileStream : SparseStream { - private Directory _dir; - private long _dirId; - private ClusterStream _stream; + private readonly Directory _dir; + private readonly long _dirId; + private readonly ClusterStream _stream; - private bool didWrite = false; + private bool didWrite; public FatFileStream(FatFileSystem fileSystem, Directory dir, long fileId, FileAccess access) { @@ -41,16 +41,10 @@ namespace DiscUtils.Fat _dirId = fileId; DirectoryEntry dirEntry = _dir.GetEntry(_dirId); - _stream = new ClusterStream(fileSystem, access, (uint)dirEntry.FirstCluster, (uint)dirEntry.FileSize); + _stream = new ClusterStream(fileSystem, access, dirEntry.FirstCluster, (uint)dirEntry.FileSize); _stream.FirstClusterChanged += FirstClusterAllocatedHandler; } - public override long Position - { - get { return _stream.Position; } - set { _stream.Position = value; } - } - public override bool CanRead { get { return _stream.CanRead; } @@ -66,20 +60,23 @@ namespace DiscUtils.Fat get { return _stream.CanWrite; } } + public override IEnumerable Extents + { + get { return new[] { new StreamExtent(0, Length) }; } + } + public override long Length { get { return _stream.Length; } } - public override IEnumerable Extents + public override long Position { - get - { - return new StreamExtent[] { new StreamExtent(0, Length) }; - } + get { return _stream.Position; } + set { _stream.Position = value; } } - public override void Close() + protected override void Dispose(bool disposing) { if (_dir.FileSystem.CanWrite) { @@ -99,7 +96,7 @@ namespace DiscUtils.Fat } finally { - base.Close(); + base.Dispose(disposing); } } } @@ -138,4 +135,4 @@ namespace DiscUtils.Fat _dir.UpdateEntry(_dirId, dirEntry); } } -} +} \ No newline at end of file diff --git a/DiscUtils/DiscUtils.Fat/FileName.cs b/DiscUtils/DiscUtils.Fat/FileName.cs index d4e4767..ab2d58d 100644 --- a/DiscUtils/DiscUtils.Fat/FileName.cs +++ b/DiscUtils/DiscUtils.Fat/FileName.cs @@ -20,23 +20,28 @@ // DEALINGS IN THE SOFTWARE. // +using System; +using System.Text; +using DiscUtils.Internal; + namespace DiscUtils.Fat { - using DiscUtils.Internal; - using System; - using System.Text; - internal sealed class FileName : IEquatable { - public static readonly FileName SelfEntryName = new FileName(new byte[] { 0x2E, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 }, 0); - public static readonly FileName ParentEntryName = new FileName(new byte[] { 0x2E, 0x2E, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 }, 0); - public static readonly FileName Null = new FileName(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0); - private const byte SpaceByte = 0x20; - private static readonly byte[] InvalidBytes = new byte[] { 0x22, 0x2A, 0x2B, 0x2C, 0x2E, 0x2F, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x5B, 0x5C, 0x5D, 0x7C }; + public static readonly FileName SelfEntryName = + new FileName(new byte[] { 0x2E, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 }, 0); - private byte[] _raw; + public static readonly FileName ParentEntryName = + new FileName(new byte[] { 0x2E, 0x2E, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 }, 0); + + public static readonly FileName Null = + new FileName(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0); + + private static readonly byte[] InvalidBytes = { 0x22, 0x2A, 0x2B, 0x2C, 0x2E, 0x2F, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x5B, 0x5C, 0x5D, 0x7C }; + + private readonly byte[] _raw; public FileName(byte[] data, int offset) { @@ -56,7 +61,7 @@ namespace DiscUtils.Fat byte b = bytes[nameIdx++]; if (b < 0x20 || Contains(InvalidBytes, b)) { - throw new ArgumentException("Invalid character in file name '" + (char)b + "'", "name"); + throw new ArgumentException("Invalid character in file name '" + (char)b + "'", nameof(name)); } _raw[rawIdx++] = b; @@ -64,11 +69,11 @@ namespace DiscUtils.Fat if (rawIdx > 8) { - throw new ArgumentException("File name too long '" + name + "'", "name"); + throw new ArgumentException("File name too long '" + name + "'", nameof(name)); } - else if (rawIdx == 0) + if (rawIdx == 0) { - throw new ArgumentException("File name too short '" + name + "'", "name"); + throw new ArgumentException("File name too short '" + name + "'", nameof(name)); } while (rawIdx < 8) @@ -86,7 +91,7 @@ namespace DiscUtils.Fat byte b = bytes[nameIdx++]; if (b < 0x20 || Contains(InvalidBytes, b)) { - throw new ArgumentException("Invalid character in file extension '" + (char)b + "'", "name"); + throw new ArgumentException("Invalid character in file extension '" + (char)b + "'", nameof(name)); } _raw[rawIdx++] = b; @@ -99,10 +104,20 @@ namespace DiscUtils.Fat if (nameIdx != bytes.Length) { - throw new ArgumentException("File extension too long '" + name + "'", "name"); + throw new ArgumentException("File extension too long '" + name + "'", nameof(name)); } } + public bool Equals(FileName other) + { + if (other == null) + { + return false; + } + + return CompareRawNames(this, other) == 0; + } + public static FileName FromPath(string path, Encoding encoding) { return new FileName(Utilities.GetFileFromPath(path), encoding); @@ -162,16 +177,6 @@ namespace DiscUtils.Fat return Equals(other as FileName); } - public bool Equals(FileName other) - { - if (other == null) - { - return false; - } - - return CompareRawNames(this, other) == 0; - } - public override int GetHashCode() { int val = 0x1A8D3C4E; @@ -190,7 +195,7 @@ namespace DiscUtils.Fat { if (a._raw[i] != b._raw[i]) { - return (int)a._raw[i] - (int)b._raw[i]; + return a._raw[i] - b._raw[i]; } } @@ -210,4 +215,4 @@ namespace DiscUtils.Fat return false; } } -} +} \ No newline at end of file diff --git a/DiscUtils/DiscUtils.Fat/Directory.cs b/DiscUtils/DiscUtils.Fat/Modified/Directory.cs similarity index 100% rename from DiscUtils/DiscUtils.Fat/Directory.cs rename to DiscUtils/DiscUtils.Fat/Modified/Directory.cs diff --git a/DiscUtils/DiscUtils.Fat/FatFileSystem.cs b/DiscUtils/DiscUtils.Fat/Modified/FatFileSystem.cs similarity index 100% rename from DiscUtils/DiscUtils.Fat/FatFileSystem.cs rename to DiscUtils/DiscUtils.Fat/Modified/FatFileSystem.cs