summaryrefslogtreecommitdiff
path: root/ConsoleApp
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
parent6a3b743987ca132729845613bc2d043f75f0d9e5 (diff)
downloadnw4rtools-fd085848e60831a8582c24de8f30ad4528f9d490.tar.gz
nw4rtools-fd085848e60831a8582c24de8f30ad4528f9d490.zip
unfinished console interface to NW4RTools added
Diffstat (limited to 'ConsoleApp')
-rw-r--r--ConsoleApp/AssemblyInfo.cs27
-rw-r--r--ConsoleApp/Command.cs15
-rw-r--r--ConsoleApp/ConsoleApp.csproj51
-rw-r--r--ConsoleApp/Main.cs84
-rw-r--r--ConsoleApp/ModelCommands.cs118
-rw-r--r--ConsoleApp/ResFileCommands.cs89
-rw-r--r--ConsoleApp/TextureCommands.cs75
-rwxr-xr-xConsoleApp/bin/Debug/ConsoleApp.exebin0 -> 12288 bytes
-rw-r--r--ConsoleApp/bin/Debug/ConsoleApp.exe.mdbbin0 -> 2945 bytes
-rwxr-xr-xConsoleApp/bin/Debug/NW4RTools.dllbin0 -> 239104 bytes
-rw-r--r--ConsoleApp/bin/Debug/NW4RTools.dll.mdbbin0 -> 114935 bytes
-rw-r--r--ConsoleApp/bin/Debug/OpenTK.dllbin0 -> 2719744 bytes
-rw-r--r--ConsoleApp/bin/Debug/OpenTK.dll.config12
13 files changed, 471 insertions, 0 deletions
diff --git a/ConsoleApp/AssemblyInfo.cs b/ConsoleApp/AssemblyInfo.cs
new file mode 100644
index 0000000..0e0b4ae
--- /dev/null
+++ b/ConsoleApp/AssemblyInfo.cs
@@ -0,0 +1,27 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+
+// Information about this assembly is defined by the following attributes.
+// Change them to the values specific to your project.
+
+[assembly: AssemblyTitle("ConsoleApp")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("")]
+[assembly: AssemblyCopyright("")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
+// The form "{Major}.{Minor}.*" will automatically update the build and revision,
+// and "{Major}.{Minor}.{Build}.*" will update just the revision.
+
+[assembly: AssemblyVersion("1.0.*")]
+
+// The following attributes are used to specify the signing key for the assembly,
+// if desired. See the Mono documentation for more information about signing.
+
+//[assembly: AssemblyDelaySign(false)]
+//[assembly: AssemblyKeyFile("")]
+
diff --git a/ConsoleApp/Command.cs b/ConsoleApp/Command.cs
new file mode 100644
index 0000000..dcb6def
--- /dev/null
+++ b/ConsoleApp/Command.cs
@@ -0,0 +1,15 @@
+using System;
+namespace ConsoleApp {
+ public abstract class Command {
+ public readonly string Description;
+
+ public Command(string description) {
+ Description = description;
+ }
+
+
+ public abstract void Execute(string[] args);
+ public abstract string GetHelp(string[] args);
+ }
+}
+
diff --git a/ConsoleApp/ConsoleApp.csproj b/ConsoleApp/ConsoleApp.csproj
new file mode 100644
index 0000000..451221d
--- /dev/null
+++ b/ConsoleApp/ConsoleApp.csproj
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>9.0.21022</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{0EDC614B-9673-48A3-BB48-3D6CC54D20ED}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <RootNamespace>ConsoleApp</RootNamespace>
+ <AssemblyName>ConsoleApp</AssemblyName>
+ <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug</OutputPath>
+ <DefineConstants>DEBUG</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <Externalconsole>true</Externalconsole>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>none</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Release</OutputPath>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <Externalconsole>true</Externalconsole>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="System" />
+ <Reference Include="System.Drawing" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Main.cs" />
+ <Compile Include="AssemblyInfo.cs" />
+ <Compile Include="Command.cs" />
+ <Compile Include="ResFileCommands.cs" />
+ <Compile Include="ModelCommands.cs" />
+ <Compile Include="TextureCommands.cs" />
+ </ItemGroup>
+ <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+ <ItemGroup>
+ <ProjectReference Include="..\NW4RTools\NW4RTools.csproj">
+ <Project>{A9C9FABD-0A5F-4DAB-979D-9F288F96866F}</Project>
+ <Name>NW4RTools</Name>
+ </ProjectReference>
+ </ItemGroup>
+</Project> \ No newline at end of file
diff --git a/ConsoleApp/Main.cs b/ConsoleApp/Main.cs
new file mode 100644
index 0000000..322d277
--- /dev/null
+++ b/ConsoleApp/Main.cs
@@ -0,0 +1,84 @@
+using System;
+using System.Collections.Generic;
+
+namespace ConsoleApp {
+ class MainClass {
+ private static Dictionary<string, Command> CommandLookup;
+
+ private static void SetupCommands() {
+ CommandLookup = new Dictionary<string, Command>();
+
+ CommandLookup.Add("init", new InitCommand());
+ CommandLookup.Add("list", new ListCommand());
+ CommandLookup.Add("import-obj", new ImportObjCommand());
+ CommandLookup.Add("export-obj", new ExportObjCommand());
+ CommandLookup.Add("export-collada", new ExportColladaCommand());
+ CommandLookup.Add("export-textures", new ExportTexturesCommand());
+ }
+
+ public static void Main(string[] args) {
+ Console.WriteLine("NW4RTools by Treeki");
+ Console.WriteLine();
+
+ SetupCommands();
+
+ // process the command line
+ string cmd;
+ string[] cmdArgs;
+
+ if (args.Length == 0) {
+ cmd = "help";
+ cmdArgs = new string[0];
+ } else {
+ cmd = args[0];
+ cmdArgs = new string[args.Length - 1];
+
+ for (int i = 1; i < args.Length; i++) {
+ cmdArgs[i - 1] = args[i];
+ }
+ }
+
+ // handle Help if needed
+ if (cmd == "help") {
+ Help(cmdArgs);
+ return;
+ }
+
+ // otherwise, pass it on
+ if (CommandLookup.ContainsKey(cmd)) {
+ CommandLookup[cmd].Execute(cmdArgs);
+ } else {
+ Console.WriteLine("Unknown command {0}. Try \"help\" for a list of usable commands", cmd);
+ }
+ }
+
+ private static void Help(string[] args) {
+ if (args.Length == 0) {
+ Console.WriteLine("Available commands:");
+
+ foreach (var cmd in CommandLookup) {
+ Console.WriteLine("- {0}: {1}", cmd.Key, cmd.Value.Description);
+ }
+
+ Console.WriteLine();
+ Console.WriteLine("For additional info, try: help <command-name>");
+
+ } else {
+ if (CommandLookup.ContainsKey(args[0])) {
+ Console.WriteLine("Help for {0}:", args[0]);
+ string[] helpArgs = new string[args.Length - 1];
+
+ for (int i = 1; i < args.Length; i++) {
+ helpArgs[i - 1] = args[i];
+ }
+
+ Console.WriteLine(CommandLookup[args[0]].GetHelp(helpArgs));
+
+ } else {
+ Console.WriteLine("Unknown command {0}. Try \"help\" for a list of usable commands", args[0]);
+ }
+ }
+ }
+ }
+}
+
diff --git a/ConsoleApp/ModelCommands.cs b/ConsoleApp/ModelCommands.cs
new file mode 100644
index 0000000..9bbf1f3
--- /dev/null
+++ b/ConsoleApp/ModelCommands.cs
@@ -0,0 +1,118 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using NW4RTools;
+
+namespace ConsoleApp {
+ public class ImportObjCommand : ResFileCommand {
+ public ImportObjCommand() : base("import an .obj model and associated textures") {
+ }
+
+ protected override void OperateOnFile(string[] args) {
+ if (args.Length < 2 || args.Length > 3) {
+ Console.WriteLine("invalid syntax.\n" + GetHelp(null));
+ return;
+ }
+
+ string currentDir = Directory.GetCurrentDirectory();
+ string objPath = Path.Combine(currentDir, args[0]);
+ string objDir = Path.GetDirectoryName(objPath);
+
+ ObjImporter.LightmapType lmType = ObjImporter.LightmapType.None;
+ if (args.Length == 3 && args[2] != "none") {
+ switch (args[2]) {
+ case "map":
+ lmType = ObjImporter.LightmapType.Map;
+ break;
+ case "mapobj":
+ lmType = ObjImporter.LightmapType.MapObj;
+ break;
+ default:
+ Console.WriteLine("warning: unknown lightmap type {0}", args[2]);
+ break;
+ }
+ }
+
+
+ Console.WriteLine("importing model...");
+
+ ObjImporter.ImportModel(objDir, new StreamReader(objPath), TargetFile, args[1], lmType);
+
+ Console.WriteLine("saving file...");
+
+ SaveFile();
+
+ Console.WriteLine("done!");
+ }
+
+ public override string GetHelp(string[] args) {
+ return "syntax: import-obj <brres-filename> <obj-filename> <model-name> [lightmap-mode]\n"
+ + " imports an .obj model and the associated textures.\n\n"
+ + " model-name will be the name of the ResMdl.\n"
+ + " lightmap-mode may be: none (default), map, mapobj";
+ }
+ }
+
+
+
+ public class ExportObjCommand : ResFileCommand {
+ public ExportObjCommand() : base("export an .obj model") {
+ }
+
+ protected override void OperateOnFile(string[] args) {
+ if (args.Length != 2) {
+ Console.WriteLine("invalid syntax.\n" + GetHelp(null));
+ return;
+ }
+
+ string currentDir = Directory.GetCurrentDirectory();
+ string objPath = Path.Combine(currentDir, args[0]);
+ string objDir = Path.GetDirectoryName(objPath);
+
+ Console.WriteLine("exporting model...");
+
+ ObjExporter.WriteModel(new StreamWriter(objPath), TargetFile, args[1]);
+
+ Console.WriteLine("done!");
+ }
+
+ public override string GetHelp(string[] args) {
+ return "syntax: export-obj <brres-filename> <obj-filename> <model-name>\n"
+ + " exports a model as .obj.\n\n"
+ + " model-name will be the name of the ResMdl.\n"
+ + " more settings will be added later.";
+ }
+ }
+
+
+
+ public class ExportColladaCommand : ResFileCommand {
+ public ExportColladaCommand() : base("export a COLLADA (.dae) model") {
+ }
+
+ protected override void OperateOnFile(string[] args) {
+ if (args.Length != 2) {
+ Console.WriteLine("invalid syntax.\n" + GetHelp(null));
+ return;
+ }
+
+ string currentDir = Directory.GetCurrentDirectory();
+ string daePath = Path.Combine(currentDir, args[0]);
+ string daeDir = Path.GetDirectoryName(daePath);
+
+ Console.WriteLine("exporting model...");
+
+ ColladaExporter.WriteModel(File.OpenWrite(daePath), TargetFile, args[1]);
+
+ Console.WriteLine("done!");
+ }
+
+ public override string GetHelp(string[] args) {
+ return "syntax: export-collada <brres-filename> <dae-filename> <model-name>\n"
+ + " exports a model as COLLADA (.dae).\n\n"
+ + " model-name will be the name of the ResMdl.\n"
+ + " more settings will be added later.";
+ }
+ }
+}
+
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";
+ }
+ }
+}
+
diff --git a/ConsoleApp/TextureCommands.cs b/ConsoleApp/TextureCommands.cs
new file mode 100644
index 0000000..3fad0c7
--- /dev/null
+++ b/ConsoleApp/TextureCommands.cs
@@ -0,0 +1,75 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using NW4RTools;
+
+namespace ConsoleApp {
+ public class ExportTexturesCommand : ResFileCommand {
+ public ExportTexturesCommand() : base("export texture(s) to PNG") {
+ }
+
+ protected override void OperateOnFile(string[] args) {
+ if (args.Length < 1) {
+ Console.WriteLine("invalid syntax.\n" + GetHelp(null));
+ return;
+ }
+
+ bool exportAll = (args.Length == 1);
+ var list = new List<string>();
+
+ for (int i = 1; i < args.Length; i++) {
+ list.Add(args[i]);
+ }
+
+
+ var texDict = TargetFile.GetTextureGroup();
+ if (texDict == null || texDict.Count == 0) {
+ Console.WriteLine("this file has no textures.");
+ return;
+ }
+
+ int exportCount = 0;
+
+ string currentDir = Directory.GetCurrentDirectory();
+ string imgDir = Path.Combine(currentDir, args[0]);
+
+ // one last check
+ if (!Directory.Exists(imgDir)) {
+ Console.WriteLine("the destination directory does not exist:\n {0}", imgDir);
+ return;
+ }
+
+ foreach (var kv in texDict) {
+ if (exportAll || list.Contains(kv.Key)) {
+ for (int i = 0; i < kv.Value.Images.Length; i++) {
+ var img = kv.Value.Images[i];
+
+ string imgName;
+ if (i == 0) {
+ // first (possibly only?) mipmap
+ imgName = String.Format("{0}.png", kv.Key);
+ } else {
+ imgName = String.Format("{0}__{1}.png", kv.Key, i);
+ }
+
+ Console.WriteLine("{0}[{4}] {1}x{2} {3}", kv.Key, img.Width, img.Height, kv.Value.Format, i);
+
+ img.Save(Path.Combine(imgDir, imgName));
+ }
+
+ exportCount++;
+ }
+ }
+
+ Console.WriteLine("done! {0} textures exported", exportCount);
+ }
+
+ public override string GetHelp(string[] args) {
+ return "syntax: export-textures <brres-filename> <dest-path> [texture-names...]\n"
+ + " exports texture(s) as .png files.\n\n"
+ + " dest-path will be the folder in which the textures are placed (eg. images).\n"
+ + " texture-names is a list of textures. if not specified, every texture is exported.";
+ }
+ }
+}
+
diff --git a/ConsoleApp/bin/Debug/ConsoleApp.exe b/ConsoleApp/bin/Debug/ConsoleApp.exe
new file mode 100755
index 0000000..0b677f2
--- /dev/null
+++ b/ConsoleApp/bin/Debug/ConsoleApp.exe
Binary files differ
diff --git a/ConsoleApp/bin/Debug/ConsoleApp.exe.mdb b/ConsoleApp/bin/Debug/ConsoleApp.exe.mdb
new file mode 100644
index 0000000..fa4218f
--- /dev/null
+++ b/ConsoleApp/bin/Debug/ConsoleApp.exe.mdb
Binary files differ
diff --git a/ConsoleApp/bin/Debug/NW4RTools.dll b/ConsoleApp/bin/Debug/NW4RTools.dll
new file mode 100755
index 0000000..3e86a0a
--- /dev/null
+++ b/ConsoleApp/bin/Debug/NW4RTools.dll
Binary files differ
diff --git a/ConsoleApp/bin/Debug/NW4RTools.dll.mdb b/ConsoleApp/bin/Debug/NW4RTools.dll.mdb
new file mode 100644
index 0000000..1bff220
--- /dev/null
+++ b/ConsoleApp/bin/Debug/NW4RTools.dll.mdb
Binary files differ
diff --git a/ConsoleApp/bin/Debug/OpenTK.dll b/ConsoleApp/bin/Debug/OpenTK.dll
new file mode 100644
index 0000000..afff0dd
--- /dev/null
+++ b/ConsoleApp/bin/Debug/OpenTK.dll
Binary files differ
diff --git a/ConsoleApp/bin/Debug/OpenTK.dll.config b/ConsoleApp/bin/Debug/OpenTK.dll.config
new file mode 100644
index 0000000..99aef86
--- /dev/null
+++ b/ConsoleApp/bin/Debug/OpenTK.dll.config
@@ -0,0 +1,12 @@
+<configuration>
+ <dllmap os="linux" dll="opengl32.dll" target="libGL.so.1"/>
+ <dllmap os="linux" dll="glu32.dll" target="libGLU.so.1"/>
+ <dllmap os="linux" dll="openal32.dll" target="libopenal.so.1"/>
+ <dllmap os="linux" dll="alut.dll" target="libalut.so.0"/>
+ <dllmap os="linux" dll="opencl.dll" target="libOpenCL.so"/>
+ <dllmap os="osx" dll="openal32.dll" target="/System/Library/Frameworks/OpenAL.framework/OpenAL" />
+ <dllmap os="osx" dll="alut.dll" target="/System/Library/Frameworks/OpenAL.framework/OpenAL" />
+ <dllmap os="osx" dll="libGLES.dll" target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES" />
+ <dllmap os="osx" dll="libGLESv2.dll" target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES" />
+ <dllmap os="osx" dll="opencl.dll" target="/System/Library/Frameworks/OpenCL.framework/OpenCL"/>
+</configuration>