[RombaSharp] Create copy flag

This commit is contained in:
Matt Nadareski
2016-10-12 15:40:06 -07:00
parent ff769ba689
commit b9e0f2caf9
3 changed files with 33 additions and 8 deletions

View File

@@ -116,8 +116,9 @@ namespace SabreTools
/// <summary> /// <summary>
/// Wrap building all files from a set of DATs /// Wrap building all files from a set of DATs
/// </summary> /// </summary>
/// <param name="inputs"></param> /// <param name="inputs">List of input DATs to rebuild from</param>
private static void InitBuild(List<string> inputs) /// <param name="copy">True if files should be copied to output, false for rebuild</param>
private static void InitBuild(List<string> inputs, bool copy)
{ {
// Verify the filenames // Verify the filenames
Dictionary<string, string> foundDats = GetValidDats(inputs); Dictionary<string, string> foundDats = GetValidDats(inputs);
@@ -165,8 +166,24 @@ namespace SabreTools
if (_depots[depot].Item2) if (_depots[depot].Item2)
{ {
if (File.Exists(Path.Combine(depot, filename))) if (File.Exists(Path.Combine(depot, filename)))
{
if (copy)
{
if (!Directory.Exists(Path.Combine(outputFolder, Path.GetDirectoryName(filename))))
{
Directory.CreateDirectory(Path.Combine(outputFolder, Path.GetDirectoryName(filename)));
}
try
{
File.Copy(Path.Combine(depot, filename), Path.Combine(outputFolder, filename), true);
}
catch { }
}
else
{ {
ArchiveTools.ExtractArchive(Path.Combine(depot, filename), _tmpdir, asl, _logger); ArchiveTools.ExtractArchive(Path.Combine(depot, filename), _tmpdir, asl, _logger);
}
continue; continue;
} }
} }
@@ -175,11 +192,14 @@ namespace SabreTools
} }
// Now that we have extracted everything, we rebuild to the output folder // Now that we have extracted everything, we rebuild to the output folder
if (!copy)
{
List<string> temp = new List<string>(); List<string> temp = new List<string>();
temp.Add(_tmpdir); temp.Add(_tmpdir);
SimpleSort ss = new SimpleSort(datFile, temp, outputFolder, "", false, false, false, true, false, false, asl, false, _logger); SimpleSort ss = new SimpleSort(datFile, temp, outputFolder, "", false, false, false, true, false, false, asl, false, _logger);
ss.StartProcessing(); ss.StartProcessing();
} }
}
dbc.Dispose(); dbc.Dispose();
} }

View File

@@ -71,6 +71,7 @@ namespace SabreTools
bool help = false, bool help = false,
archive = false, archive = false,
build = false, build = false,
copy = false,
dbstats = false, dbstats = false,
diffdat = false, diffdat = false,
dir2dat = false, dir2dat = false,
@@ -104,6 +105,9 @@ namespace SabreTools
case "build": case "build":
build = true; build = true;
break; break;
case "-copy":
copy = true;
break;
case "dbstats": case "dbstats":
dbstats = true; dbstats = true;
break; break;
@@ -201,7 +205,7 @@ namespace SabreTools
// For each specified DAT file it creates the torrentzip files // For each specified DAT file it creates the torrentzip files
else if (build) else if (build)
{ {
InitBuild(inputs); InitBuild(inputs, copy);
} }
// Prints db stats // Prints db stats

View File

@@ -83,6 +83,7 @@ namespace SabreTools.Helper
helptext.Add(" archive Adds ROM files from the specified directories to depot"); helptext.Add(" archive Adds ROM files from the specified directories to depot");
helptext.Add(" -only-needed Only archive ROM files in database"); helptext.Add(" -only-needed Only archive ROM files in database");
helptext.Add(" build For each specified DAT file it creates TZip files"); helptext.Add(" build For each specified DAT file it creates TZip files");
helptext.Add(" -copy Copy files instead of rebuilding");
helptext.Add(" dbstats Prints db stats"); helptext.Add(" dbstats Prints db stats");
helptext.Add(" diffdat Creates a DAT file for entries found in the new DAT"); helptext.Add(" diffdat Creates a DAT file for entries found in the new DAT");
helptext.Add(" -new= DAT to compare to"); helptext.Add(" -new= DAT to compare to");