mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[FileTypes/] Move some things around
This commit is contained in:
@@ -131,91 +131,6 @@ namespace SabreTools.Library.Tools
|
||||
|
||||
#region Information
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve file information for a single torrent GZ file
|
||||
/// </summary>
|
||||
/// <param name="input">Filename to get information from</param>
|
||||
/// <returns>Populated DatItem object if success, empty one on error</returns>
|
||||
public static Rom GetTorrentGZFileInfo(string input)
|
||||
{
|
||||
// Check for the file existing first
|
||||
if (!File.Exists(input))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
string datum = Path.GetFileName(input).ToLowerInvariant();
|
||||
long filesize = new FileInfo(input).Length;
|
||||
|
||||
// If we have the romba depot files, just skip them gracefully
|
||||
if (datum == ".romba_size" || datum == ".romba_size.backup")
|
||||
{
|
||||
Globals.Logger.Verbose("Romba depot file found, skipping: {0}", input);
|
||||
return null;
|
||||
}
|
||||
|
||||
// Check if the name is the right length
|
||||
if (!Regex.IsMatch(datum, @"^[0-9a-f]{" + Constants.SHA1Length + @"}\.gz")) // TODO: When updating to SHA-256, this needs to update to Constants.SHA256Length
|
||||
{
|
||||
Globals.Logger.Warning("Non SHA-1 filename found, skipping: '{0}'", Path.GetFullPath(input));
|
||||
return null;
|
||||
}
|
||||
|
||||
// Check if the file is at least the minimum length
|
||||
if (filesize < 40 /* bytes */)
|
||||
{
|
||||
Globals.Logger.Warning("Possibly corrupt file '{0}' with size {1}", Path.GetFullPath(input), Style.GetBytesReadable(filesize));
|
||||
return null;
|
||||
}
|
||||
|
||||
// Get the Romba-specific header data
|
||||
byte[] header; // Get preamble header for checking
|
||||
byte[] headermd5; // MD5
|
||||
byte[] headercrc; // CRC
|
||||
ulong headersz; // Int64 size
|
||||
BinaryReader br = new BinaryReader(FileTools.TryOpenRead(input));
|
||||
header = br.ReadBytes(12);
|
||||
headermd5 = br.ReadBytes(16);
|
||||
headercrc = br.ReadBytes(4);
|
||||
headersz = br.ReadUInt64();
|
||||
br.Dispose();
|
||||
|
||||
// If the header is not correct, return a blank rom
|
||||
bool correct = true;
|
||||
for (int i = 0; i < header.Length; i++)
|
||||
{
|
||||
// This is a temp fix to ignore the modification time and OS until romba can be fixed
|
||||
if (i == 4 || i == 5 || i == 6 || i == 7 || i == 9)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
correct &= (header[i] == Constants.TorrentGZHeader[i]);
|
||||
}
|
||||
if (!correct)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// Now convert the data and get the right position
|
||||
string gzmd5 = BitConverter.ToString(headermd5).Replace("-", string.Empty);
|
||||
string gzcrc = BitConverter.ToString(headercrc).Replace("-", string.Empty);
|
||||
long extractedsize = (long)headersz;
|
||||
|
||||
Rom rom = new Rom
|
||||
{
|
||||
Type = ItemType.Rom,
|
||||
Name = Path.GetFileNameWithoutExtension(input).ToLowerInvariant(),
|
||||
Size = extractedsize,
|
||||
CRC = gzcrc.ToLowerInvariant(),
|
||||
MD5 = gzmd5.ToLowerInvariant(),
|
||||
SHA1 = Path.GetFileNameWithoutExtension(input).ToLowerInvariant(), // TODO: When updating to SHA-256, this needs to update to SHA256
|
||||
|
||||
MachineName = Path.GetFileNameWithoutExtension(input).ToLowerInvariant(),
|
||||
};
|
||||
|
||||
return rom;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the archive type of an input file
|
||||
/// </summary>
|
||||
@@ -621,49 +536,6 @@ namespace SabreTools.Library.Tools
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// (INCOMPLETE) Get the T7Z status of the file
|
||||
/// </summary>
|
||||
/// <param name="filename">Name of the file to check</param>
|
||||
/// <returns>0 if the file isn't 7z, 1 if the file is t7z, 2 if the file is 7z</returns>
|
||||
public static int IsT7z(string filename)
|
||||
{
|
||||
int ist7z = 0;
|
||||
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
try
|
||||
{
|
||||
Stream fread = FileTools.TryOpenRead(filename);
|
||||
uint ar, offs = 0;
|
||||
fread.Seek(0, SeekOrigin.Begin);
|
||||
byte[] buffer = new byte[128];
|
||||
ar = (uint)fread.Read(buffer, 0, 4 + Constants.Torrent7ZipSignature.Length + 4);
|
||||
if (ar < (4 + Constants.Torrent7ZipSignature.Length + 4))
|
||||
{
|
||||
if (ar >= Constants.Torrent7ZipSignature.Length + 4)
|
||||
{
|
||||
ar -= (uint)(Constants.Torrent7ZipSignature.Length + 4);
|
||||
}
|
||||
if (ar <= Constants.Torrent7ZipHeader.Length)
|
||||
{
|
||||
ar = (uint)Constants.Torrent7ZipHeader.Length;
|
||||
}
|
||||
// memset(buffer+offs+ar,0,crcsz-ar)
|
||||
}
|
||||
|
||||
fread.Dispose();
|
||||
}
|
||||
catch
|
||||
{
|
||||
Globals.Logger.Warning("File '{0}' could not be opened", filename);
|
||||
ist7z = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return ist7z;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user