Do not raise InvalidOperationException in AppleDouble and PCExchange filters

when the parent path is null.
This commit is contained in:
2019-05-30 19:56:12 +01:00
parent df0b00174b
commit 65a9d212ec
2 changed files with 56 additions and 52 deletions

View File

@@ -131,9 +131,11 @@ namespace DiscImageChef.Filters
string filenameNoExt = Path.GetFileNameWithoutExtension(path); string filenameNoExt = Path.GetFileNameWithoutExtension(path);
string parentFolder = Path.GetDirectoryName(path); string parentFolder = Path.GetDirectoryName(path);
parentFolder = parentFolder ?? "";
if(filename is null || filenameNoExt is null) return false;
// Prepend data fork name with "R." // Prepend data fork name with "R."
string ProDosAppleDouble = string ProDosAppleDouble = Path.Combine(parentFolder, "R." + filename);
Path.Combine(parentFolder ?? throw new InvalidOperationException(), "R." + filename);
// Prepend data fork name with '%' // Prepend data fork name with '%'
string UNIXAppleDouble = Path.Combine(parentFolder, "%" + filename); string UNIXAppleDouble = Path.Combine(parentFolder, "%" + filename);
// Change file extension to ADF // Change file extension to ADF
@@ -141,8 +143,7 @@ namespace DiscImageChef.Filters
// Change file extension to adf // Change file extension to adf
string DOSAppleDoubleLower = Path.Combine(parentFolder, filenameNoExt + ".adf"); string DOSAppleDoubleLower = Path.Combine(parentFolder, filenameNoExt + ".adf");
// Store AppleDouble header file in ".AppleDouble" folder with same name // Store AppleDouble header file in ".AppleDouble" folder with same name
string NetatalkAppleDouble = string NetatalkAppleDouble = Path.Combine(parentFolder, ".AppleDouble", filename);
Path.Combine(parentFolder, ".AppleDouble", filename ?? throw new InvalidOperationException());
// Store AppleDouble header file in "resource.frk" folder with same name // Store AppleDouble header file in "resource.frk" folder with same name
string DAVEAppleDouble = Path.Combine(parentFolder, "resource.frk", filename); string DAVEAppleDouble = Path.Combine(parentFolder, "resource.frk", filename);
// Prepend data fork name with "._" // Prepend data fork name with "._"
@@ -289,9 +290,11 @@ namespace DiscImageChef.Filters
string filenameNoExt = Path.GetFileNameWithoutExtension(path); string filenameNoExt = Path.GetFileNameWithoutExtension(path);
string parentFolder = Path.GetDirectoryName(path); string parentFolder = Path.GetDirectoryName(path);
parentFolder = parentFolder ?? "";
if(filename is null || filenameNoExt is null) throw new ArgumentNullException(nameof(path));
// Prepend data fork name with "R." // Prepend data fork name with "R."
string ProDosAppleDouble = string ProDosAppleDouble = Path.Combine(parentFolder, "R." + filename);
Path.Combine(parentFolder ?? throw new InvalidOperationException(), "R." + filename);
// Prepend data fork name with '%' // Prepend data fork name with '%'
string UNIXAppleDouble = Path.Combine(parentFolder, "%" + filename); string UNIXAppleDouble = Path.Combine(parentFolder, "%" + filename);
// Change file extension to ADF // Change file extension to ADF
@@ -299,8 +302,7 @@ namespace DiscImageChef.Filters
// Change file extension to adf // Change file extension to adf
string DOSAppleDoubleLower = Path.Combine(parentFolder, filenameNoExt + ".adf"); string DOSAppleDoubleLower = Path.Combine(parentFolder, filenameNoExt + ".adf");
// Store AppleDouble header file in ".AppleDouble" folder with same name // Store AppleDouble header file in ".AppleDouble" folder with same name
string NetatalkAppleDouble = string NetatalkAppleDouble = Path.Combine(parentFolder, ".AppleDouble", filename);
Path.Combine(parentFolder, ".AppleDouble", filename ?? throw new InvalidOperationException());
// Store AppleDouble header file in "resource.frk" folder with same name // Store AppleDouble header file in "resource.frk" folder with same name
string DAVEAppleDouble = Path.Combine(parentFolder, "resource.frk", filename); string DAVEAppleDouble = Path.Combine(parentFolder, "resource.frk", filename);
// Prepend data fork name with "._" // Prepend data fork name with "._"
@@ -543,64 +545,64 @@ namespace DiscImageChef.Filters
[StructLayout(LayoutKind.Sequential, Pack = 1)] [StructLayout(LayoutKind.Sequential, Pack = 1)]
struct AppleDoubleHeader struct AppleDoubleHeader
{ {
public uint magic; public readonly uint magic;
public uint version; public readonly uint version;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public byte[] homeFilesystem; public readonly byte[] homeFilesystem;
public ushort entries; public readonly ushort entries;
} }
[StructLayout(LayoutKind.Sequential, Pack = 1)] [StructLayout(LayoutKind.Sequential, Pack = 1)]
struct AppleDoubleEntry struct AppleDoubleEntry
{ {
public uint id; public uint id;
public uint offset; public readonly uint offset;
public uint length; public uint length;
} }
[StructLayout(LayoutKind.Sequential, Pack = 1)] [StructLayout(LayoutKind.Sequential, Pack = 1)]
struct AppleDoubleFileDates struct AppleDoubleFileDates
{ {
public uint creationDate; public readonly uint creationDate;
public uint modificationDate; public readonly uint modificationDate;
public uint backupDate; public readonly uint backupDate;
public uint accessDate; public readonly uint accessDate;
} }
[StructLayout(LayoutKind.Sequential, Pack = 1)] [StructLayout(LayoutKind.Sequential, Pack = 1)]
struct AppleDoubleMacFileInfo struct AppleDoubleMacFileInfo
{ {
public uint creationDate; public readonly uint creationDate;
public uint modificationDate; public readonly uint modificationDate;
public uint backupDate; public readonly uint backupDate;
public uint accessDate; public readonly uint accessDate;
} }
[StructLayout(LayoutKind.Sequential, Pack = 1)] [StructLayout(LayoutKind.Sequential, Pack = 1)]
struct AppleDoubleUNIXFileInfo struct AppleDoubleUNIXFileInfo
{ {
public uint creationDate; public readonly uint creationDate;
public uint accessDate; public readonly uint accessDate;
public uint modificationDate; public readonly uint modificationDate;
} }
[StructLayout(LayoutKind.Sequential, Pack = 1)] [StructLayout(LayoutKind.Sequential, Pack = 1)]
struct AppleDoubleDOSFileInfo struct AppleDoubleDOSFileInfo
{ {
public ushort modificationDate; public readonly ushort modificationDate;
public ushort modificationTime; public readonly ushort modificationTime;
public ushort attributes; public readonly ushort attributes;
} }
[StructLayout(LayoutKind.Sequential, Pack = 1)] [StructLayout(LayoutKind.Sequential, Pack = 1)]
struct AppleDoubleProDOSFileInfo struct AppleDoubleProDOSFileInfo
{ {
public uint creationDate; public readonly uint creationDate;
public uint modificationDate; public readonly uint modificationDate;
public uint backupDate; public readonly uint backupDate;
public ushort access; public readonly ushort access;
public ushort fileType; public readonly ushort fileType;
public uint auxType; public readonly uint auxType;
} }
} }
} }

