[DatFile, Utilities] Use subpath where possible

Using the subpath in the name of the output file can sometimes help distinguish which verison of a file is being used if the numbering doesn't help.
This commit is contained in:
Matt Nadareski
2018-04-23 13:03:15 -07:00
parent 46dbbaae96
commit 284568bc33
2 changed files with 30 additions and 2 deletions

View File

@@ -2583,6 +2583,34 @@ namespace SabreTools.Library.Tools
return ext;
}
/// <summary>
/// Get the proper filename (with subpath) from the file and parent combination
/// </summary>
/// <param name="path">Input combined path to use</param>
/// <param name="sanitize">True if path separators should be converted to '-', false otherwise</param>
/// <returns>Subpath for the file</returns>
public static string GetFilenameFromFileAndParent(string path, bool sanitize)
{
// Check that we have a combined path first
if (!path.Contains("¬"))
{
return Path.GetFileName(path).Replace('/', '-').Replace('\\', '-');
}
// First separate out the parts
string child = path.Split('¬')[0];
string parent = path.Split('¬')[1];
// If the parts are the same, return the filename from the first part
if (child == parent)
{
return Path.GetFileName(child).Replace('/', '-').Replace('\\', '-');
}
// Otherwise, remove the parent from the child and return the remainder
return child.Remove(0, parent.Length + 1).Replace('/', '-').Replace('\\', '-');
}
/// <summary>
/// Get the dictionary key that should be used for a given item and sorting type
/// </summary>