-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAcSmXml.cs
167 lines (149 loc) · 7.27 KB
/
AcSmXml.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Xml;
using System.ComponentModel;
namespace SheetSetManager
{
//Source http://www.theswamp.org/index.php?topic=46497.0
public class AcSmXml : XmlDocument
{
static readonly byte[] encode = new byte[] {
0x8C, 0x8F, 0x8E, 0x89, 0x88, 0x8B, 0x8A, 0x85, 0x84, 0x87, 0x86, 0x81, 0x80, 0x83, 0x82, 0x8D,
0xBC, 0xBF, 0xBE, 0xB9, 0xB8, 0xBB, 0xBA, 0xB5, 0xB4, 0xB7, 0xB6, 0xB1, 0xB0, 0xB3, 0xB2, 0xAD,
0xAC, 0xAF, 0xAE, 0xA9, 0xA8, 0xAB, 0xAA, 0xA5, 0xA4, 0xA7, 0xA6, 0xA1, 0xA0, 0xA3, 0xA2, 0xDD,
0xDC, 0xDF, 0xDE, 0xD9, 0xD8, 0xDB, 0xDA, 0xD5, 0xD4, 0xD7, 0xD6, 0xD1, 0xD0, 0xD3, 0xD2, 0xCD,
0xCC, 0xCF, 0xCE, 0xC9, 0xC8, 0xCB, 0xCA, 0xC5, 0xC4, 0xC7, 0xC6, 0xC1, 0xC0, 0xC3, 0xC2, 0xFD,
0xFC, 0xFF, 0xFE, 0xF9, 0xF8, 0xFB, 0xFA, 0xF5, 0xF4, 0xF7, 0xF6, 0xF1, 0xF0, 0xF3, 0xF2, 0xED,
0xEC, 0xEF, 0xEE, 0xE9, 0xE8, 0xEB, 0xEA, 0xE5, 0xE4, 0xE7, 0xE6, 0xE1, 0xE0, 0xE3, 0xE2, 0x1D,
0x1C, 0x1F, 0x1E, 0x19, 0x18, 0x1B, 0x1A, 0x15, 0x14, 0x17, 0x16, 0x11, 0x10, 0x13, 0x12, 0xD,
0xC, 0xF, 0xE, 0x9, 0x8, 0xB, 0xA, 0x5, 0x4, 0x7, 0x6, 0x1, 0x0, 0x3, 0x2, 0x3D,
0x3C, 0x3F, 0x3E, 0x39, 0x38, 0x3B, 0x3A, 0x35, 0x34, 0x37, 0x36, 0x31, 0x30, 0x33, 0x32, 0x2D,
0x2C, 0x2F, 0x2E, 0x29, 0x28, 0x2B, 0x2A, 0x25, 0x24, 0x27, 0x26, 0x21, 0x20, 0x23, 0x22, 0x5D,
0x5C, 0x5F, 0x5E, 0x59, 0x58, 0x5B, 0x5A, 0x55, 0x54, 0x57, 0x56, 0x51, 0x50, 0x3, 0x52, 0x4D,
0x4C, 0x4F, 0x4E, 0x49, 0x48, 0x4B, 0x4A, 0x45, 0x44, 0x47, 0x46, 0x41, 0x40, 0x43, 0x42, 0x7D,
0x7C, 0x7F, 0x7E, 0x79, 0x78, 0x7B, 0x7A, 0x75, 0x74, 0x77, 0x76, 0x71, 0x70, 0x73, 0x72, 0x6D,
0x6C, 0x6F, 0x6E, 0x69, 0x68, 0x6B, 0x6A, 0x65, 0x64, 0x67, 0x66, 0x61, 0x60, 0x63, 0x62, 0x9D,
0x9C, 0x9F, 0x9E, 0x99, 0x98, 0x9B, 0x9A, 0x95, 0x94, 0x97, 0x96, 0x91, 0x90, 0x93, 0x92, 0xFF
};
static readonly byte[] decode = new byte[] {
0x8c, 0x8b, 0x8e, 0x8d, 0x88, 0x87, 0x8a, 0x89, 0x84, 0x83, 0x86, 0x85, 0x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4d, 0x48, 0x47, 0x4a, 0x49, 0x44, 0x43, 0x46, 0x45, 0x40, 0x3f, 0x42, 0x41,
0x3c, 0x3b, 0x3e, 0x3d, 0x38, 0x37, 0x3a, 0x39, 0x34, 0x33, 0x36, 0x35, 0x30, 0x2f, 0x32, 0x31,
0x6c, 0x6b, 0x6e, 0x6d, 0x68, 0x67, 0x6a, 0x69, 0x64, 0x63, 0x66, 0x65, 0x60, 0x5f, 0x62, 0x61,
0x5c, 0x5b, 0x5e, 0x5d, 0x58, 0x57, 0x5a, 0x59, 0x54, 0x53, 0x56, 0x55, 0x50, 0x4f, 0x52, 0x51
};
public String filename;
private bool fread = false;
public void LoadFromDstFile(string nfilename)
{
if (!File.Exists(nfilename))
{
throw new FileNotFoundException();
}
//
filename = nfilename;
byte[] xmlSource = File.ReadAllBytes(Environment.ExpandEnvironmentVariables(filename));
var ms = new MemoryStream(DecryptFile(xmlSource));
base.Load(ms);
fread = true;
}
public void ReLoad()
{
if (!File.Exists(filename))
{
throw new FileNotFoundException();
}
//
byte[] xmlSource = File.ReadAllBytes(Environment.ExpandEnvironmentVariables(filename));
var ms = new MemoryStream(DecryptFile(xmlSource));
base.Load(ms);
fread = true;
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
if (worker.CancellationPending == true)
{
e.Cancel = true;
}
else
{
byte[] xmlSource = File.ReadAllBytes(Environment.ExpandEnvironmentVariables(filename));
worker.ReportProgress(0);
var ms = new MemoryStream(DecryptFile(xmlSource));
worker.ReportProgress(1);
base.Load(ms);
fread = true;
}
}
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
OnReadComplete(new EventArgs());
}
public void LoadAsyncFromDstFile()
{
fread = false;
if (!File.Exists(filename))
{
throw new FileNotFoundException();
}
//
BackgroundWorker backgroundWorker1 = new BackgroundWorker();
backgroundWorker1.WorkerReportsProgress = true;
backgroundWorker1.WorkerSupportsCancellation = true;
backgroundWorker1.DoWork += new DoWorkEventHandler(backgroundWorker1_DoWork);
backgroundWorker1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker1_RunWorkerCompleted);
backgroundWorker1.RunWorkerAsync();
}
public void SaveAsDstFile(string nfilename)
{
var ms = new MemoryStream();
this.Save(ms);
filename = nfilename;
File.WriteAllBytes(filename, EncryptFile(ms.ToArray()));
}
private static byte[] DecryptFile(IEnumerable<byte> bytes)
{
return bytes.Select(t => decode[t]).ToArray();
}
private static byte[] EncryptFile(IEnumerable<byte> bytes)
{
return bytes.Select(t => encode[t]).ToArray();
}
public static String CreateGuid()
{
return "g" + Guid.NewGuid().ToString().ToUpper();
}
public event EventHandler<EventArgs> ReadComplete;
public void OnReadComplete(EventArgs e)
{
EventHandler<EventArgs> handler = ReadComplete;
if (handler != null)
{
handler(this, e);
}
}
public bool isReady
{
get { return fread; }
set
{
fread = true;
OnReadComplete(new EventArgs());
}
}
}
}