1 |
william |
94 |
using System; |
2 |
|
|
using System.Collections.Generic; |
3 |
|
|
using System.Linq; |
4 |
|
|
using System.Text; |
5 |
|
|
using gr2lib.core.interfaces; |
6 |
|
|
using gr2lib.core.helpers; |
7 |
|
|
using System.Diagnostics; |
8 |
|
|
|
9 |
|
|
namespace gr2lib.core.coreclasses.header |
10 |
|
|
{ |
11 |
|
|
public class granny_magic : igranny_magic |
12 |
|
|
{ |
13 |
|
|
private const int GrannyGRNMagixValueCount = 4; |
14 |
|
|
private const int GrannyGRNReservedCount = 2; |
15 |
|
|
|
16 |
|
|
public granny_magic() |
17 |
|
|
{ |
18 |
|
|
this.HeaderSize = 0; |
19 |
|
|
this.HeaderFormat = 0; |
20 |
|
|
this.MagicValue = new int[GrannyGRNMagixValueCount]; |
21 |
|
|
this.Reserved = new int[GrannyGRNReservedCount]; |
22 |
|
|
|
23 |
|
|
for (int i = 0; i < GrannyGRNMagixValueCount; i++) { this.MagicValue[i] = 0; } |
24 |
|
|
for (int i = 0; i < GrannyGRNReservedCount; i++) { this.Reserved[i] = 0; } |
25 |
|
|
} |
26 |
|
|
|
27 |
|
|
internal static granny_magic ReadFromMemory(IntPtr pointer) |
28 |
|
|
{ |
29 |
|
|
try |
30 |
|
|
{ |
31 |
|
|
if (pointer == IntPtr.Zero) return null; |
32 |
|
|
gr2lib.core.coretypes.native.granny_grn_file_magic_value native = Helpers.ReadFromMemory<gr2lib.core.coretypes.native.granny_grn_file_magic_value>(pointer); |
33 |
|
|
granny_magic managed = ReadFromNative(native); |
34 |
|
|
managed.NativePointer = pointer; |
35 |
|
|
return managed; |
36 |
|
|
} |
37 |
|
|
catch (Exception ex) |
38 |
|
|
{ |
39 |
|
|
StackTrace st = new StackTrace(true); |
40 |
|
|
Console.WriteLine(st.ToString() + "\n\n" + "Stack Trace: \n" + ex.ToString()); |
41 |
|
|
return default(granny_magic); |
42 |
|
|
} |
43 |
|
|
} |
44 |
|
|
internal static granny_magic ReadFromNative(gr2lib.core.coretypes.native.granny_grn_file_magic_value native) |
45 |
|
|
{ |
46 |
|
|
try |
47 |
|
|
{ |
48 |
|
|
granny_magic managed = new granny_magic(); |
49 |
|
|
//process magic |
50 |
|
|
|
51 |
|
|
managed.MagicValue = native.MagicValue; |
52 |
|
|
managed.HeaderSize = native.HeaderSize; |
53 |
|
|
managed.HeaderFormat = native.HeaderFormat; |
54 |
|
|
managed.Reserved = native.Reserved; |
55 |
|
|
|
56 |
|
|
return managed; |
57 |
|
|
} |
58 |
|
|
catch (Exception ex) |
59 |
|
|
{ |
60 |
|
|
StackTrace st = new StackTrace(true); |
61 |
|
|
Console.WriteLine(st.ToString() + "\n\n" + "Stack Trace: \n" + ex.ToString()); |
62 |
|
|
return default(granny_magic); |
63 |
|
|
} |
64 |
|
|
} |
65 |
|
|
#region INativePointer Members |
66 |
|
|
private IntPtr _NativePointer; |
67 |
|
|
public IntPtr NativePointer { get { return _NativePointer; } set { _NativePointer = value; } } |
68 |
|
|
#endregion |
69 |
|
|
|
70 |
|
|
#region igranny_magic members |
71 |
|
|
|
72 |
|
|
private Int32[] _MagicValue; |
73 |
|
|
private Int32 _HeaderSize; |
74 |
|
|
private Int32 _HeaderFormat; |
75 |
|
|
private Int32[] _Reserved; |
76 |
|
|
|
77 |
|
|
public Int32[] MagicValue { get { return _MagicValue; } set { if (value.Length > GrannyGRNMagixValueCount) throw new InvalidOperationException("The size of MagicValue cannot be greater than " + GrannyGRNMagixValueCount); _MagicValue = value; } } // size 4 |
78 |
|
|
public Int32 HeaderSize { get { return _HeaderSize; } set { _HeaderSize = value; } } |
79 |
|
|
public Int32 HeaderFormat { get { return _HeaderFormat; } set { _HeaderFormat = value; } } |
80 |
|
|
public Int32[] Reserved { get { return _Reserved; } set { if (value.Length > GrannyGRNReservedCount) throw new InvalidOperationException("The size of Reserved cannot be greater than " + GrannyGRNReservedCount); _Reserved = value; } } // size 2 |
81 |
|
|
#endregion |
82 |
|
|
} |
83 |
|
|
} |