summaryrefslogtreecommitdiff
path: root/ConsoleApp/ResFileCommands.cs
diff options
context:
space:
mode:
authorTreeki <treeki@gmail.com>2011-03-26 03:45:34 +0100
committerTreeki <treeki@gmail.com>2011-03-26 03:45:34 +0100
commitfd085848e60831a8582c24de8f30ad4528f9d490 (patch)
treeb00fd7539c1cb02ff5187f212b5bd2e8128e82bd /ConsoleApp/ResFileCommands.cs
parent6a3b743987ca132729845613bc2d043f75f0d9e5 (diff)
downloadnw4rtools-fd085848e60831a8582c24de8f30ad4528f9d490.tar.gz
nw4rtools-fd085848e60831a8582c24de8f30ad4528f9d490.zip
unfinished console interface to NW4RTools added
Diffstat (limited to '')
-rw-r--r--ConsoleApp/ResFileCommands.cs89
1 files changed, 89 insertions, 0 deletions
diff --git a/ConsoleApp/ResFileCommands.cs b/ConsoleApp/ResFileCommands.cs
new file mode 100644
index 0000000..ac734e4
--- /dev/null
+++ b/ConsoleApp/ResFileCommands.cs
@@ -0,0 +1,89 @@
+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 <filename> -- 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 <filename> -- lists the contents of a .brres file";
+ }
+ }
+}
+