mirror of
https://github.com/ReneLergner/WPinternals.git
synced 2026-08-10 01:51:15 +10:00
DiscUtils: Fat: Merge more upstream changes
This commit is contained in:
@@ -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<FileName>
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user