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);
|
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
|
#endregion
|
||||||
|
|
||||||
#region File Information
|
#region File Information
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ namespace SabreTools
|
|||||||
simpleSort = true,
|
simpleSort = true,
|
||||||
tgz = false,
|
tgz = false,
|
||||||
toFolder = false,
|
toFolder = false,
|
||||||
|
tzip = false,
|
||||||
updateDat = false,
|
updateDat = false,
|
||||||
verify = false;
|
verify = false;
|
||||||
int sevenzip = 0,
|
int sevenzip = 0,
|
||||||
@@ -95,6 +96,10 @@ namespace SabreTools
|
|||||||
case "--tgz":
|
case "--tgz":
|
||||||
tgz = true;
|
tgz = true;
|
||||||
break;
|
break;
|
||||||
|
case "-tzip":
|
||||||
|
case "--tzip":
|
||||||
|
tzip = true;
|
||||||
|
break;
|
||||||
case "-ud":
|
case "-ud":
|
||||||
case "--updated-dat":
|
case "--updated-dat":
|
||||||
updateDat = true;
|
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 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");
|
logger.Error("This feature requires at least one input");
|
||||||
Build.Help();
|
Build.Help();
|
||||||
@@ -190,8 +195,14 @@ namespace SabreTools
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TorrentZip a folder
|
||||||
|
if (tzip)
|
||||||
|
{
|
||||||
|
InitTorrentZip(inputs, outdir, tempdir, logger);
|
||||||
|
}
|
||||||
|
|
||||||
// If we are converting the folder to TGZ
|
// If we are converting the folder to TGZ
|
||||||
if (convert)
|
else if (convert)
|
||||||
{
|
{
|
||||||
InitConvertFolderTGZ(inputs, outdir, tempdir, delete, romba, sevenzip, gz, rar, zip, logger);
|
InitConvertFolderTGZ(inputs, outdir, tempdir, delete, romba, sevenzip, gz, rar, zip, logger);
|
||||||
}
|
}
|
||||||
@@ -223,6 +234,24 @@ namespace SabreTools
|
|||||||
return;
|
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>
|
/// <summary>
|
||||||
/// Wrap sorting files using an input DAT
|
/// Wrap sorting files using an input DAT
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user