- using System.Collections.Generic;
- 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> [encode/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(" -e = Extract text from file");
- Trace.WriteLine(" -i = Insert text from file");
- Trace.WriteLine(" file : File to process (-l, -p, -u=Index file (the first one of each decade : xenosaga.00, xenosaga.10, xenosaga.20...) ; -e, -i : filename)");
- Trace.WriteLine(" encode : (-e) Encoding of the output/input file (ANSI( default), ASCII, UTF8, UNICODE)");
- Trace.WriteLine(" regroup : (-p) true to pack 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();
- List<string> listActions = new List<string>() { "-l", "-p", "-u", "-e", "-i" };
-
- Trace.Write("Checking arguments : ");
-
- if (args.Length != 2 && args.Length != 3)
- {
- Trace.WriteLine("Incorrect number of parameter!");
- return false;
- }
-
- if (!listActions.Contains(args[0]))
- {
- Trace.WriteLine("Incorrect parameter - unknown <option>");
- return false;
- }
-
- if (!File.Exists(args[1]) && !Directory.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;
- }
- if ((args.Length == 3 && (args[0] == "-e" || args[0] == "-i")) && (args[2] != "ANSI" && args[2] != "ASCII" && args[2] != "UTF8" && args[2] != "UNICODE"))
- {
- Trace.WriteLine("Incorrect parameter - unknown <encode>");
- return false;
- }
-
- listArgs.option = args[0];
- listArgs.filename = args[1];
- if (args.Length == 3 && listArgs.option == "-p")
- listArgs.regroup = args[2] == "true" ? true : false;
- listArgs.encode = args.Length == 2 ? Encoding.Default : null;
- if (args.Length == 3 && (listArgs.option == "-e" || listArgs.option == "-i"))
- {
- switch (args[2])
- {
- case "ASCII":
- listArgs.encode = Encoding.ASCII;
- break;
-
- case "UTF8":
- listArgs.encode = Encoding.UTF8;
- break;
-
- case "UNICODE":
- listArgs.encode = Encoding.Unicode;
- break;
-
- case "ANSI":
- default:
- listArgs.encode = Encoding.Default;
- break;
- }
- }
-
- Trace.WriteLine("OK");
-
- return true;
- }
- }
- }
|