public static void Main(string[] args) { FtexToolArguments arguments = FtexToolArguments.Parse(args); if (arguments.Errors.Any()) { foreach (var error in arguments.Errors) { Console.WriteLine(error); } return; } if (arguments.DisplayHelp) { ShowUsageInfo(); return; } if (arguments.DirectoryInput) { DirectoryInfo fileDirectory = new DirectoryInfo(arguments.InputPath); var files = GetFileList(fileDirectory, true, ".ftex"); foreach (var file in files) { try { UnpackFtexFile(file.FullName, arguments.OutputPath); } catch (Exception e) { Console.WriteLine("Error while unpacking '{0}': {1}", file.FullName, e.Message); } } } else { if (arguments.InputPath.EndsWith(".ftex", StringComparison.OrdinalIgnoreCase)) { UnpackFtexFile(arguments.InputPath, arguments.OutputPath); } else if (arguments.InputPath.EndsWith(".dds", StringComparison.OrdinalIgnoreCase)) { PackDdsFile( arguments.InputPath, arguments.OutputPath, arguments.TextureType, arguments.UnknownFlags, arguments.FtexsFileCount); } else { Console.WriteLine("Input file is not ending in ftex or dds."); } } }
private static FtexToolArguments ParseArguments(string[] args) { FtexToolArguments arguments = new FtexToolArguments { DisplayHelp = false, TextureType = FtexTextureType.DiffuseMap, InputPath = "", OutputPath = "" }; if (args.Length == 0) { arguments.DisplayHelp = true; return arguments; } bool expectType = false; bool expectInput = false; bool expectOutput = false; int argIndex = 0; while (argIndex < args.Length) { string arg = args[argIndex]; argIndex++; if (expectType) { arguments.ReadType(arg); expectType = false; } else if (expectInput) { arguments.ReadInput(arg); expectInput = false; } else if (expectOutput) { arguments.ReadOutput(arg); expectOutput = false; } else if (arg.StartsWith("-")) { switch (arg) { case "-h": case "-help": arguments.DisplayHelp = true; break; case "-t": case "-type": expectType = true; break; case "-i": case "-input": expectInput = true; break; case "-o": case "-output": expectOutput = true; break; default: arguments.Errors.Add("Unknown option"); break; } } else { expectInput = true; expectOutput = true; argIndex--; } } return arguments; }
public static FtexToolArguments Parse(string[] args) { FtexToolArguments arguments = new FtexToolArguments { DisplayHelp = false, TextureType = FtexTextureType.DiffuseMap, UnknownFlags = FtexUnknownFlags.Default, InputPath = "", OutputPath = "" }; if (args.Length == 0) { arguments.DisplayHelp = true; return(arguments); } bool expectType = false; bool expectUnknownFlags = false; bool expectFtexs = false; bool expectInput = false; bool expectOutput = false; int argIndex = 0; while (argIndex < args.Length) { string arg = args[argIndex]; argIndex++; if (expectType) { arguments.ReadType(arg); expectType = false; } else if (expectFtexs) { arguments.ReadFtexsCount(arg); expectFtexs = false; } else if (expectUnknownFlags) { arguments.ReadUnknownFlags(arg); expectUnknownFlags = false; } else if (expectInput) { arguments.ReadInput(arg); expectInput = false; } else if (expectOutput) { arguments.ReadOutput(arg); expectOutput = false; } else if (arg.StartsWith("-")) { switch (arg) { case "-h": case "-help": arguments.DisplayHelp = true; break; case "-t": case "-type": expectType = true; break; case "-fl": case "-flags": expectUnknownFlags = true; break; case "-f": case "-ftexs": expectFtexs = true; break; case "-i": case "-input": expectInput = true; break; case "-o": case "-output": expectOutput = true; break; default: arguments.Errors.Add("Unknown option"); break; } } else { expectInput = true; expectOutput = true; argIndex--; } } return(arguments); }