Skip to content
Browse files

[monkeydoc] Introduce support for versioned tree and gracefully handl…

…e old trees.
  • Loading branch information...
1 parent a527653 commit ed413baf00089ed010b94244f774437cdd0c71af @garuma garuma committed
Showing with 16 additions and 3 deletions.
  1. +16 −3 mcs/tools/monkeydoc/MonkeyDoc/Tree.cs
View
19 mcs/tools/monkeydoc/MonkeyDoc/Tree.cs
@@ -18,6 +18,7 @@ namespace MonkeyDoc
*/
public class Tree
{
+ const long CurrentVersionNumber = 1;
public readonly HelpSource HelpSource;
FileStream InputStream;
@@ -31,6 +32,7 @@ public class Tree
/// </summary>
public Tree (HelpSource hs, string filename)
{
+ HelpSource = hs;
Encoding utf8 = new UTF8Encoding (false, true);
if (!File.Exists (filename)){
@@ -45,11 +47,15 @@ public Tree (HelpSource hs, string filename)
throw new Exception ("Invalid file format");
InputStream.Position = 4;
+ // Try to read version information
+ if (InputReader.ReadInt32 () == -(int)'v')
+ VersionNumber = InputReader.ReadInt64 ();
+ else
+ InputStream.Position -= 4;
+
var position = InputReader.ReadInt32 ();
rootNode = new Node (this, position);
InflateNode (rootNode);
-
- HelpSource = hs;
}
/// <summary>
@@ -73,7 +79,7 @@ public void Save (string file)
Encoding utf8 = new UTF8Encoding (false, true);
using (FileStream output = File.OpenWrite (file)){
// Skip over the pointer to the first node.
- output.Position = 8;
+ output.Position = 4 + 4 + 8 + 4;
using (BinaryWriter writer = new BinaryWriter (output, utf8)) {
// Recursively dump
@@ -81,6 +87,8 @@ public void Save (string file)
output.Position = 0;
writer.Write (new byte [] { (byte) 'M', (byte) 'o', (byte) 'H', (byte) 'P' });
+ writer.Write (-(int)'v');
+ writer.Write (CurrentVersionNumber);
writer.Write (rootNode.Address);
}
}
@@ -92,6 +100,11 @@ public void Save (string file)
}
}
+ public long VersionNumber {
+ get;
+ private set;
+ }
+
static bool GoodSig (byte [] sig)
{
if (sig.Length != 4)

0 comments on commit ed413ba

Please sign in to comment.
Something went wrong with that request. Please try again.