Tool dedicated to isohacking for Xenosaga on Playstation 2
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
3.2 KiB

using System.Diagnostics;
using System.IO;
using System.Text;
namespace Hack.Xenosaga.Common
{
public class Functions
{
public static void usage()
{
Trace.WriteLine("");
Trace.WriteLine("xenosaga <option> <file> [regroup]");
Trace.WriteLine(" option : -l = List files from index");
Trace.WriteLine(" -u = Unpack files from index");
Trace.WriteLine(" -p = Pack files from index");
Trace.WriteLine(" file : Index file (the first one of each decade : xenosaga.00, xenosaga.10, xenosaga.20...)");
Trace.WriteLine(" regroup : true to regroup all files in only one (ex: 11, 12, 13 in 11) ; false or empty (default) to keep the same system of increment files");
}
public static bool CheckArgs(string[] args, out Variables.stArgs listArgs)
{
listArgs = new Variables.stArgs();
Trace.Write("Checking arguments : ");
if (args.Length != 2 && args.Length != 3)
{
Trace.WriteLine("Incorrect number of parameter!");
return false;
}
if (args[0] != "-l" && args[0] != "-p" && args[0] != "-u" && args[0] != "-e")
{
Trace.WriteLine("Incorrect parameter - unknown <option>");
return false;
}
if (!File.Exists(args[1]))
{
Trace.WriteLine("Incorrect parameter - unknown <file>");
return false;
}
if ((args.Length == 3 && args[0] == "-p") && (args[2] != "true" && args[2] != "false"))
{
Trace.WriteLine("Incorrect parameter - unknown <regroup>");
return false;
}
listArgs.option = args[0];
listArgs.filename = args[1];
if (args.Length == 3 && listArgs.option == "-p")
listArgs.regroup = args[2] == "true" ? true : false;
Trace.WriteLine("OK");
return true;
}
public static void ManageListener(bool consoleTrace, bool fileTrace = false, StreamWriter sw = null)
{
string traceFileName = "TraceFile";
string traceConsoleName = "TraceConsole";
for (int i = 0; i < Trace.Listeners.Count; i++)
{
TraceListener trace = Trace.Listeners[i];
if (trace.Name == "Default" || (trace.Name == traceConsoleName && !consoleTrace) || (trace.Name == traceFileName && !fileTrace))
{
Trace.Listeners.Remove(trace);
trace.Dispose();
}
}
if (consoleTrace)
{
ConsoleTraceListener traceConsole = new ConsoleTraceListener();
traceConsole.Name = traceConsoleName;
Trace.Listeners.Add(traceConsole);
}
if (fileTrace)
{
TextWriterTraceListener traceFile = new TextWriterTraceListener(sw);
traceFile.Name = traceFileName;
Trace.Listeners.Add(traceFile);
}
}
}
}