View File

@@ -99,8 +99,9 @@ namespace DiscImageChef.Filters
{ {
string parentFolder = Path.GetDirectoryName(path); string parentFolder = Path.GetDirectoryName(path);
if(!File.Exists(Path.Combine(parentFolder ?? throw new InvalidOperationException(), FINDER_INFO))) parentFolder = parentFolder ?? "";
return false;
if(!File.Exists(Path.Combine(parentFolder, FINDER_INFO))) return false;
if(!Directory.Exists(Path.Combine(parentFolder, RESOURCES))) return false; if(!Directory.Exists(Path.Combine(parentFolder, RESOURCES))) return false;
@@ -164,9 +165,10 @@ namespace DiscImageChef.Filters
string parentFolder = Path.GetDirectoryName(path); string parentFolder = Path.GetDirectoryName(path);
string baseFilename = Path.GetFileName(path); string baseFilename = Path.GetFileName(path);
parentFolder = parentFolder ?? "";
FileStream finderDatStream = FileStream finderDatStream =
new FileStream(Path.Combine(parentFolder ?? throw new InvalidOperationException(), FINDER_INFO), new FileStream(Path.Combine(parentFolder, FINDER_INFO), FileMode.Open, FileAccess.Read);
FileMode.Open, FileAccess.Read);
while(finderDatStream.Position + 0x5C <= finderDatStream.Length) while(finderDatStream.Position + 0x5C <= finderDatStream.Length)
{ {
@@ -223,59 +225,59 @@ namespace DiscImageChef.Filters
/// Illegal characters for FAT get substituted with '_' both here and in FAT's LFN entry. /// Illegal characters for FAT get substituted with '_' both here and in FAT's LFN entry.
/// </summary> /// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)] [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
public byte[] macName; public readonly byte[] macName;
/// <summary> /// <summary>
/// File type /// File type
/// </summary> /// </summary>
public uint type; public readonly uint type;
/// <summary> /// <summary>
/// File creator /// File creator
/// </summary> /// </summary>
public uint creator; public readonly uint creator;
/// <summary> /// <summary>
/// Finder flags /// Finder flags
/// </summary> /// </summary>
public ushort fdFlags; public readonly ushort fdFlags;
/// <summary> /// <summary>
/// File's icon vertical position within its window /// File's icon vertical position within its window
/// </summary> /// </summary>
public ushort verticalPosition; public readonly ushort verticalPosition;
/// <summary> /// <summary>
/// File's icon horizontal position within its window /// File's icon horizontal position within its window
/// </summary> /// </summary>
public ushort horizontalPosition; public readonly ushort horizontalPosition;
/// <summary> /// <summary>
/// Unknown, all bytes are empty but last, except in volume's label entry /// Unknown, all bytes are empty but last, except in volume's label entry
/// </summary> /// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 18)] [MarshalAs(UnmanagedType.ByValArray, SizeConst = 18)]
public byte[] unknown1; public readonly byte[] unknown1;
/// <summary> /// <summary>
/// File's creation date /// File's creation date
/// </summary> /// </summary>
public uint creationDate; public readonly uint creationDate;
/// <summary> /// <summary>
/// File's modification date /// File's modification date
/// </summary> /// </summary>
public uint modificationDate; public readonly uint modificationDate;
/// <summary> /// <summary>
/// File's last backup date /// File's last backup date
/// </summary> /// </summary>
public uint backupDate; public readonly uint backupDate;
/// <summary> /// <summary>
/// Unknown, but is unique, starts 0x7FFFFFFF and counts in reverse. /// Unknown, but is unique, starts 0x7FFFFFFF and counts in reverse.
/// Probably file ID for alias look up? /// Probably file ID for alias look up?
/// </summary> /// </summary>
public uint unknown2; public readonly uint unknown2;
/// <summary> /// <summary>
/// Name as in FAT entry (not LFN). /// Name as in FAT entry (not LFN).
/// Resource fork file is always using this name, never LFN. /// Resource fork file is always using this name, never LFN.
/// </summary> /// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 11)] [MarshalAs(UnmanagedType.ByValArray, SizeConst = 11)]
public byte[] dosName; public readonly byte[] dosName;
/// <summary> /// <summary>
/// Unknown, flags? /// Unknown, flags?
/// </summary> /// </summary>
public byte unknown3; public readonly byte unknown3;
} }
} }
} }