mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Reduce more complexity
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using SabreTools.Hashing;
|
using SabreTools.Hashing;
|
||||||
|
using SabreTools.IO.Extensions;
|
||||||
using SabreTools.Matching;
|
using SabreTools.Matching;
|
||||||
|
|
||||||
namespace SabreTools.Core.Tools
|
namespace SabreTools.Core.Tools
|
||||||
@@ -45,6 +46,18 @@ namespace SabreTools.Core.Tools
|
|||||||
return string.Equals(firstHash, secondHash, StringComparison.OrdinalIgnoreCase);
|
return string.Equals(firstHash, secondHash, StringComparison.OrdinalIgnoreCase);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get a proper romba sub path
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="hash">SHA-1 hash to get the path for</param>
|
||||||
|
/// <param name="depth">Positive value representing the depth of the depot</param>
|
||||||
|
/// <returns>Subfolder path for the given hash</returns>
|
||||||
|
public static string? GetDepotPath(byte[]? hash, int depth)
|
||||||
|
{
|
||||||
|
string? sha1 = ByteArrayExtensions.ByteArrayToString(hash);
|
||||||
|
return GetDepotPath(sha1, depth);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get a proper romba sub path
|
/// Get a proper romba sub path
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -467,27 +467,30 @@ namespace SabreTools.DatFiles
|
|||||||
if (item is Disk disk)
|
if (item is Disk disk)
|
||||||
{
|
{
|
||||||
// We can only write out if there's a SHA-1
|
// We can only write out if there's a SHA-1
|
||||||
if (!string.IsNullOrEmpty(disk.GetStringFieldValue(Models.Metadata.Disk.SHA1Key)))
|
string? sha1 = disk.GetStringFieldValue(Models.Metadata.Disk.SHA1Key);
|
||||||
|
if (!string.IsNullOrEmpty(sha1))
|
||||||
{
|
{
|
||||||
name = Utilities.GetDepotPath(disk.GetStringFieldValue(Models.Metadata.Disk.SHA1Key), outputDepot.Depth)?.Replace('\\', '/');
|
name = Utilities.GetDepotPath(sha1, outputDepot.Depth)?.Replace('\\', '/');
|
||||||
item.SetName($"{pre}{name}{post}");
|
item.SetName($"{pre}{name}{post}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (item is Media media)
|
else if (item is Media media)
|
||||||
{
|
{
|
||||||
// We can only write out if there's a SHA-1
|
// We can only write out if there's a SHA-1
|
||||||
if (!string.IsNullOrEmpty(media.GetStringFieldValue(Models.Metadata.Media.SHA1Key)))
|
string? sha1 = media.GetStringFieldValue(Models.Metadata.Media.SHA1Key);
|
||||||
|
if (!string.IsNullOrEmpty(sha1))
|
||||||
{
|
{
|
||||||
name = Utilities.GetDepotPath(media.GetStringFieldValue(Models.Metadata.Media.SHA1Key), outputDepot.Depth)?.Replace('\\', '/');
|
name = Utilities.GetDepotPath(sha1, outputDepot.Depth)?.Replace('\\', '/');
|
||||||
item.SetName($"{pre}{name}{post}");
|
item.SetName($"{pre}{name}{post}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (item is Rom rom)
|
else if (item is Rom rom)
|
||||||
{
|
{
|
||||||
// We can only write out if there's a SHA-1
|
// We can only write out if there's a SHA-1
|
||||||
if (!string.IsNullOrEmpty(rom.GetStringFieldValue(Models.Metadata.Rom.SHA1Key)))
|
string? sha1 = rom.GetStringFieldValue(Models.Metadata.Rom.SHA1Key);
|
||||||
|
if (!string.IsNullOrEmpty(sha1))
|
||||||
{
|
{
|
||||||
name = Utilities.GetDepotPath(rom.GetStringFieldValue(Models.Metadata.Rom.SHA1Key), outputDepot.Depth)?.Replace('\\', '/');
|
name = Utilities.GetDepotPath(sha1, outputDepot.Depth)?.Replace('\\', '/');
|
||||||
item.SetName($"{pre}{name}{post}");
|
item.SetName($"{pre}{name}{post}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -567,27 +570,30 @@ namespace SabreTools.DatFiles
|
|||||||
if (item.Item2 is Disk disk)
|
if (item.Item2 is Disk disk)
|
||||||
{
|
{
|
||||||
// We can only write out if there's a SHA-1
|
// We can only write out if there's a SHA-1
|
||||||
if (!string.IsNullOrEmpty(disk.GetStringFieldValue(Models.Metadata.Disk.SHA1Key)))
|
string? sha1 = disk.GetStringFieldValue(Models.Metadata.Disk.SHA1Key);
|
||||||
|
if (!string.IsNullOrEmpty(sha1))
|
||||||
{
|
{
|
||||||
name = Utilities.GetDepotPath(disk.GetStringFieldValue(Models.Metadata.Disk.SHA1Key), outputDepot.Depth)?.Replace('\\', '/');
|
name = Utilities.GetDepotPath(sha1, outputDepot.Depth)?.Replace('\\', '/');
|
||||||
item.Item2.SetName($"{pre}{name}{post}");
|
item.Item2.SetName($"{pre}{name}{post}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (item.Item2 is Media media)
|
else if (item.Item2 is Media media)
|
||||||
{
|
{
|
||||||
// We can only write out if there's a SHA-1
|
// We can only write out if there's a SHA-1
|
||||||
if (!string.IsNullOrEmpty(media.GetStringFieldValue(Models.Metadata.Media.SHA1Key)))
|
string? sha1 = media.GetStringFieldValue(Models.Metadata.Media.SHA1Key);
|
||||||
|
if (!string.IsNullOrEmpty(sha1))
|
||||||
{
|
{
|
||||||
name = Utilities.GetDepotPath(media.GetStringFieldValue(Models.Metadata.Media.SHA1Key), outputDepot.Depth)?.Replace('\\', '/');
|
name = Utilities.GetDepotPath(sha1, outputDepot.Depth)?.Replace('\\', '/');
|
||||||
item.Item2.SetName($"{pre}{name}{post}");
|
item.Item2.SetName($"{pre}{name}{post}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (item.Item2 is Rom rom)
|
else if (item.Item2 is Rom rom)
|
||||||
{
|
{
|
||||||
// We can only write out if there's a SHA-1
|
// We can only write out if there's a SHA-1
|
||||||
if (!string.IsNullOrEmpty(rom.GetStringFieldValue(Models.Metadata.Rom.SHA1Key)))
|
string? sha1 = rom.GetStringFieldValue(Models.Metadata.Rom.SHA1Key);
|
||||||
|
if (!string.IsNullOrEmpty(sha1))
|
||||||
{
|
{
|
||||||
name = Utilities.GetDepotPath(rom.GetStringFieldValue(Models.Metadata.Rom.SHA1Key), outputDepot.Depth)?.Replace('\\', '/');
|
name = Utilities.GetDepotPath(sha1, outputDepot.Depth)?.Replace('\\', '/');
|
||||||
item.Item2.SetName($"{pre}{name}{post}");
|
item.Item2.SetName($"{pre}{name}{post}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -446,7 +446,7 @@ namespace SabreTools.FileTypes.Archives
|
|||||||
baseFile = GetInfo(inputStream, keepReadOpen: true);
|
baseFile = GetInfo(inputStream, keepReadOpen: true);
|
||||||
|
|
||||||
// Get the output file name
|
// Get the output file name
|
||||||
string outfile = Path.Combine(outDir, Utilities.GetDepotPath(ByteArrayExtensions.ByteArrayToString(baseFile.SHA1), Depth) ?? string.Empty);
|
string outfile = Path.Combine(outDir, Utilities.GetDepotPath(baseFile.SHA1, Depth) ?? string.Empty);
|
||||||
|
|
||||||
// Check to see if the folder needs to be created
|
// Check to see if the folder needs to be created
|
||||||
if (!Directory.Exists(Path.GetDirectoryName(outfile)))
|
if (!Directory.Exists(Path.GetDirectoryName(outfile)))
|
||||||
|
|||||||
@@ -334,7 +334,7 @@ namespace SabreTools.FileTypes.Archives
|
|||||||
baseFile = GetInfo(inputStream, keepReadOpen: true);
|
baseFile = GetInfo(inputStream, keepReadOpen: true);
|
||||||
|
|
||||||
// Get the output file name
|
// Get the output file name
|
||||||
string outfile = Path.Combine(outDir, Utilities.GetDepotPath(ByteArrayExtensions.ByteArrayToString(baseFile.SHA1), Depth)!);
|
string outfile = Path.Combine(outDir, Utilities.GetDepotPath(baseFile.SHA1, Depth)!);
|
||||||
outfile = outfile.Replace(".gz", ".xz");
|
outfile = outfile.Replace(".gz", ".xz");
|
||||||
|
|
||||||
// Check to see if the folder needs to be created
|
// Check to see if the folder needs to be created
|
||||||
|
|||||||
Reference in New Issue
Block a user