🎨Converted all plugin types to interfaces.

This commit is contained in:
2017-12-26 06:05:12 +00:00
parent a002253fa4
commit f66a0bdd42
295 changed files with 9499 additions and 10414 deletions

View File

@@ -40,7 +40,7 @@ namespace DiscImageChef.Filters
/// <summary>
/// Decodes AppleDouble files
/// </summary>
public class AppleDouble : Filter
public class AppleDouble : IFilter
{
const uint AppleDoubleMagic = 0x00051607;
const uint AppleDoubleVersion = 0x00010000;
@@ -68,68 +68,65 @@ namespace DiscImageChef.Filters
bool opened;
AppleDoubleEntry rsrcFork;
public AppleDouble()
{
Name = "AppleDouble";
UUID = new Guid("1B2165EE-C9DF-4B21-BBBB-9E5892B2DF4D");
}
public virtual string Name => "AppleDouble";
public virtual Guid Id => new Guid("1B2165EE-C9DF-4B21-BBBB-9E5892B2DF4D");
public override void Close()
public virtual void Close()
{
opened = false;
}
public override string GetBasePath()
public virtual string GetBasePath()
{
return basePath;
}
public override DateTime GetCreationTime()
public virtual DateTime GetCreationTime()
{
return creationTime;
}
public override long GetDataForkLength()
public virtual long GetDataForkLength()
{
return dataFork.length;
}
public override Stream GetDataForkStream()
public virtual Stream GetDataForkStream()
{
return new FileStream(basePath, FileMode.Open, FileAccess.Read);
}
public override string GetFilename()
public virtual string GetFilename()
{
return Path.GetFileName(basePath);
}
public override DateTime GetLastWriteTime()
public virtual DateTime GetLastWriteTime()
{
return lastWriteTime;
}
public override long GetLength()
public virtual long GetLength()
{
return dataFork.length + rsrcFork.length;
}
public override string GetParentFolder()
public virtual string GetParentFolder()
{
return Path.GetDirectoryName(basePath);
}
public override string GetPath()
public virtual string GetPath()
{
return basePath;
}
public override long GetResourceForkLength()
public virtual long GetResourceForkLength()
{
return rsrcFork.length;
}
public override Stream GetResourceForkStream()
public virtual Stream GetResourceForkStream()
{
if(rsrcFork.length == 0) return null;
@@ -137,24 +134,24 @@ namespace DiscImageChef.Filters
rsrcFork.offset + rsrcFork.length - 1);
}
public override bool HasResourceFork()
public virtual bool HasResourceFork()
{
return rsrcFork.length > 0;
}
public override bool Identify(byte[] buffer)
public virtual bool Identify(byte[] buffer)
{
// Now way to have two files in a single byte array
return false;
}
public override bool Identify(Stream stream)
public virtual bool Identify(Stream stream)
{
// Now way to have two files in a single stream
return false;
}
public override bool Identify(string path)
public virtual bool Identify(string path)
{
// Prepend data fork name with "R."
string ProDosAppleDouble;
@@ -306,24 +303,24 @@ namespace DiscImageChef.Filters
(header.version == AppleDoubleVersion || header.version == AppleDoubleVersion2);
}
public override bool IsOpened()
public virtual bool IsOpened()
{
return opened;
}
public override void Open(byte[] buffer)
public virtual void Open(byte[] buffer)
{
// Now way to have two files in a single byte array
throw new NotSupportedException();
}
public override void Open(Stream stream)
public virtual void Open(Stream stream)
{
// Now way to have two files in a single stream
throw new NotSupportedException();
}
public override void Open(string path)
public virtual void Open(string path)
{
// Prepend data fork name with "R."
string ProDosAppleDouble;

View File

@@ -40,7 +40,7 @@ namespace DiscImageChef.Filters
/// <summary>
/// Decodes AppleSingle files
/// </summary>
public class AppleSingle : Filter
public class AppleSingle : IFilter
{
const uint AppleSingleMagic = 0x00051600;
const uint AppleSingleVersion = 0x00010000;
@@ -69,13 +69,10 @@ namespace DiscImageChef.Filters
AppleSingleEntry rsrcFork;
Stream stream;
public AppleSingle()
{
Name = "AppleSingle";
UUID = new Guid("A69B20E8-F4D3-42BB-BD2B-4A7263394A05");
}
public virtual string Name => "AppleSingle";
public virtual Guid Id => new Guid("A69B20E8-F4D3-42BB-BD2B-4A7263394A05");
public override void Close()
public virtual void Close()
{
bytes = null;
stream?.Close();
@@ -85,22 +82,22 @@ namespace DiscImageChef.Filters
opened = false;
}
public override string GetBasePath()
public virtual string GetBasePath()
{
return basePath;
}
public override DateTime GetCreationTime()
public virtual DateTime GetCreationTime()
{
return creationTime;
}
public override long GetDataForkLength()
public virtual long GetDataForkLength()
{
return dataFork.length;
}
public override Stream GetDataForkStream()
public virtual Stream GetDataForkStream()
{
if(dataFork.length == 0) return null;
@@ -113,37 +110,37 @@ namespace DiscImageChef.Filters
return null;
}
public override string GetFilename()
public virtual string GetFilename()
{
return Path.GetFileName(basePath);
}
public override DateTime GetLastWriteTime()
public virtual DateTime GetLastWriteTime()
{
return lastWriteTime;
}
public override long GetLength()
public virtual long GetLength()
{
return dataFork.length + rsrcFork.length;
}
public override string GetParentFolder()
public virtual string GetParentFolder()
{
return Path.GetDirectoryName(basePath);
}
public override string GetPath()
public virtual string GetPath()
{
return basePath;
}
public override long GetResourceForkLength()
public virtual long GetResourceForkLength()
{
return rsrcFork.length;
}
public override Stream GetResourceForkStream()
public virtual Stream GetResourceForkStream()
{
if(rsrcFork.length == 0) return null;
@@ -156,12 +153,12 @@ namespace DiscImageChef.Filters
return null;
}
public override bool HasResourceFork()
public virtual bool HasResourceFork()
{
return rsrcFork.length > 0;
}
public override bool Identify(byte[] buffer)
public virtual bool Identify(byte[] buffer)
{
if(buffer == null || buffer.Length < 26) return false;
@@ -173,7 +170,7 @@ namespace DiscImageChef.Filters
(header.version == AppleSingleVersion || header.version == AppleSingleVersion2);
}
public override bool Identify(Stream stream)
public virtual bool Identify(Stream stream)
{
if(stream == null || stream.Length < 26) return false;
@@ -186,7 +183,7 @@ namespace DiscImageChef.Filters
(header.version == AppleSingleVersion || header.version == AppleSingleVersion2);
}
public override bool Identify(string path)
public virtual bool Identify(string path)
{
FileStream fstream = new FileStream(path, FileMode.Open, FileAccess.Read);
if(fstream.Length < 26) return false;
@@ -200,12 +197,12 @@ namespace DiscImageChef.Filters
(header.version == AppleSingleVersion || header.version == AppleSingleVersion2);
}
public override bool IsOpened()
public virtual bool IsOpened()
{
return opened;
}
public override void Open(byte[] buffer)
public virtual void Open(byte[] buffer)
{
MemoryStream ms = new MemoryStream(buffer);
ms.Seek(0, SeekOrigin.Begin);
@@ -283,7 +280,7 @@ namespace DiscImageChef.Filters
bytes = buffer;
}
public override void Open(Stream stream)
public virtual void Open(Stream stream)
{
stream.Seek(0, SeekOrigin.Begin);
@@ -360,7 +357,7 @@ namespace DiscImageChef.Filters
this.stream = stream;
}
public override void Open(string path)
public virtual void Open(string path)
{
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
fs.Seek(0, SeekOrigin.Begin);

View File

@@ -40,7 +40,7 @@ namespace DiscImageChef.Filters
/// <summary>
/// Decompress bz2 files while reading
/// </summary>
public class BZip2 : Filter
public class BZip2 : IFilter
{
string basePath;
DateTime creationTime;
@@ -50,13 +50,10 @@ namespace DiscImageChef.Filters
DateTime lastWriteTime;
bool opened;
public BZip2()
{
Name = "BZip2";
UUID = new Guid("FCCFB0C3-32EF-40D8-9714-2333F6AC72A9");
}
public virtual string Name => "BZip2";
public virtual Guid Id => new Guid("FCCFB0C3-32EF-40D8-9714-2333F6AC72A9");
public override void Close()
public virtual void Close()
{
dataStream?.Close();
dataStream = null;
@@ -64,32 +61,32 @@ namespace DiscImageChef.Filters
opened = false;
}
public override string GetBasePath()
public virtual string GetBasePath()
{
return basePath;
}
public override Stream GetDataForkStream()
public virtual Stream GetDataForkStream()
{
return innerStream;
}
public override string GetPath()
public virtual string GetPath()
{
return basePath;
}
public override Stream GetResourceForkStream()
public virtual Stream GetResourceForkStream()
{
return null;
}
public override bool HasResourceFork()
public virtual bool HasResourceFork()
{
return false;
}
public override bool Identify(byte[] buffer)
public virtual bool Identify(byte[] buffer)
{
if(buffer[0] != 0x42 || buffer[1] != 0x5A || buffer[2] != 0x68 || buffer[3] < 0x31 ||
buffer[3] > 0x39) return false;
@@ -100,7 +97,7 @@ namespace DiscImageChef.Filters
buffer[buffer.Length - 510] != 0x6C || buffer[buffer.Length - 509] != 0x79;
}
public override bool Identify(Stream stream)
public virtual bool Identify(Stream stream)
{
byte[] buffer = new byte[4];
@@ -120,7 +117,7 @@ namespace DiscImageChef.Filters
return buffer[0] != 0x6B || buffer[1] != 0x6F || buffer[2] != 0x6C || buffer[3] != 0x79;
}
public override bool Identify(string path)
public virtual bool Identify(string path)
{
if(!File.Exists(path)) return false;
@@ -145,7 +142,7 @@ namespace DiscImageChef.Filters
return true;
}
public override void Open(byte[] buffer)
public virtual void Open(byte[] buffer)
{
dataStream = new MemoryStream(buffer);
basePath = null;
@@ -156,7 +153,7 @@ namespace DiscImageChef.Filters
opened = true;
}
public override void Open(Stream stream)
public virtual void Open(Stream stream)
{
dataStream = stream;
basePath = null;
@@ -167,7 +164,7 @@ namespace DiscImageChef.Filters
opened = true;
}
public override void Open(string path)
public virtual void Open(string path)
{
dataStream = new FileStream(path, FileMode.Open, FileAccess.Read);
basePath = Path.GetFullPath(path);
@@ -183,32 +180,32 @@ namespace DiscImageChef.Filters
opened = true;
}
public override DateTime GetCreationTime()
public virtual DateTime GetCreationTime()
{
return creationTime;
}
public override long GetDataForkLength()
public virtual long GetDataForkLength()
{
return decompressedSize;
}
public override DateTime GetLastWriteTime()
public virtual DateTime GetLastWriteTime()
{
return lastWriteTime;
}
public override long GetLength()
public virtual long GetLength()
{
return decompressedSize;
}
public override long GetResourceForkLength()
public virtual long GetResourceForkLength()
{
return 0;
}
public override string GetFilename()
public virtual string GetFilename()
{
if(basePath?.EndsWith(".bz2", StringComparison.InvariantCultureIgnoreCase) == true)
return basePath.Substring(0, basePath.Length - 4);
@@ -218,12 +215,12 @@ namespace DiscImageChef.Filters
return basePath;
}
public override string GetParentFolder()
public virtual string GetParentFolder()
{
return Path.GetDirectoryName(basePath);
}
public override bool IsOpened()
public virtual bool IsOpened()
{
return opened;
}

View File

@@ -38,7 +38,7 @@
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="OffsetStream.cs" />
<Compile Include="Filter.cs" />
<Compile Include="IFilter.cs" />
<Compile Include="Filters.cs" />
<Compile Include="ZZZNoFilter.cs" />
<Compile Include="ForcedSeekStream.cs" />

View File

@@ -32,6 +32,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using DiscImageChef.Console;
@@ -39,22 +40,20 @@ namespace DiscImageChef.Filters
{
public class FiltersList
{
public SortedDictionary<string, Filter> Filters;
public SortedDictionary<string, IFilter> Filters;
/// <summary>
/// Fills the list of all known filters
/// </summary>
public FiltersList()
{
Assembly assembly = Assembly.GetAssembly(typeof(Filter));
Filters = new SortedDictionary<string, Filter>();
Assembly assembly = Assembly.GetAssembly(typeof(IFilter));
Filters = new SortedDictionary<string, IFilter>();
foreach(Type type in assembly.GetTypes())
foreach(Type type in assembly.GetTypes().Where(t => t.GetInterfaces().Contains(typeof(IFilter))))
try
{
if(!type.IsSubclassOf(typeof(Filter))) continue;
Filter filter = (Filter)type.GetConstructor(Type.EmptyTypes)?.Invoke(new object[] { });
IFilter filter = (IFilter)type.GetConstructor(Type.EmptyTypes)?.Invoke(new object[] { });
if(filter != null && !Filters.ContainsKey(filter.Name.ToLower()))
Filters.Add(filter.Name.ToLower(), filter);
}
@@ -66,17 +65,17 @@ namespace DiscImageChef.Filters
/// </summary>
/// <param name="path">Path</param>
/// <returns>The filter that allows reading the specified path</returns>
public Filter GetFilter(string path)
public IFilter GetFilter(string path)
{
Filter noFilter = null;
IFilter noFilter = null;
foreach(Filter filter in Filters.Values)
if(filter.UUID != new Guid("12345678-AAAA-BBBB-CCCC-123456789000"))
foreach(IFilter filter in Filters.Values)
if(filter.Id != new Guid("12345678-AAAA-BBBB-CCCC-123456789000"))
{
if(!filter.Identify(path)) continue;
Filter foundFilter =
(Filter)filter.GetType().GetConstructor(Type.EmptyTypes)?.Invoke(new object[] { });
IFilter foundFilter =
(IFilter)filter.GetType().GetConstructor(Type.EmptyTypes)?.Invoke(new object[] { });
foundFilter?.Open(path);
@@ -95,7 +94,7 @@ namespace DiscImageChef.Filters
/// Gets all known filters
/// </summary>
/// <returns>Known filters</returns>
public SortedDictionary<string, Filter> GetFiltersList()
public SortedDictionary<string, IFilter> GetFiltersList()
{
return Filters;
}

View File

@@ -39,7 +39,7 @@ namespace DiscImageChef.Filters
/// <summary>
/// Decompress gzip files while reading
/// </summary>
public class GZip : Filter
public class GZip : IFilter
{
string basePath;
DateTime creationTime;
@@ -49,13 +49,10 @@ namespace DiscImageChef.Filters
bool opened;
Stream zStream;
public GZip()
{
Name = "GZip";
UUID = new Guid("F4996661-4A29-42C9-A2C7-3904EF40F3B0");
}
public virtual string Name => "GZip";
public virtual Guid Id => new Guid("F4996661-4A29-42C9-A2C7-3904EF40F3B0");
public override void Close()
public virtual void Close()
{
dataStream?.Close();
dataStream = null;
@@ -63,37 +60,37 @@ namespace DiscImageChef.Filters
opened = false;
}
public override string GetBasePath()
public virtual string GetBasePath()
{
return basePath;
}
public override Stream GetDataForkStream()
public virtual Stream GetDataForkStream()
{
return zStream;
}
public override string GetPath()
public virtual string GetPath()
{
return basePath;
}
public override Stream GetResourceForkStream()
public virtual Stream GetResourceForkStream()
{
return null;
}
public override bool HasResourceFork()
public virtual bool HasResourceFork()
{
return false;
}
public override bool Identify(byte[] buffer)
public virtual bool Identify(byte[] buffer)
{
return buffer[0] == 0x1F && buffer[1] == 0x8B && buffer[2] == 0x08;
}
public override bool Identify(Stream stream)
public virtual bool Identify(Stream stream)
{
byte[] buffer = new byte[3];
@@ -104,7 +101,7 @@ namespace DiscImageChef.Filters
return buffer[0] == 0x1F && buffer[1] == 0x8B && buffer[2] == 0x08;
}
public override bool Identify(string path)
public virtual bool Identify(string path)
{
if(!File.Exists(path)) return false;
@@ -118,7 +115,7 @@ namespace DiscImageChef.Filters
return buffer[0] == 0x1F && buffer[1] == 0x8B && buffer[2] == 0x08;
}
public override void Open(byte[] buffer)
public virtual void Open(byte[] buffer)
{
byte[] mtime_b = new byte[4];
byte[] isize_b = new byte[4];
@@ -144,7 +141,7 @@ namespace DiscImageChef.Filters
opened = true;
}
public override void Open(Stream stream)
public virtual void Open(Stream stream)
{
byte[] mtime_b = new byte[4];
byte[] isize_b = new byte[4];
@@ -170,7 +167,7 @@ namespace DiscImageChef.Filters
opened = true;
}
public override void Open(string path)
public virtual void Open(string path)
{
byte[] mtime_b = new byte[4];
byte[] isize_b = new byte[4];
@@ -197,32 +194,32 @@ namespace DiscImageChef.Filters
opened = true;
}
public override DateTime GetCreationTime()
public virtual DateTime GetCreationTime()
{
return creationTime;
}
public override long GetDataForkLength()
public virtual long GetDataForkLength()
{
return decompressedSize;
}
public override DateTime GetLastWriteTime()
public virtual DateTime GetLastWriteTime()
{
return lastWriteTime;
}
public override long GetLength()
public virtual long GetLength()
{
return decompressedSize;
}
public override long GetResourceForkLength()
public virtual long GetResourceForkLength()
{
return 0;
}
public override string GetFilename()
public virtual string GetFilename()
{
if(basePath?.EndsWith(".gz", StringComparison.InvariantCultureIgnoreCase) == true)
return basePath.Substring(0, basePath.Length - 3);
@@ -232,12 +229,12 @@ namespace DiscImageChef.Filters
return basePath;
}
public override string GetParentFolder()
public virtual string GetParentFolder()
{
return Path.GetDirectoryName(basePath);
}
public override bool IsOpened()
public virtual bool IsOpened()
{
return opened;
}

View File

@@ -2,7 +2,7 @@
// The Disc Image Chef
// ----------------------------------------------------------------------------
//
// Filename : Filter.cs
// Filename : IFilter.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : Filters.
@@ -35,135 +35,138 @@ using System.IO;
namespace DiscImageChef.Filters
{
public abstract class Filter
public interface IFilter
{
public string Name;
public Guid UUID;
/// <summary>Descriptive name of the plugin</summary>
string Name { get; }
/// <summary>Unique UUID of the plugin</summary>
Guid Id { get; }
/// <summary>
/// Closes all opened streams.
/// </summary>
public abstract void Close();
void Close();
/// <summary>
/// Gets the path used to open this filter.<br />
/// UNIX: /path/to/archive.zip/path/to/file.bin => /path/to/archive.zip/path/to/file.bin <br />
/// Windows: C:\path\to\archive.zip\path\to\file.bin => C:\path\to\archive.zip\path\to\file.bin
/// UNIX: /path/to/archive.zip/path/to/file.bin =&gt; /path/to/archive.zip/path/to/file.bin <br />
/// Windows: C:\path\to\archive.zip\path\to\file.bin =&gt; C:\path\to\archive.zip\path\to\file.bin
/// </summary>
/// <returns>Path used to open this filter.</returns>
public abstract string GetBasePath();
string GetBasePath();
/// <summary>
/// Gets creation time of file referenced by this filter.
/// </summary>
/// <returns>The creation time.</returns>
public abstract DateTime GetCreationTime();
DateTime GetCreationTime();
/// <summary>
/// Gets length of this filter's data fork.
/// </summary>
/// <returns>The data fork length.</returns>
public abstract long GetDataForkLength();
long GetDataForkLength();
/// <summary>
/// Gets a stream to access the data fork contents.
/// </summary>
/// <returns>The data fork stream.</returns>
public abstract Stream GetDataForkStream();
Stream GetDataForkStream();
/// <summary>
/// Gets the filename for the file referenced by this filter.<br />
/// UNIX: /path/to/archive.zip/path/to/file.bin => file.bin <br />
/// Windows: C:\path\to\archive.zip\path\to\file.bin => file.bin
/// UNIX: /path/to/archive.zip/path/to/file.bin =&gt; file.bin <br />
/// Windows: C:\path\to\archive.zip\path\to\file.bin =&gt; file.bin
/// </summary>
/// <returns>The filename.</returns>
public abstract string GetFilename();
string GetFilename();
/// <summary>
/// Gets last write time of file referenced by this filter.
/// </summary>
/// <returns>The last write time.</returns>
public abstract DateTime GetLastWriteTime();
DateTime GetLastWriteTime();
/// <summary>
/// Gets length of file referenced by ths filter.
/// </summary>
/// <returns>The length.</returns>
public abstract long GetLength();
long GetLength();
/// <summary>
/// Gets full path to file referenced by this filter. If it's an archive, it's the path inside the archive.<br />
/// UNIX: /path/to/archive.zip/path/to/file.bin => /path/to/file.bin <br />
/// Windows: C:\path\to\archive.zip\path\to\file.bin => \path\to\file.bin
/// UNIX: /path/to/archive.zip/path/to/file.bin =&gt; /path/to/file.bin <br />
/// Windows: C:\path\to\archive.zip\path\to\file.bin =&gt; \path\to\file.bin
/// </summary>
/// <returns>The path.</returns>
public abstract string GetPath();
string GetPath();
/// <summary>
/// Gets path to parent folder to the file referenced by this filter. If it's an archive, it's the full path to the
/// archive itself.<br />
/// UNIX: /path/to/archive.zip/path/to/file.bin => /path/to/archive.zip <br />
/// Windows: C:\path\to\archive.zip\path\to\file.bin => C:\path\to\archive.zip
/// UNIX: /path/to/archive.zip/path/to/file.bin =&gt; /path/to/archive.zip <br />
/// Windows: C:\path\to\archive.zip\path\to\file.bin =&gt; C:\path\to\archive.zip
/// </summary>
/// <returns>The parent folder.</returns>
public abstract string GetParentFolder();
string GetParentFolder();
/// <summary>
/// Gets length of this filter's resource fork.
/// </summary>
/// <returns>The resource fork length.</returns>
public abstract long GetResourceForkLength();
long GetResourceForkLength();
/// <summary>
/// Gets a stream to access the resource fork contents.
/// </summary>
/// <returns>The resource fork stream.</returns>
public abstract Stream GetResourceForkStream();
Stream GetResourceForkStream();
/// <summary>
/// Returns true if the file referenced by this filter has a resource fork
/// </summary>
public abstract bool HasResourceFork();
bool HasResourceFork();
/// <summary>
/// Identifies if the specified path contains data recognizable by this filter instance
/// </summary>
/// <param name="path">Path.</param>
public abstract bool Identify(string path);
bool Identify(string path);
/// <summary>
/// Identifies if the specified stream contains data recognizable by this filter instance
/// </summary>
/// <param name="stream">Stream.</param>
public abstract bool Identify(Stream stream);
bool Identify(Stream stream);
/// <summary>
/// Identifies if the specified buffer contains data recognizable by this filter instance
/// </summary>
/// <param name="buffer">Buffer.</param>
public abstract bool Identify(byte[] buffer);
bool Identify(byte[] buffer);
/// <summary>
/// Returns true if the filter has a file/stream/buffer currently opened and no <see cref="Close" /> has been issued.
/// Returns true if the filter has a file/stream/buffer currently opened and no
/// <see cref="M:DiscImageChef.Filters.Filter.Close" /> has been issued.
/// </summary>
public abstract bool IsOpened();
bool IsOpened();
/// <summary>
/// Opens the specified path with this filter instance
/// </summary>
/// <param name="path">Path.</param>
public abstract void Open(string path);
void Open(string path);
/// <summary>
/// Opens the specified stream with this filter instance
/// </summary>
/// <param name="stream">Stream.</param>
public abstract void Open(Stream stream);
void Open(Stream stream);
/// <summary>
/// Opens the specified buffer with this filter instance
/// </summary>
/// <param name="buffer">Buffer.</param>
public abstract void Open(byte[] buffer);
void Open(byte[] buffer);
}
}

View File

@@ -40,7 +40,7 @@ namespace DiscImageChef.Filters
/// <summary>
/// Decompress lzip files while reading
/// </summary>
public class LZip : Filter
public class LZip : IFilter
{
string basePath;
DateTime creationTime;
@@ -50,13 +50,10 @@ namespace DiscImageChef.Filters
DateTime lastWriteTime;
bool opened;
public LZip()
{
Name = "LZip";
UUID = new Guid("09D715E9-20C0-48B1-A8D9-D8897CEC57C9");
}
public virtual string Name => "LZip";
public virtual Guid Id => new Guid("09D715E9-20C0-48B1-A8D9-D8897CEC57C9");
public override void Close()
public virtual void Close()
{
dataStream?.Close();
dataStream = null;
@@ -64,38 +61,38 @@ namespace DiscImageChef.Filters
opened = false;
}
public override string GetBasePath()
public virtual string GetBasePath()
{
return basePath;
}
public override Stream GetDataForkStream()
public virtual Stream GetDataForkStream()
{
return innerStream;
}
public override string GetPath()
public virtual string GetPath()
{
return basePath;
}
public override Stream GetResourceForkStream()
public virtual Stream GetResourceForkStream()
{
return null;
}
public override bool HasResourceFork()
public virtual bool HasResourceFork()
{
return false;
}
public override bool Identify(byte[] buffer)
public virtual bool Identify(byte[] buffer)
{
return buffer[0] == 0x4C && buffer[1] == 0x5A && buffer[2] == 0x49 && buffer[3] == 0x50 &&
buffer[4] == 0x01;
}
public override bool Identify(Stream stream)
public virtual bool Identify(Stream stream)
{
byte[] buffer = new byte[5];
@@ -107,7 +104,7 @@ namespace DiscImageChef.Filters
buffer[4] == 0x01;
}
public override bool Identify(string path)
public virtual bool Identify(string path)
{
if(!File.Exists(path)) return false;
@@ -122,7 +119,7 @@ namespace DiscImageChef.Filters
buffer[4] == 0x01;
}
public override void Open(byte[] buffer)
public virtual void Open(byte[] buffer)
{
dataStream = new MemoryStream(buffer);
basePath = null;
@@ -134,7 +131,7 @@ namespace DiscImageChef.Filters
opened = true;
}
public override void Open(Stream stream)
public virtual void Open(Stream stream)
{
dataStream = stream;
basePath = null;
@@ -150,7 +147,7 @@ namespace DiscImageChef.Filters
opened = true;
}
public override void Open(string path)
public virtual void Open(string path)
{
dataStream = new FileStream(path, FileMode.Open, FileAccess.Read);
basePath = Path.GetFullPath(path);
@@ -171,32 +168,32 @@ namespace DiscImageChef.Filters
opened = true;
}
public override DateTime GetCreationTime()
public virtual DateTime GetCreationTime()
{
return creationTime;
}
public override long GetDataForkLength()
public virtual long GetDataForkLength()
{
return decompressedSize;
}
public override DateTime GetLastWriteTime()
public virtual DateTime GetLastWriteTime()
{
return lastWriteTime;
}
public override long GetLength()
public virtual long GetLength()
{
return decompressedSize;
}
public override long GetResourceForkLength()
public virtual long GetResourceForkLength()
{
return 0;
}
public override string GetFilename()
public virtual string GetFilename()
{
if(basePath?.EndsWith(".lz", StringComparison.InvariantCultureIgnoreCase) == true)
return basePath.Substring(0, basePath.Length - 3);
@@ -206,12 +203,12 @@ namespace DiscImageChef.Filters
return basePath;
}
public override string GetParentFolder()
public virtual string GetParentFolder()
{
return Path.GetDirectoryName(basePath);
}
public override bool IsOpened()
public virtual bool IsOpened()
{
return opened;
}

View File

@@ -41,7 +41,7 @@ namespace DiscImageChef.Filters
/// <summary>
/// Decodes MacBinary files
/// </summary>
public class MacBinary : Filter
public class MacBinary : IFilter
{
const uint MACBINARY_MAGIC = 0x6D42494E;
string basePath;
@@ -56,13 +56,10 @@ namespace DiscImageChef.Filters
long rsrcForkOff;
Stream stream;
public MacBinary()
{
Name = "MacBinary";
UUID = new Guid("D7C321D3-E51F-45DF-A150-F6BFDF0D7704");
}
public virtual string Name => "MacBinary";
public virtual Guid Id => new Guid("D7C321D3-E51F-45DF-A150-F6BFDF0D7704");
public override void Close()
public virtual void Close()
{
bytes = null;
stream?.Close();
@@ -72,22 +69,22 @@ namespace DiscImageChef.Filters
opened = false;
}
public override string GetBasePath()
public virtual string GetBasePath()
{
return basePath;
}
public override DateTime GetCreationTime()
public virtual DateTime GetCreationTime()
{
return creationTime;
}
public override long GetDataForkLength()
public virtual long GetDataForkLength()
{
return header.dataLength;
}
public override Stream GetDataForkStream()
public virtual Stream GetDataForkStream()
{
if(header.dataLength == 0) return null;
@@ -100,37 +97,37 @@ namespace DiscImageChef.Filters
return null;
}
public override string GetFilename()
public virtual string GetFilename()
{
return filename;
}
public override DateTime GetLastWriteTime()
public virtual DateTime GetLastWriteTime()
{
return lastWriteTime;
}
public override long GetLength()
public virtual long GetLength()
{
return header.dataLength + header.resourceLength;
}
public override string GetParentFolder()
public virtual string GetParentFolder()
{
return Path.GetDirectoryName(basePath);
}
public override string GetPath()
public virtual string GetPath()
{
return basePath;
}
public override long GetResourceForkLength()
public virtual long GetResourceForkLength()
{
return header.resourceLength;
}
public override Stream GetResourceForkStream()
public virtual Stream GetResourceForkStream()
{
if(header.resourceLength == 0) return null;
@@ -143,12 +140,12 @@ namespace DiscImageChef.Filters
return null;
}
public override bool HasResourceFork()
public virtual bool HasResourceFork()
{
return header.resourceLength > 0;
}
public override bool Identify(byte[] buffer)
public virtual bool Identify(byte[] buffer)
{
if(buffer == null || buffer.Length < 128) return false;
@@ -161,7 +158,7 @@ namespace DiscImageChef.Filters
(header.dataLength > 0 || header.resourceLength > 0);
}
public override bool Identify(Stream stream)
public virtual bool Identify(Stream stream)
{
if(stream == null || stream.Length < 128) return false;
@@ -175,7 +172,7 @@ namespace DiscImageChef.Filters
(header.dataLength > 0 || header.resourceLength > 0);
}
public override bool Identify(string path)
public virtual bool Identify(string path)
{
FileStream fstream = new FileStream(path, FileMode.Open, FileAccess.Read);
if(fstream.Length < 128) return false;
@@ -190,12 +187,12 @@ namespace DiscImageChef.Filters
(header.dataLength > 0 || header.resourceLength > 0);
}
public override bool IsOpened()
public virtual bool IsOpened()
{
return opened;
}
public override void Open(byte[] buffer)
public virtual void Open(byte[] buffer)
{
MemoryStream ms = new MemoryStream(buffer);
ms.Seek(0, SeekOrigin.Begin);
@@ -222,7 +219,7 @@ namespace DiscImageChef.Filters
bytes = buffer;
}
public override void Open(Stream stream)
public virtual void Open(Stream stream)
{
stream.Seek(0, SeekOrigin.Begin);
@@ -248,7 +245,7 @@ namespace DiscImageChef.Filters
this.stream = stream;
}
public override void Open(string path)
public virtual void Open(string path)
{
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
fs.Seek(0, SeekOrigin.Begin);

View File

@@ -42,7 +42,7 @@ namespace DiscImageChef.Filters
/// <summary>
/// Decodes PCExchange files
/// </summary>
public class PCExchange : Filter
public class PCExchange : IFilter
{
const string FILE_ID = "FILEID.DAT";
const string FINDER_INFO = "FINDER.DAT";
@@ -57,89 +57,86 @@ namespace DiscImageChef.Filters
long rsrcLen;
string rsrcPath;
public PCExchange()
{
Name = "PCExchange";
UUID = new Guid("9264EB9F-D634-4F9B-BE12-C24CD44988C6");
}
public virtual string Name => "PCExchange";
public virtual Guid Id => new Guid("9264EB9F-D634-4F9B-BE12-C24CD44988C6");
public override void Close()
public virtual void Close()
{
opened = false;
}
public override string GetBasePath()
public virtual string GetBasePath()
{
return basePath;
}
public override DateTime GetCreationTime()
public virtual DateTime GetCreationTime()
{
return creationTime;
}
public override long GetDataForkLength()
public virtual long GetDataForkLength()
{
return dataLen;
}
public override Stream GetDataForkStream()
public virtual Stream GetDataForkStream()
{
return new FileStream(dataPath, FileMode.Open, FileAccess.Read);
}
public override string GetFilename()
public virtual string GetFilename()
{
return Path.GetFileName(basePath);
}
public override DateTime GetLastWriteTime()
public virtual DateTime GetLastWriteTime()
{
return lastWriteTime;
}
public override long GetLength()
public virtual long GetLength()
{
return dataLen + rsrcLen;
}
public override string GetParentFolder()
public virtual string GetParentFolder()
{
return Path.GetDirectoryName(basePath);
}
public override string GetPath()
public virtual string GetPath()
{
return basePath;
}
public override long GetResourceForkLength()
public virtual long GetResourceForkLength()
{
return rsrcLen;
}
public override Stream GetResourceForkStream()
public virtual Stream GetResourceForkStream()
{
return new FileStream(rsrcPath, FileMode.Open, FileAccess.Read);
}
public override bool HasResourceFork()
public virtual bool HasResourceFork()
{
return rsrcPath != null;
}
public override bool Identify(byte[] buffer)
public virtual bool Identify(byte[] buffer)
{
return false;
}
public override bool Identify(Stream stream)
public virtual bool Identify(Stream stream)
{
System.Console.WriteLine("parentFolder");
return false;
}
public override bool Identify(string path)
public virtual bool Identify(string path)
{
string parentFolder = Path.GetDirectoryName(path);
@@ -190,22 +187,22 @@ namespace DiscImageChef.Filters
return dataFound && rsrcFound;
}
public override bool IsOpened()
public virtual bool IsOpened()
{
return opened;
}
public override void Open(byte[] buffer)
public virtual void Open(byte[] buffer)
{
throw new NotSupportedException();
}
public override void Open(Stream stream)
public virtual void Open(Stream stream)
{
throw new NotSupportedException();
}
public override void Open(string path)
public virtual void Open(string path)
{
string parentFolder = Path.GetDirectoryName(path);
string baseFilename = Path.GetFileName(path);

View File

@@ -39,7 +39,7 @@ namespace DiscImageChef.Filters
/// <summary>
/// Decompress xz files while reading
/// </summary>
public class XZ : Filter
public class XZ : IFilter
{
string basePath;
DateTime creationTime;
@@ -49,13 +49,10 @@ namespace DiscImageChef.Filters
DateTime lastWriteTime;
bool opened;
public XZ()
{
Name = "XZ";
UUID = new Guid("666A8617-0444-4C05-9F4F-DF0FD758D0D2");
}
public virtual string Name => "XZ";
public virtual Guid Id => new Guid("666A8617-0444-4C05-9F4F-DF0FD758D0D2");
public override void Close()
public virtual void Close()
{
dataStream?.Close();
dataStream = null;
@@ -63,39 +60,39 @@ namespace DiscImageChef.Filters
opened = false;
}
public override string GetBasePath()
public virtual string GetBasePath()
{
return basePath;
}
public override Stream GetDataForkStream()
public virtual Stream GetDataForkStream()
{
return innerStream;
}
public override string GetPath()
public virtual string GetPath()
{
return basePath;
}
public override Stream GetResourceForkStream()
public virtual Stream GetResourceForkStream()
{
return null;
}
public override bool HasResourceFork()
public virtual bool HasResourceFork()
{
return false;
}
public override bool Identify(byte[] buffer)
public virtual bool Identify(byte[] buffer)
{
return buffer[0] == 0xFD && buffer[1] == 0x37 && buffer[2] == 0x7A && buffer[3] == 0x58 &&
buffer[4] == 0x5A && buffer[5] == 0x00 && buffer[buffer.Length - 2] == 0x59 &&
buffer[buffer.Length - 1] == 0x5A;
}
public override bool Identify(Stream stream)
public virtual bool Identify(Stream stream)
{
byte[] buffer = new byte[6];
byte[] footer = new byte[2];
@@ -110,7 +107,7 @@ namespace DiscImageChef.Filters
buffer[4] == 0x5A && buffer[5] == 0x00 && footer[0] == 0x59 && footer[1] == 0x5A;
}
public override bool Identify(string path)
public virtual bool Identify(string path)
{
if(!File.Exists(path)) return false;
@@ -175,7 +172,7 @@ namespace DiscImageChef.Filters
return i;
}
public override void Open(byte[] buffer)
public virtual void Open(byte[] buffer)
{
dataStream = new MemoryStream(buffer);
basePath = null;
@@ -186,7 +183,7 @@ namespace DiscImageChef.Filters
opened = true;
}
public override void Open(Stream stream)
public virtual void Open(Stream stream)
{
dataStream = stream;
basePath = null;
@@ -197,7 +194,7 @@ namespace DiscImageChef.Filters
opened = true;
}
public override void Open(string path)
public virtual void Open(string path)
{
dataStream = new FileStream(path, FileMode.Open, FileAccess.Read);
basePath = Path.GetFullPath(path);
@@ -213,32 +210,32 @@ namespace DiscImageChef.Filters
opened = true;
}
public override DateTime GetCreationTime()
public virtual DateTime GetCreationTime()
{
return creationTime;
}
public override long GetDataForkLength()
public virtual long GetDataForkLength()
{
return decompressedSize;
}
public override DateTime GetLastWriteTime()
public virtual DateTime GetLastWriteTime()
{
return lastWriteTime;
}
public override long GetLength()
public virtual long GetLength()
{
return decompressedSize;
}
public override long GetResourceForkLength()
public virtual long GetResourceForkLength()
{
return 0;
}
public override string GetFilename()
public virtual string GetFilename()
{
if(basePath?.EndsWith(".xz", StringComparison.InvariantCultureIgnoreCase) == true)
return basePath.Substring(0, basePath.Length - 3);
@@ -248,12 +245,12 @@ namespace DiscImageChef.Filters
: basePath;
}
public override string GetParentFolder()
public virtual string GetParentFolder()
{
return Path.GetDirectoryName(basePath);
}
public override bool IsOpened()
public virtual bool IsOpened()
{
return opened;
}

View File

@@ -38,7 +38,7 @@ namespace DiscImageChef.Filters
/// <summary>
/// No filter for reading files not recognized by any filter
/// </summary>
public class ZZZNoFilter : Filter
public class ZZZNoFilter : IFilter
{
string basePath;
DateTime creationTime;
@@ -46,13 +46,10 @@ namespace DiscImageChef.Filters
DateTime lastWriteTime;
bool opened;
public ZZZNoFilter()
{
Name = "No filter";
UUID = new Guid("12345678-AAAA-BBBB-CCCC-123456789000");
}
public virtual string Name => "No filter";
public virtual Guid Id => new Guid("12345678-AAAA-BBBB-CCCC-123456789000");
public override void Close()
public virtual void Close()
{
dataStream?.Close();
dataStream = null;
@@ -60,48 +57,48 @@ namespace DiscImageChef.Filters
opened = false;
}
public override string GetBasePath()
public virtual string GetBasePath()
{
return basePath;
}
public override Stream GetDataForkStream()
public virtual Stream GetDataForkStream()
{
return dataStream;
}
public override string GetPath()
public virtual string GetPath()
{
return basePath;
}
public override Stream GetResourceForkStream()
public virtual Stream GetResourceForkStream()
{
return null;
}
public override bool HasResourceFork()
public virtual bool HasResourceFork()
{
// TODO: Implement support for xattrs/ADS
return false;
}
public override bool Identify(byte[] buffer)
public virtual bool Identify(byte[] buffer)
{
return buffer != null && buffer.Length > 0;
}
public override bool Identify(Stream stream)
public virtual bool Identify(Stream stream)
{
return stream != null && stream.Length > 0;
}
public override bool Identify(string path)
public virtual bool Identify(string path)
{
return File.Exists(path);
}
public override void Open(byte[] buffer)
public virtual void Open(byte[] buffer)
{
dataStream = new MemoryStream(buffer);
basePath = null;
@@ -110,7 +107,7 @@ namespace DiscImageChef.Filters
opened = true;
}
public override void Open(Stream stream)
public virtual void Open(Stream stream)
{
dataStream = stream;
basePath = null;
@@ -119,7 +116,7 @@ namespace DiscImageChef.Filters
opened = true;
}
public override void Open(string path)
public virtual void Open(string path)
{
dataStream = new FileStream(path, FileMode.Open, FileAccess.Read);
basePath = Path.GetFullPath(path);
@@ -129,42 +126,42 @@ namespace DiscImageChef.Filters
opened = true;
}
public override DateTime GetCreationTime()
public virtual DateTime GetCreationTime()
{
return creationTime;
}
public override long GetDataForkLength()
public virtual long GetDataForkLength()
{
return dataStream.Length;
}
public override DateTime GetLastWriteTime()
public virtual DateTime GetLastWriteTime()
{
return lastWriteTime;
}
public override long GetLength()
public virtual long GetLength()
{
return dataStream.Length;
}
public override long GetResourceForkLength()
public virtual long GetResourceForkLength()
{
return 0;
}
public override string GetFilename()
public virtual string GetFilename()
{
return Path.GetFileName(basePath);
}
public override string GetParentFolder()
public virtual string GetParentFolder()
{
return Path.GetDirectoryName(basePath);
}
public override bool IsOpened()
public virtual bool IsOpened()
{
return opened;
}