mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Move more helper methods around
This commit is contained in:
@@ -555,7 +555,7 @@ CREATE TABLE IF NOT EXISTS dat (
|
||||
if (lowerCaseDats.Contains(input.ToLowerInvariant()))
|
||||
{
|
||||
string fullpath = Path.GetFullPath(datRootDats[lowerCaseDats.IndexOf(input.ToLowerInvariant())]);
|
||||
string sha1 = Utilities.ByteArrayToString(BaseFile.GetInfo(fullpath, hashes: Hash.SHA1).SHA1);
|
||||
string sha1 = TextHelper.ByteArrayToString(BaseFile.GetInfo(fullpath, hashes: Hash.SHA1).SHA1);
|
||||
foundDats.Add(sha1, fullpath);
|
||||
}
|
||||
else
|
||||
|
||||
33
SabreTools.Core/Tools/DateTimeHelper.cs
Normal file
33
SabreTools.Core/Tools/DateTimeHelper.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
|
||||
namespace SabreTools.Core.Tools
|
||||
{
|
||||
public static class DateTimeHelper
|
||||
{
|
||||
// <summary>
|
||||
/// Convert .NET DateTime to MS-DOS date format
|
||||
/// </summary>
|
||||
/// <remarks>Adapted from 7-zip Source Code: CPP/Windows/TimeUtils.cpp:FileTimeToDosTime</remarks>
|
||||
public static long ConvertToMsDosTimeFormat(DateTime dateTime)
|
||||
{
|
||||
uint year = (uint)((dateTime.Year - 1980) % 128);
|
||||
uint mon = (uint)dateTime.Month;
|
||||
uint day = (uint)dateTime.Day;
|
||||
uint hour = (uint)dateTime.Hour;
|
||||
uint min = (uint)dateTime.Minute;
|
||||
uint sec = (uint)dateTime.Second;
|
||||
|
||||
return (year << 25) | (mon << 21) | (day << 16) | (hour << 11) | (min << 5) | (sec >> 1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert MS-DOS date format to .NET DateTime
|
||||
/// </summary>
|
||||
/// <remarks>Adapted from 7-zip Source Code: CPP/Windows/TimeUtils.cpp:DosTimeToFileTime</remarks>
|
||||
public static DateTime ConvertFromMsDosTimeFormat(uint msDosDateTime)
|
||||
{
|
||||
return new DateTime((int)(1980 + (msDosDateTime >> 25)), (int)((msDosDateTime >> 21) & 0xF), (int)((msDosDateTime >> 16) & 0x1F),
|
||||
(int)((msDosDateTime >> 11) & 0x1F), (int)((msDosDateTime >> 5) & 0x3F), (int)((msDosDateTime & 0x1F) * 2));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@@ -7,6 +8,58 @@ namespace SabreTools.Core.Tools
|
||||
{
|
||||
public static class TextHelper
|
||||
{
|
||||
#region Conversion
|
||||
|
||||
/// <summary>
|
||||
/// Convert a byte array to a hex string
|
||||
/// </summary>
|
||||
public static string? ByteArrayToString(byte[]? bytes)
|
||||
{
|
||||
// If we get null in, we send null out
|
||||
if (bytes == null)
|
||||
return null;
|
||||
|
||||
try
|
||||
{
|
||||
string hex = BitConverter.ToString(bytes);
|
||||
return hex.Replace("-", string.Empty).ToLowerInvariant();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert a hex string to a byte array
|
||||
/// </summary>
|
||||
public static byte[]? StringToByteArray(string? hex)
|
||||
{
|
||||
// If we get null in, we send null out
|
||||
if (string.IsNullOrWhiteSpace(hex))
|
||||
return null;
|
||||
|
||||
try
|
||||
{
|
||||
int NumberChars = hex.Length;
|
||||
byte[] bytes = new byte[NumberChars / 2];
|
||||
for (int i = 0; i < NumberChars; i += 2)
|
||||
{
|
||||
bytes[i / 2] = Convert.ToByte(hex.Substring(i, 2), 16);
|
||||
}
|
||||
|
||||
return bytes;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Normalization
|
||||
|
||||
/// <summary>
|
||||
/// Normalize a string to the WoD standard
|
||||
/// </summary>
|
||||
@@ -75,6 +128,8 @@ namespace SabreTools.Core.Tools
|
||||
return new string(input.Where(c => !invalidPath.Contains(c)).ToArray());
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Helpers
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.IO;
|
||||
|
||||
namespace SabreTools.Core.Tools
|
||||
{
|
||||
@@ -8,92 +7,6 @@ namespace SabreTools.Core.Tools
|
||||
/// </summary>
|
||||
public static class Utilities
|
||||
{
|
||||
/// <summary>
|
||||
/// Convert a byte array to a hex string
|
||||
/// </summary>
|
||||
/// <param name="bytes">Byte array to convert</param>
|
||||
/// <returns>Hex string representing the byte array</returns>
|
||||
/// <link>http://stackoverflow.com/questions/311165/how-do-you-convert-byte-array-to-hexadecimal-string-and-vice-versa</link>
|
||||
public static string? ByteArrayToString(byte[]? bytes)
|
||||
{
|
||||
// If we get null in, we send null out
|
||||
if (bytes == null)
|
||||
return null;
|
||||
|
||||
try
|
||||
{
|
||||
string hex = BitConverter.ToString(bytes);
|
||||
return hex.Replace("-", string.Empty).ToLowerInvariant();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert a hex string to a byte array
|
||||
/// </summary>
|
||||
/// <param name="hex">Hex string to convert</param>
|
||||
/// <returns>Byte array represenging the hex string</returns>
|
||||
/// <link>http://stackoverflow.com/questions/311165/how-do-you-convert-byte-array-to-hexadecimal-string-and-vice-versa</link>
|
||||
public static byte[]? StringToByteArray(string? hex)
|
||||
{
|
||||
// If we get null in, we send null out
|
||||
if (string.IsNullOrWhiteSpace(hex))
|
||||
return null;
|
||||
|
||||
try
|
||||
{
|
||||
int NumberChars = hex.Length;
|
||||
byte[] bytes = new byte[NumberChars / 2];
|
||||
for (int i = 0; i < NumberChars; i += 2)
|
||||
{
|
||||
bytes[i / 2] = Convert.ToByte(hex.Substring(i, 2), 16);
|
||||
}
|
||||
|
||||
return bytes;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert .NET DateTime to MS-DOS date format
|
||||
/// </summary>
|
||||
/// <param name="dateTime">.NET DateTime object to convert</param>
|
||||
/// <returns>UInt32 representing the MS-DOS date</returns>
|
||||
/// <remarks>
|
||||
/// Adapted from 7-zip Source Code: CPP/Windows/TimeUtils.cpp:FileTimeToDosTime
|
||||
/// </remarks>
|
||||
public static long ConvertDateTimeToMsDosTimeFormat(DateTime dateTime)
|
||||
{
|
||||
uint year = (uint)((dateTime.Year - 1980) % 128);
|
||||
uint mon = (uint)dateTime.Month;
|
||||
uint day = (uint)dateTime.Day;
|
||||
uint hour = (uint)dateTime.Hour;
|
||||
uint min = (uint)dateTime.Minute;
|
||||
uint sec = (uint)dateTime.Second;
|
||||
|
||||
return (year << 25) | (mon << 21) | (day << 16) | (hour << 11) | (min << 5) | (sec >> 1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert MS-DOS date format to .NET DateTime
|
||||
/// </summary>
|
||||
/// <param name="msDosDateTime">UInt32 representing the MS-DOS date to convert</param>
|
||||
/// <returns>.NET DateTime object representing the converted date</returns>
|
||||
/// <remarks>
|
||||
/// Adapted from 7-zip Source Code: CPP/Windows/TimeUtils.cpp:DosTimeToFileTime
|
||||
/// </remarks>
|
||||
public static DateTime ConvertMsDosTimeFormatToDateTime(uint msDosDateTime)
|
||||
{
|
||||
return new DateTime((int)(1980 + (msDosDateTime >> 25)), (int)((msDosDateTime >> 21) & 0xF), (int)((msDosDateTime >> 16) & 0x1F),
|
||||
(int)((msDosDateTime >> 11) & 0x1F), (int)((msDosDateTime >> 5) & 0x3F), (int)((msDosDateTime & 0x1F) * 2));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a proper romba sub path
|
||||
/// </summary>
|
||||
|
||||
@@ -196,8 +196,8 @@ namespace SabreTools.DatItems.Formats
|
||||
public Disk(BaseFile baseFile)
|
||||
{
|
||||
Name = baseFile.Filename;
|
||||
MD5 = Utilities.ByteArrayToString(baseFile.MD5);
|
||||
SHA1 = Utilities.ByteArrayToString(baseFile.SHA1);
|
||||
MD5 = TextHelper.ByteArrayToString(baseFile.MD5);
|
||||
SHA1 = TextHelper.ByteArrayToString(baseFile.SHA1);
|
||||
|
||||
ItemType = ItemType.Disk;
|
||||
DupeType = 0x00;
|
||||
@@ -237,8 +237,8 @@ namespace SabreTools.DatItems.Formats
|
||||
{
|
||||
Filename = this.Name,
|
||||
Parent = this.Machine?.Name,
|
||||
MD5 = Utilities.StringToByteArray(this.MD5),
|
||||
SHA1 = Utilities.StringToByteArray(this.SHA1),
|
||||
MD5 = TextHelper.StringToByteArray(this.MD5),
|
||||
SHA1 = TextHelper.StringToByteArray(this.SHA1),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -53,8 +53,8 @@ namespace SabreTools.DatItems.Formats
|
||||
[JsonProperty("crc", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("crc")]
|
||||
public string? CRC
|
||||
{
|
||||
get { return _crc.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_crc); }
|
||||
set { _crc = (value == "null" ? Constants.CRCZeroBytes : Utilities.StringToByteArray(TextHelper.NormalizeCRC32(value))); }
|
||||
get { return _crc.IsNullOrEmpty() ? null : TextHelper.ByteArrayToString(_crc); }
|
||||
set { _crc = (value == "null" ? Constants.CRCZeroBytes : TextHelper.StringToByteArray(TextHelper.NormalizeCRC32(value))); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -63,8 +63,8 @@ namespace SabreTools.DatItems.Formats
|
||||
[JsonProperty("md5", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("md5")]
|
||||
public string? MD5
|
||||
{
|
||||
get { return _md5.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_md5); }
|
||||
set { _md5 = Utilities.StringToByteArray(TextHelper.NormalizeMD5(value)); }
|
||||
get { return _md5.IsNullOrEmpty() ? null : TextHelper.ByteArrayToString(_md5); }
|
||||
set { _md5 = TextHelper.StringToByteArray(TextHelper.NormalizeMD5(value)); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -73,8 +73,8 @@ namespace SabreTools.DatItems.Formats
|
||||
[JsonProperty("sha1", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("sha1")]
|
||||
public string? SHA1
|
||||
{
|
||||
get { return _sha1.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_sha1); }
|
||||
set { _sha1 = Utilities.StringToByteArray(TextHelper.NormalizeSHA1(value)); }
|
||||
get { return _sha1.IsNullOrEmpty() ? null : TextHelper.ByteArrayToString(_sha1); }
|
||||
set { _sha1 = TextHelper.StringToByteArray(TextHelper.NormalizeSHA1(value)); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -83,8 +83,8 @@ namespace SabreTools.DatItems.Formats
|
||||
[JsonProperty("sha256", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("sha256")]
|
||||
public string? SHA256
|
||||
{
|
||||
get { return _sha256.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_sha256); }
|
||||
set { _sha256 = Utilities.StringToByteArray(TextHelper.NormalizeSHA256(value)); }
|
||||
get { return _sha256.IsNullOrEmpty() ? null : TextHelper.ByteArrayToString(_sha256); }
|
||||
set { _sha256 = TextHelper.StringToByteArray(TextHelper.NormalizeSHA256(value)); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -101,10 +101,10 @@ namespace SabreTools.DatItems.Formats
|
||||
public Media(BaseFile baseFile)
|
||||
{
|
||||
Name = baseFile.Filename;
|
||||
MD5 = Utilities.ByteArrayToString(baseFile.MD5);
|
||||
SHA1 = Utilities.ByteArrayToString(baseFile.SHA1);
|
||||
SHA256 = Utilities.ByteArrayToString(baseFile.SHA256);
|
||||
SpamSum = Utilities.ByteArrayToString(baseFile.SpamSum);
|
||||
MD5 = TextHelper.ByteArrayToString(baseFile.MD5);
|
||||
SHA1 = TextHelper.ByteArrayToString(baseFile.SHA1);
|
||||
SHA256 = TextHelper.ByteArrayToString(baseFile.SHA256);
|
||||
SpamSum = TextHelper.ByteArrayToString(baseFile.SpamSum);
|
||||
|
||||
ItemType = ItemType.Media;
|
||||
DupeType = 0x00;
|
||||
@@ -139,10 +139,10 @@ namespace SabreTools.DatItems.Formats
|
||||
{
|
||||
Filename = this.Name,
|
||||
Parent = this.Machine?.Name,
|
||||
MD5 = Utilities.StringToByteArray(this.MD5),
|
||||
SHA1 = Utilities.StringToByteArray(this.SHA1),
|
||||
SHA256 = Utilities.StringToByteArray(this.SHA256),
|
||||
SpamSum = Utilities.StringToByteArray(this.SpamSum),
|
||||
MD5 = TextHelper.StringToByteArray(this.MD5),
|
||||
SHA1 = TextHelper.StringToByteArray(this.SHA1),
|
||||
SHA256 = TextHelper.StringToByteArray(this.SHA256),
|
||||
SpamSum = TextHelper.StringToByteArray(this.SpamSum),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -481,13 +481,13 @@ namespace SabreTools.DatItems.Formats
|
||||
{
|
||||
Name = baseFile.Filename;
|
||||
Size = baseFile.Size;
|
||||
CRC = Utilities.ByteArrayToString(baseFile.CRC);
|
||||
MD5 = Utilities.ByteArrayToString(baseFile.MD5);
|
||||
SHA1 = Utilities.ByteArrayToString(baseFile.SHA1);
|
||||
SHA256 = Utilities.ByteArrayToString(baseFile.SHA256);
|
||||
SHA384 = Utilities.ByteArrayToString(baseFile.SHA384);
|
||||
SHA512 = Utilities.ByteArrayToString(baseFile.SHA512);
|
||||
SpamSum = Utilities.ByteArrayToString(baseFile.SpamSum);
|
||||
CRC = TextHelper.ByteArrayToString(baseFile.CRC);
|
||||
MD5 = TextHelper.ByteArrayToString(baseFile.MD5);
|
||||
SHA1 = TextHelper.ByteArrayToString(baseFile.SHA1);
|
||||
SHA256 = TextHelper.ByteArrayToString(baseFile.SHA256);
|
||||
SHA384 = TextHelper.ByteArrayToString(baseFile.SHA384);
|
||||
SHA512 = TextHelper.ByteArrayToString(baseFile.SHA512);
|
||||
SpamSum = TextHelper.ByteArrayToString(baseFile.SpamSum);
|
||||
|
||||
ItemType = ItemType.Rom;
|
||||
DupeType = 0x00;
|
||||
@@ -530,13 +530,13 @@ namespace SabreTools.DatItems.Formats
|
||||
Parent = this.Machine?.Name,
|
||||
Date = this.Date,
|
||||
Size = this.Size,
|
||||
CRC = Utilities.StringToByteArray(this.CRC),
|
||||
MD5 = Utilities.StringToByteArray(this.MD5),
|
||||
SHA1 = Utilities.StringToByteArray(this.SHA1),
|
||||
SHA256 = Utilities.StringToByteArray(this.SHA256),
|
||||
SHA384 = Utilities.StringToByteArray(this.SHA384),
|
||||
SHA512 = Utilities.StringToByteArray(this.SHA512),
|
||||
SpamSum = Utilities.StringToByteArray(this.SpamSum),
|
||||
CRC = TextHelper.StringToByteArray(this.CRC),
|
||||
MD5 = TextHelper.StringToByteArray(this.MD5),
|
||||
SHA1 = TextHelper.StringToByteArray(this.SHA1),
|
||||
SHA256 = TextHelper.StringToByteArray(this.SHA256),
|
||||
SHA384 = TextHelper.StringToByteArray(this.SHA384),
|
||||
SHA512 = TextHelper.StringToByteArray(this.SHA512),
|
||||
SpamSum = TextHelper.StringToByteArray(this.SpamSum),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -397,7 +397,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
Size = extractedsize,
|
||||
CRC = headercrc,
|
||||
MD5 = headermd5,
|
||||
SHA1 = Utilities.StringToByteArray(Path.GetFileNameWithoutExtension(this.Filename)),
|
||||
SHA1 = TextHelper.StringToByteArray(Path.GetFileNameWithoutExtension(this.Filename)),
|
||||
|
||||
Parent = Path.GetFileNameWithoutExtension(this.Filename).ToLowerInvariant(),
|
||||
};
|
||||
@@ -444,7 +444,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
baseFile = GetInfo(inputStream, keepReadOpen: true);
|
||||
|
||||
// Get the output file name
|
||||
string outfile = Path.Combine(outDir, Utilities.GetDepotPath(Utilities.ByteArrayToString(baseFile.SHA1), Depth));
|
||||
string outfile = Path.Combine(outDir, Utilities.GetDepotPath(TextHelper.ByteArrayToString(baseFile.SHA1), Depth));
|
||||
|
||||
// Check to see if the folder needs to be created
|
||||
if (!Directory.Exists(Path.GetDirectoryName(outfile)))
|
||||
|
||||
@@ -440,7 +440,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
DateTime dt = DateTime.Now;
|
||||
if (UseDates && !string.IsNullOrWhiteSpace(baseFile.Date) && DateTime.TryParse(baseFile.Date.Replace('\\', '/'), out dt))
|
||||
{
|
||||
long msDosDateTime = Utilities.ConvertDateTimeToMsDosTimeFormat(dt);
|
||||
long msDosDateTime = DateTimeHelper.ConvertToMsDosTimeFormat(dt);
|
||||
TimeStamps ts = new() { ModTime = msDosDateTime };
|
||||
zipFile.ZipFileOpenWriteStream(false, false, baseFile.Filename.Replace('\\', '/'), istreamSize, 0, out writeStream, ts);
|
||||
}
|
||||
@@ -516,7 +516,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
DateTime dt = DateTime.Now;
|
||||
if (UseDates && !string.IsNullOrWhiteSpace(baseFile.Date) && DateTime.TryParse(baseFile.Date.Replace('\\', '/'), out dt))
|
||||
{
|
||||
long msDosDateTime = Utilities.ConvertDateTimeToMsDosTimeFormat(dt);
|
||||
long msDosDateTime = DateTimeHelper.ConvertToMsDosTimeFormat(dt);
|
||||
TimeStamps ts = new() { ModTime = msDosDateTime };
|
||||
zipFile.ZipFileOpenWriteStream(false, false, baseFile.Filename.Replace('\\', '/'), istreamSize, 0, out writeStream, ts);
|
||||
}
|
||||
@@ -656,7 +656,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
DateTime dt = DateTime.Now;
|
||||
if (UseDates && !string.IsNullOrWhiteSpace(baseFiles[index].Date) && DateTime.TryParse(baseFiles[index].Date.Replace('\\', '/'), out dt))
|
||||
{
|
||||
long msDosDateTime = Utilities.ConvertDateTimeToMsDosTimeFormat(dt);
|
||||
long msDosDateTime = DateTimeHelper.ConvertToMsDosTimeFormat(dt);
|
||||
TimeStamps ts = new() { ModTime = msDosDateTime };
|
||||
zipFile.ZipFileOpenWriteStream(false, false, baseFiles[index].Filename.Replace('\\', '/'), istreamSize, 0, out writeStream, ts);
|
||||
}
|
||||
@@ -740,7 +740,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
DateTime dt = DateTime.Now;
|
||||
if (UseDates && !string.IsNullOrWhiteSpace(baseFiles[-index - 1].Date) && DateTime.TryParse(baseFiles[-index - 1].Date.Replace('\\', '/'), out dt))
|
||||
{
|
||||
long msDosDateTime = Utilities.ConvertDateTimeToMsDosTimeFormat(dt);
|
||||
long msDosDateTime = DateTimeHelper.ConvertToMsDosTimeFormat(dt);
|
||||
TimeStamps ts = new() { ModTime = msDosDateTime };
|
||||
zipFile.ZipFileOpenWriteStream(false, false, baseFiles[-index - 1].Filename.Replace('\\', '/'), istreamSize, 0, out writeStream, ts);
|
||||
}
|
||||
|
||||
@@ -289,7 +289,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
BaseFile baseFile = new()
|
||||
{
|
||||
Filename = Path.GetFileNameWithoutExtension(this.Filename).ToLowerInvariant(),
|
||||
SHA1 = Utilities.StringToByteArray(Path.GetFileNameWithoutExtension(this.Filename)),
|
||||
SHA1 = TextHelper.StringToByteArray(Path.GetFileNameWithoutExtension(this.Filename)),
|
||||
|
||||
Parent = Path.GetFileNameWithoutExtension(this.Filename).ToLowerInvariant(),
|
||||
};
|
||||
@@ -336,7 +336,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
baseFile = GetInfo(inputStream, keepReadOpen: true);
|
||||
|
||||
// Get the output file name
|
||||
string outfile = Path.Combine(outDir, Utilities.GetDepotPath(Utilities.ByteArrayToString(baseFile.SHA1), Depth));
|
||||
string outfile = Path.Combine(outDir, Utilities.GetDepotPath(TextHelper.ByteArrayToString(baseFile.SHA1), Depth));
|
||||
outfile = outfile.Replace(".gz", ".xz");
|
||||
|
||||
// Check to see if the folder needs to be created
|
||||
|
||||
@@ -453,7 +453,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
DateTime dt = DateTime.Now;
|
||||
if (UseDates && !string.IsNullOrWhiteSpace(baseFile.Date) && DateTime.TryParse(baseFile.Date.Replace('\\', '/'), out dt))
|
||||
{
|
||||
long msDosDateTime = Utilities.ConvertDateTimeToMsDosTimeFormat(dt);
|
||||
long msDosDateTime = DateTimeHelper.ConvertToMsDosTimeFormat(dt);
|
||||
TimeStamps ts = new() { ModTime = msDosDateTime };
|
||||
zipFile.ZipFileOpenWriteStream(false, false, baseFile.Filename.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, out writeStream, ts);
|
||||
}
|
||||
@@ -527,7 +527,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
DateTime dt = DateTime.Now;
|
||||
if (UseDates && !string.IsNullOrWhiteSpace(baseFile.Date) && DateTime.TryParse(baseFile.Date.Replace('\\', '/'), out dt))
|
||||
{
|
||||
long msDosDateTime = Utilities.ConvertDateTimeToMsDosTimeFormat(dt);
|
||||
long msDosDateTime = DateTimeHelper.ConvertToMsDosTimeFormat(dt);
|
||||
TimeStamps ts = new() { ModTime = msDosDateTime };
|
||||
zipFile.ZipFileOpenWriteStream(false, false, baseFile.Filename.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, out writeStream, ts);
|
||||
}
|
||||
@@ -669,7 +669,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
DateTime dt = DateTime.Now;
|
||||
if (UseDates && !string.IsNullOrWhiteSpace(baseFiles[index].Date) && DateTime.TryParse(baseFiles[index].Date.Replace('\\', '/'), out dt))
|
||||
{
|
||||
long msDosDateTime = Utilities.ConvertDateTimeToMsDosTimeFormat(dt);
|
||||
long msDosDateTime = DateTimeHelper.ConvertToMsDosTimeFormat(dt);
|
||||
TimeStamps ts = new() { ModTime = msDosDateTime };
|
||||
zipFile.ZipFileOpenWriteStream(false, false, baseFiles[index].Filename.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, out writeStream, ts);
|
||||
}
|
||||
|
||||
@@ -31,12 +31,12 @@ namespace SabreTools.Test.FileTypes
|
||||
var baseFile = BaseFile.GetInfo(filename, hashes: Hash.All);
|
||||
|
||||
// Extract all the hashes to string
|
||||
string actualCrc = Utilities.ByteArrayToString(baseFile.CRC);
|
||||
string actualMd5 = Utilities.ByteArrayToString(baseFile.MD5);
|
||||
string actualSha1 = Utilities.ByteArrayToString(baseFile.SHA1);
|
||||
string actualSha256 = Utilities.ByteArrayToString(baseFile.SHA256);
|
||||
string actualSha384 = Utilities.ByteArrayToString(baseFile.SHA384);
|
||||
string actualSha512 = Utilities.ByteArrayToString(baseFile.SHA512);
|
||||
string actualCrc = TextHelper.ByteArrayToString(baseFile.CRC);
|
||||
string actualMd5 = TextHelper.ByteArrayToString(baseFile.MD5);
|
||||
string actualSha1 = TextHelper.ByteArrayToString(baseFile.SHA1);
|
||||
string actualSha256 = TextHelper.ByteArrayToString(baseFile.SHA256);
|
||||
string actualSha384 = TextHelper.ByteArrayToString(baseFile.SHA384);
|
||||
string actualSha512 = TextHelper.ByteArrayToString(baseFile.SHA512);
|
||||
string actualSpamSum = Encoding.UTF8.GetString(baseFile.SpamSum);
|
||||
|
||||
// Verify all of the hashes match
|
||||
|
||||
@@ -93,7 +93,7 @@ The following systems have headers that this program can work with:
|
||||
using var fs = File.OpenRead(file);
|
||||
byte[] hbin = new byte[int.Parse(rule.StartOffset)];
|
||||
fs.Read(hbin, 0, int.Parse(rule.StartOffset));
|
||||
hstr = Utilities.ByteArrayToString(hbin);
|
||||
hstr = TextHelper.ByteArrayToString(hbin);
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -112,7 +112,7 @@ The following systems have headers that this program can work with:
|
||||
if (!nostore)
|
||||
{
|
||||
BaseFile baseFile = BaseFile.GetInfo(newfile, hashes: Hash.SHA1, asFiles: TreatAsFile.NonArchive);
|
||||
AddHeaderToDatabase(hstr, Utilities.ByteArrayToString(baseFile.SHA1), rule.SourceFile);
|
||||
AddHeaderToDatabase(hstr, TextHelper.ByteArrayToString(baseFile.SHA1), rule.SourceFile);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -71,7 +71,7 @@ The following systems have headers that this program can work with:
|
||||
BaseFile baseFile = BaseFile.GetInfo(file, hashes: Hash.SHA1, asFiles: TreatAsFile.NonArchive);
|
||||
|
||||
// Retrieve a list of all related headers from the database
|
||||
List<string> headers = RetrieveHeadersFromDatabase(Utilities.ByteArrayToString(baseFile.SHA1));
|
||||
List<string> headers = RetrieveHeadersFromDatabase(TextHelper.ByteArrayToString(baseFile.SHA1));
|
||||
|
||||
// If we have nothing retrieved, we return false
|
||||
if (headers.Count == 0)
|
||||
@@ -82,7 +82,7 @@ The following systems have headers that this program can work with:
|
||||
{
|
||||
string outputFile = (string.IsNullOrWhiteSpace(outDir) ? $"{Path.GetFullPath(file)}.new" : Path.Combine(outDir, Path.GetFileName(file))) + i;
|
||||
logger.User($"Creating reheadered file: {outputFile}");
|
||||
AppendBytes(file, outputFile, Utilities.StringToByteArray(headers[i]), null);
|
||||
AppendBytes(file, outputFile, TextHelper.StringToByteArray(headers[i]), null);
|
||||
logger.User("Reheadered file created!");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user