summaryrefslogtreecommitdiff
path: root/NW4RTools/Logger.cs
diff options
context:
space:
mode:
authorTreeki <treeki@gmail.com>2011-02-04 15:40:12 +0100
committerTreeki <treeki@gmail.com>2011-02-04 15:40:12 +0100
commitdb8fc350b2bffda63d27797bfe7ae4afb4af327e (patch)
treea0a89cd83615e7794d9507d10c329e30c4226670 /NW4RTools/Logger.cs
downloadnw4rtools-db8fc350b2bffda63d27797bfe7ae4afb4af327e.tar.gz
nw4rtools-db8fc350b2bffda63d27797bfe7ae4afb4af327e.zip
Initial commit of NW4RTools.
Supports BRRES reading for: Model Bytecode, Model Nodes, Model Vertex Data, and incomplete Materials. Writing is completely unimplemented so far.
Diffstat (limited to 'NW4RTools/Logger.cs')
-rw-r--r--NW4RTools/Logger.cs81
1 files changed, 81 insertions, 0 deletions
diff --git a/NW4RTools/Logger.cs b/NW4RTools/Logger.cs
new file mode 100644
index 0000000..d5a76f3
--- /dev/null
+++ b/NW4RTools/Logger.cs
@@ -0,0 +1,81 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace NW4RTools {
+ public class LogContext : IDisposable {
+ // An awful, awful hack
+ private readonly Logger Owner;
+
+ public LogContext(Logger owner) {
+ Owner = owner;
+ }
+
+ void IDisposable.Dispose() {
+ Owner.Pop();
+ }
+ }
+
+ public class Logger {
+ private List<string> PrefixElements;
+ private List<string> Names;
+ private int BlockCount;
+ private string Prefix;
+
+ public Logger() {
+ Names = new List<string>();
+ Names.Add("root");
+
+ PrefixElements = new List<string>();
+ PrefixElements.Add("|");
+
+ RebuildPrefix();
+ }
+
+ private void RebuildPrefix() {
+ Prefix = string.Join(" ", PrefixElements.ToArray()) + "- ";
+ }
+
+ public void Send(string format, params object[] args) {
+ if (BlockCount > 0)
+ return;
+
+ Console.Write(Prefix);
+ Console.WriteLine(format, args);
+ }
+
+ public LogContext Push(string format, params object[] args) {
+ string n = string.Format(format, args);
+ Console.Write(Prefix);
+ Console.Write("=== ");
+ Console.WriteLine(n);
+
+ Names.Add(n);
+
+ PrefixElements.Add("-");
+ RebuildPrefix();
+
+ return new LogContext(this);
+ }
+
+ public void Pop() {
+ PrefixElements.RemoveAt(PrefixElements.Count - 1);
+ RebuildPrefix();
+
+ string n = Names[Names.Count - 1];
+ Names.RemoveAt(Names.Count - 1);
+ Console.Write(Prefix);
+ Console.Write("=/= end ");
+ Console.WriteLine(n);
+ }
+
+ public void Block() {
+ BlockCount += 1;
+ }
+
+ public void Unblock() {
+ BlockCount -= 1;
+ }
+ }
+}
+