diff --git a/BinaryObjectScanner/FileType/AACSMediaKeyBlock.cs b/BinaryObjectScanner/FileType/AACSMediaKeyBlock.cs
index 641484ec..d4f90f7d 100644
--- a/BinaryObjectScanner/FileType/AACSMediaKeyBlock.cs
+++ b/BinaryObjectScanner/FileType/AACSMediaKeyBlock.cs
@@ -1,26 +1,15 @@
using System;
using System.IO;
-using BinaryObjectScanner.Interfaces;
namespace BinaryObjectScanner.FileType
{
///
/// AACS media key block
///
- public class AACSMediaKeyBlock : IDetectable
+ public class AACSMediaKeyBlock : DetectableBase
{
///
- public string? Detect(string file, bool includeDebug)
- {
- if (!File.Exists(file))
- return null;
-
- using var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
- return Detect(fs, file, includeDebug);
- }
-
- ///
- public string? Detect(Stream stream, string file, bool includeDebug)
+ public override string? Detect(Stream stream, string file, bool includeDebug)
{
// Create the wrapper
var mkb = SabreTools.Serialization.Wrappers.AACSMediaKeyBlock.Create(stream);
diff --git a/BinaryObjectScanner/FileType/DetectableBase.cs b/BinaryObjectScanner/FileType/DetectableBase.cs
new file mode 100644
index 00000000..bf4f6cd6
--- /dev/null
+++ b/BinaryObjectScanner/FileType/DetectableBase.cs
@@ -0,0 +1,34 @@
+using System.IO;
+using BinaryObjectScanner.Interfaces;
+
+namespace BinaryObjectScanner.FileType
+{
+ ///
+ /// Base class for all standard detectable types
+ ///
+ public abstract class DetectableBase : IDetectable
+ {
+ #region Constructors
+
+ public DetectableBase() { }
+
+ #endregion
+
+ #region IDetectable Implementations
+
+ ///
+ public string? Detect(string file, bool includeDebug)
+ {
+ if (!File.Exists(file))
+ return null;
+
+ using var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
+ return Detect(fs, file, includeDebug);
+ }
+
+ ///
+ public abstract string? Detect(Stream stream, string file, bool includeDebug);
+
+ #endregion
+ }
+}
\ No newline at end of file
diff --git a/BinaryObjectScanner/FileType/DetectableBaseT.cs b/BinaryObjectScanner/FileType/DetectableBaseT.cs
new file mode 100644
index 00000000..b7922acf
--- /dev/null
+++ b/BinaryObjectScanner/FileType/DetectableBaseT.cs
@@ -0,0 +1,13 @@
+using BinaryObjectScanner.Interfaces;
+using SabreTools.Serialization.Interfaces;
+
+namespace BinaryObjectScanner.FileType
+{
+ ///
+ /// Base class for all standard detectable types with a wrapper
+ ///
+ public abstract class DetectableBase : DetectableBase, IDetectable where T : IWrapper
+ {
+
+ }
+}
\ No newline at end of file
diff --git a/BinaryObjectScanner/FileType/LDSCRYPT.cs b/BinaryObjectScanner/FileType/LDSCRYPT.cs
index a66c7bc6..366b2093 100644
--- a/BinaryObjectScanner/FileType/LDSCRYPT.cs
+++ b/BinaryObjectScanner/FileType/LDSCRYPT.cs
@@ -1,6 +1,5 @@
using System;
using System.IO;
-using BinaryObjectScanner.Interfaces;
using SabreTools.Matching;
namespace BinaryObjectScanner.FileType
@@ -8,20 +7,10 @@ namespace BinaryObjectScanner.FileType
///
/// Link Data Security encrypted file
///
- public class LDSCRYPT : IDetectable
+ public class LDSCRYPT : DetectableBase
{
///
- public string? Detect(string file, bool includeDebug)
- {
- if (!File.Exists(file))
- return null;
-
- using var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
- return Detect(fs, file, includeDebug);
- }
-
- ///
- public string? Detect(Stream stream, string file, bool includeDebug)
+ public override string? Detect(Stream stream, string file, bool includeDebug)
{
try
{
diff --git a/BinaryObjectScanner/FileType/PLJ.cs b/BinaryObjectScanner/FileType/PLJ.cs
index 6cacc7a6..cc0a0169 100644
--- a/BinaryObjectScanner/FileType/PLJ.cs
+++ b/BinaryObjectScanner/FileType/PLJ.cs
@@ -1,6 +1,5 @@
using System;
using System.IO;
-using BinaryObjectScanner.Interfaces;
using SabreTools.Matching;
namespace BinaryObjectScanner.FileType
@@ -8,20 +7,10 @@ namespace BinaryObjectScanner.FileType
///
/// PlayJ audio file
///
- public class PLJ : IDetectable
+ public class PLJ : DetectableBase
{
///
- public string? Detect(string file, bool includeDebug)
- {
- if (!File.Exists(file))
- return null;
-
- using var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
- return Detect(fs, file, includeDebug);
- }
-
- ///
- public string? Detect(Stream stream, string file, bool includeDebug)
+ public override string? Detect(Stream stream, string file, bool includeDebug)
{
try
{
diff --git a/BinaryObjectScanner/FileType/RealArcadeInstaller.cs b/BinaryObjectScanner/FileType/RealArcadeInstaller.cs
index 31422cc1..8e32ce29 100644
--- a/BinaryObjectScanner/FileType/RealArcadeInstaller.cs
+++ b/BinaryObjectScanner/FileType/RealArcadeInstaller.cs
@@ -1,6 +1,5 @@
using System;
using System.IO;
-using BinaryObjectScanner.Interfaces;
using SabreTools.Matching;
namespace BinaryObjectScanner.FileType
@@ -10,20 +9,10 @@ namespace BinaryObjectScanner.FileType
///
/// TODO: Add further parsing, game ID and name should be possible to parse.
///
- public class RealArcadeInstaller : IDetectable
+ public class RealArcadeInstaller : DetectableBase
{
///
- public string? Detect(string file, bool includeDebug)
- {
- if (!File.Exists(file))
- return null;
-
- using var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
- return Detect(fs, file, includeDebug);
- }
-
- ///
- public string? Detect(Stream stream, string file, bool includeDebug)
+ public override string? Detect(Stream stream, string file, bool includeDebug)
{
try
{
diff --git a/BinaryObjectScanner/FileType/RealArcadeMezzanine.cs b/BinaryObjectScanner/FileType/RealArcadeMezzanine.cs
index 5603269f..7a9e7a05 100644
--- a/BinaryObjectScanner/FileType/RealArcadeMezzanine.cs
+++ b/BinaryObjectScanner/FileType/RealArcadeMezzanine.cs
@@ -1,6 +1,5 @@
using System;
using System.IO;
-using BinaryObjectScanner.Interfaces;
using SabreTools.Matching;
namespace BinaryObjectScanner.FileType
@@ -10,20 +9,10 @@ namespace BinaryObjectScanner.FileType
///
/// TODO: Add further parsing, game ID should be possible to parse.
///
- public class RealArcadeMezzanine : IDetectable
+ public class RealArcadeMezzanine : DetectableBase
{
///
- public string? Detect(string file, bool includeDebug)
- {
- if (!File.Exists(file))
- return null;
-
- using var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
- return Detect(fs, file, includeDebug);
- }
-
- ///
- public string? Detect(Stream stream, string file, bool includeDebug)
+ public override string? Detect(Stream stream, string file, bool includeDebug)
{
try
{
diff --git a/BinaryObjectScanner/FileType/SFFS.cs b/BinaryObjectScanner/FileType/SFFS.cs
index d8e2b565..4e6650f4 100644
--- a/BinaryObjectScanner/FileType/SFFS.cs
+++ b/BinaryObjectScanner/FileType/SFFS.cs
@@ -9,20 +9,10 @@ namespace BinaryObjectScanner.FileType
/// StarForce Filesystem file
///
///
- public class SFFS : IExtractable, IDetectable
+ public class SFFS : DetectableBase, IExtractable
{
///
- public string? Detect(string file, bool includeDebug)
- {
- if (!File.Exists(file))
- return null;
-
- using var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
- return Detect(fs, file, includeDebug);
- }
-
- ///
- public string? Detect(Stream stream, string file, bool includeDebug)
+ public override string? Detect(Stream stream, string file, bool includeDebug)
{
try
{
diff --git a/BinaryObjectScanner/FileType/Textfile.cs b/BinaryObjectScanner/FileType/Textfile.cs
index 9ba288c6..acf25391 100644
--- a/BinaryObjectScanner/FileType/Textfile.cs
+++ b/BinaryObjectScanner/FileType/Textfile.cs
@@ -2,27 +2,16 @@
using System.Collections.Generic;
using System.IO;
using System.Text;
-using BinaryObjectScanner.Interfaces;
namespace BinaryObjectScanner.FileType
{
///
/// Various generic textfile formats
///
- public class Textfile : IDetectable
+ public class Textfile : DetectableBase
{
///
- public string? Detect(string file, bool includeDebug)
- {
- if (!File.Exists(file))
- return null;
-
- using var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
- return Detect(fs, file, includeDebug);
- }
-
- ///
- public string? Detect(Stream stream, string file, bool includeDebug)
+ public override string? Detect(Stream stream, string file, bool includeDebug)
{
// Files can be protected in multiple ways
var protections = new List();