From fbe2a5949ff15d497719a45311eb0cc5da18cc0a Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Wed, 8 Nov 2017 13:40:41 -0800 Subject: [PATCH] [Utilities] Add "create output path" helper --- SabreTools.Library/Tools/Utilities.cs | 56 +++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/SabreTools.Library/Tools/Utilities.cs b/SabreTools.Library/Tools/Utilities.cs index 15d1e700..f8a56851 100644 --- a/SabreTools.Library/Tools/Utilities.cs +++ b/SabreTools.Library/Tools/Utilities.cs @@ -1888,6 +1888,62 @@ namespace SabreTools.Library.Tools return outDir; } + /// + /// Get the proper output path for a given input file and output directory + /// + /// Output directory to use + /// Input path to create output for + /// True if the output file should go to the same input folder, false otherwise + /// True if the input path should be treated as an appended parent directory, false otherwise (default) + /// Complete output path + public static string GetOutputPath(string outDir, string inputpath, bool inplace, bool splitpath = false) + { + // First, we need to ensure the output directory + outDir = EnsureOutputDirectory(outDir); + + // If we have a split path, we need to treat the input separately + if (splitpath) + { + string[] split = inputpath.Split('¬'); + + // If we have an inplace output, use the directory name from the input path + if (inplace) + { + outDir = Path.GetDirectoryName(split[1]); + } + + // If we are processing a path that is coming from a directory, we want to get the subfolder to write to + else if (split[0].Length != split[1].Length) + { + outDir = Path.GetDirectoryName(Path.Combine(outDir, split[0].Remove(0, split[1].Length + 1))); + } + + // If we are processing a single file from the root of a directory, we just use the output directory + else + { + // No-op + } + } + // Otherwise, assume the input path is just a filename + else + { + // If we have an inplace output, use the directory name from the input path + if (inplace) + { + outDir = Path.GetDirectoryName(inputpath); + } + + // Otherwise, just use the supplied output directory + else + { + // No-op + } + } + + // Finally, return the output directory + return outDir; + } + /// /// Get a proper romba sub path ///