-
Notifications
You must be signed in to change notification settings - Fork 0
/
ByteBlock.cs
113 lines (91 loc) · 3.19 KB
/
ByteBlock.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OpenPGPExplorer
{
public delegate void ByteBlockProcess();
public delegate void StatusUpdates(string Message, int Percent = -1);
public delegate void ErrorDelegate(string Message, bool Reset);
public class ByteBlock
{
public string Label { get; set; }
public string Description { get; set; }
public byte[] RawBytes { get; set; }
public long Position { get; set; }
public ByteBlockType Type { get; set; }
public ByteBlock NextBlock { get; private set; }
public ByteBlock ChildBlock { get; private set; }
public ByteBlockProcess ProcessBlock;
public StatusUpdates StatusUpdate;
public ByteBlock()
{
}
//public void ClearMessageBlocks()
//{
// var Next = NextBlock;
// var PrevBlock = NextBlock;
// while(Next != null)
// {
// if (Next.Type == ByteBlockType.MessageBlock)
// PrevBlock.NextBlock = Next.NextBlock;
// else
// PrevBlock = Next.NextBlock;
// Next = PrevBlock;
// }
//}
public ByteBlock(string Label, string Description, long Position, byte[] RawBytes)
{
this.Label = Label;
this.Description = Description;
this.Position = Position;
this.RawBytes = RawBytes;
}
public ByteBlock AddBlock(ByteBlock NewBlock)
{
var LastBlock = NextBlock;
var PreviousBlock = NextBlock;
while (LastBlock != null)
{
PreviousBlock = LastBlock;
LastBlock = LastBlock.NextBlock;
}
if (PreviousBlock == null)
NextBlock = NewBlock;
else
PreviousBlock.NextBlock = NewBlock;
return NewBlock;
}
public ByteBlock AddBlock(string Label, string Description, long Position, byte[] RawBytes, ByteBlockType Type = ByteBlockType.Normal)
{
var NewBlock = new ByteBlock(Label, Description, Position, RawBytes);
NewBlock.Type = Type;
return AddBlock(NewBlock);
}
public ByteBlock AddChildBlock(string Label, string Description, long Position, byte[] RawBytes)
{
var NewBlock = new ByteBlock(Label, Description, Position, RawBytes);
return AddChildBlock(NewBlock);
}
public ByteBlock AddChildBlock(ByteBlock block)
{
var LastBlock = ChildBlock;
var PreviousBlock = ChildBlock;
while (LastBlock != null)
{
PreviousBlock = LastBlock;
LastBlock = LastBlock.NextBlock;
}
if (PreviousBlock == null)
ChildBlock = block;
else
PreviousBlock.NextBlock = block;
return block;
}
}
public enum ByteBlockType
{
Normal, TooBig, Calculated, CalculatedError, CalculatedSuccess
}
}