using System; using System.Collections.Generic; using NW4RTools; namespace ConsoleApp { public abstract class ResFileCommand : Command { public ResFileCommand(string description) : base(description) { } public ResFile TargetFile { get; private set; } public string TargetPath { get; private set; } public override void Execute(string[] args) { if (args.Length == 0) { Console.WriteLine("No path entered"); return; } // don't override this var newArgs = new string[args.Length - 1]; for (int i = 1; i < args.Length; i++) { newArgs[i - 1] = args[i]; } var data = System.IO.File.ReadAllBytes(args[0]); TargetFile = BrresReader.LoadFile(data, false); TargetPath = args[0]; OperateOnFile(newArgs); } protected abstract void OperateOnFile(string[] args); protected void SaveFile() { var data = BrresWriter.WriteFile(TargetFile); System.IO.File.WriteAllBytes(TargetPath, data); } } public class InitCommand : Command { // this class doesn't inherit from ResFileCommand because it is a special case: // instead of operating on an existing file, it creates one public InitCommand() : base("create an empty .brres file") { } public override void Execute(string[] args) { if (args.Length == 0) { Console.WriteLine("No path entered"); return; } var rf = new ResFile(); System.IO.File.WriteAllBytes(args[0], BrresWriter.WriteFile(rf)); } public override string GetHelp(string[] args) { return "syntax: init -- creates an empty .brres file"; } } public class ListCommand : ResFileCommand { public ListCommand() : base("list the resources in a .brres file") { } protected override void OperateOnFile(string[] args) { foreach (var g in TargetFile) { Console.WriteLine("{0}", g.Key); // time to try hackishness var dict = g.Value as System.Collections.Specialized.IOrderedDictionary; foreach (var e in dict.Keys) { Console.WriteLine(" - {0}", e); } } } public override string GetHelp(string[] args) { return "syntax: list -- lists the contents of a .brres file"; } } }