mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Fix pathing issues and overhaul SingleGame
This commit is contained in:
@@ -126,11 +126,12 @@ Options:
|
|||||||
case "SingleGame":
|
case "SingleGame":
|
||||||
Console.WriteLine(@"SingleGame - Process DATs for use in server environments
|
Console.WriteLine(@"SingleGame - Process DATs for use in server environments
|
||||||
-----------------------------------------
|
-----------------------------------------
|
||||||
Usage: SingleGame.exe <filename> [-r=rootdir|-n]
|
Usage: SingleGame.exe <file|folder> [-r=rootdir|-n]
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-r=rootdir Set the directory name for path size
|
-r=rootdir Set the directory name for path size
|
||||||
-n Disable single-game mode
|
-n Disable single-game mode
|
||||||
|
-z Disable forceunzipping
|
||||||
");
|
");
|
||||||
break;
|
break;
|
||||||
case "DATFromDir":
|
case "DATFromDir":
|
||||||
|
|||||||
@@ -25,6 +25,12 @@ namespace SabreTools.Helper
|
|||||||
/// <returns>Tru if the DAT was written correctly, false otherwise</returns>
|
/// <returns>Tru if the DAT was written correctly, false otherwise</returns>
|
||||||
public static bool WriteToDat(string name, string description, string version, string date, string category, string author, bool forceunzip, bool old, string outDir, List<RomData> roms, Logger logger)
|
public static bool WriteToDat(string name, string description, string version, string date, string category, string author, bool forceunzip, bool old, string outDir, List<RomData> 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
|
// Double check the outdir for the end delim
|
||||||
if (!outDir.EndsWith(Path.DirectorySeparatorChar.ToString()))
|
if (!outDir.EndsWith(Path.DirectorySeparatorChar.ToString()))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ namespace SabreTools
|
|||||||
private static string _filename = "";
|
private static string _filename = "";
|
||||||
private static string _path = "";
|
private static string _path = "";
|
||||||
private static bool _rename = true;
|
private static bool _rename = true;
|
||||||
|
private static bool _forceunpack = true;
|
||||||
|
private static Logger logger;
|
||||||
|
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
@@ -30,7 +32,7 @@ namespace SabreTools
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger logger = new Logger(false, "singlegame.log");
|
logger = new Logger(false, "singlegame.log");
|
||||||
logger.Start();
|
logger.Start();
|
||||||
|
|
||||||
// Output the title
|
// Output the title
|
||||||
@@ -47,6 +49,9 @@ namespace SabreTools
|
|||||||
case "-n":
|
case "-n":
|
||||||
_rename = false;
|
_rename = false;
|
||||||
break;
|
break;
|
||||||
|
case "-z":
|
||||||
|
_forceunpack = false;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
if (args[i].StartsWith("-r"))
|
if (args[i].StartsWith("-r"))
|
||||||
{
|
{
|
||||||
@@ -59,37 +64,64 @@ namespace SabreTools
|
|||||||
|
|
||||||
_path = (_path == "" ? Environment.CurrentDirectory : _path);
|
_path = (_path == "" ? Environment.CurrentDirectory : _path);
|
||||||
|
|
||||||
// Import the existing DAT
|
// Drag and drop means quotes; we don't want quotes
|
||||||
List<RomData> roms = RomManipulation.Parse(_filename, 0, 0, logger);
|
_filename = _filename.Replace("\"", "");
|
||||||
|
|
||||||
// If we are in single game mode, rename all games
|
// If it's a single file, handle it as such
|
||||||
if (_rename)
|
if (!Directory.Exists(_filename) && File.Exists(_filename))
|
||||||
{
|
{
|
||||||
roms.ForEach(delegate (RomData x)
|
ProcessDAT(_filename, _path, _rename);
|
||||||
{
|
|
||||||
x.Game = "!";
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
// If it's a directory, loop through the files and see if any are DATs
|
||||||
// Trim all file names according to the path that's set
|
else if (Directory.Exists(_filename))
|
||||||
roms.ForEach(delegate (RomData x)
|
|
||||||
{
|
{
|
||||||
// Windows max name length is 260
|
foreach (string file in Directory.EnumerateFiles(_filename))
|
||||||
int usableLength = 259 - _path.Length;
|
|
||||||
|
|
||||||
if (x.Name.Length > usableLength)
|
|
||||||
{
|
{
|
||||||
string ext = Path.GetExtension(x.Name);
|
ProcessDAT(file, _path, _rename);
|
||||||
x.Name = x.Name.Substring(0, usableLength - ext.Length);
|
|
||||||
x.Name += ext;
|
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
// Now write the file out accordingly
|
|
||||||
Output.WriteToDat(Path.GetFileNameWithoutExtension(_filename),
|
|
||||||
Path.GetFileNameWithoutExtension(_filename), "", "", "", "", false, Path.GetExtension(_filename) == ".dat", "", roms, logger);
|
|
||||||
|
|
||||||
logger.Close();
|
logger.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Import the existing DAT(s)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filename">Name of the file to be processed</param>
|
||||||
|
/// <param name="path">The base path to be used for comparison</param>
|
||||||
|
/// <param name="rename">True if roms are to be renamed</param>
|
||||||
|
private static void ProcessDAT(string filename, string path, bool rename)
|
||||||
|
{
|
||||||
|
List<RomData> roms = RomManipulation.Parse(_filename, 0, 0, logger);
|
||||||
|
|
||||||
|
// Trim all file names according to the path that's set
|
||||||
|
List<RomData> outroms = new List<RomData>();
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user