Add support for V3.10
This commit is contained in:
parent
11aeb8fcdd
commit
9a42fb4512
|
@ -9,16 +9,30 @@ namespace Lucidiot.Raima {
|
|||
/// <summary>
|
||||
/// Version 3.00, with a <c>V3.00 + 0x1A</c> file magic.
|
||||
/// </summary>
|
||||
V300
|
||||
V300,
|
||||
|
||||
/// <summary>
|
||||
/// Version 3.10, with a <c>V3.10 + 0x1A</c> file magic.
|
||||
/// </summary>
|
||||
V310
|
||||
}
|
||||
|
||||
public class DatabaseSchema {
|
||||
private short _pageSize = 512;
|
||||
public short PageSize { get { return _pageSize; } }
|
||||
|
||||
public const DatabaseVersion Version = DatabaseVersion.V300;
|
||||
public DatabaseVersion Version = DatabaseVersion.V300;
|
||||
|
||||
public const string Magic = "V3.00\x1a";
|
||||
public const int MagicNumberLength = 6;
|
||||
|
||||
public Dictionary<string, DatabaseVersion> MagicNumbers {
|
||||
get {
|
||||
Dictionary<string, DatabaseVersion> numbers = new Dictionary<string,DatabaseVersion>();
|
||||
numbers["V3.00\x1a"] = DatabaseVersion.V300;
|
||||
numbers["V3.10\x1a"] = DatabaseVersion.V310;
|
||||
return numbers;
|
||||
}
|
||||
}
|
||||
|
||||
public string DatabaseFileName;
|
||||
|
||||
|
@ -71,6 +85,10 @@ namespace Lucidiot.Raima {
|
|||
this.StorageMethod = storage;
|
||||
}
|
||||
|
||||
public DatabaseSchema(string fileName, IDatabaseStorage storage, DatabaseVersion version) : this(fileName, storage) {
|
||||
this.Version = version;
|
||||
}
|
||||
|
||||
public static DatabaseSchema Load(string fileName, IDatabaseStorage storage) {
|
||||
if (!storage.CanRead)
|
||||
throw new NotSupportedException("A readable storage method is required to load an existing database.");
|
||||
|
@ -82,9 +100,10 @@ namespace Lucidiot.Raima {
|
|||
}
|
||||
|
||||
private void Parse(BinaryReader br) {
|
||||
string foundMagic = new String(Encoding.ASCII.GetChars(br.ReadBytes(Magic.Length)));
|
||||
if (foundMagic != Magic)
|
||||
string foundMagic = new String(Encoding.ASCII.GetChars(br.ReadBytes(MagicNumberLength)));
|
||||
if (!MagicNumbers.ContainsKey(foundMagic))
|
||||
throw new InvalidDataException("Unexpected file magic: " + foundMagic);
|
||||
Version = MagicNumbers[foundMagic];
|
||||
short pageSize = br.ReadInt16();
|
||||
if (pageSize % 512 != 0)
|
||||
throw new ArgumentOutOfRangeException("Page size must be a multiple of 512 bytes.");
|
||||
|
|
Loading…
Reference in New Issue