-
Notifications
You must be signed in to change notification settings - Fork 1
/
Program.cs
871 lines (711 loc) · 35.2 KB
/
Program.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.IO;
using System.Xml.Serialization;
using System.Xml;
using System.Threading;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
namespace SC2Scrapbook
{
static class Program
{
static Mutex mutex = new Mutex(true, "{8f294ecd-7a0f-4a71-a76b-e32268fef2cf}");
internal static Models.Patch ActivePatch { get; set; }
internal static BuildCollection BuildsDB { get; set; }
internal static List<Models.Patch> PatchList { get; set; }
internal static string SCDirectory { get; set; }
internal static string DataDirectory { get; set; }
internal static bool Initialized { get; set; }
internal static Thread _sc2InteractionThread;
internal static System.Drawing.Rectangle SC2WindowRect;
internal static double xScale { get; set; }
internal static double yScale { get; set; }
internal static frmPlayerInfo PlayerInfoForm {get;set;}
internal static frmIngameBuildSelection IngameBuildSelectionForm { get; set; }
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
string sharecode = null;
string[] args = Environment.GetCommandLineArgs();
DataDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
string sc2Path = string.Format("{0}{1}StarCraft II", Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), Path.DirectorySeparatorChar);
if (Directory.Exists(sc2Path))
{
SCDirectory = sc2Path;
DataDirectory = string.Format("{0}{1}Scrapbook", sc2Path, Path.DirectorySeparatorChar);
Directory.CreateDirectory(DataDirectory);
}
if (mutex.WaitOne(TimeSpan.Zero, true))
{
frmSplash.ShowSplash();
try
{
if (args.Length < 2)
{
var key = Microsoft.Win32.Registry.ClassesRoot.CreateSubKey("sc2bo");
key.SetValue("URL Protocol", "");
var commandKey = key.CreateSubKey("shell\\open\\command");
commandKey.SetValue("", string.Format("\"{0}\" \"%1\"", System.Reflection.Assembly.GetExecutingAssembly().Location));
commandKey.Close();
key.Close();
}
else
{
if (args[1].ToLower().StartsWith("sc2bo://"))
{
sharecode = args[1].Substring(8);
}
}
}
catch { }
SC2WindowRect = new System.Drawing.Rectangle();
LoadPatchData();
LoadConfigurationXML();
LoadBuildsXML();
if (Configuration.Instance.UseAdvancedOptions)
StartSC2InteractionThread();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new frmMain(sharecode));
mutex.ReleaseMutex();
}
else
{
if (args.Length < 2)
{
Win32.PostMessage((IntPtr)Win32.HWND_BROADCAST, Win32.WM_SHOWBON, IntPtr.Zero, IntPtr.Zero);
}
else
{
if (args[1].ToLower().StartsWith("sc2bo://"))
{
// Yes, this is bad. But trying to SendMessage a COPYDATASTRUCT is much worse.
File.WriteAllText(string.Format("{0}\\{1}.import", DataDirectory, new Random().Next()), args[1].Substring(8));
Win32.PostMessage((IntPtr)Win32.HWND_BROADCAST, Win32.WM_BONIMPORT, IntPtr.Zero, IntPtr.Zero);
}
}
}
}
internal static void StartSC2InteractionThread()
{
if (_sc2InteractionThread != null)
KillSC2InteractionThread();
_sc2InteractionThread = new Thread(new ThreadStart(SC2InteractionThreadWorker));
_sc2InteractionThread.Start();
}
internal static void KillSC2InteractionThread()
{
if (_sc2InteractionThread != null)
{
_sc2InteractionThread.Abort();
HideBuildSelection();
HideOverlay();
HidePlayerInfo();
}
}
internal static void ShowPlayerInfo(Models.Player player)
{
if (frmMain.Instance.InvokeRequired)
{
frmMain.Instance.BeginInvoke(new Action<Models.Player>(ShowPlayerInfo), player);
}
else
{
if (PlayerInfoForm != null)
PlayerInfoForm.Dispose();
PlayerInfoForm = new frmPlayerInfo(player);
PlayerInfoForm.Show();
}
}
internal static void HidePlayerInfo()
{
if (frmMain.Instance.InvokeRequired)
{
frmMain.Instance.BeginInvoke(new Action(HidePlayerInfo));
}
else
{
if (PlayerInfoForm != null)
{
PlayerInfoForm.Animator.Direction = FormAnimator.AnimationDirection.Left;
PlayerInfoForm.Close();
}
}
}
internal static void ShowBuildSelection()
{
if (frmMain.Instance.InvokeRequired)
{
frmMain.Instance.BeginInvoke(new Action(ShowBuildSelection));
}
else
{
if (IngameBuildSelectionForm != null)
IngameBuildSelectionForm.Dispose();
IngameBuildSelectionForm = new frmIngameBuildSelection();
#if DEBUG
IngameBuildSelectionForm.Top = 0;
IngameBuildSelectionForm.Left = 0;
#else
IngameBuildSelectionForm.Top = SC2WindowRect.Top + (SC2WindowRect.Height - IngameBuildSelectionForm.Height - 20);
IngameBuildSelectionForm.Left = SC2WindowRect.Left + ((SC2WindowRect.Width / 2) - IngameBuildSelectionForm.Width / 2);
#endif
IngameBuildSelectionForm.Show();
}
}
internal static void HideBuildSelection()
{
if (frmMain.Instance.InvokeRequired)
{
frmMain.Instance.BeginInvoke(new Action(HideBuildSelection));
}
else
{
if (IngameBuildSelectionForm != null)
{
IngameBuildSelectionForm.Close();
IngameBuildSelectionForm = null;
}
}
}
internal static void HideOverlay()
{
if (frmMain.Instance.InvokeRequired)
{
frmMain.Instance.BeginInvoke(new Action(HideOverlay));
}
else
{
if (frmBuildOverlay.Instance != null)
{
frmBuildOverlay.Instance.Close();
frmBuildOverlay.Instance = null;
}
}
}
private static string ReadBufferToNull(byte[] buffer, int start, int length)
{
int len = start;
for (int i = 0; i < length; i++)
{
if (buffer[i] == 0)
{
break;
}
len++;
}
return Encoding.UTF8.GetString(buffer, 0, len);
}
private static string GetProfileFromID(string name, string id)
{
Match match = Regex.Match(id, @"(\d)-S2-(\d)-(\d+)");
// Region-Game-Generation/Expo-ID
// I've observed that Generation/Expo is usually 1 or 2. From my observations on NA and KR,
// Generation has been 1 for NA and KR players, and 2 for LA and TW players.
// Not really relevant, but interesting.
if (match.Success)
{
int region = int.Parse(match.Groups[1].Value);
string domain = "";
string language = "";
switch (region)
{
case 1:
domain = "us.battle.net";
language = "en";
break;
case 2:
domain = "eu.battle.net";
language = "en";
break;
case 3:
domain = "kr.battle.net";
language = "kr";
break;
case 5:
domain = "www.battlenet.com.cn";
language = "cn";
break;
case 6:
domain = "sea.battle.net";
language = "en";
break;
default:
return null;
//What region is 4? LA or TW maybe.
}
return string.Format("http://{0}/sc2/{1}/profile/{2}/{3}/{4}/", domain, language, match.Groups[3].Value, match.Groups[2].Value, name);
}
else
{
return null;
// Should probably do something meaningful here, since we're likely boned.
}
}
internal static Models.Player GetPlayer(string name, string id)
{
string url = GetProfileFromID(name, id);
if (string.IsNullOrEmpty(url))
return null;
try
{
System.Net.WebClient client = new System.Net.WebClient();
string data = client.DownloadString(url);
int initPos = data.IndexOf(@"<h3 class=""title-globe"">");
int boundary = -1;
int pos = initPos;
int pos2 = -1;
if (pos == -1)
return null;
string race = "";
pos = data.IndexOf(@"<div class=""module-body snapshot-", initPos);
if (pos == -1)
race = "random";
else
{
pos += 33;
pos2 = data.IndexOf(@"""", pos);
race = data.Substring(pos, pos2 - pos);
}
Models.Player.PortraitData portrait = null;
pos = data.IndexOf(@"<span class=""icon-frame """);
if (pos > -1)
{
pos = data.IndexOf(@"style=""", pos);
if (pos > -1)
{
pos += 7;
pos2 = data.IndexOf('"', pos);
string style = data.Substring(pos, pos2 - pos);
Match match = Regex.Match(style, @".*background: url\('(.*)'\) \-?(\d+)px \-?(\d+)px.*");
if (match.Success)
{
Uri uri = new Uri(url);
uri = new Uri(string.Format("http://{0}{1}", uri.Host, match.Groups[1].Value));
string localFile = string.Format(@"{0}\PortraitCache\{1}\{2}", Program.DataDirectory, uri.Query.Trim('?'), Path.GetFileName(uri.LocalPath));
if (!File.Exists(localFile))
{
try
{
Directory.CreateDirectory(Path.GetDirectoryName(localFile));
client.DownloadFile(uri, localFile);
}
catch { localFile = null; }
}
if (localFile != null)
{
portrait = new Models.Player.PortraitData(localFile, int.Parse(match.Groups[2].Value), int.Parse(match.Groups[3].Value), 90, 90);
}
}
}
}
url = string.Format("{0}ladder/leagues", url);
data = client.DownloadString(url);
string league = "none";
int rank = 0;
int wins = -1;
int losses = -1;
int points = -1;
if (data.Contains("<title>1v1"))
{
try
{
pos = data.IndexOf(@"<span class=""badge badge-", pos);
if ((pos == -1) || pos > boundary)
league = "none";
else
{
pos += 25;
pos2 = data.IndexOf(@" badge", pos);
league = data.Substring(pos, pos2 - pos);
}
initPos = data.IndexOf("id=\"current-rank");
boundary = data.IndexOf("<tr", initPos);
pos = data.IndexOf("<td", initPos);
pos = data.IndexOf("<td", pos + 3);
pos = data.IndexOf(">", pos);
if ((pos == -1))
rank = 0;
else
{
pos += 1;
pos2 = data.IndexOf('<', pos);
if (!int.TryParse(Regex.Replace(data.Substring(pos, pos2 - pos).Trim('\r'), @"\D", "", RegexOptions.IgnoreCase), out rank))
rank = 0;
}
if (rank > 0)
{
pos = data.IndexOf(@"<a href=""", initPos);
if (pos > -1)
{
pos += 9;
if (pos < boundary)
{
pos2 = data.IndexOf(@""">", pos);
string ladderPath = data.Substring(pos, pos2 - pos);
Uri uri = new Uri(url);
uri = new Uri(string.Format("http://{0}{1}", uri.Host, ladderPath));
try
{
string ladderData = data;
pos = ladderData.IndexOf(@"id=""current-rank"">");
if (pos > -1)
{
int ladderBoundary = ladderData.IndexOf("</tr>", pos);
if (ladderBoundary > -1)
{
pos = ladderData.IndexOf(@"<td class=""align-center"">", pos);
if (pos > -1 && pos < ladderBoundary)
{
pos += 25;
pos2 = ladderData.IndexOf("</td>", pos);
if (!int.TryParse(ladderData.Substring(pos, pos2 - pos), out points))
{
points = -1;
}
pos = ladderData.IndexOf(@"<td class=""align-center"">", pos2);
if (pos > -1 && pos < ladderBoundary)
{
pos += 25;
pos2 = ladderData.IndexOf("</td>", pos);
if (!int.TryParse(ladderData.Substring(pos, pos2 - pos), out wins))
{
wins = -1;
}
pos = ladderData.IndexOf(@"<td class=""align-center"">", pos2);
if (pos > -1 && pos < ladderBoundary)
{
pos += 25;
pos2 = ladderData.IndexOf("</td>", pos);
if (!int.TryParse(ladderData.Substring(pos, pos2 - pos), out losses))
{
losses = -1;
}
}
}
}
}
}
}
catch { }
}
}
}
}
catch { }
}
return new Models.Player(name, race, league, rank, points, wins, losses, portrait);
}
catch { return null; }
}
internal static void SC2InteractionThreadWorker()
{
try
{
var processNames = new string[] { "SC2_X64", "SC2" };
while (true)
{
Process sc2Process = null;
while (sc2Process == null)
{
if (!Configuration.Instance.UseAdvancedOptions)
throw new Exception();
System.Threading.Thread.Sleep(100);
foreach (var name in processNames)
{
Process[] processes = Process.GetProcessesByName(name);
foreach (Process p in processes)
{
if (!p.HasExited)
{
if (p.MainWindowTitle == "StarCraft II")
{
sc2Process = p;
}
}
}
if (sc2Process != null)
{
break;
}
}
}
byte[] buffer = new byte[256];
int read;
bool inGame = false;
bool tabbed = false;
string game_player_1 = null;
string game_player_1_id = null;
string game_player_2 = null;
string game_player_2_id = null;
while (!sc2Process.HasExited)
{
if (!Configuration.Instance.UseAdvancedOptions)
throw new Exception();
if (Program.ActivePatch != null)
{
if (sc2Process.MainWindowHandle == IntPtr.Zero || !Win32.IsWindow(sc2Process.MainWindowHandle))
{
inGame = false;
Debug.WriteLine("SC2 main window gone.");
HidePlayerInfo();
HideBuildSelection();
HideOverlay();
}
Win32.RECT rct;
Win32.GetWindowRect(sc2Process.MainWindowHandle, out rct);
SC2WindowRect.X = rct.Left;
SC2WindowRect.Y = rct.Top;
SC2WindowRect.Width = rct.Right - rct.Left;
SC2WindowRect.Height = rct.Bottom - rct.Top;
yScale = (double)Program.SC2WindowRect.Height / (double)720;
xScale = (double)Program.SC2WindowRect.Width / (double)1280;
//Console.WriteLine(Thread.CurrentThread.ManagedThreadId);
if (!inGame)
{
bool result = Win32.ReadProcessMemory(sc2Process.Handle, Program.ActivePatch.Ptr1, buffer, 256, out read);
if (result)
{
if (buffer[0] != 0)
{
game_player_1 = ReadBufferToNull(buffer, 0, read);
Win32.ReadProcessMemory(sc2Process.Handle, Program.ActivePatch.Ptr1 + Program.ActivePatch.Ptr1Size, buffer, 256, out read);
game_player_2 = ReadBufferToNull(buffer, 0, read);
Win32.ReadProcessMemory(sc2Process.Handle, Program.ActivePatch.Ptr2, buffer, 256, out read);
game_player_1_id = ReadBufferToNull(buffer, 0, read);
Win32.ReadProcessMemory(sc2Process.Handle, Program.ActivePatch.Ptr2 + Program.ActivePatch.Ptr2Size, buffer, 256, out read);
game_player_2_id = ReadBufferToNull(buffer, 0, read);
if (string.IsNullOrEmpty(game_player_1_id) && (string.IsNullOrEmpty(game_player_2_id)))
{
Debug.WriteLine("AI Showmatch?");
}
else if (!string.IsNullOrEmpty(game_player_1_id) && (string.IsNullOrEmpty(game_player_2_id)))
{
Debug.WriteLine(string.Format("Now in game: {0} @ {1} ({2})", game_player_1, game_player_1_id, GetProfileFromID(game_player_1, game_player_1_id)));
Debug.WriteLine("Now in game: AI?");
if (Configuration.Instance.BuildSelectionOverlay)
{
ShowBuildSelection();
}
}
else
{
Debug.WriteLine(string.Format("Now in game: {0} @ {1} ({2})", game_player_1, game_player_1_id, GetProfileFromID(game_player_1, game_player_1_id)));
Debug.WriteLine(string.Format("Now in game: {0} @ {1} ({2})", game_player_2, game_player_2_id, GetProfileFromID(game_player_2, game_player_2_id)));
if (Configuration.Instance.OpponentInfoOverlay)
{
Models.Player player = null;
if (game_player_1.ToLower() == Configuration.Instance.MySC2Character.ToLower())
{
player = GetPlayer(game_player_2, game_player_2_id);
}
else
{
player = GetPlayer(game_player_1, game_player_1_id);
}
ShowPlayerInfo(player);
}
if (Configuration.Instance.BuildSelectionOverlay)
{
ShowBuildSelection();
}
}
inGame = true;
}
}
}
else
{
bool result = Win32.ReadProcessMemory(sc2Process.Handle, Program.ActivePatch.Ptr1, buffer, 256, out read);
if (!result)
{
inGame = false;
}
else
{
if (buffer[0] == 0)
{
inGame = false;
Debug.WriteLine("Now out of game.");
HidePlayerInfo();
HideBuildSelection();
HideOverlay();
}
else
{
IntPtr fgw = Win32.GetForegroundWindow();
if (tabbed)
{
if (fgw == sc2Process.MainWindowHandle)
{
tabbed = false;
Debug.WriteLine("Tabbed in");
if (frmPlayerInfo.Instance != null)
{
frmPlayerInfo.Instance.ShowNoActivate();
}
}
}
else
{
if (fgw != sc2Process.MainWindowHandle)
{
tabbed = true;
Debug.WriteLine("Tabbed out");
if (frmPlayerInfo.Instance != null)
{
frmPlayerInfo.Instance.HideWindow();
}
}
}
}
}
}
}
System.Threading.Thread.Sleep(500);
}
inGame = false;
Debug.WriteLine("Process exited");
HidePlayerInfo();
HideBuildSelection();
HideOverlay();
}
}
catch
{
HidePlayerInfo();
HideBuildSelection();
_sc2InteractionThread = null;
}
}
internal static void LoadDefaultBuilds()
{
System.Net.WebClient client = new System.Net.WebClient();
try
{
client.DownloadFile("https://bitbucket.org/Veritasimo/sc2-scrapbook/downloads/builds.xml", string.Format("{0}{1}{2}", DataDirectory, Path.DirectorySeparatorChar, "builds.xml"));
if (!File.ReadAllText(string.Format("{0}{1}{2}", DataDirectory, Path.DirectorySeparatorChar, "builds.xml")).StartsWith("<?xml"))
{
throw new XmlException();
}
}
catch {
try
{
File.WriteAllText(string.Format("{0}{1}{2}", DataDirectory, Path.DirectorySeparatorChar, "builds.xml"), Properties.Resources.builds);
}
catch (Exception ex)
{
// shit, son.
MessageBox.Show("Failed to save the build defaults. Something is probably wrong here. {0}", ex.ToString());
}
}
}
internal static void LoadPatchData()
{
XmlDocument document = new XmlDocument();
ActivePatch = null;
PatchList = new List<Models.Patch>();
try
{
System.Net.WebClient c = new System.Net.WebClient();
c.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore);
string data = c.DownloadString("https://bitbucket.org/Veritasimo/sc2-scrapbook/downloads/patch.xml");
document.LoadXml(data);
}
catch
{
try
{
document.LoadXml(Properties.Resources.patch);
}
catch (Exception ex)
{
document = null;
}
}
if (document == null)
{
MessageBox.Show("The patch data couldn't load. There's probably a horrific error with the XML file. Tell someone in charge.");
return;
}
XmlNodeList nodes = document.GetElementsByTagName("Patch");
foreach (XmlNode node in nodes)
{
PatchList.Add(new Models.Patch(node.Attributes["Version"].Value, (IntPtr)int.Parse(node.Attributes["Ptr1"].Value, System.Globalization.NumberStyles.HexNumber), (IntPtr)int.Parse(node.Attributes["Ptr2"].Value, System.Globalization.NumberStyles.HexNumber), int.Parse(node.Attributes["Size1"].Value, System.Globalization.NumberStyles.HexNumber), int.Parse(node.Attributes["Size2"].Value, System.Globalization.NumberStyles.HexNumber)));
}
if (PatchList.Count > 0)
ActivePatch = PatchList[0];
}
internal static void LoadBuildsXML()
{
XmlSerializer serializer = new XmlSerializer(typeof(BuildCollection));
if (!File.Exists(string.Format("{0}{1}{2}", DataDirectory, Path.DirectorySeparatorChar, "builds.xml")))
LoadDefaultBuilds();
if (File.Exists(string.Format("{0}{1}{2}", DataDirectory, Path.DirectorySeparatorChar, "builds.xml")))
{
XmlReader reader = XmlReader.Create(string.Format("{0}{1}{2}", DataDirectory, Path.DirectorySeparatorChar, "builds.xml"));
BuildsDB = (BuildCollection)serializer.Deserialize(reader);
reader.Close();
}
else
{
BuildsDB = new BuildCollection();
SaveBuildsXML();
}
}
internal static void SaveBuildsXML()
{
XmlSerializer serializer = new XmlSerializer(typeof(BuildCollection));
XmlWriterSettings xws = new XmlWriterSettings();
xws.Indent = true;
xws.IndentChars = "\t";
xws.NewLineHandling = NewLineHandling.Entitize;
XmlWriter writer = XmlWriter.Create(string.Format("{0}{1}{2}", DataDirectory, Path.DirectorySeparatorChar, "builds.xml"), xws);
serializer.Serialize(writer, BuildsDB);
writer.Close();
}
internal static void LoadConfigurationXML()
{
XmlSerializer configSerializer = new XmlSerializer(typeof(Configuration));
if (File.Exists(string.Format("{0}{1}{2}", DataDirectory, Path.DirectorySeparatorChar, "config.xml")))
{
XmlReader reader = XmlReader.Create(string.Format("{0}{1}{2}", DataDirectory, Path.DirectorySeparatorChar, "config.xml"));
Configuration.Instance = (Configuration)configSerializer.Deserialize(reader);
Configuration.Instance.FirstRun = false;
reader.Close();
}
else
{
Configuration.Instance = new Configuration();
Configuration.Instance.FirstRun = true;
Configuration.Instance.OverlayContentFont = "Arial";
Configuration.Instance.OverlayTitleFont = "Arial";
Configuration.Instance.OverlayTitleSize = 24.0f;
Configuration.Instance.OverlayContentSize = 16.0f;
Configuration.Instance.OverlayTextColour = System.Drawing.Color.FromArgb(255, 255, 255);
Configuration.Instance.OverlayTextOutlineColour = System.Drawing.Color.FromArgb(255, 0, 128, 192);
Configuration.Instance.OverlayTextOutlineSize = 1;
Configuration.Instance.OverlayImageScale = 2;
}
}
internal static void SaveConfigurationXML()
{
XmlSerializer configSerializer = new XmlSerializer(typeof(Configuration));
XmlWriterSettings xws = new XmlWriterSettings();
xws.Indent = true;
xws.IndentChars = "\t";
xws.NewLineHandling = NewLineHandling.Entitize;
XmlWriter writer = XmlWriter.Create(string.Format("{0}{1}{2}", DataDirectory, Path.DirectorySeparatorChar, "config.xml"), xws);
configSerializer.Serialize(writer, Configuration.Instance);
writer.Close();
}
}
}