diff --git a/SabreHelper/Build.cs b/SabreHelper/Build.cs index 200044f8..d1ffcbf6 100644 --- a/SabreHelper/Build.cs +++ b/SabreHelper/Build.cs @@ -126,11 +126,12 @@ Options: case "SingleGame": Console.WriteLine(@"SingleGame - Process DATs for use in server environments ----------------------------------------- -Usage: SingleGame.exe [-r=rootdir|-n] +Usage: SingleGame.exe [-r=rootdir|-n] Options: -r=rootdir Set the directory name for path size -n Disable single-game mode + -z Disable forceunzipping "); break; case "DATFromDir": diff --git a/SabreHelper/Output.cs b/SabreHelper/Output.cs index f98e8ef8..8ea4309d 100644 --- a/SabreHelper/Output.cs +++ b/SabreHelper/Output.cs @@ -25,6 +25,12 @@ namespace SabreTools.Helper /// Tru if the DAT was written correctly, false otherwise public static bool WriteToDat(string name, string description, string version, string date, string category, string author, bool forceunzip, bool old, string outDir, List roms, Logger logger) { + // If it's empty, use the current folder + if (outDir.Trim() == "") + { + outDir = Environment.CurrentDirectory; + } + // Double check the outdir for the end delim if (!outDir.EndsWith(Path.DirectorySeparatorChar.ToString())) { diff --git a/SingleGame/SingleGame.cs b/SingleGame/SingleGame.cs index 0d7747b8..28778a1e 100644 --- a/SingleGame/SingleGame.cs +++ b/SingleGame/SingleGame.cs @@ -12,6 +12,8 @@ namespace SabreTools private static string _filename = ""; private static string _path = ""; private static bool _rename = true; + private static bool _forceunpack = true; + private static Logger logger; public static void Main(string[] args) { @@ -30,7 +32,7 @@ namespace SabreTools return; } - Logger logger = new Logger(false, "singlegame.log"); + logger = new Logger(false, "singlegame.log"); logger.Start(); // Output the title @@ -47,6 +49,9 @@ namespace SabreTools case "-n": _rename = false; break; + case "-z": + _forceunpack = false; + break; default: if (args[i].StartsWith("-r")) { @@ -59,37 +64,64 @@ namespace SabreTools _path = (_path == "" ? Environment.CurrentDirectory : _path); - // Import the existing DAT - List roms = RomManipulation.Parse(_filename, 0, 0, logger); + // Drag and drop means quotes; we don't want quotes + _filename = _filename.Replace("\"", ""); - // If we are in single game mode, rename all games - if (_rename) + // If it's a single file, handle it as such + if (!Directory.Exists(_filename) && File.Exists(_filename)) { - roms.ForEach(delegate (RomData x) - { - x.Game = "!"; - }); + ProcessDAT(_filename, _path, _rename); } - - // Trim all file names according to the path that's set - roms.ForEach(delegate (RomData x) + // If it's a directory, loop through the files and see if any are DATs + else if (Directory.Exists(_filename)) { - // Windows max name length is 260 - int usableLength = 259 - _path.Length; - - if (x.Name.Length > usableLength) + foreach (string file in Directory.EnumerateFiles(_filename)) { - string ext = Path.GetExtension(x.Name); - x.Name = x.Name.Substring(0, usableLength - ext.Length); - x.Name += ext; + ProcessDAT(file, _path, _rename); } - }); - - // Now write the file out accordingly - Output.WriteToDat(Path.GetFileNameWithoutExtension(_filename), - Path.GetFileNameWithoutExtension(_filename), "", "", "", "", false, Path.GetExtension(_filename) == ".dat", "", roms, logger); + } logger.Close(); } + + /// + /// Import the existing DAT(s) + /// + /// Name of the file to be processed + /// The base path to be used for comparison + /// True if roms are to be renamed + private static void ProcessDAT(string filename, string path, bool rename) + { + List roms = RomManipulation.Parse(_filename, 0, 0, logger); + + // Trim all file names according to the path that's set + List outroms = new List(); + while (roms.Count != 0) + { + RomData rom = roms[0]; + roms.RemoveAt(0); + + // If we are in single game mode, rename all games + if (rename) + { + rom.Game = "!"; + } + + // Windows max name length is 260 + int usableLength = 259 - _path.Length; + if (rom.Name.Length > usableLength) + { + string ext = Path.GetExtension(rom.Name); + rom.Name = rom.Name.Substring(0, usableLength - ext.Length); + rom.Name += ext; + } + + outroms.Add(rom); + } + + // Now write the file out accordingly + Output.WriteToDat(Path.GetFileNameWithoutExtension(_filename), + Path.GetFileNameWithoutExtension(_filename), "", "", "", "", _forceunpack, Path.GetExtension(filename) == ".dat", "", outroms, logger); + } } }