2016-04-06 00:01:54 -07:00
|
|
|
|
using System;
|
2016-04-18 16:32:17 -07:00
|
|
|
|
using System.Collections.Generic;
|
2016-04-06 00:01:54 -07:00
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Xml;
|
|
|
|
|
|
|
|
|
|
|
|
using SabreTools.Helper;
|
|
|
|
|
|
|
|
|
|
|
|
namespace SabreTools
|
|
|
|
|
|
{
|
|
|
|
|
|
public class SingleGame
|
|
|
|
|
|
{
|
2016-04-06 13:03:25 -07:00
|
|
|
|
private static string _filename = "";
|
|
|
|
|
|
private static string _path = "";
|
|
|
|
|
|
private static bool _rename = true;
|
2016-04-06 00:01:54 -07:00
|
|
|
|
|
|
|
|
|
|
public static void Main(string[] args)
|
|
|
|
|
|
{
|
2016-04-18 20:04:38 -07:00
|
|
|
|
Console.Clear();
|
2016-04-06 00:35:39 -07:00
|
|
|
|
|
2016-04-18 16:32:17 -07:00
|
|
|
|
// Credits take precidence over all
|
|
|
|
|
|
if ((new List<string>(args)).Contains("--credits"))
|
|
|
|
|
|
{
|
|
|
|
|
|
Build.Credits();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-04-06 13:03:25 -07:00
|
|
|
|
if (args.Length == 0)
|
2016-04-06 00:01:54 -07:00
|
|
|
|
{
|
2016-04-06 14:19:01 -07:00
|
|
|
|
Build.Help();
|
2016-04-06 00:01:54 -07:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-04-19 01:11:23 -07:00
|
|
|
|
Logger logger = new Logger(false, "singlegame.log");
|
|
|
|
|
|
logger.Start();
|
|
|
|
|
|
|
2016-04-18 20:04:38 -07:00
|
|
|
|
// Output the title
|
|
|
|
|
|
Build.Start("SingleGame");
|
|
|
|
|
|
|
2016-04-06 00:47:28 -07:00
|
|
|
|
_filename = args[0];
|
2016-04-06 00:01:54 -07:00
|
|
|
|
|
2016-04-06 13:03:25 -07:00
|
|
|
|
if (args.Length > 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (int i = 1; i < args.Length; i++)
|
|
|
|
|
|
{
|
2016-04-19 02:09:48 -07:00
|
|
|
|
switch (args[i])
|
|
|
|
|
|
{
|
|
|
|
|
|
case "-n":
|
|
|
|
|
|
_rename = false;
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
if (args[i].StartsWith("-r"))
|
|
|
|
|
|
{
|
|
|
|
|
|
_path = args[i].Split('=')[1];
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2016-04-06 13:03:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_path = (_path == "" ? Environment.CurrentDirectory : _path);
|
|
|
|
|
|
|
2016-04-19 01:11:23 -07:00
|
|
|
|
// Import the existing DAT
|
|
|
|
|
|
List<RomData> roms = RomManipulation.Parse(_filename, 0, 0, logger);
|
2016-04-06 00:01:54 -07:00
|
|
|
|
|
2016-04-19 01:11:23 -07:00
|
|
|
|
// If we are in single game mode, rename all games
|
|
|
|
|
|
if (_rename)
|
2016-04-06 00:01:54 -07:00
|
|
|
|
{
|
2016-04-19 01:11:23 -07:00
|
|
|
|
roms.ForEach(delegate (RomData x)
|
2016-04-06 00:01:54 -07:00
|
|
|
|
{
|
2016-04-19 01:11:23 -07:00
|
|
|
|
x.Game = "!";
|
|
|
|
|
|
});
|
2016-04-06 00:01:54 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-04-19 01:11:23 -07:00
|
|
|
|
// Trim all file names according to the path that's set
|
|
|
|
|
|
roms.ForEach(delegate (RomData x)
|
2016-04-06 00:01:54 -07:00
|
|
|
|
{
|
2016-04-19 01:11:23 -07:00
|
|
|
|
// Windows max name length is 260
|
|
|
|
|
|
int usableLength = 259 - _path.Length;
|
2016-04-06 00:01:54 -07:00
|
|
|
|
|
2016-04-19 01:11:23 -07:00
|
|
|
|
if (x.Name.Length > usableLength)
|
2016-04-06 00:01:54 -07:00
|
|
|
|
{
|
2016-04-19 01:11:23 -07:00
|
|
|
|
string ext = Path.GetExtension(x.Name);
|
|
|
|
|
|
x.Name = x.Name.Substring(0, usableLength - ext.Length);
|
|
|
|
|
|
x.Name += ext;
|
2016-04-06 00:01:54 -07:00
|
|
|
|
}
|
2016-04-19 01:11:23 -07:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// Now write the file out accordingly
|
|
|
|
|
|
Output.WriteToDat(Path.GetFileNameWithoutExtension(_filename),
|
|
|
|
|
|
Path.GetFileNameWithoutExtension(_filename), "", "", "", "", false, Path.GetExtension(_filename) == ".dat", "", roms, logger);
|
2016-04-06 00:01:54 -07:00
|
|
|
|
|
2016-04-19 01:11:23 -07:00
|
|
|
|
logger.Close();
|
2016-04-06 00:01:54 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|