mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[SabreTools] Updates to splitting and output path
This commit is contained in:
@@ -255,7 +255,7 @@ namespace RombaSharp
|
|||||||
datdata.PopulateFromDir(input, Hash.DeepHashes /* omitFromScan */, true /* bare */, false /* archivesAsFiles */,
|
datdata.PopulateFromDir(input, Hash.DeepHashes /* omitFromScan */, true /* bare */, false /* archivesAsFiles */,
|
||||||
SkipFileType.None, false /* addBlanks */, false /* addDate */, _tmpdir /* tempDir */, false /* copyFiles */,
|
SkipFileType.None, false /* addBlanks */, false /* addDate */, _tmpdir /* tempDir */, false /* copyFiles */,
|
||||||
null /* headerToCheckAgainst */, true /* chdsAsFiles */);
|
null /* headerToCheckAgainst */, true /* chdsAsFiles */);
|
||||||
datdata.WriteToFile("");
|
datdata.WriteToFile();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1625,9 +1625,6 @@ namespace SabreTools.Library.DatFiles
|
|||||||
public void DetermineUpdateType(List<string> inputPaths, List<string> basePaths, string outDir, bool merge, UpdateMode updateMode, bool inplace, bool skip,
|
public void DetermineUpdateType(List<string> inputPaths, List<string> basePaths, string outDir, bool merge, UpdateMode updateMode, bool inplace, bool skip,
|
||||||
bool bare, bool clean, bool remUnicode, bool descAsName, Filter filter, SplitType splitType, bool trim, bool single, string root)
|
bool bare, bool clean, bool remUnicode, bool descAsName, Filter filter, SplitType splitType, bool trim, bool single, string root)
|
||||||
{
|
{
|
||||||
// First, we want to ensure the output directory
|
|
||||||
outDir = Utilities.EnsureOutputDirectory(outDir);
|
|
||||||
|
|
||||||
// If we're in merging or diffing mode, use the full list of inputs
|
// If we're in merging or diffing mode, use the full list of inputs
|
||||||
if (merge || (updateMode != UpdateMode.None
|
if (merge || (updateMode != UpdateMode.None
|
||||||
&& (updateMode & UpdateMode.DiffAgainst) == 0)
|
&& (updateMode & UpdateMode.DiffAgainst) == 0)
|
||||||
@@ -1833,19 +1830,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Determine the output path for the DAT
|
// Determine the output path for the DAT
|
||||||
string interOutDir = Utilities.EnsureOutputDirectory(outDir);
|
string interOutDir = Utilities.GetOutputPath(outDir, path, inplace, splitpath: true);
|
||||||
if (inplace)
|
|
||||||
{
|
|
||||||
interOutDir = Path.GetDirectoryName(splitpath[1]);
|
|
||||||
}
|
|
||||||
else if (splitpath[0].Length == splitpath[1].Length)
|
|
||||||
{
|
|
||||||
interOutDir = Path.GetDirectoryName(Path.Combine(interOutDir, Path.GetFileName(splitpath[0])));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
interOutDir = Path.GetDirectoryName(Path.Combine(interOutDir, splitpath[0].Remove(0, splitpath[1].Length + 1)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Once we're done, try writing out
|
// Once we're done, try writing out
|
||||||
intDat.WriteToFile(interOutDir);
|
intDat.WriteToFile(interOutDir);
|
||||||
@@ -1923,19 +1908,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Determine the output path for the DAT
|
// Determine the output path for the DAT
|
||||||
string interOutDir = Utilities.EnsureOutputDirectory(outDir);
|
string interOutDir = Utilities.GetOutputPath(outDir, path, inplace, splitpath: true);
|
||||||
if (inplace)
|
|
||||||
{
|
|
||||||
interOutDir = Path.GetDirectoryName(splitpath[1]);
|
|
||||||
}
|
|
||||||
else if (splitpath[0].Length == splitpath[1].Length)
|
|
||||||
{
|
|
||||||
interOutDir = Path.GetDirectoryName(Path.Combine(interOutDir, Path.GetFileName(splitpath[0])));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
interOutDir = Path.GetDirectoryName(Path.Combine(interOutDir, splitpath[0].Remove(0, splitpath[1].Length + 1)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Once we're done, try writing out
|
// Once we're done, try writing out
|
||||||
intDat.WriteToFile(interOutDir);
|
intDat.WriteToFile(interOutDir);
|
||||||
@@ -2024,19 +1997,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
Parallel.For((skip ? 1 : 0), inputs.Count, Globals.ParallelOptions, j =>
|
Parallel.For((skip ? 1 : 0), inputs.Count, Globals.ParallelOptions, j =>
|
||||||
{
|
{
|
||||||
// If we have an output directory set, replace the path
|
string path = Utilities.GetOutputPath(outDir, inputs[j], inplace, splitpath: true);
|
||||||
string path = "";
|
|
||||||
if (inplace)
|
|
||||||
{
|
|
||||||
path = Path.GetDirectoryName(inputs[j].Split('¬')[0]);
|
|
||||||
}
|
|
||||||
else if (outDir != Environment.CurrentDirectory)
|
|
||||||
{
|
|
||||||
string[] split = inputs[j].Split('¬');
|
|
||||||
path = outDir + (split[0] == split[1]
|
|
||||||
? Path.GetFileName(split[0])
|
|
||||||
: (Path.GetDirectoryName(split[0]).Remove(0, split[1].Length))); ;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try to output the file
|
// Try to output the file
|
||||||
outDats[j].WriteToFile(path);
|
outDats[j].WriteToFile(path);
|
||||||
@@ -2195,12 +2156,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
{
|
{
|
||||||
Parallel.For(0, inputs.Count, Globals.ParallelOptions, j =>
|
Parallel.For(0, inputs.Count, Globals.ParallelOptions, j =>
|
||||||
{
|
{
|
||||||
// If we have an output directory set, replace the path
|
string path = Utilities.GetOutputPath(outDir, inputs[j], false /* inplace */, splitpath: true);
|
||||||
string[] split = inputs[j].Split('¬');
|
|
||||||
string path = Path.Combine(outDir,
|
|
||||||
(split[0] == split[1]
|
|
||||||
? Path.GetFileName(split[0])
|
|
||||||
: (Path.GetDirectoryName(split[0]).Remove(0, split[1].Length))));
|
|
||||||
|
|
||||||
// Try to output the file
|
// Try to output the file
|
||||||
outDats[j].WriteToFile(path);
|
outDats[j].WriteToFile(path);
|
||||||
@@ -2274,60 +2230,53 @@ namespace SabreTools.Library.DatFiles
|
|||||||
for (int i = 0; i < inputFileNames.Count; i++)
|
for (int i = 0; i < inputFileNames.Count; i++)
|
||||||
{
|
{
|
||||||
// Get the input file name
|
// Get the input file name
|
||||||
string inputFileName = inputFileNames[i];
|
string inputPath = inputFileNames[i];
|
||||||
|
|
||||||
// Clean the input string
|
// Clean the input string
|
||||||
if (inputFileName != "")
|
if (inputPath != "")
|
||||||
{
|
{
|
||||||
inputFileName = Path.GetFullPath(inputFileName);
|
inputPath = Path.GetFullPath(inputPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (File.Exists(inputFileName))
|
if (File.Exists(inputPath))
|
||||||
{
|
{
|
||||||
// If inplace is set, override the output dir
|
|
||||||
string realOutDir = outDir;
|
|
||||||
if (inplace)
|
|
||||||
{
|
|
||||||
realOutDir = Path.GetDirectoryName(inputFileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
DatFile innerDatdata = new DatFile(this);
|
DatFile innerDatdata = new DatFile(this);
|
||||||
Globals.Logger.User("Processing '{0}'", Path.GetFileName(inputFileName));
|
Globals.Logger.User("Processing '{0}'", Path.GetFileName(inputPath));
|
||||||
innerDatdata.Parse(inputFileName, 0, 0, splitType, keep: true, clean: clean, remUnicode: remUnicode, descAsName: descAsName,
|
innerDatdata.Parse(inputPath, 0, 0, splitType, keep: true, clean: clean, remUnicode: remUnicode, descAsName: descAsName,
|
||||||
keepext: ((innerDatdata.DatFormat & DatFormat.TSV) != 0 || (innerDatdata.DatFormat & DatFormat.CSV) != 0));
|
keepext: ((innerDatdata.DatFormat & DatFormat.TSV) != 0 || (innerDatdata.DatFormat & DatFormat.CSV) != 0));
|
||||||
innerDatdata.Filter(filter, trim, single, root);
|
innerDatdata.Filter(filter, trim, single, root);
|
||||||
|
|
||||||
// Try to output the file
|
// Get the correct output path
|
||||||
innerDatdata.WriteToFile((realOutDir == Environment.CurrentDirectory ? Path.GetDirectoryName(inputFileName) : realOutDir), overwrite: (realOutDir != Environment.CurrentDirectory));
|
string realOutDir = Utilities.GetOutputPath(outDir, inputPath, inplace, splitpath: false);
|
||||||
|
|
||||||
|
// Try to output the file, overwriting only if it's not in the current directory
|
||||||
|
// TODO: Figure out if overwriting should always happen of if there should be a user flag
|
||||||
|
innerDatdata.WriteToFile(realOutDir, overwrite: (realOutDir != Environment.CurrentDirectory));
|
||||||
}
|
}
|
||||||
else if (Directory.Exists(inputFileName))
|
else if (Directory.Exists(inputPath))
|
||||||
{
|
{
|
||||||
inputFileName = Path.GetFullPath(inputFileName) + Path.DirectorySeparatorChar;
|
inputPath = Path.GetFullPath(inputPath) + Path.DirectorySeparatorChar;
|
||||||
|
|
||||||
// If inplace is set, override the output dir
|
List<string> subFiles = Directory.EnumerateFiles(inputPath, "*", SearchOption.AllDirectories).ToList();
|
||||||
string realOutDir = outDir;
|
|
||||||
if (inplace)
|
|
||||||
{
|
|
||||||
realOutDir = Path.GetDirectoryName(inputFileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<string> subFiles = Directory.EnumerateFiles(inputFileName, "*", SearchOption.AllDirectories).ToList();
|
|
||||||
Parallel.ForEach(subFiles, Globals.ParallelOptions, file =>
|
Parallel.ForEach(subFiles, Globals.ParallelOptions, file =>
|
||||||
{
|
{
|
||||||
Globals.Logger.User("Processing '{0}'", Path.GetFullPath(file).Remove(0, inputFileName.Length));
|
Globals.Logger.User("Processing '{0}'", Path.GetFullPath(file).Remove(0, inputPath.Length));
|
||||||
DatFile innerDatdata = new DatFile(this);
|
DatFile innerDatdata = new DatFile(this);
|
||||||
innerDatdata.Parse(file, 0, 0, splitType, keep: true, clean: clean, remUnicode: remUnicode, descAsName: descAsName,
|
innerDatdata.Parse(file, 0, 0, splitType, keep: true, clean: clean, remUnicode: remUnicode, descAsName: descAsName,
|
||||||
keepext: ((innerDatdata.DatFormat & DatFormat.TSV) != 0 || (innerDatdata.DatFormat & DatFormat.CSV) != 0));
|
keepext: ((innerDatdata.DatFormat & DatFormat.TSV) != 0 || (innerDatdata.DatFormat & DatFormat.CSV) != 0));
|
||||||
innerDatdata.Filter(filter, trim, single, root);
|
innerDatdata.Filter(filter, trim, single, root);
|
||||||
|
|
||||||
// Try to output the file
|
// Get the correct output path
|
||||||
innerDatdata.WriteToFile((realOutDir == Environment.CurrentDirectory ? Path.GetDirectoryName(file) : realOutDir + Path.GetDirectoryName(file).Remove(0, inputFileName.Length - 1)),
|
string realOutDir = Utilities.GetOutputPath(outDir, file, inplace, splitpath: false);
|
||||||
overwrite: (realOutDir != Environment.CurrentDirectory));
|
|
||||||
|
// Try to output the file, overwriting only if it's not in the current directory
|
||||||
|
// TODO: Figure out if overwriting should always happen of if there should be a user flag
|
||||||
|
innerDatdata.WriteToFile(realOutDir, overwrite: (realOutDir != Environment.CurrentDirectory));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Globals.Logger.Error("I'm sorry but '{0}' doesn't exist!", inputFileName);
|
Globals.Logger.Error("I'm sorry but '{0}' doesn't exist!", inputPath);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4692,7 +4641,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
FileName = "fixDAT_" + FileName;
|
FileName = "fixDAT_" + FileName;
|
||||||
Name = "fixDAT_" + Name;
|
Name = "fixDAT_" + Name;
|
||||||
Description = "fixDAT_" + Description;
|
Description = "fixDAT_" + Description;
|
||||||
WriteToFile(null);
|
WriteToFile();
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
@@ -4768,7 +4717,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Now output the fixdat to the main folder
|
// Now output the fixdat to the main folder
|
||||||
success &= matched.WriteToFile("", stats: true);
|
success &= matched.WriteToFile(stats: true);
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
@@ -4781,11 +4730,11 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// Split a DAT by input extensions
|
/// Split a DAT by input extensions
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="outDir">Name of the directory to write the DATs out to</param>
|
/// <param name="outDir">Name of the directory to write the DATs out to</param>
|
||||||
/// <param name="basepath">Parent path for replacement</param>
|
/// <param name="inplace">True if files should be written to the source folders, false otherwise</param>
|
||||||
/// <param name="extA">List of extensions to split on (first DAT)</param>
|
/// <param name="extA">List of extensions to split on (first DAT)</param>
|
||||||
/// <param name="extB">List of extensions to split on (second DAT)</param>
|
/// <param name="extB">List of extensions to split on (second DAT)</param>
|
||||||
/// <returns>True if split succeeded, false otherwise</returns>
|
/// <returns>True if split succeeded, false otherwise</returns>
|
||||||
public bool SplitByExtension(string outDir, string basepath, List<string> extA, List<string> extB)
|
public bool SplitByExtension(string outDir, bool inplace, List<string> extA, List<string> extB)
|
||||||
{
|
{
|
||||||
// Make sure all of the extensions have a dot at the beginning
|
// Make sure all of the extensions have a dot at the beginning
|
||||||
List<string> newExtA = new List<string>();
|
List<string> newExtA = new List<string>();
|
||||||
@@ -4864,14 +4813,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Get the output directory
|
// Get the output directory
|
||||||
if (outDir != "")
|
outDir = Utilities.GetOutputPath(outDir, FileName, inplace);
|
||||||
{
|
|
||||||
outDir = outDir + Path.GetDirectoryName(this.FileName).Remove(0, basepath.Length - 1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
outDir = Path.GetDirectoryName(this.FileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Then write out both files
|
// Then write out both files
|
||||||
bool success = datdataA.WriteToFile(outDir);
|
bool success = datdataA.WriteToFile(outDir);
|
||||||
@@ -4884,13 +4826,10 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// Split a DAT by best available hashes
|
/// Split a DAT by best available hashes
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="outDir">Name of the directory to write the DATs out to</param>
|
/// <param name="outDir">Name of the directory to write the DATs out to</param>
|
||||||
/// <param name="basepath">Parent path for replacement</param>
|
/// <param name="inplace">True if files should be written to the source folders, false otherwise</param>
|
||||||
/// <returns>True if split succeeded, false otherwise</returns>
|
/// <returns>True if split succeeded, false otherwise</returns>
|
||||||
public bool SplitByHash(string outDir, string basepath)
|
public bool SplitByHash(string outDir, bool inplace)
|
||||||
{
|
{
|
||||||
// Sanitize the basepath to be more predictable
|
|
||||||
basepath = (basepath.EndsWith(Path.DirectorySeparatorChar.ToString()) ? basepath : basepath + Path.DirectorySeparatorChar);
|
|
||||||
|
|
||||||
// Create each of the respective output DATs
|
// Create each of the respective output DATs
|
||||||
Globals.Logger.User("Creating and populating new DATs");
|
Globals.Logger.User("Creating and populating new DATs");
|
||||||
DatFile nodump = new DatFile
|
DatFile nodump = new DatFile
|
||||||
@@ -5125,14 +5064,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Get the output directory
|
// Get the output directory
|
||||||
if (outDir != "")
|
outDir = Utilities.GetOutputPath(outDir, FileName, inplace);
|
||||||
{
|
|
||||||
outDir = outDir + Path.GetDirectoryName(this.FileName).Remove(0, basepath.Length - 1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
outDir = Path.GetDirectoryName(this.FileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now, output all of the files to the output directory
|
// Now, output all of the files to the output directory
|
||||||
Globals.Logger.User("DAT information created, outputting new files");
|
Globals.Logger.User("DAT information created, outputting new files");
|
||||||
@@ -5152,15 +5084,12 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// Split a SuperDAT by lowest available directory level
|
/// Split a SuperDAT by lowest available directory level
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="outDir">Name of the directory to write the DATs out to</param>
|
/// <param name="outDir">Name of the directory to write the DATs out to</param>
|
||||||
/// <param name="basepath">Parent path for replacement</param>
|
/// <param name="inplace">True if files should be written to the source folders, false otherwise</param>
|
||||||
/// <param name="shortname">True if short names should be used, false otherwise</param>
|
/// <param name="shortname">True if short names should be used, false otherwise</param>
|
||||||
/// <param name="basedat">True if original filenames should be used as the base for output filename, false otherwise</param>
|
/// <param name="basedat">True if original filenames should be used as the base for output filename, false otherwise</param>
|
||||||
/// <returns>True if split succeeded, false otherwise</returns>
|
/// <returns>True if split succeeded, false otherwise</returns>
|
||||||
public bool SplitByLevel(string outDir, string basepath, bool shortname, bool basedat)
|
public bool SplitByLevel(string outDir, bool inplace, bool shortname, bool basedat)
|
||||||
{
|
{
|
||||||
// Sanitize the basepath to be more predictable
|
|
||||||
basepath = (basepath.EndsWith(Path.DirectorySeparatorChar.ToString()) ? basepath : basepath + Path.DirectorySeparatorChar);
|
|
||||||
|
|
||||||
// First, organize by games so that we can do the right thing
|
// First, organize by games so that we can do the right thing
|
||||||
BucketBy(SortedBy.Game, DedupeType.None, lower: false, norename: true);
|
BucketBy(SortedBy.Game, DedupeType.None, lower: false, norename: true);
|
||||||
|
|
||||||
@@ -5181,7 +5110,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
if (tempDat.Name != null && tempDat.Name != Path.GetDirectoryName(key))
|
if (tempDat.Name != null && tempDat.Name != Path.GetDirectoryName(key))
|
||||||
{
|
{
|
||||||
// Process and output the DAT
|
// Process and output the DAT
|
||||||
SplitByLevelHelper(tempDat, outDir, shortname, basedat);
|
SplitByLevelHelper(tempDat, outDir, shortname, basedat, inplace);
|
||||||
|
|
||||||
// Reset the DAT for the next items
|
// Reset the DAT for the next items
|
||||||
tempDat = new DatFile(this)
|
tempDat = new DatFile(this)
|
||||||
@@ -5203,7 +5132,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Then we write the last DAT out since it would be skipped otherwise
|
// Then we write the last DAT out since it would be skipped otherwise
|
||||||
SplitByLevelHelper(tempDat, outDir, shortname, basedat);
|
SplitByLevelHelper(tempDat, outDir, shortname, basedat, inplace);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -5234,16 +5163,15 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <param name="outDir">Directory to write out to</param>
|
/// <param name="outDir">Directory to write out to</param>
|
||||||
/// <param name="shortname">True if short naming scheme should be used, false otherwise</param>
|
/// <param name="shortname">True if short naming scheme should be used, false otherwise</param>
|
||||||
/// <param name="restore">True if original filenames should be used as the base for output filename, false otherwise</param>
|
/// <param name="restore">True if original filenames should be used as the base for output filename, false otherwise</param>
|
||||||
private void SplitByLevelHelper(DatFile datFile, string outDir, bool shortname, bool restore)
|
/// <param name="inplace">True if files should be written to the source folders, false otherwise</param>
|
||||||
|
private void SplitByLevelHelper(DatFile datFile, string outDir, bool shortname, bool restore, bool inplace)
|
||||||
{
|
{
|
||||||
// Get the name from the DAT to use separately
|
// Get the name from the DAT to use separately
|
||||||
string name = datFile.Name;
|
string name = datFile.Name;
|
||||||
string expName = name.Replace("/", " - ").Replace("\\", " - ");
|
string expName = name.Replace("/", " - ").Replace("\\", " - ");
|
||||||
|
|
||||||
// Get the path that the file will be written out to
|
// Get the output directory
|
||||||
string path = HttpUtility.HtmlDecode(String.IsNullOrWhiteSpace(name)
|
outDir = Utilities.GetOutputPath(outDir, FileName, inplace);
|
||||||
? outDir
|
|
||||||
: Path.Combine(outDir, name));
|
|
||||||
|
|
||||||
// Now set the new output values
|
// Now set the new output values
|
||||||
datFile.FileName = HttpUtility.HtmlDecode(String.IsNullOrWhiteSpace(name)
|
datFile.FileName = HttpUtility.HtmlDecode(String.IsNullOrWhiteSpace(name)
|
||||||
@@ -5259,20 +5187,17 @@ namespace SabreTools.Library.DatFiles
|
|||||||
datFile.Type = null;
|
datFile.Type = null;
|
||||||
|
|
||||||
// Write out the temporary DAT to the proper directory
|
// Write out the temporary DAT to the proper directory
|
||||||
datFile.WriteToFile(path);
|
datFile.WriteToFile(outDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Split a DAT by type of Rom
|
/// Split a DAT by type of Rom
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="outDir">Name of the directory to write the DATs out to</param>
|
/// <param name="outDir">Name of the directory to write the DATs out to</param>
|
||||||
/// <param name="basepath">Parent path for replacement</param>
|
/// <param name="inplace">True if files should be written to the source folders, false otherwise</param>
|
||||||
/// <returns>True if split succeeded, false otherwise</returns>
|
/// <returns>True if split succeeded, false otherwise</returns>
|
||||||
public bool SplitByType(string outDir, string basepath)
|
public bool SplitByType(string outDir, bool inplace)
|
||||||
{
|
{
|
||||||
// Sanitize the basepath to be more predictable
|
|
||||||
basepath = (basepath.EndsWith(Path.DirectorySeparatorChar.ToString()) ? basepath : basepath + Path.DirectorySeparatorChar);
|
|
||||||
|
|
||||||
// Create each of the respective output DATs
|
// Create each of the respective output DATs
|
||||||
Globals.Logger.User("Creating and populating new DATs");
|
Globals.Logger.User("Creating and populating new DATs");
|
||||||
DatFile romdat = new DatFile
|
DatFile romdat = new DatFile
|
||||||
@@ -5365,14 +5290,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Get the output directory
|
// Get the output directory
|
||||||
if (outDir != "")
|
outDir = Utilities.GetOutputPath(outDir, FileName, inplace);
|
||||||
{
|
|
||||||
outDir = outDir + Path.GetDirectoryName(this.FileName).Remove(0, basepath.Length - 1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
outDir = Path.GetDirectoryName(this.FileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now, output all of the files to the output directory
|
// Now, output all of the files to the output directory
|
||||||
Globals.Logger.User("DAT information created, outputting new files");
|
Globals.Logger.User("DAT information created, outputting new files");
|
||||||
@@ -5471,14 +5389,13 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create and open an output file for writing direct from a dictionary
|
/// Create and open an output file for writing direct from a dictionary
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="datdata">All information for creating the datfile header</param>
|
/// <param name="outDir">Set the output directory (default current directory)</param>
|
||||||
/// <param name="outDir">Set the output directory</param>
|
|
||||||
/// <param name="norename">True if games should only be compared on game and file name (default), false if system and source are counted</param>
|
/// <param name="norename">True if games should only be compared on game and file name (default), false if system and source are counted</param>
|
||||||
/// <param name="stats">True if DAT statistics should be output on write, false otherwise (default)</param>
|
/// <param name="stats">True if DAT statistics should be output on write, false otherwise (default)</param>
|
||||||
/// <param name="ignoreblanks">True if blank roms should be skipped on output, false otherwise (default)</param>
|
/// <param name="ignoreblanks">True if blank roms should be skipped on output, false otherwise (default)</param>
|
||||||
/// <param name="overwrite">True if files should be overwritten (default), false if they should be renamed instead</param>
|
/// <param name="overwrite">True if files should be overwritten (default), false if they should be renamed instead</param>
|
||||||
/// <returns>True if the DAT was written correctly, false otherwise</returns>
|
/// <returns>True if the DAT was written correctly, false otherwise</returns>
|
||||||
public bool WriteToFile(string outDir, bool norename = true, bool stats = false, bool ignoreblanks = false, bool overwrite = true)
|
public bool WriteToFile(string outDir = null, bool norename = true, bool stats = false, bool ignoreblanks = false, bool overwrite = true)
|
||||||
{
|
{
|
||||||
// If there's nothing there, abort
|
// If there's nothing there, abort
|
||||||
if (Count == 0)
|
if (Count == 0)
|
||||||
|
|||||||
@@ -384,6 +384,11 @@ Options:
|
|||||||
This sets an output folder to be used when the files are created. If
|
This sets an output folder to be used when the files are created. If
|
||||||
a path is not defined, the application directory is used instead.
|
a path is not defined, the application directory is used instead.
|
||||||
|
|
||||||
|
-ip, --inplace Write to the input directories
|
||||||
|
This will write out the split files to the source folder instead of
|
||||||
|
writing them out to the runtime folder by default (or the output
|
||||||
|
folder if overridden).
|
||||||
|
|
||||||
-ex, --extract Backup and remove copier headers
|
-ex, --extract Backup and remove copier headers
|
||||||
This will detect, store, and remove copier headers from a file or folder
|
This will detect, store, and remove copier headers from a file or folder
|
||||||
of files. The headers are backed up and collated by the hash of the
|
of files. The headers are backed up and collated by the hash of the
|
||||||
@@ -426,6 +431,11 @@ Options:
|
|||||||
This sets an output folder to be used when the files are created. If
|
This sets an output folder to be used when the files are created. If
|
||||||
a path is not defined, the application directory is used instead.
|
a path is not defined, the application directory is used instead.
|
||||||
|
|
||||||
|
-ip, --inplace Write to the input directories
|
||||||
|
This will write out the split files to the source folder instead of
|
||||||
|
writing them out to the runtime folder by default (or the output
|
||||||
|
folder if overridden).
|
||||||
|
|
||||||
-ls, --lvl-split Split a SuperDAT or folder by lowest available level
|
-ls, --lvl-split Split a SuperDAT or folder by lowest available level
|
||||||
For a DAT, or set of DATs, allow for splitting based on the lowest
|
For a DAT, or set of DATs, allow for splitting based on the lowest
|
||||||
available level of game name. That is, if a game name is top/mid/last,
|
available level of game name. That is, if a game name is top/mid/last,
|
||||||
@@ -436,6 +446,11 @@ Options:
|
|||||||
This sets an output folder to be used when the files are created. If
|
This sets an output folder to be used when the files are created. If
|
||||||
a path is not defined, the application directory is used instead.
|
a path is not defined, the application directory is used instead.
|
||||||
|
|
||||||
|
-ip, --inplace Write to the input directories
|
||||||
|
This will write out the split files to the source folder instead of
|
||||||
|
writing them out to the runtime folder by default (or the output
|
||||||
|
folder if overridden).
|
||||||
|
|
||||||
-s, --short Use short names for outputted DATs
|
-s, --short Use short names for outputted DATs
|
||||||
Instead of using ClrMamePro-style long names for DATs, use just the
|
Instead of using ClrMamePro-style long names for DATs, use just the
|
||||||
name of the folder as the name of the DAT. This can be used in
|
name of the folder as the name of the DAT. This can be used in
|
||||||
@@ -712,6 +727,11 @@ Options:
|
|||||||
This sets an output folder to be used when the files are created. If
|
This sets an output folder to be used when the files are created. If
|
||||||
a path is not defined, the application directory is used instead.
|
a path is not defined, the application directory is used instead.
|
||||||
|
|
||||||
|
-ip, --inplace Write to the input directories
|
||||||
|
This will write out the split files to the source folder instead of
|
||||||
|
writing them out to the runtime folder by default (or the output
|
||||||
|
folder if overridden).
|
||||||
|
|
||||||
-ud, --update Update and manipulate DAT(s)
|
-ud, --update Update and manipulate DAT(s)
|
||||||
This is the multitool part of the program, allowing for almost every
|
This is the multitool part of the program, allowing for almost every
|
||||||
manipulation to a DAT, or set of DATs. This is also a combination of
|
manipulation to a DAT, or set of DATs. This is also a combination of
|
||||||
|
|||||||
@@ -339,6 +339,11 @@ namespace SabreTools
|
|||||||
"Output directory",
|
"Output directory",
|
||||||
FeatureType.String,
|
FeatureType.String,
|
||||||
null));
|
null));
|
||||||
|
extSplit.AddFeature("inplace", new Feature(
|
||||||
|
new List<string>() { "-ip", "--inplace" },
|
||||||
|
"Write to the input directories",
|
||||||
|
FeatureType.Flag,
|
||||||
|
null));
|
||||||
|
|
||||||
// Create the Hash Split feature
|
// Create the Hash Split feature
|
||||||
Feature hashSplit = new Feature(
|
Feature hashSplit = new Feature(
|
||||||
@@ -351,6 +356,11 @@ namespace SabreTools
|
|||||||
"Output directory",
|
"Output directory",
|
||||||
FeatureType.String,
|
FeatureType.String,
|
||||||
null));
|
null));
|
||||||
|
hashSplit.AddFeature("inplace", new Feature(
|
||||||
|
new List<string>() { "-ip", "--inplace" },
|
||||||
|
"Write to the input directories",
|
||||||
|
FeatureType.Flag,
|
||||||
|
null));
|
||||||
|
|
||||||
// Create the Level Split feature
|
// Create the Level Split feature
|
||||||
Feature levelSplit = new Feature(
|
Feature levelSplit = new Feature(
|
||||||
@@ -363,6 +373,11 @@ namespace SabreTools
|
|||||||
"Output directory",
|
"Output directory",
|
||||||
FeatureType.String,
|
FeatureType.String,
|
||||||
null));
|
null));
|
||||||
|
levelSplit.AddFeature("inplace", new Feature(
|
||||||
|
new List<string>() { "-ip", "--inplace" },
|
||||||
|
"Write to the input directories",
|
||||||
|
FeatureType.Flag,
|
||||||
|
null));
|
||||||
levelSplit.AddFeature("short", new Feature(
|
levelSplit.AddFeature("short", new Feature(
|
||||||
new List<string>() { "-s", "--short" },
|
new List<string>() { "-s", "--short" },
|
||||||
"Use short output names",
|
"Use short output names",
|
||||||
@@ -635,6 +650,11 @@ namespace SabreTools
|
|||||||
"Output directory",
|
"Output directory",
|
||||||
FeatureType.String,
|
FeatureType.String,
|
||||||
null));
|
null));
|
||||||
|
typeSplit.AddFeature("inplace", new Feature(
|
||||||
|
new List<string>() { "-ip", "--inplace" },
|
||||||
|
"Write to the input directories",
|
||||||
|
FeatureType.Flag,
|
||||||
|
null));
|
||||||
|
|
||||||
// Create the Update feature
|
// Create the Update feature
|
||||||
Feature update = new Feature(
|
Feature update = new Feature(
|
||||||
|
|||||||
@@ -186,34 +186,27 @@ namespace SabreTools
|
|||||||
/// <param name="exta">First extension to split on</param>
|
/// <param name="exta">First extension to split on</param>
|
||||||
/// <param name="extb">Second extension to split on</param>
|
/// <param name="extb">Second extension to split on</param>
|
||||||
/// <param name="outDir">Output directory for the split files</param>
|
/// <param name="outDir">Output directory for the split files</param>
|
||||||
private static void InitExtSplit(List<string> inputs, List<string> exta, List<string> extb, string outDir)
|
/// <param name="inplace">True if files should be written to the source folders, false otherwise</param>
|
||||||
|
private static void InitExtSplit(List<string> inputs, List<string> exta, List<string> extb, string outDir, bool inplace)
|
||||||
{
|
{
|
||||||
|
// Get only files from the inputs
|
||||||
|
List<string> files = Utilities.GetOnlyFilesFromInputs(inputs, appendparent: true);
|
||||||
|
|
||||||
// Loop over the input files
|
// Loop over the input files
|
||||||
foreach (string input in inputs)
|
foreach (string file in files)
|
||||||
{
|
{
|
||||||
if (File.Exists(input))
|
// Split the input filename
|
||||||
{
|
string[] splitpath = file.Split('¬');
|
||||||
DatFile datFile = new DatFile();
|
|
||||||
datFile.Parse(Path.GetFullPath(input), 0, 0);
|
// Create and fill the new DAT
|
||||||
datFile.SplitByExtension(outDir, Path.GetDirectoryName(input), exta, extb);
|
DatFile datFile = new DatFile();
|
||||||
}
|
datFile.Parse(splitpath[0], 0, 0);
|
||||||
else if (Directory.Exists(input))
|
|
||||||
{
|
// Get the output directory
|
||||||
foreach (string file in Directory.EnumerateFiles(input, "*", SearchOption.AllDirectories))
|
outDir = Utilities.GetOutputPath(outDir, file, inplace, splitpath: true);
|
||||||
{
|
|
||||||
DatFile datFile = new DatFile();
|
// Split and write the DAT
|
||||||
datFile.Parse(Path.GetFullPath(file), 0, 0);
|
datFile.SplitByExtension(outDir, inplace, exta, extb);
|
||||||
datFile.SplitByExtension(outDir, (input.EndsWith(Path.DirectorySeparatorChar.ToString()) ? input : input + Path.DirectorySeparatorChar),
|
|
||||||
exta, extb);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Globals.Logger.Error("'{0}' is not a valid file or folder!", input);
|
|
||||||
Console.WriteLine();
|
|
||||||
_help.OutputIndividualFeature("Extension Split");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,33 +215,27 @@ namespace SabreTools
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="inputs">List of inputs to be used</param>
|
/// <param name="inputs">List of inputs to be used</param>
|
||||||
/// <param name="outDir">Output directory for the split files</param>
|
/// <param name="outDir">Output directory for the split files</param>
|
||||||
private static void InitHashSplit(List<string> inputs, string outDir)
|
/// <param name="inplace">True if files should be written to the source folders, false otherwise</param>
|
||||||
|
private static void InitHashSplit(List<string> inputs, string outDir, bool inplace)
|
||||||
{
|
{
|
||||||
|
// Get only files from the inputs
|
||||||
|
List<string> files = Utilities.GetOnlyFilesFromInputs(inputs, appendparent: true);
|
||||||
|
|
||||||
// Loop over the input files
|
// Loop over the input files
|
||||||
foreach (string input in inputs)
|
foreach (string file in files)
|
||||||
{
|
{
|
||||||
if (File.Exists(input))
|
// Split the input filename
|
||||||
{
|
string[] splitpath = file.Split('¬');
|
||||||
DatFile datFile = new DatFile();
|
|
||||||
datFile.Parse(Path.GetFullPath(input), 0, 0);
|
// Create and fill the new DAT
|
||||||
datFile.SplitByHash(outDir, Path.GetDirectoryName(input));
|
DatFile datFile = new DatFile();
|
||||||
}
|
datFile.Parse(splitpath[0], 0, 0);
|
||||||
else if (Directory.Exists(input))
|
|
||||||
{
|
// Get the output directory
|
||||||
foreach (string file in Directory.EnumerateFiles(input, "*", SearchOption.AllDirectories))
|
outDir = Utilities.GetOutputPath(outDir, file, inplace, splitpath: true);
|
||||||
{
|
|
||||||
DatFile datFile = new DatFile();
|
// Split and write the DAT
|
||||||
datFile.Parse(Path.GetFullPath(file), 0, 0);
|
datFile.SplitByHash(outDir, inplace);
|
||||||
datFile.SplitByHash(outDir, (input.EndsWith(Path.DirectorySeparatorChar.ToString()) ? input : input + Path.DirectorySeparatorChar));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Globals.Logger.Error("'{0}' is not a valid file or folder!", input);
|
|
||||||
Console.WriteLine();
|
|
||||||
_help.OutputIndividualFeature("Hash Split");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -280,36 +267,29 @@ namespace SabreTools
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="inputs">List of inputs to be used</param>
|
/// <param name="inputs">List of inputs to be used</param>
|
||||||
/// <param name="outDir">Output directory for the split files</param>
|
/// <param name="outDir">Output directory for the split files</param>
|
||||||
|
/// <param name="inplace">True if files should be written to the source folders, false otherwise</param>
|
||||||
/// <param name="shortname">True if short filenames should be used, false otherwise</param>
|
/// <param name="shortname">True if short filenames should be used, false otherwise</param>
|
||||||
/// <param name="basedat">True if original filenames should be used as the base for output filename, false otherwise</param>
|
/// <param name="basedat">True if original filenames should be used as the base for output filename, false otherwise</param>
|
||||||
private static void InitLevelSplit(List<string> inputs, string outDir, bool shortname, bool basedat)
|
private static void InitLevelSplit(List<string> inputs, string outDir, bool inplace, bool shortname, bool basedat)
|
||||||
{
|
{
|
||||||
|
// Get only files from the inputs
|
||||||
|
List<string> files = Utilities.GetOnlyFilesFromInputs(inputs, appendparent: true);
|
||||||
|
|
||||||
// Loop over the input files
|
// Loop over the input files
|
||||||
foreach (string input in inputs)
|
foreach (string file in files)
|
||||||
{
|
{
|
||||||
if (File.Exists(input))
|
// Split the input filename
|
||||||
{
|
string[] splitpath = file.Split('¬');
|
||||||
DatFile datFile = new DatFile();
|
|
||||||
datFile.Parse(Path.GetFullPath(input), 0, 0, keep: true);
|
// Create and fill the new DAT
|
||||||
datFile.SplitByLevel(outDir, Path.GetDirectoryName(input), shortname, basedat);
|
DatFile datFile = new DatFile();
|
||||||
}
|
datFile.Parse(splitpath[0], 0, 0);
|
||||||
else if (Directory.Exists(input))
|
|
||||||
{
|
// Get the output directory
|
||||||
foreach (string file in Directory.EnumerateFiles(input, "*", SearchOption.AllDirectories))
|
outDir = Utilities.GetOutputPath(outDir, file, inplace, splitpath: true);
|
||||||
{
|
|
||||||
DatFile datFile = new DatFile();
|
// Split and write the DAT
|
||||||
datFile.Parse(Path.GetFullPath(file), 0, 0, keep: true);
|
datFile.SplitByLevel(outDir, inplace, shortname, basedat);
|
||||||
datFile.SplitByLevel(outDir, (input.EndsWith(Path.DirectorySeparatorChar.ToString()) ? input : input + Path.DirectorySeparatorChar),
|
|
||||||
shortname, basedat);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Globals.Logger.Error("'{0}' is not a valid file or folder!", input);
|
|
||||||
Console.WriteLine();
|
|
||||||
_help.OutputIndividualFeature("Level Split");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -389,33 +369,27 @@ namespace SabreTools
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="inputs">List of inputs to be used</param>
|
/// <param name="inputs">List of inputs to be used</param>
|
||||||
/// <param name="outDir">Output directory for the split files</param>
|
/// <param name="outDir">Output directory for the split files</param>
|
||||||
private static void InitTypeSplit(List<string> inputs, string outDir)
|
/// <param name="inplace">True if files should be written to the source folders, false otherwise</param>
|
||||||
|
private static void InitTypeSplit(List<string> inputs, string outDir, bool inplace)
|
||||||
{
|
{
|
||||||
|
// Get only files from the inputs
|
||||||
|
List<string> files = Utilities.GetOnlyFilesFromInputs(inputs, appendparent: true);
|
||||||
|
|
||||||
// Loop over the input files
|
// Loop over the input files
|
||||||
foreach (string input in inputs)
|
foreach (string file in files)
|
||||||
{
|
{
|
||||||
if (File.Exists(input))
|
// Split the input filename
|
||||||
{
|
string[] splitpath = file.Split('¬');
|
||||||
DatFile datFile = new DatFile();
|
|
||||||
datFile.Parse(Path.GetFullPath(input), 0, 0);
|
// Create and fill the new DAT
|
||||||
datFile.SplitByType(outDir, Path.GetFullPath(Path.GetDirectoryName(input)));
|
DatFile datFile = new DatFile();
|
||||||
}
|
datFile.Parse(splitpath[0], 0, 0);
|
||||||
else if (Directory.Exists(input))
|
|
||||||
{
|
// Get the output directory
|
||||||
foreach (string file in Directory.EnumerateFiles(input, "*", SearchOption.AllDirectories))
|
outDir = Utilities.GetOutputPath(outDir, file, inplace, splitpath: true);
|
||||||
{
|
|
||||||
DatFile datFile = new DatFile();
|
// Split and write the DAT
|
||||||
datFile.Parse(Path.GetFullPath(file), 0, 0);
|
datFile.SplitByType(outDir, inplace);
|
||||||
datFile.SplitByType(outDir, Path.GetFullPath((input.EndsWith(Path.DirectorySeparatorChar.ToString()) ? input : input + Path.DirectorySeparatorChar)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Globals.Logger.Error("{0} is not a valid file or folder!", input);
|
|
||||||
Console.WriteLine();
|
|
||||||
_help.OutputIndividualFeature("Type Split");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1300,25 +1300,25 @@ namespace SabreTools
|
|||||||
// Split a DAT by extension
|
// Split a DAT by extension
|
||||||
else if (splitByExt)
|
else if (splitByExt)
|
||||||
{
|
{
|
||||||
InitExtSplit(inputs, exta, extb, outDir);
|
InitExtSplit(inputs, exta, extb, outDir, inplace);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Split a DAT by available hashes
|
// Split a DAT by available hashes
|
||||||
else if (splitByHash)
|
else if (splitByHash)
|
||||||
{
|
{
|
||||||
InitHashSplit(inputs, outDir);
|
InitHashSplit(inputs, outDir, inplace);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Split a SuperDAT by lowest available level
|
// Split a SuperDAT by lowest available level
|
||||||
else if (splitByLevel)
|
else if (splitByLevel)
|
||||||
{
|
{
|
||||||
InitLevelSplit(inputs, outDir, shortname, basedat);
|
InitLevelSplit(inputs, outDir, inplace, shortname, basedat);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Split a DAT by item type
|
// Split a DAT by item type
|
||||||
else if (splitByType)
|
else if (splitByType)
|
||||||
{
|
{
|
||||||
InitTypeSplit(inputs, outDir);
|
InitTypeSplit(inputs, outDir, inplace);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get statistics on input files
|
// Get statistics on input files
|
||||||
|
|||||||
Reference in New Issue
Block a user