mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[SimpleSort, FileTools] Add undocumented TZIP WIP
This commit is contained in:
@@ -403,6 +403,86 @@ namespace SabreTools.Helper
|
||||
return WriteToArchive(tempfile, outputDirectory, destEntry);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reorder all of the files in the archive based on lowercase filename
|
||||
/// </summary>
|
||||
/// <param name="inputArchive">Source archive name</param>
|
||||
/// <param name="logger">Logger object for file and console output</param>
|
||||
/// <returns>True if the operation succeeded, false otherwise</returns>
|
||||
public static bool TorrentZipArchive(string inputArchive, Logger logger)
|
||||
{
|
||||
bool success = false;
|
||||
|
||||
// If the input file doesn't exist, return
|
||||
if (!File.Exists(inputArchive))
|
||||
{
|
||||
return success;
|
||||
}
|
||||
|
||||
// Make sure the file is a zip file to begin with
|
||||
if (GetCurrentArchiveType(inputArchive, logger) != ArchiveType.Zip)
|
||||
{
|
||||
return success;
|
||||
}
|
||||
|
||||
ZipArchive outarchive = null;
|
||||
try
|
||||
{
|
||||
// If the archive doesn't exist, create it
|
||||
if (!File.Exists(inputArchive))
|
||||
{
|
||||
outarchive = ZipFile.Open(inputArchive, ZipArchiveMode.Create);
|
||||
outarchive.Dispose();
|
||||
}
|
||||
|
||||
// Open the archive for sorting
|
||||
Dictionary<string, string> entries = new Dictionary<string, string>();
|
||||
using (outarchive = ZipFile.Open(inputArchive, ZipArchiveMode.Update))
|
||||
{
|
||||
// Get and sort the entries
|
||||
foreach (ZipArchiveEntry entry in outarchive.Entries)
|
||||
{
|
||||
entries.Add(entry.Name.ToLowerInvariant(), entry.Name);
|
||||
}
|
||||
}
|
||||
|
||||
// Now write out the entries by name
|
||||
List<string> keys = entries.Keys.ToList();
|
||||
keys.Sort(Style.CompareNumeric);
|
||||
|
||||
foreach (string key in keys)
|
||||
{
|
||||
Rom temp = new Rom
|
||||
{
|
||||
Machine = new Machine
|
||||
{
|
||||
Name = Path.GetFileNameWithoutExtension(inputArchive) + ".new",
|
||||
},
|
||||
Name = entries[key],
|
||||
Date = "12/24/1996 11:32 PM",
|
||||
};
|
||||
CopyFileBetweenArchives(inputArchive, Path.GetDirectoryName(inputArchive), entries[key], temp, logger);
|
||||
}
|
||||
|
||||
string newfile = Path.Combine(Path.GetDirectoryName(inputArchive), Path.GetFileNameWithoutExtension(inputArchive) + ".new.zip");
|
||||
File.Delete(inputArchive);
|
||||
File.Move(newfile, inputArchive);
|
||||
|
||||
success = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex);
|
||||
success = false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
outarchive?.Dispose();
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region File Information
|
||||
|
||||
@@ -50,6 +50,7 @@ namespace SabreTools
|
||||
simpleSort = true,
|
||||
tgz = false,
|
||||
toFolder = false,
|
||||
tzip = false,
|
||||
updateDat = false,
|
||||
verify = false;
|
||||
int sevenzip = 0,
|
||||
@@ -95,6 +96,10 @@ namespace SabreTools
|
||||
case "--tgz":
|
||||
tgz = true;
|
||||
break;
|
||||
case "-tzip":
|
||||
case "--tzip":
|
||||
tzip = true;
|
||||
break;
|
||||
case "-ud":
|
||||
case "--updated-dat":
|
||||
updateDat = true;
|
||||
@@ -182,7 +187,7 @@ namespace SabreTools
|
||||
}
|
||||
|
||||
// If a switch that requires a filename is set and no file is, show the help screen
|
||||
if (inputs.Count == 0 && ((simpleSort && !verify) || convert))
|
||||
if (inputs.Count == 0 && ((simpleSort && !verify) || convert || tzip))
|
||||
{
|
||||
logger.Error("This feature requires at least one input");
|
||||
Build.Help();
|
||||
@@ -190,8 +195,14 @@ namespace SabreTools
|
||||
return;
|
||||
}
|
||||
|
||||
// TorrentZip a folder
|
||||
if (tzip)
|
||||
{
|
||||
InitTorrentZip(inputs, outdir, tempdir, logger);
|
||||
}
|
||||
|
||||
// If we are converting the folder to TGZ
|
||||
if (convert)
|
||||
else if (convert)
|
||||
{
|
||||
InitConvertFolderTGZ(inputs, outdir, tempdir, delete, romba, sevenzip, gz, rar, zip, logger);
|
||||
}
|
||||
@@ -223,6 +234,24 @@ namespace SabreTools
|
||||
return;
|
||||
}
|
||||
|
||||
private static void InitTorrentZip(List<string> inputs, string outdir, string tempdir, Logger logger)
|
||||
{
|
||||
foreach (string input in inputs)
|
||||
{
|
||||
if (File.Exists(input))
|
||||
{
|
||||
FileTools.TorrentZipArchive(input, logger);
|
||||
}
|
||||
else if (Directory.Exists(input))
|
||||
{
|
||||
foreach (string file in Directory.EnumerateFiles(input, "*", SearchOption.AllDirectories))
|
||||
{
|
||||
FileTools.TorrentZipArchive(file, logger);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wrap sorting files using an input DAT
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user