mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[ArchiveTools] Make it easier to rebuild to TGZ
This commit is contained in:
@@ -143,7 +143,7 @@ namespace SabreTools.Helper.Dats
|
||||
logger.User("Checking hash '" + hash + "'");
|
||||
|
||||
// Get the extension path for the hash
|
||||
string subpath = Path.Combine(hash.Substring(0, 2), hash.Substring(2, 2), hash.Substring(4, 2), hash.Substring(6, 2), hash + ".gz");
|
||||
string subpath = Style.GetRombaPath(hash);
|
||||
|
||||
// Find the first depot that includes the hash
|
||||
string foundpath = null;
|
||||
|
||||
@@ -1330,7 +1330,18 @@ namespace SabreTools.Helper.Tools
|
||||
Rom rom = FileTools.GetFileInfo(input, logger);
|
||||
|
||||
// Get the output file name
|
||||
string outfile = Path.Combine(outDir, rom.SHA1 + ".gz");
|
||||
string outfile = null;
|
||||
|
||||
// If we have a romba output, add the romba path
|
||||
if (romba)
|
||||
{
|
||||
outfile = Path.Combine(outDir, Style.GetRombaPath(rom.SHA1));
|
||||
}
|
||||
// Otherwise, we're just rebuilding to the main directory
|
||||
else
|
||||
{
|
||||
outfile = Path.Combine(outDir, rom.SHA1 + ".gz");
|
||||
}
|
||||
|
||||
// If the output file exists, don't try to write again
|
||||
if (!File.Exists(outfile))
|
||||
@@ -1373,12 +1384,6 @@ namespace SabreTools.Helper.Tools
|
||||
inputStream.Dispose();
|
||||
}
|
||||
|
||||
// If we're in romba mode, create the subfolder and move the file
|
||||
if (romba)
|
||||
{
|
||||
FileTools.MoveToRombaFolder(rom, outDir, outfile, logger);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -417,18 +417,6 @@ namespace SabreTools.Helper.Tools
|
||||
return outputs;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the romba path for a file based on the rom's SHA-1
|
||||
/// </summary>
|
||||
/// <param name="rom">Rom to get the sha1 from</param>
|
||||
/// <param name="baseOutDir">Base output folder</param>
|
||||
/// <returns>Formatted path string to use</returns>
|
||||
public static string GetRombaPath(Rom rom, string baseOutDir)
|
||||
{
|
||||
string subfolder = Path.Combine(rom.SHA1.Substring(0, 2), rom.SHA1.Substring(2, 2), rom.SHA1.Substring(4, 2), rom.SHA1.Substring(6, 2));
|
||||
return Path.Combine(baseOutDir, subfolder);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the XmlTextReader associated with a file, if possible
|
||||
/// </summary>
|
||||
@@ -458,32 +446,6 @@ namespace SabreTools.Helper.Tools
|
||||
return xtr;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Move a file to a named, Romba-style subdirectory
|
||||
/// </summary>
|
||||
/// <param name="rom">Rom to get the sha1 from</param>
|
||||
/// <param name="baseOutDir">Base output folder</param>
|
||||
/// <param name="filename">Name of the file to be moved</param>
|
||||
/// <param name="logger">Logger object for file and console output</param>
|
||||
public static void MoveToRombaFolder(Rom rom, string baseOutDir, string filename, Logger logger)
|
||||
{
|
||||
string outDir = GetRombaPath(rom, baseOutDir);
|
||||
if (!Directory.Exists(outDir))
|
||||
{
|
||||
Directory.CreateDirectory(outDir);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
File.Move(filename, Path.Combine(outDir, Path.GetFileName(filename)));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Warning(ex.ToString());
|
||||
File.Delete(filename);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Detect and replace header(s) to the given file
|
||||
/// </summary>
|
||||
|
||||
@@ -387,6 +387,22 @@ namespace SabreTools.Helper.Tools
|
||||
.ToArray());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a proper romba sub path
|
||||
/// </summary>
|
||||
/// <param name="hash">SHA-1 hash to get the path for</param>
|
||||
/// <returns>Subfolder path for the given hash</returns>
|
||||
public static string GetRombaPath(string hash)
|
||||
{
|
||||
// If the hash isn't the right size, then we return null
|
||||
if (hash.Length != Constants.SHA1Length)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return Path.Combine(hash.Substring(0, 2), hash.Substring(2, 2), hash.Substring(4, 2), hash.Substring(6, 2), hash + ".gz");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get if a string contains Unicode characters
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user