mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Fix build and move constants
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using SabreTools.IO.Extensions;
|
using SabreTools.IO.Extensions;
|
||||||
using SabreTools.Matching;
|
using SabreTools.Matching;
|
||||||
|
using static SabreTools.FileTypes.Constants;
|
||||||
|
|
||||||
namespace SabreTools.FileTypes.Aaru
|
namespace SabreTools.FileTypes.Aaru
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -239,7 +239,7 @@ namespace SabreTools.FileTypes.Archives
|
|||||||
var gz = new gZip();
|
var gz = new gZip();
|
||||||
ZipReturn ret = gz.ZipFileOpen(Filename);
|
ZipReturn ret = gz.ZipFileOpen(Filename);
|
||||||
ret = gz.ZipFileOpenReadStream(0, out Stream? gzstream, out ulong streamSize);
|
ret = gz.ZipFileOpenReadStream(0, out Stream? gzstream, out ulong streamSize);
|
||||||
gzipEntryRom = GetInfo(gzstream, hashes: _hashTypes);
|
gzipEntryRom = FileTypeTool.GetInfo(gzstream, hashes: _hashTypes);
|
||||||
gzipEntryRom.Filename = gz.GetLocalFile(0).Filename;
|
gzipEntryRom.Filename = gz.GetLocalFile(0).Filename;
|
||||||
gzipEntryRom.Parent = gamename;
|
gzipEntryRom.Parent = gamename;
|
||||||
gzipEntryRom.Date = (gz.TimeStamp > 0 ? gz.TimeStamp.ToString() : null);
|
gzipEntryRom.Date = (gz.TimeStamp > 0 ? gz.TimeStamp.ToString() : null);
|
||||||
@@ -284,7 +284,7 @@ namespace SabreTools.FileTypes.Archives
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if the name is the right length
|
// Check if the name is the right length
|
||||||
if (!Regex.IsMatch(datum, @"^[0-9a-f]{" + Constants.SHA1Length + @"}\.gz"))
|
if (!Regex.IsMatch(datum, @"^[0-9a-f]{" + Hashing.Constants.SHA1Length + @"}\.gz"))
|
||||||
{
|
{
|
||||||
_logger.Warning($"Non SHA-1 filename found, skipping: '{Path.GetFullPath(Filename)}'");
|
_logger.Warning($"Non SHA-1 filename found, skipping: '{Path.GetFullPath(Filename)}'");
|
||||||
return false;
|
return false;
|
||||||
@@ -345,7 +345,7 @@ namespace SabreTools.FileTypes.Archives
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if the name is the right length
|
// Check if the name is the right length
|
||||||
if (!Regex.IsMatch(datum, @"^[0-9a-f]{" + Constants.SHA1Length + @"}\.gz"))
|
if (!Regex.IsMatch(datum, @"^[0-9a-f]{" + Hashing.Constants.SHA1Length + @"}\.gz"))
|
||||||
{
|
{
|
||||||
_logger.Warning($"Non SHA-1 filename found, skipping: '{Path.GetFullPath(Filename)}'");
|
_logger.Warning($"Non SHA-1 filename found, skipping: '{Path.GetFullPath(Filename)}'");
|
||||||
return null;
|
return null;
|
||||||
@@ -440,7 +440,7 @@ namespace SabreTools.FileTypes.Archives
|
|||||||
outDir = Path.GetFullPath(outDir);
|
outDir = Path.GetFullPath(outDir);
|
||||||
|
|
||||||
// Now get the Rom info for the file so we have hashes and size
|
// Now get the Rom info for the file so we have hashes and size
|
||||||
baseFile = GetInfo(inputStream, keepReadOpen: true);
|
baseFile = FileTypeTool.GetInfo(inputStream, keepReadOpen: true);
|
||||||
|
|
||||||
// Get the output file name
|
// Get the output file name
|
||||||
string outfile = Path.Combine(outDir, Utilities.GetDepotPath(baseFile.SHA1, Depth) ?? string.Empty);
|
string outfile = Path.Combine(outDir, Utilities.GetDepotPath(baseFile.SHA1, Depth) ?? string.Empty);
|
||||||
|
|||||||
@@ -210,7 +210,7 @@ namespace SabreTools.FileTypes.Archives
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
using Stream entryStream = entry.OpenEntryStream();
|
using Stream entryStream = entry.OpenEntryStream();
|
||||||
rarEntryRom = GetInfo(entryStream, size: entry.Size, hashes: _hashTypes);
|
rarEntryRom = FileTypeTool.GetInfo(entryStream, size: entry.Size, hashes: _hashTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fill in common details and add to the list
|
// Fill in common details and add to the list
|
||||||
|
|||||||
@@ -282,7 +282,7 @@ namespace SabreTools.FileTypes.Archives
|
|||||||
// Otherwise, use the stream directly
|
// Otherwise, use the stream directly
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
zipEntryRom = GetInfo(readStream, size: (long)zf.GetLocalFile(i).UncompressedSize, hashes: _hashTypes, keepReadOpen: true);
|
zipEntryRom = FileTypeTool.GetInfo(readStream, size: (long)zf.GetLocalFile(i).UncompressedSize, hashes: _hashTypes, keepReadOpen: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fill in common details and add to the list
|
// Fill in common details and add to the list
|
||||||
|
|||||||
@@ -203,7 +203,7 @@ namespace SabreTools.FileTypes.Archives
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
using Stream entryStream = entry.OpenEntryStream();
|
using Stream entryStream = entry.OpenEntryStream();
|
||||||
tarEntryRom = GetInfo(entryStream, size: entry.Size, hashes: _hashTypes);
|
tarEntryRom = FileTypeTool.GetInfo(entryStream, size: entry.Size, hashes: _hashTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fill in common details and add to the list
|
// Fill in common details and add to the list
|
||||||
|
|||||||
@@ -2,7 +2,9 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
#if NET462_OR_GREATER || NETCOREAPP
|
||||||
using SabreTools.Hashing;
|
using SabreTools.Hashing;
|
||||||
|
#endif
|
||||||
using SabreTools.IO.Extensions;
|
using SabreTools.IO.Extensions;
|
||||||
#if NET462_OR_GREATER || NETCOREAPP
|
#if NET462_OR_GREATER || NETCOREAPP
|
||||||
using SharpCompress.Compressors.Xz;
|
using SharpCompress.Compressors.Xz;
|
||||||
@@ -213,7 +215,7 @@ namespace SabreTools.FileTypes.Archives
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
var xzStream = new XZStream(File.OpenRead(Filename!));
|
var xzStream = new XZStream(File.OpenRead(Filename!));
|
||||||
xzEntryRom = GetInfo(xzStream, hashes: _hashTypes);
|
xzEntryRom = FileTypeTool.GetInfo(xzStream, hashes: _hashTypes);
|
||||||
xzEntryRom.Filename = gamename;
|
xzEntryRom.Filename = gamename;
|
||||||
xzStream.Dispose();
|
xzStream.Dispose();
|
||||||
}
|
}
|
||||||
@@ -252,7 +254,7 @@ namespace SabreTools.FileTypes.Archives
|
|||||||
string datum = Path.GetFileName(Filename).ToLowerInvariant();
|
string datum = Path.GetFileName(Filename).ToLowerInvariant();
|
||||||
|
|
||||||
// Check if the name is the right length
|
// Check if the name is the right length
|
||||||
if (!Regex.IsMatch(datum, @"^[0-9a-f]{" + Constants.SHA1Length + @"}\.xz"))
|
if (!Regex.IsMatch(datum, @"^[0-9a-f]{" + Hashing.Constants.SHA1Length + @"}\.xz"))
|
||||||
{
|
{
|
||||||
_logger.Warning($"Non SHA-1 filename found, skipping: '{Path.GetFullPath(Filename)}'");
|
_logger.Warning($"Non SHA-1 filename found, skipping: '{Path.GetFullPath(Filename)}'");
|
||||||
return false;
|
return false;
|
||||||
@@ -274,7 +276,7 @@ namespace SabreTools.FileTypes.Archives
|
|||||||
string datum = Path.GetFileName(Filename).ToLowerInvariant();
|
string datum = Path.GetFileName(Filename).ToLowerInvariant();
|
||||||
|
|
||||||
// Check if the name is the right length
|
// Check if the name is the right length
|
||||||
if (!Regex.IsMatch(datum, @"^[0-9a-f]{" + Constants.SHA1Length + @"}\.xz"))
|
if (!Regex.IsMatch(datum, @"^[0-9a-f]{" + Hashing.Constants.SHA1Length + @"}\.xz"))
|
||||||
{
|
{
|
||||||
_logger.Warning($"Non SHA-1 filename found, skipping: '{Path.GetFullPath(Filename)}'");
|
_logger.Warning($"Non SHA-1 filename found, skipping: '{Path.GetFullPath(Filename)}'");
|
||||||
return null;
|
return null;
|
||||||
@@ -328,7 +330,7 @@ namespace SabreTools.FileTypes.Archives
|
|||||||
outDir = Path.GetFullPath(outDir);
|
outDir = Path.GetFullPath(outDir);
|
||||||
|
|
||||||
// Now get the Rom info for the file so we have hashes and size
|
// Now get the Rom info for the file so we have hashes and size
|
||||||
baseFile = GetInfo(inputStream, keepReadOpen: true);
|
baseFile = FileTypeTool.GetInfo(inputStream, keepReadOpen: true);
|
||||||
|
|
||||||
// Get the output file name
|
// Get the output file name
|
||||||
string outfile = Path.Combine(outDir, Core.Tools.Utilities.GetDepotPath(baseFile.SHA1, Depth)!);
|
string outfile = Path.Combine(outDir, Core.Tools.Utilities.GetDepotPath(baseFile.SHA1, Depth)!);
|
||||||
|
|||||||
@@ -361,7 +361,7 @@ namespace SabreTools.FileTypes.Archives
|
|||||||
// Otherwise, use the stream directly
|
// Otherwise, use the stream directly
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
zipEntryRom = GetInfo(readStream,
|
zipEntryRom = FileTypeTool.GetInfo(readStream,
|
||||||
size: (long)localFile.UncompressedSize,
|
size: (long)localFile.UncompressedSize,
|
||||||
hashes: _hashTypes,
|
hashes: _hashTypes,
|
||||||
keepReadOpen: true);
|
keepReadOpen: true);
|
||||||
@@ -418,7 +418,7 @@ namespace SabreTools.FileTypes.Archives
|
|||||||
// Otherwise, use the stream directly
|
// Otherwise, use the stream directly
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
zipEntryRom = GetInfo(readStream,
|
zipEntryRom = FileTypeTool.GetInfo(readStream,
|
||||||
size: localFile.Length,
|
size: localFile.Length,
|
||||||
hashes: _hashTypes,
|
hashes: _hashTypes,
|
||||||
keepReadOpen: false);
|
keepReadOpen: false);
|
||||||
|
|||||||
23
SabreTools.FileTypes/Constants.cs
Normal file
23
SabreTools.FileTypes/Constants.cs
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
namespace SabreTools.FileTypes
|
||||||
|
{
|
||||||
|
internal static class Constants
|
||||||
|
{
|
||||||
|
public static readonly byte[] SevenZipSignature = [0x37, 0x7a, 0xbc, 0xaf, 0x27, 0x1c];
|
||||||
|
|
||||||
|
public static readonly byte[] AaruFormatSignature = [0x41, 0x41, 0x52, 0x55, 0x46, 0x52, 0x4d, 0x54];
|
||||||
|
|
||||||
|
public static readonly byte[] CHDSignature = [0x4d, 0x43, 0x6f, 0x6d, 0x70, 0x72, 0x48, 0x44];
|
||||||
|
|
||||||
|
public static readonly byte[] GzSignature = [0x1f, 0x8b, 0x08];
|
||||||
|
|
||||||
|
public static readonly byte[] RarSignature = [0x52, 0x61, 0x72, 0x21, 0x1a, 0x07, 0x00];
|
||||||
|
|
||||||
|
public static readonly byte[] RarFiveSignature = [0x52, 0x61, 0x72, 0x21, 0x1a, 0x07, 0x01, 0x00];
|
||||||
|
|
||||||
|
public static readonly byte[] TarSignature = [0x75, 0x73, 0x74, 0x61, 0x72, 0x20, 0x20, 0x00];
|
||||||
|
|
||||||
|
public static readonly byte[] TarZeroSignature = [0x75, 0x73, 0x74, 0x61, 0x72, 0x00, 0x30, 0x30];
|
||||||
|
|
||||||
|
public static readonly byte[] XZSignature = [0xfd, 0x37, 0x7a, 0x58, 0x5a, 0x00, 0x00];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,25 +7,12 @@ using SabreTools.Hashing;
|
|||||||
using SabreTools.IO.Extensions;
|
using SabreTools.IO.Extensions;
|
||||||
using SabreTools.Matching;
|
using SabreTools.Matching;
|
||||||
using SabreTools.Skippers;
|
using SabreTools.Skippers;
|
||||||
|
using static SabreTools.FileTypes.Constants;
|
||||||
|
|
||||||
namespace SabreTools.FileTypes
|
namespace SabreTools.FileTypes
|
||||||
{
|
{
|
||||||
public static class FileTypeTool
|
public static class FileTypeTool
|
||||||
{
|
{
|
||||||
#region Constants
|
|
||||||
|
|
||||||
private static readonly byte[] SevenZipSignature = [0x37, 0x7a, 0xbc, 0xaf, 0x27, 0x1c];
|
|
||||||
private static readonly byte[] AaruFormatSignature = [0x41, 0x41, 0x52, 0x55, 0x46, 0x52, 0x4d, 0x54];
|
|
||||||
private static readonly byte[] CHDSignature = [0x4d, 0x43, 0x6f, 0x6d, 0x70, 0x72, 0x48, 0x44];
|
|
||||||
private static readonly byte[] GzSignature = [0x1f, 0x8b, 0x08];
|
|
||||||
private static readonly byte[] RarSignature = [0x52, 0x61, 0x72, 0x21, 0x1a, 0x07, 0x00];
|
|
||||||
private static readonly byte[] RarFiveSignature = [0x52, 0x61, 0x72, 0x21, 0x1a, 0x07, 0x01, 0x00];
|
|
||||||
private static readonly byte[] TarSignature = [0x75, 0x73, 0x74, 0x61, 0x72, 0x20, 0x20, 0x00];
|
|
||||||
private static readonly byte[] TarZeroSignature = [0x75, 0x73, 0x74, 0x61, 0x72, 0x00, 0x30, 0x30];
|
|
||||||
private static readonly byte[] XZSignature = [0xfd, 0x37, 0x7a, 0x58, 0x5a, 0x00, 0x00];
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region File Info
|
#region File Info
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user