diff --git a/SabreTools.Helper/Objects/SimpleSort.cs b/SabreTools.Helper/Objects/SimpleSort.cs
index 02cc8980..aaa0ada6 100644
--- a/SabreTools.Helper/Objects/SimpleSort.cs
+++ b/SabreTools.Helper/Objects/SimpleSort.cs
@@ -921,158 +921,5 @@ namespace SabreTools.Helper
return success;
}
-
- ///
- /// Process inputs and convert to TorrentZip or TorrentGZ, optionally converting to Romba
- ///
- /// True if processing was a success, false otherwise
- public bool Convert()
- {
- bool success = true;
-
- // First, check that the output directory exists
- if (!Directory.Exists(_outDir))
- {
- Directory.CreateDirectory(_outDir);
- _outDir = Path.GetFullPath(_outDir);
- }
-
- // Then create or clean the temp directory
- if (!Directory.Exists(_tempDir))
- {
- Directory.CreateDirectory(_tempDir);
- }
- else
- {
- FileTools.CleanDirectory(_tempDir);
- }
-
- // Now process all of the inputs
- foreach (string input in _inputs)
- {
- _logger.User("Examining file " + input);
-
- // Get if the file should be scanned internally and externally
- bool shouldExternalProcess, shouldInternalProcess;
- ArchiveTools.GetInternalExternalProcess(input, _archiveScanLevel, _logger, out shouldExternalProcess, out shouldInternalProcess);
-
- // Do an external scan of the file, if necessary
- if (shouldExternalProcess)
- {
- // If a DAT is defined, we want to make sure that this file is not in there
- Rom rom = FileTools.GetFileInfo(input, _logger);
- if (_datdata != null && _datdata.Files.Count > 0)
- {
- if (rom.HasDuplicates(_datdata, _logger))
- {
- _logger.User("File '" + input + "' existed in the DAT, skipping...");
- continue;
- }
- }
-
- _logger.User("Processing file " + input);
-
- if (_tgz)
- {
- success &= ArchiveTools.WriteTorrentGZ(input, _outDir, _romba, _logger);
- }
- else
- {
- success &= ArchiveTools.WriteToArchive(input, _outDir, rom, _logger);
- }
- }
-
- // Process the file as an archive, if necessary
- if (shouldInternalProcess)
- {
- // Now, if the file is a supported archive type, also run on all files within
- bool encounteredErrors = ArchiveTools.ExtractArchive(input, _tempDir, _archiveScanLevel, _logger);
-
- // If no errors were encountered, we loop through the temp directory
- if (!encounteredErrors)
- {
- _logger.Verbose("Archive found! Successfully extracted");
- foreach (string file in Directory.EnumerateFiles(_tempDir, "*", SearchOption.AllDirectories))
- {
- // If a DAT is defined, we want to make sure that this file is not in there
- Rom rom = FileTools.GetFileInfo(file, _logger);
- if (_datdata != null && _datdata.Files.Count > 0)
- {
- if (rom.HasDuplicates(_datdata, _logger))
- {
- _logger.User("File '" + file + "' existed in the DAT, skipping...");
- continue;
- }
- }
-
- _logger.User("Processing file " + input);
-
- if (_tgz)
- {
- success &= ArchiveTools.WriteTorrentGZ(file, _outDir, _romba, _logger);
- }
- else
- {
- success &= ArchiveTools.WriteToArchive(file, _outDir, rom, _logger);
- }
- }
-
- FileTools.CleanDirectory(_tempDir);
- }
- }
-
- // Delete the source file if we're supposed to
- if (_delete)
- {
- try
- {
- _logger.User("Attempting to delete " + input);
- File.Delete(input);
- }
- catch (Exception ex)
- {
- _logger.Error(ex.ToString());
- success &= false;
- }
- }
- }
-
- // Now one final delete of the temp directory
- while (Directory.Exists(_tempDir))
- {
- try
- {
- Directory.Delete(_tempDir, true);
- }
- catch
- {
- continue;
- }
- }
-
- // If we're in romba mode and the size file doesn't exist, create it
- if (_romba && !File.Exists(Path.Combine(_outDir, ".romba_size")))
- {
- // Get the size of all of the files in the output folder
- long size = 0;
- foreach (string file in Directory.EnumerateFiles(_outDir, "*", SearchOption.AllDirectories))
- {
- FileInfo tempinfo = new FileInfo(file);
- size += tempinfo.Length;
- }
-
- // Write out the value to each of the romba depot files
- StreamWriter tw = new StreamWriter(File.Open(Path.Combine(_outDir, ".romba_size"), FileMode.Create, FileAccess.Write));
- StreamWriter twb = new StreamWriter(File.Open(Path.Combine(_outDir, ".romba_size.backup"), FileMode.Create, FileAccess.Write));
-
- tw.Write(size);
- twb.Write(size);
-
- tw.Dispose();
- twb.Dispose();
- }
-
- return success;
- }
}
}
diff --git a/SabreTools.Helper/Tools/FileTools.cs b/SabreTools.Helper/Tools/FileTools.cs
index 007677ae..176eba8b 100644
--- a/SabreTools.Helper/Tools/FileTools.cs
+++ b/SabreTools.Helper/Tools/FileTools.cs
@@ -4,7 +4,6 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
-using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Xml;
using System.Xml.Schema;
@@ -456,6 +455,169 @@ namespace SabreTools.Helper
#region Rebuilding and Verifying
+ ///
+ /// Process inputs and convert to TorrentZip or TorrentGZ, optionally converting to Romba format
+ ///
+ /// DatFile to use as a filter in conversion, null otherwise
+ /// List of inputs to convert over to TorrentZip or TorrentGZ
+ /// Output folder to rebuild to, blank is the current directory
+ /// Temporary directory to use in file extraction
+ /// True if files should be output in TorrentGZ format, false for TorrentZip
+ /// True if TorrentGZ files should be output in romba depot format, false otherwise
+ /// True if input files should be deleted, false otherwise
+ /// ArchiveScanLevel representing how files should be treated
+ /// Logger object for file and console output
+ /// True if processing was a success, false otherwise
+ public static bool ConvertFiles(DatFile datFile, List inputs, string outDir, string tempDir, bool tgz,
+ bool romba, bool delete, ArchiveScanLevel archiveScanLevel, Logger logger)
+ {
+ bool success = true;
+
+ // First, check that the output directory exists
+ if (!Directory.Exists(outDir))
+ {
+ Directory.CreateDirectory(outDir);
+ outDir = Path.GetFullPath(outDir);
+ }
+
+ // Then create or clean the temp directory
+ if (!Directory.Exists(tempDir))
+ {
+ Directory.CreateDirectory(tempDir);
+ }
+ else
+ {
+ CleanDirectory(tempDir);
+ }
+
+ // Now process all of the inputs
+ foreach (string input in inputs)
+ {
+ logger.User("Examining file " + input);
+
+ // Get if the file should be scanned internally and externally
+ bool shouldExternalProcess, shouldInternalProcess;
+ ArchiveTools.GetInternalExternalProcess(input, archiveScanLevel, logger, out shouldExternalProcess, out shouldInternalProcess);
+
+ // Do an external scan of the file, if necessary
+ if (shouldExternalProcess)
+ {
+ // If a DAT is defined, we want to make sure that this file is not in there
+ Rom rom = FileTools.GetFileInfo(input, logger);
+ if (datFile != null && datFile.Files.Count > 0)
+ {
+ if (rom.HasDuplicates(datFile, logger))
+ {
+ logger.User("File '" + input + "' existed in the DAT, skipping...");
+ continue;
+ }
+ }
+
+ logger.User("Processing file " + input);
+
+ if (tgz)
+ {
+ success &= ArchiveTools.WriteTorrentGZ(input, outDir, romba, logger);
+ }
+ else
+ {
+ success &= ArchiveTools.WriteToArchive(input, outDir, rom, logger);
+ }
+ }
+
+ // Process the file as an archive, if necessary
+ if (shouldInternalProcess)
+ {
+ // Now, if the file is a supported archive type, also run on all files within
+ bool encounteredErrors = ArchiveTools.ExtractArchive(input, tempDir, archiveScanLevel, logger);
+
+ // If no errors were encountered, we loop through the temp directory
+ if (!encounteredErrors)
+ {
+ logger.Verbose("Archive found! Successfully extracted");
+ foreach (string file in Directory.EnumerateFiles(tempDir, "*", SearchOption.AllDirectories))
+ {
+ // If a DAT is defined, we want to make sure that this file is not in there
+ Rom rom = FileTools.GetFileInfo(file, logger);
+ if (datFile != null && datFile.Files.Count > 0)
+ {
+ if (rom.HasDuplicates(datFile, logger))
+ {
+ logger.User("File '" + file + "' existed in the DAT, skipping...");
+ continue;
+ }
+ }
+
+ logger.User("Processing file " + input);
+
+ if (tgz)
+ {
+ success &= ArchiveTools.WriteTorrentGZ(file, outDir, romba, logger);
+ }
+ else
+ {
+ success &= ArchiveTools.WriteToArchive(file, outDir, rom, logger);
+ }
+ }
+
+ FileTools.CleanDirectory(tempDir);
+ }
+ }
+
+ // Delete the source file if we're supposed to
+ if (delete)
+ {
+ try
+ {
+ logger.User("Attempting to delete " + input);
+ File.Delete(input);
+ }
+ catch (Exception ex)
+ {
+ logger.Error(ex.ToString());
+ success &= false;
+ }
+ }
+ }
+
+ // Now one final delete of the temp directory
+ while (Directory.Exists(tempDir))
+ {
+ try
+ {
+ Directory.Delete(tempDir, true);
+ }
+ catch
+ {
+ continue;
+ }
+ }
+
+ // If we're in romba mode and the size file doesn't exist, create it
+ if (romba && !File.Exists(Path.Combine(outDir, ".romba_size")))
+ {
+ // Get the size of all of the files in the output folder
+ long size = 0;
+ foreach (string file in Directory.EnumerateFiles(outDir, "*", SearchOption.AllDirectories))
+ {
+ FileInfo tempinfo = new FileInfo(file);
+ size += tempinfo.Length;
+ }
+
+ // Write out the value to each of the romba depot files
+ StreamWriter tw = new StreamWriter(File.Open(Path.Combine(outDir, ".romba_size"), FileMode.Create, FileAccess.Write));
+ StreamWriter twb = new StreamWriter(File.Open(Path.Combine(outDir, ".romba_size.backup"), FileMode.Create, FileAccess.Write));
+
+ tw.Write(size);
+ twb.Write(size);
+
+ tw.Dispose();
+ twb.Dispose();
+ }
+
+ return success;
+ }
+
///
/// Process the DAT and verify the output directory
///
diff --git a/SabreTools/Partials/SabreTools_Inits.cs b/SabreTools/Partials/SabreTools_Inits.cs
index 78a8e4eb..1199a28e 100644
--- a/SabreTools/Partials/SabreTools_Inits.cs
+++ b/SabreTools/Partials/SabreTools_Inits.cs
@@ -61,9 +61,7 @@ namespace SabreTools
}
_logger.User("Organizing complete in " + DateTime.Now.Subtract(start).ToString(@"hh\:mm\:ss\.fffff"));
- SimpleSort ss = new SimpleSort(datdata, newinputs, outDir, tempDir, false, false,
- false, delete, tgz, romba, asl, false, null, _logger);
- return ss.Convert();
+ return FileTools.ConvertFiles(datdata, inputs, outDir, tempDir, tgz, romba, delete, asl, _logger);
}
///
diff --git a/SabreTools/SabreTools.cs b/SabreTools/SabreTools.cs
index e3f5768d..115cb124 100644
--- a/SabreTools/SabreTools.cs
+++ b/SabreTools/SabreTools.cs
@@ -939,8 +939,7 @@ namespace SabreTools
// Convert a folder to TGZ or TorrentZip
if (convert)
{
- InitConvertFolder(datfiles, inputs, outDir, tempDir, delete, tgz, romba, sevenzip,
- gz, rar, zip);
+ InitConvertFolder(datfiles, inputs, outDir, tempDir, delete, tgz, romba, sevenzip, gz, rar, zip);
}
// Create a DAT from a directory or set of directories
diff --git a/SimpleSort/SimpleSortApp.cs b/SimpleSort/SimpleSortApp.cs
index 8241dc15..31d3228d 100644
--- a/SimpleSort/SimpleSortApp.cs
+++ b/SimpleSort/SimpleSortApp.cs
@@ -386,9 +386,7 @@ namespace SabreTools
}
logger.User("Organizing complete in " + DateTime.Now.Subtract(start).ToString(@"hh\:mm\:ss\.fffff"));
- SimpleSort ss = new SimpleSort(datdata, newinputs, outDir, tempDir, false, false,
- false, delete, tgz, romba, asl, false, null, logger);
- return ss.Convert();
+ return FileTools.ConvertFiles(datdata, inputs, outDir, tempDir, tgz, romba, delete, asl, logger);
}
///