initial commit
This commit is contained in:
commit
1b60743303
274 changed files with 25866 additions and 0 deletions
199
ImageReader/ISO9660/DirectoryRecords/DirectoryRecord.cs
Normal file
199
ImageReader/ISO9660/DirectoryRecords/DirectoryRecord.cs
Normal file
|
@ -0,0 +1,199 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: ImageReader.ISO9660.DirectoryRecords.DirectoryRecord
|
||||
// Assembly: ImageReader, Version=1.5.2.0, Culture=neutral, PublicKeyToken=611be24fdeb07e08
|
||||
// MVID: E0717604-B50B-4CB4-B85C-C17F43D5C04B
|
||||
// Assembly location: ImageReader.dll
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace ImageReader.ISO9660.DirectoryRecords
|
||||
{
|
||||
public class DirectoryRecord
|
||||
{
|
||||
public static readonly char DIRECTORY_SEPARATOR_CHAR = Path.DirectorySeparatorChar;
|
||||
public static readonly string DIRECTORY_SEPARATOR = DirectoryRecord.DIRECTORY_SEPARATOR_CHAR.ToString();
|
||||
public static readonly string ROOT_DIRECTORY_NAME = DirectoryRecord.DIRECTORY_SEPARATOR_CHAR.ToString();
|
||||
public static readonly string SELF_DIRECTORY_NAME = ".";
|
||||
public static readonly string PARENT_DIRECTORY_NAME = "..";
|
||||
internal static readonly byte ROOT_OR_SELF_DIRECTORY_FILE_IDENTIFIER = 0;
|
||||
internal static readonly byte PARENT_DIRECTORY_FILE_IDENTIFIER = 1;
|
||||
internal ushort extendAttributeLength;
|
||||
internal uint extentTypeL;
|
||||
internal uint extentTypeM;
|
||||
internal uint extentSizeTypeL;
|
||||
internal uint extentSizeTypeM;
|
||||
internal ushort fileUnitSize;
|
||||
internal ushort fileGapSize;
|
||||
internal ushort volumeSequenceNumberTypeL;
|
||||
internal ushort volumeSequenceNumberTypeM;
|
||||
internal DirectoryRecord parent;
|
||||
internal List<DirectoryRecord> children;
|
||||
|
||||
public static string FindCommonPathPrefix(List<DirectoryRecord> directoryRecords)
|
||||
{
|
||||
if (directoryRecords.Count < 1)
|
||||
return (string) null;
|
||||
Dictionary<DirectoryRecord, string> source = new Dictionary<DirectoryRecord, string>();
|
||||
foreach (DirectoryRecord directoryRecord in directoryRecords)
|
||||
source[directoryRecord] = directoryRecord.IsDirectory ? directoryRecord.FullPath : Path.GetDirectoryName(directoryRecord.FullPath);
|
||||
int minDepth = source.Min<KeyValuePair<DirectoryRecord, string>>((Func<KeyValuePair<DirectoryRecord, string>, int>) (pkv => pkv.Value.Split(new char[1]
|
||||
{
|
||||
DirectoryRecord.DIRECTORY_SEPARATOR_CHAR
|
||||
}, StringSplitOptions.RemoveEmptyEntries).Length));
|
||||
string pathPrefix = source.First<KeyValuePair<DirectoryRecord, string>>((Func<KeyValuePair<DirectoryRecord, string>, bool>) (pkv => pkv.Value.Split(new char[1]
|
||||
{
|
||||
DirectoryRecord.DIRECTORY_SEPARATOR_CHAR
|
||||
}, StringSplitOptions.RemoveEmptyEntries).Length == minDepth)).Value;
|
||||
for (int index = 0; index < minDepth && !directoryRecords.TrueForAll((Predicate<DirectoryRecord>) (dr => dr.FullPath.StartsWith(pathPrefix))); ++index)
|
||||
pathPrefix = Path.GetDirectoryName(pathPrefix);
|
||||
if (directoryRecords.Count == 1 && directoryRecords[0].IsDirectory && !directoryRecords[0].IsRoot)
|
||||
pathPrefix = Path.GetDirectoryName(pathPrefix);
|
||||
return pathPrefix;
|
||||
}
|
||||
|
||||
internal DirectoryRecord() => this.children = new List<DirectoryRecord>();
|
||||
|
||||
public byte RecordLength { get; internal set; }
|
||||
|
||||
public string Name { get; internal set; }
|
||||
|
||||
public uint Extent => !BitConverter.IsLittleEndian ? this.extentTypeM : this.extentTypeL;
|
||||
|
||||
public uint ExtentSize => !BitConverter.IsLittleEndian ? this.extentSizeTypeM : this.extentSizeTypeL;
|
||||
|
||||
public DateTime? RecordingDateTime { get; internal set; }
|
||||
|
||||
public DirectoryRecordFlags Flags { get; internal set; }
|
||||
|
||||
public bool HasValidFileIdentifier { get; internal set; }
|
||||
|
||||
public ushort VolumeSequenceNumber => !BitConverter.IsLittleEndian ? this.volumeSequenceNumberTypeM : this.volumeSequenceNumberTypeL;
|
||||
|
||||
public int Depth
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.IsRoot)
|
||||
return 0;
|
||||
return this.FullPath.Split(new char[1]
|
||||
{
|
||||
Path.DirectorySeparatorChar
|
||||
}, StringSplitOptions.RemoveEmptyEntries).Length;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsHidden => (this.Flags & DirectoryRecordFlags.HIDDEN_FILE) != DirectoryRecordFlags.NONE;
|
||||
|
||||
public bool IsDirectory => (this.Flags & DirectoryRecordFlags.DIRECTORY) != DirectoryRecordFlags.NONE;
|
||||
|
||||
public bool IsAssociated => (this.Flags & DirectoryRecordFlags.ASSOCIATED_FILE) != DirectoryRecordFlags.NONE;
|
||||
|
||||
public bool HasExtentedAttributeRecord => (this.Flags & DirectoryRecordFlags.EXTENDED_ATTRIBUTE_RECORD) != DirectoryRecordFlags.NONE;
|
||||
|
||||
public bool HasOwnerAndGroupPermissions => (this.Flags & DirectoryRecordFlags.OWNER_AND_GROUP_PERMISSIONS) != DirectoryRecordFlags.NONE;
|
||||
|
||||
public bool HasReservedFlags => (this.Flags & DirectoryRecordFlags.RESERVED_FLAGS) != DirectoryRecordFlags.NONE;
|
||||
|
||||
public bool IsNotFinalRecord => (this.Flags & DirectoryRecordFlags.NOT_FINAL_RECORD) != DirectoryRecordFlags.NONE;
|
||||
|
||||
public bool IsFlagSet(DirectoryRecordFlags flags) => (this.Flags & flags) != DirectoryRecordFlags.NONE;
|
||||
|
||||
public bool IsRoot => this.parent == null;
|
||||
|
||||
public DirectoryRecord RootDirectory => this.IsRoot ? this : this.parent.RootDirectory;
|
||||
|
||||
public DirectoryRecord ParentDirectory => this.parent;
|
||||
|
||||
public List<DirectoryRecord> SubDirectories => this.children;
|
||||
|
||||
public List<DirectoryRecord> GetAllSubFolder()
|
||||
{
|
||||
List<DirectoryRecord> list = new List<DirectoryRecord>();
|
||||
this.GetAllSubDirectoriesRec(list, true, false);
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<DirectoryRecord> GetAllSubFiles()
|
||||
{
|
||||
List<DirectoryRecord> list = new List<DirectoryRecord>();
|
||||
this.GetAllSubDirectoriesRec(list, false, true);
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<DirectoryRecord> GetAllSubDirectories()
|
||||
{
|
||||
List<DirectoryRecord> list = new List<DirectoryRecord>();
|
||||
this.GetAllSubDirectoriesRec(list, true, true);
|
||||
return list;
|
||||
}
|
||||
|
||||
private void GetAllSubDirectoriesRec(
|
||||
List<DirectoryRecord> list,
|
||||
bool includeFolders,
|
||||
bool includeFiles)
|
||||
{
|
||||
foreach (DirectoryRecord child in this.children)
|
||||
{
|
||||
if (includeFolders && child.IsDirectory)
|
||||
list.Add(child);
|
||||
if (includeFiles && !child.IsDirectory)
|
||||
list.Add(child);
|
||||
child.GetAllSubDirectoriesRec(list, includeFolders, includeFiles);
|
||||
}
|
||||
}
|
||||
|
||||
public bool Contains(string directoryRecordName) => this.children.Find((Predicate<DirectoryRecord>) (directoryRecord => directoryRecord.Name.Equals(directoryRecordName))) != null;
|
||||
|
||||
public DirectoryRecord Find(DirectoryRecord directoryRecord)
|
||||
{
|
||||
if (directoryRecord == this)
|
||||
return this;
|
||||
DirectoryRecord directoryRecord1 = (DirectoryRecord) null;
|
||||
if (directoryRecord.FullPath.StartsWith(this.FullPath))
|
||||
{
|
||||
foreach (DirectoryRecord child in this.children)
|
||||
{
|
||||
directoryRecord1 = child.Find(directoryRecord);
|
||||
if (directoryRecord1 != null)
|
||||
break;
|
||||
}
|
||||
}
|
||||
return directoryRecord1;
|
||||
}
|
||||
|
||||
public DirectoryRecord Find(string path)
|
||||
{
|
||||
if (this.FullPath.Equals(path))
|
||||
return this;
|
||||
DirectoryRecord directoryRecord = (DirectoryRecord) null;
|
||||
if (path.StartsWith(this.FullPath))
|
||||
{
|
||||
foreach (DirectoryRecord child in this.children)
|
||||
{
|
||||
directoryRecord = child.Find(path);
|
||||
if (directoryRecord != null)
|
||||
break;
|
||||
}
|
||||
}
|
||||
return directoryRecord;
|
||||
}
|
||||
|
||||
public string FullPath => this.parent != null ? Path.Combine(this.parent.FullPath, this.Name) : this.Name;
|
||||
|
||||
public uint UsedSpace
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!this.IsDirectory)
|
||||
return this.ExtentSize;
|
||||
uint num = 0;
|
||||
foreach (DirectoryRecord child in this.children)
|
||||
num += child.UsedSpace;
|
||||
return num;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
114
ImageReader/ISO9660/DirectoryRecords/DirectoryRecordConverter.cs
Normal file
114
ImageReader/ISO9660/DirectoryRecords/DirectoryRecordConverter.cs
Normal file
|
@ -0,0 +1,114 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: ImageReader.ISO9660.DirectoryRecords.DirectoryRecordConverter
|
||||
// Assembly: ImageReader, Version=1.5.2.0, Culture=neutral, PublicKeyToken=611be24fdeb07e08
|
||||
// MVID: E0717604-B50B-4CB4-B85C-C17F43D5C04B
|
||||
// Assembly location: ImageReader.dll
|
||||
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace ImageReader.ISO9660.DirectoryRecords
|
||||
{
|
||||
public class DirectoryRecordConverter
|
||||
{
|
||||
private static readonly Logger.ILog logger = Logger.CreateLog();
|
||||
private static readonly byte DIRECTORY_RECORD_MIN_SIZE = 34;
|
||||
private static readonly byte OFFSET_RECORD_LENGTH = 0;
|
||||
private static readonly byte OFFSET_EXTENDED_ATTRIBUTE_LENGTH = 1;
|
||||
private static readonly byte OFFSET_TYPE_L_EXTENT_LOCATION = 2;
|
||||
private static readonly byte OFFSET_TYPE_M_EXTENT_LOCATION = 6;
|
||||
private static readonly byte OFFSET_TYPE_L_EXTENT_SIZE = 10;
|
||||
private static readonly byte OFFSET_TYPE_M_EXTENT_SIZE = 14;
|
||||
private static readonly byte OFFSET_DATETIME = 18;
|
||||
private static readonly byte OFFSET_FLAGS = 25;
|
||||
private static readonly byte OFFSET_INTERLEAVED_FILE_UNIT_SIZE = 26;
|
||||
private static readonly byte OFFSET_INTERLEAVED_FILE_GAP_SIZE = 27;
|
||||
private static readonly byte OFFSET_TYPE_L_VOLUME_SEQUENCE_NUMBER = 28;
|
||||
private static readonly byte OFFSET_TYPE_M_VOLUME_SEQUENCE_NUMBER = 30;
|
||||
private static readonly byte OFFSET_FILE_IDENTIFIER_LENGTH = 32;
|
||||
private static readonly byte OFFSET_FILE_IDENTIFIER = 33;
|
||||
private static readonly Regex VALID_FILENAME = new Regex("[^A-Z0-9._]+", RegexOptions.IgnoreCase);
|
||||
|
||||
public static DirectoryRecord ToDirectoryRecord(byte[] buffer, int startIndex) => DirectoryRecordConverter.ToDirectoryRecord(buffer, startIndex, false);
|
||||
|
||||
public static DirectoryRecord ToRootDirectoryRecord(
|
||||
byte[] buffer,
|
||||
int startIndex)
|
||||
{
|
||||
return DirectoryRecordConverter.ToDirectoryRecord(buffer, startIndex, true);
|
||||
}
|
||||
|
||||
private static DirectoryRecord ToDirectoryRecord(
|
||||
byte[] buffer,
|
||||
int startIndex,
|
||||
bool isForRootDirectory)
|
||||
{
|
||||
byte num1 = buffer[startIndex + (int) DirectoryRecordConverter.OFFSET_RECORD_LENGTH];
|
||||
if (startIndex < 0 || buffer.Length - startIndex < (int) num1 || (int) num1 < (int) DirectoryRecordConverter.DIRECTORY_RECORD_MIN_SIZE)
|
||||
throw new ArgumentOutOfRangeException();
|
||||
DirectoryRecord directoryRecord = new DirectoryRecord();
|
||||
directoryRecord.RecordLength = num1;
|
||||
directoryRecord.extendAttributeLength = (ushort) buffer[startIndex + (int) DirectoryRecordConverter.OFFSET_EXTENDED_ATTRIBUTE_LENGTH];
|
||||
directoryRecord.extentTypeL = BitConverter.ToUInt32(buffer, startIndex + (int) DirectoryRecordConverter.OFFSET_TYPE_L_EXTENT_LOCATION);
|
||||
directoryRecord.extentTypeM = BitConverter.ToUInt32(buffer, startIndex + (int) DirectoryRecordConverter.OFFSET_TYPE_M_EXTENT_LOCATION);
|
||||
directoryRecord.extentSizeTypeL = BitConverter.ToUInt32(buffer, startIndex + (int) DirectoryRecordConverter.OFFSET_TYPE_L_EXTENT_SIZE);
|
||||
directoryRecord.extentSizeTypeM = BitConverter.ToUInt32(buffer, startIndex + (int) DirectoryRecordConverter.OFFSET_TYPE_M_EXTENT_SIZE);
|
||||
directoryRecord.RecordingDateTime = DirectoryRecordConverter.DirectoryRecordDateTimeConverter.ToDateTime(buffer, startIndex + (int) DirectoryRecordConverter.OFFSET_DATETIME);
|
||||
directoryRecord.Flags = (DirectoryRecordFlags) buffer[startIndex + (int) DirectoryRecordConverter.OFFSET_FLAGS];
|
||||
directoryRecord.fileUnitSize = (ushort) buffer[startIndex + (int) DirectoryRecordConverter.OFFSET_INTERLEAVED_FILE_UNIT_SIZE];
|
||||
directoryRecord.fileGapSize = (ushort) buffer[startIndex + (int) DirectoryRecordConverter.OFFSET_INTERLEAVED_FILE_GAP_SIZE];
|
||||
directoryRecord.volumeSequenceNumberTypeL = BitConverter.ToUInt16(buffer, startIndex + (int) DirectoryRecordConverter.OFFSET_TYPE_L_VOLUME_SEQUENCE_NUMBER);
|
||||
directoryRecord.volumeSequenceNumberTypeM = BitConverter.ToUInt16(buffer, startIndex + (int) DirectoryRecordConverter.OFFSET_TYPE_M_VOLUME_SEQUENCE_NUMBER);
|
||||
byte num2 = buffer[startIndex + (int) DirectoryRecordConverter.OFFSET_FILE_IDENTIFIER_LENGTH];
|
||||
if ((int) buffer[startIndex + (int) DirectoryRecordConverter.OFFSET_FILE_IDENTIFIER] == (int) DirectoryRecord.ROOT_OR_SELF_DIRECTORY_FILE_IDENTIFIER)
|
||||
directoryRecord.Name = !isForRootDirectory ? DirectoryRecord.SELF_DIRECTORY_NAME : DirectoryRecord.ROOT_DIRECTORY_NAME;
|
||||
else if ((int) buffer[startIndex + (int) DirectoryRecordConverter.OFFSET_FILE_IDENTIFIER] == (int) DirectoryRecord.PARENT_DIRECTORY_FILE_IDENTIFIER)
|
||||
{
|
||||
directoryRecord.Name = DirectoryRecord.PARENT_DIRECTORY_NAME;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!directoryRecord.IsDirectory)
|
||||
num2 -= (byte) 2;
|
||||
string input = Encoding.Default.GetString(buffer, startIndex + (int) DirectoryRecordConverter.OFFSET_FILE_IDENTIFIER, (int) num2);
|
||||
directoryRecord.Name = DirectoryRecordConverter.VALID_FILENAME.Replace(input, "_invalid_");
|
||||
directoryRecord.HasValidFileIdentifier = directoryRecord.Name.Equals(input);
|
||||
}
|
||||
return directoryRecord;
|
||||
}
|
||||
|
||||
private sealed class DirectoryRecordDateTimeConverter
|
||||
{
|
||||
private static readonly byte DATETIME_SIZE = 7;
|
||||
private static readonly byte OFFSET_YEAR = 0;
|
||||
private static readonly byte OFFSET_MONTH = 1;
|
||||
private static readonly byte OFFSET_DAY = 2;
|
||||
private static readonly byte OFFSET_HOUR = 3;
|
||||
private static readonly byte OFFSET_MINUTE = 4;
|
||||
private static readonly byte OFFSET_SECOND = 5;
|
||||
private static readonly byte OFFSET_TIME_ZONE = 6;
|
||||
|
||||
internal static DateTime? ToDateTime(byte[] buffer, int startIndex)
|
||||
{
|
||||
if (startIndex < 0 || buffer.Length - startIndex < (int) DirectoryRecordConverter.DirectoryRecordDateTimeConverter.DATETIME_SIZE)
|
||||
throw new ArgumentOutOfRangeException();
|
||||
byte num1 = buffer[startIndex + (int) DirectoryRecordConverter.DirectoryRecordDateTimeConverter.OFFSET_YEAR];
|
||||
byte num2 = buffer[startIndex + (int) DirectoryRecordConverter.DirectoryRecordDateTimeConverter.OFFSET_MONTH];
|
||||
byte num3 = buffer[startIndex + (int) DirectoryRecordConverter.DirectoryRecordDateTimeConverter.OFFSET_DAY];
|
||||
byte num4 = buffer[startIndex + (int) DirectoryRecordConverter.DirectoryRecordDateTimeConverter.OFFSET_HOUR];
|
||||
byte num5 = buffer[startIndex + (int) DirectoryRecordConverter.DirectoryRecordDateTimeConverter.OFFSET_MINUTE];
|
||||
byte num6 = buffer[startIndex + (int) DirectoryRecordConverter.DirectoryRecordDateTimeConverter.OFFSET_SECOND];
|
||||
try
|
||||
{
|
||||
return new DateTime?(new DateTime(1900 + (int) num1, (int) num2, (int) num3, (int) num4, (int) num5, (int) num6, DateTimeKind.Local));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(ex);
|
||||
return new DateTime?();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
24
ImageReader/ISO9660/DirectoryRecords/DirectoryRecordFlags.cs
Normal file
24
ImageReader/ISO9660/DirectoryRecords/DirectoryRecordFlags.cs
Normal file
|
@ -0,0 +1,24 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: ImageReader.ISO9660.DirectoryRecords.DirectoryRecordFlags
|
||||
// Assembly: ImageReader, Version=1.5.2.0, Culture=neutral, PublicKeyToken=611be24fdeb07e08
|
||||
// MVID: E0717604-B50B-4CB4-B85C-C17F43D5C04B
|
||||
// Assembly location: ImageReader.dll
|
||||
|
||||
using System;
|
||||
|
||||
namespace ImageReader.ISO9660.DirectoryRecords
|
||||
{
|
||||
[Flags]
|
||||
public enum DirectoryRecordFlags : byte
|
||||
{
|
||||
NONE = 0,
|
||||
HIDDEN_FILE = 1,
|
||||
DIRECTORY = 2,
|
||||
ASSOCIATED_FILE = 4,
|
||||
EXTENDED_ATTRIBUTE_RECORD = 8,
|
||||
OWNER_AND_GROUP_PERMISSIONS = EXTENDED_ATTRIBUTE_RECORD | ASSOCIATED_FILE | DIRECTORY | HIDDEN_FILE, // 0x0F
|
||||
RESERVED_FLAGS = 48, // 0x30
|
||||
NOT_FINAL_RECORD = 64, // 0x40
|
||||
ANY = 255, // 0xFF
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue