-
Notifications
You must be signed in to change notification settings - Fork 8
/
Program.cs
2673 lines (2330 loc) · 144 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
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Xml;
using System.Globalization;
using System.Text.RegularExpressions;
using System.Text;
using System.Drawing;
namespace SatellaWave
{
static class Program
{
/// <summary>
/// Point d'entrée principal de l'application.
/// </summary>
public static MainWindow mainWindow;
public static string lastSavedXMLFile = "";
public static byte lastExportID = 0;
public static string lastExportDirectory = "";
public static readonly string[] buildingList = {
"Robot Tower",
"News Wall",
"Broadcast Station",
"Burger Shop",
"Police Box",
"Calculator Building",
"Beach House (Shop)",
"Stadium",
"Convenience Center (Shop)",
"Girls School",
"Game Factory",
"Department Store",
"Game Museum",
"Abacus Building",
"Tofu Hall",
"Event Plaza",
"Bagpotamia Temple",
"Celebrity House",
"Private House",
"Telephone Booth",
"Sewerage (Shop)"
};
public static readonly string[] peopleList =
{
"[Coconut at the Beach]",
"Dr. Hiroshi",
"Dororin",
"Hikari Ota (Bakusho Mondai)",
"Yuji Tanaka (Bakusho Mondai)",
"Ghost",
"Otakuman",
"Gorou",
"Samson",
"Gozen Reiji",
"Tamotsu Sekishita",
"Mr. Arai",
"Rinzo Charikawa",
"Star Rarawo",
"Manbei",
"Kenichi",
"Youta",
"MIO",
"MIO (School Uniform)",
"Reiko",
"Marina",
"Akane",
"Mako",
"Midori",
"Suzu Charikawa",
"Ms. Sera",
"Secretary Akiko",
"Tomoko Shirase",
"Yuka Tsutsumi",
"Ina Sanda",
"Fortuneteller Miki",
"Asaji Kayo",
"Kimono Girl",
"Ikebe",
"Ms. Ochiyo",
"Old Woman",
"Tell",
"Sachiko",
"Akiko",
"Rocky (Dog)",
"Jitsu Hyoue (Cat)",
"Quack (Duck)",
"TeeVee",
"Wide TeeVee",
"[Custom Script 1]",
"[Custom Script 2]"
};
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
mainWindow = new MainWindow();
Application.Run(mainWindow);
}
public static void NewRepository()
{
//New repository needs Town Status and Directory at least
mainWindow.treeViewChn.Nodes.Clear();
AddChannel(1);
AddChannel(2);
lastSavedXMLFile = "";
lastExportID = 0;
mainWindow.setTitle("");
}
public static void AddChannel(Channel _chn)
{
TreeNode _node = new TreeNode(_chn.name + " (" + _chn.GetChannelNumberString() + ")");
_node.Tag = _chn;
if (_chn.GetType() != typeof(Directory))
_node.ContextMenuStrip = mainWindow.contextMenuStripChannelMenu;
else
_node.ContextMenuStrip = mainWindow.contextMenuStripDirectoryMenu;
mainWindow.treeViewChn.Nodes.Add(_node);
mainWindow.treeViewChn.SelectedNode = _node;
}
public static void AddChannel(int type)
{
if (type == 0)
{
//BS-X - Welcome Message (1.1.0.4)
//Check if already present
if (CheckUsedChannel("1.1.0.4"))
{
MessageBox.Show("There is already a BS-X Message Channel (1.1.0.4).", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
MessageChannel _msg = new MessageChannel(0x0101, 0x0004, "Welcome Message", GetNextLCI(), "");
AddChannel(_msg);
}
else if(type == 1)
{
//BS-X - Town Status (1.1.0.5)
//Check if already present
if (CheckUsedChannel("1.1.0.5"))
{
MessageBox.Show("There is already a BS-X Town Status Channel (1.1.0.5).", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
TownStatus _town = new TownStatus(0x0101, 0x0005, "Town Status", GetNextLCI());
AddChannel(_town);
}
else if (type == 2)
{
//BS-X - Directory (1.1.0.6)
//Check if already present
if (CheckUsedChannel("1.1.0.6"))
{
MessageBox.Show("There is already a BS-X Directory Channel (1.1.0.6).", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
Directory _dir = new Directory(0x0101, 0x0006, "Directory", GetNextLCI());
AddChannel(_dir);
}
else if (type == 3)
{
//BS-X - Patch (1.1.0.7)
//Check if already present
if (CheckUsedChannel("1.1.0.7"))
{
MessageBox.Show("There is already a BS-X Patch Channel (1.1.0.7).", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
Patch _patch = new Patch(0x0101, 0x0007, "Patch", GetNextLCI());
AddChannel(_patch);
}
else if (type == 4)
{
//BS-X - Time Channel (1.1.0.8)
if (CheckUsedChannel("1.1.0.8"))
{
MessageBox.Show("There is already a BS-X Time Channel (1.1.0.8).", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
Channel _time = new Channel(0x0101, 0x0008, "Time Channel [BS-X]", 0x0000);
AddChannel(_time);
}
else if (type == 5)
{
//Game - Time Channel (1.2.0.48)
if (CheckUsedChannel("1.2.0.48"))
{
MessageBox.Show("There is already a Game Time Channel (1.2.0.48).", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
Channel _time = new Channel(0x0102, 0x0030, "Time Channel [Game]", 0x0000);
AddChannel(_time);
}
else if (type == 6)
{
//Itoi Shigesato no Bass Tsuri No. 1 - Contest 1 (1.2.130.0)
if (CheckUsedChannel("1.2.130.0"))
{
MessageBox.Show("There is already a Itoi Shigesato no Bass Tsuri No. 1 - Contest 1 Channel (1.2.130.0).", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
Channel _contest = new Channel(0x0102, 0x8200, "Itoi Shigesato no Bass Tsuri No. 1 - Contest 1", 0x0000);
AddChannel(_contest);
}
else if (type == 7)
{
//Itoi Shigesato no Bass Tsuri No. 1 - Contest 2 (1.2.130.16)
if (CheckUsedChannel("1.2.130.16"))
{
MessageBox.Show("There is already a Itoi Shigesato no Bass Tsuri No. 1 - Contest 2 Channel (1.2.130.16).", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
Channel _contest = new Channel(0x0102, 0x8210, "Itoi Shigesato no Bass Tsuri No. 1 - Contest 2", 0x0000);
AddChannel(_contest);
}
else if (type == 8)
{
//Itoi Shigesato no Bass Tsuri No. 1 - Contest 3 (1.2.130.32)
if (CheckUsedChannel("1.2.130.32"))
{
MessageBox.Show("There is already a Itoi Shigesato no Bass Tsuri No. 1 - Contest 3 Channel (1.2.130.32).", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
Channel _contest = new Channel(0x0102, 0x8220, "Itoi Shigesato no Bass Tsuri No. 1 - Contest 3", 0x0000);
AddChannel(_contest);
}
else if (type == 9)
{
//Itoi Shigesato no Bass Tsuri No. 1 - Contest 4 (1.2.130.48)
if (CheckUsedChannel("1.2.130.48"))
{
MessageBox.Show("There is already a Itoi Shigesato no Bass Tsuri No. 1 - Contest 4 Channel (1.2.130.48).", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
Channel _contest = new Channel(0x0102, 0x8230, "Itoi Shigesato no Bass Tsuri No. 1 - Contest 4", 0x0000);
AddChannel(_contest);
}
}
public static void AddExpansionPlaza(TreeNode _node)
{
if (_node.Tag.GetType() == typeof(Directory))
{
foreach (TreeNode _temp in _node.Nodes)
{
if (_temp.Tag.GetType() == typeof(EventPlaza))
{
MessageBox.Show("There is already an Event Plaza Expansion. You cannot have an extra one.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
EventPlaza _eventplaza = new EventPlaza();
TreeNode _tnode = new TreeNode("Expansion - Event Plaza");
_tnode.Tag = _eventplaza;
_tnode.ContextMenuStrip = mainWindow.contextMenuStripEventPlazaMenu;
_node.Nodes.Add(_tnode);
mainWindow.treeViewChn.SelectedNode = _tnode;
}
}
public static void AddFolder(TreeNode _node)
{
if (_node.Tag.GetType() == typeof(Directory))
{
Folder _folder = new Folder();
TreeNode _tnode = new TreeNode(_folder.name);
_tnode.Tag = _folder;
_tnode.ContextMenuStrip = mainWindow.contextMenuStripFolderMenu;
_node.Nodes.Add(_tnode);
mainWindow.treeViewChn.SelectedNode = _tnode;
}
}
public static void AddFile(TreeNode _node)
{
if (_node.Tag.GetType() == typeof(Folder))
{
if (_node.Nodes.Count >= 10)
{
MessageBox.Show("Reached the file limit for this folder.\nCannot add any more files.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if ((_node.Tag as Folder).purpose == 1)
{
//Shop
bool canAdd = true;
if ((_node.Tag as Folder).type == 0)
{
//Building
if ((_node.Tag as Folder).id == 6)
{
//Beach House
if (_node.Nodes.Count >= (10 - 3))
{
canAdd = false;
}
}
else if((_node.Tag as Folder).id == 8)
{
//Convenience Center
if (_node.Nodes.Count >= (10 - 8))
{
canAdd = false;
}
}
else if ((_node.Tag as Folder).id == 20)
{
//Sewerage
if (_node.Nodes.Count >= (10 - 4))
{
canAdd = false;
}
}
}
else
{
//NPC
if ((_node.Tag as Folder).id == 1)
{
//Dr. Hiroshi
if (_node.Nodes.Count >= (10 - 2))
{
canAdd = false;
}
}
}
if (!canAdd)
{
MessageBox.Show("Reached the item limit for this folder.\nCannot add any more items.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
DownloadFile _file = new DownloadFile((_node.Tag as Folder).purpose == 1, GetNextFileID());
_file.lci = GetNextLCI();
_file.program_number = GetNextProgramNumber();
_file.service_broadcast = 0x0103; //Dedicated to content, more than enough
TreeNode _tnode = new TreeNode(_file.name);
_tnode.Tag = _file;
_tnode.ContextMenuStrip = mainWindow.contextMenuStripFileMenu;
_node.Nodes.Add(_tnode);
mainWindow.treeViewChn.SelectedNode = _tnode;
}
else if (_node.Tag.GetType() == typeof(DownloadFile))
{
DownloadFile _file = new DownloadFile((_node.Tag as DownloadFile).isItem, (_node.Tag as DownloadFile).fileID);
_file.lci = GetNextLCI();
_file.program_number = (_node.Tag as DownloadFile).program_number;
_file.service_broadcast = (_node.Tag as DownloadFile).service_broadcast; //Dedicated to content, more than enough
while (CheckUsedChannel(_file.GetChannelNumberString()))
{
_file.program_number += 1;
}
TreeNode _tnode = new TreeNode(_file.name);
_tnode.Tag = _file;
_tnode.ContextMenuStrip = mainWindow.contextMenuStripChannelMenu;
_node.Nodes.Add(_tnode);
mainWindow.treeViewChn.SelectedNode = _tnode;
}
}
public static bool CheckUsedChannel(string _chnNumber)
{
foreach (TreeNode _node in mainWindow.treeViewChn.Nodes)
{
if (_node.Tag.GetType() == typeof(Directory))
{
if ((_node.Tag as Channel).GetChannelNumberString() == _chnNumber)
{
return true;
}
//Check Folders
foreach (TreeNode _nodeChildFolder in _node.Nodes)
{
if (_nodeChildFolder.Tag.GetType() == typeof(Folder))
{
//Check Files
foreach (TreeNode _nodeFile in _nodeChildFolder.Nodes)
{
if ((_nodeFile.Tag as DownloadFile).GetChannelNumberString() == _chnNumber)
{
return true;
}
if (_nodeFile.Nodes.Count > 0)
{
//Check Include Files if they exist
foreach (TreeNode _nodeIncFile in _nodeFile.Nodes)
{
if ((_nodeIncFile.Tag as DownloadFile).GetChannelNumberString() == _chnNumber)
{
return true;
}
}
}
}
}
}
}
else
{
if ((_node.Tag as Channel).GetChannelNumberString() == _chnNumber)
{
return true;
}
}
}
return false;
}
public static bool CheckUsedChannel(string _chnNumber, TreeNode _ignore)
{
foreach (TreeNode _node in mainWindow.treeViewChn.Nodes)
{
if (!_node.Equals(_ignore))
{
if (_node.Tag.GetType() == typeof(Directory))
{
if ((_node.Tag as Channel).GetChannelNumberString() == _chnNumber)
{
return true;
}
//Check Folders
foreach (TreeNode _nodeChildFolder in _node.Nodes)
{
if (_nodeChildFolder.Tag.GetType() == typeof(Folder))
{
//Check Files
foreach (TreeNode _nodeFile in _nodeChildFolder.Nodes)
{
if ((_nodeFile.Tag as DownloadFile).GetChannelNumberString() == _chnNumber)
{
return true;
}
if (_nodeFile.Nodes.Count > 0)
{
//Check Include Files if they exist
foreach (TreeNode _nodeIncFile in _nodeFile.Nodes)
{
if ((_nodeIncFile.Tag as DownloadFile).GetChannelNumberString() == _chnNumber)
{
return true;
}
}
}
}
}
}
}
else
{
if ((_node.Tag as Channel).GetChannelNumberString() == _chnNumber)
{
return true;
}
}
}
}
return false;
}
public static bool CheckUsedChannel(ushort _service, ushort _program)
{
return CheckUsedChannel((_service >> 8).ToString()
+ "." + (_service & 0xFF).ToString()
+ "." + (_program >> 8).ToString()
+ "." + (_program & 0xFF).ToString());
}
public static bool CheckUsedChannel(ushort _service, ushort _program, TreeNode _ignore)
{
return CheckUsedChannel((_service >> 8).ToString()
+ "." + (_service & 0xFF).ToString()
+ "." + (_program >> 8).ToString()
+ "." + (_program & 0xFF).ToString(),
_ignore);
}
public static bool CheckUsedLCI(ushort _lci)
{
if (_lci == 0x0124)
return true;
foreach (TreeNode _node in mainWindow.treeViewChn.Nodes)
{
if (_node.Tag.GetType() == typeof(Directory))
{
if ((_node.Tag as Directory).lci == _lci)
{
return true;
}
//Check Folders
foreach (TreeNode _nodeChildFolder in _node.Nodes)
{
if (_nodeChildFolder.Tag.GetType() == typeof(Folder))
{
//Check Files
foreach (TreeNode _nodeFile in _nodeChildFolder.Nodes)
{
if ((_nodeFile.Tag as DownloadFile).lci == _lci)
{
return true;
}
if (_nodeFile.Nodes.Count > 0)
{
//Check Include Files if they exist
foreach (TreeNode _nodeIncFile in _nodeFile.Nodes)
{
if ((_nodeIncFile.Tag as DownloadFile).lci == _lci)
{
return true;
}
}
}
}
}
}
}
else
{
if ((_node.Tag as Channel).lci == _lci)
{
return true;
}
}
}
//not found
return false;
}
public static bool CheckUsedLCI(ushort _lci, TreeNode _ignore)
{
if (_lci == 0x0124)
return true;
foreach (TreeNode _node in mainWindow.treeViewChn.Nodes)
{
if (!_node.Equals(_ignore))
{
if (_node.Tag.GetType() == typeof(Directory))
{
if ((_node.Tag as Directory).lci == _lci)
{
return true;
}
//Check Folders
foreach (TreeNode _nodeChildFolder in _node.Nodes)
{
if (_nodeChildFolder.Tag.GetType() == typeof(Folder))
{
//Check Files
foreach (TreeNode _nodeFile in _nodeChildFolder.Nodes)
{
if ((_nodeFile.Tag as DownloadFile).lci == _lci)
{
return true;
}
if (_nodeFile.Nodes.Count > 0)
{
//Check Include Files if they exist
foreach (TreeNode _nodeIncFile in _nodeFile.Nodes)
{
if ((_nodeIncFile.Tag as DownloadFile).lci == _lci)
{
return true;
}
}
}
}
}
}
}
else
{
if ((_node.Tag as Channel).lci == _lci)
{
return true;
}
}
}
}
//not found
return false;
}
public static bool CheckUsedFileID(byte _fileID)
{
foreach (TreeNode _node in mainWindow.treeViewChn.Nodes)
{
if (_node.Tag.GetType() == typeof(Directory))
{
//Check Folders
foreach (TreeNode _nodeChildFolder in _node.Nodes)
{
if (_nodeChildFolder.Tag.GetType() == typeof(Folder))
{
//Check Files (don't need to check include files, it shares the same file ID)
foreach (TreeNode _nodeFile in _nodeChildFolder.Nodes)
{
if ((_nodeFile.Tag as DownloadFile).fileID == _fileID)
{
return true;
}
}
}
}
}
}
//not found
return false;
}
public static bool CheckUsedChannelType(System.Type _type)
{
foreach (TreeNode _node in mainWindow.treeViewChn.Nodes)
{
if (_node.Tag.GetType() == _type)
{
return true;
}
}
//not found
return false;
}
public static byte GetNextFileID()
{
byte nextfileid = 0;
while (CheckUsedFileID(nextfileid))
{
nextfileid++;
}
return nextfileid;
}
public static ushort GetNextLCI()
{
ushort nextlci = 0x0120;
while (CheckUsedLCI(nextlci))
{
nextlci = (ushort)(nextlci & 0x1F | (nextlci >> 3));
nextlci++;
nextlci = (ushort)(nextlci | ((nextlci & 0x3E0) << 3) | 0x0020);
}
return nextlci;
}
public static ushort GetNextProgramNumber()
{
ushort nextprgnumber = 0;
while (CheckUsedChannel(0x0103, nextprgnumber))
nextprgnumber += 0x0100;
return nextprgnumber;
}
public static bool CheckBSXRepository()
{
//Check for conflicts in the repository
foreach (TreeNode _node in mainWindow.treeViewChn.Nodes)
{
//Check Software Channel
if (CheckUsedChannel((_node.Tag as Channel).GetChannelNumberString(), _node))
{
return false;
}
//Check Logical Channel (exception of LCI 0x0000 which is the time, can be shared between channels)
if (CheckUsedLCI((_node.Tag as Channel).lci, _node) && ((_node.Tag as Channel).lci != 0))
{
return false;
}
if (_node.Tag.GetType() == typeof(Directory))
{
//Check Folders
foreach (TreeNode _nodeChildFolder in _node.Nodes)
{
if (_nodeChildFolder.Tag.GetType() == typeof(Folder))
{
//Check Files
foreach (TreeNode _nodeFile in _nodeChildFolder.Nodes)
{
//Check Software Channel
if (CheckUsedChannel((_nodeFile.Tag as DownloadFile).GetChannelNumberString(), _node))
{
return false;
}
//Check Logical Channel
if (CheckUsedLCI((_nodeFile.Tag as DownloadFile).lci, _node))
{
return false;
}
foreach (TreeNode _inclNode in _nodeFile.Nodes)
{
//Check Software Channel
if (CheckUsedChannel((_inclNode.Tag as DownloadFile).GetChannelNumberString(), _node))
{
return false;
}
//Check Logical Channel
if (CheckUsedLCI((_inclNode.Tag as DownloadFile).lci, _node))
{
return false;
}
}
}
}
}
}
}
//Everything is fine
return true;
}
public static void LoadBSXRepository(string xmlPath)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(xmlPath);
List<TreeNode> nodelist = new List<TreeNode>();
if (xmlDoc.DocumentElement.Name == "bsx")
{
foreach (XmlNode nodeChannel in xmlDoc.DocumentElement.ChildNodes)
{
if (nodeChannel.Name == "channel")
{
//Verify Channel Integrity
if (!(new Regex(@"^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$").Match(nodeChannel.Attributes["broadcast"].Value).Success))
{
//Software Channel
MessageBox.Show("Software Channel is invalid in channel " + nodeChannel.BaseURI + " (" + nodeChannel.Attributes["name"].Value + ")", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (!(new Regex(@"^[0-9a-fA-F]{4}$").Match(nodeChannel.Attributes["lci"].Value).Success))
{
//LCI
MessageBox.Show("Logical Channel LCI is invalid in channel " + nodeChannel.BaseURI + " (" + nodeChannel.Attributes["name"].Value + ")", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (!(new Regex(@"^[0-9]+$").Match(nodeChannel.Attributes["timeout"].Value).Success))
{
//Timeout
MessageBox.Show("Timeout is invalid in channel " + nodeChannel.BaseURI + " (" + nodeChannel.Attributes["name"].Value + ")", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
ushort _pv = (ushort)((Convert.ToByte(nodeChannel.Attributes["broadcast"].Value.Split('.')[0]) << 8) | Convert.ToByte(nodeChannel.Attributes["broadcast"].Value.Split('.')[1]));
ushort _pr = (ushort)((Convert.ToByte(nodeChannel.Attributes["broadcast"].Value.Split('.')[2]) << 8) | Convert.ToByte(nodeChannel.Attributes["broadcast"].Value.Split('.')[3]));
string _name = nodeChannel.Attributes["name"].Value;
ushort _lci;
ushort.TryParse(nodeChannel.Attributes["lci"].Value, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out _lci);
ushort _timeout = Convert.ToUInt16(nodeChannel.Attributes["timeout"].Value);
if (nodeChannel.ChildNodes.Count > 0)
{
if (nodeChannel.ChildNodes[0].Name == "message")
{
//Message Channel
MessageChannel msgchn = new MessageChannel(_pv, _pr, _name, _lci, _timeout, nodeChannel.ChildNodes[0].InnerText);
TreeNode msgnode = new TreeNode(msgchn.name + " (" + msgchn.GetChannelNumberString() + ")");
msgnode.Tag = msgchn;
msgnode.ContextMenuStrip = mainWindow.contextMenuStripChannelMenu;
nodelist.Add(msgnode);
}
else if (nodeChannel.ChildNodes[0].Name == "town")
{
//Town Status
if (!(new Regex(@"^[0-3]$").Match(nodeChannel.ChildNodes[0].Attributes["apu"].Value).Success))
{
//apu
MessageBox.Show("APU Setup is invalid in town channel " + nodeChannel.BaseURI + " (" + nodeChannel.Attributes["name"].Value + ")", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (!(new Regex(@"^[0-3]$").Match(nodeChannel.ChildNodes[0].Attributes["radio"].Value).Success))
{
//radio
MessageBox.Show("Radio Setup is invalid in town channel " + nodeChannel.BaseURI + " (" + nodeChannel.Attributes["name"].Value + ")", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (!(new Regex(@"^(?:1[0-2]|[0-9]?)$").Match(nodeChannel.ChildNodes[0].Attributes["fountain"].Value).Success))
{
//fountain
MessageBox.Show("Fountain Setup is invalid in town channel " + nodeChannel.BaseURI + " (" + nodeChannel.Attributes["name"].Value + ")", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (!(new Regex(@"^[0-4]$").Match(nodeChannel.ChildNodes[0].Attributes["season"].Value).Success))
{
//season
MessageBox.Show("Season Setup is invalid in town channel " + nodeChannel.BaseURI + " (" + nodeChannel.Attributes["name"].Value + ")", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (!(new Regex(@"^[0-1]{64}$").Match(nodeChannel.ChildNodes[0].Attributes["npc"].Value).Success))
{
//npc
MessageBox.Show("NPC Setup is invalid in town channel " + nodeChannel.BaseURI + " (" + nodeChannel.Attributes["name"].Value + ")", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
TownStatus townchn = new TownStatus(_pv, _pr, _name, _lci, _timeout);
townchn.apu_setup = Convert.ToByte(nodeChannel.ChildNodes[0].Attributes["apu"].Value);
townchn.radio_setup = Convert.ToByte(nodeChannel.ChildNodes[0].Attributes["radio"].Value);
townchn.fountain = Convert.ToByte(nodeChannel.ChildNodes[0].Attributes["fountain"].Value);
townchn.season = Convert.ToByte(nodeChannel.ChildNodes[0].Attributes["season"].Value);
for (int i = 0; i < townchn.npc_flags.Length; i++)
{
townchn.npc_flags[i] = (nodeChannel.ChildNodes[0].Attributes["npc"].Value[i] == '1');
}
TreeNode townnode = new TreeNode(townchn.name + " (" + townchn.GetChannelNumberString() + ")");
townnode.Tag = townchn;
townnode.ContextMenuStrip = mainWindow.contextMenuStripChannelMenu;
nodelist.Add(townnode);
}
else if (nodeChannel.ChildNodes[0].Name == "directory")
{
Directory dirchn = new Directory(_pv, _pr, _name, _lci, _timeout);
TreeNode dirnode = new TreeNode(dirchn.name + " (" + dirchn.GetChannelNumberString() + ")");
dirnode.Tag = dirchn;
foreach (XmlNode folderData in nodeChannel.ChildNodes[0].ChildNodes)
{
if (folderData.Name == "folder")
{
if (!(new Regex(@"^[0-1]$").Match(folderData.Attributes["purpose"].Value).Success))
{
//Timeout
MessageBox.Show("Purpose is invalid in folder " + folderData.BaseURI + " (" + folderData.Attributes["name"].Value + ")", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (!(new Regex(@"^[0-1]$").Match(folderData.Attributes["type"].Value).Success))
{
//Timeout
MessageBox.Show("Type is invalid in folder " + folderData.BaseURI + " (" + folderData.Attributes["name"].Value + ")", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (!(new Regex(@"^[0-9]+$").Match(folderData.Attributes["id"].Value).Success))
{
//Timeout
MessageBox.Show("ID is invalid in folder " + folderData.BaseURI + " (" + folderData.Attributes["name"].Value + ")", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (!(new Regex(@"^[0-9]+$").Match(folderData.Attributes["mugshot"].Value).Success))
{
//Timeout
MessageBox.Show("Mugshot is invalid in folder " + folderData.BaseURI + " (" + folderData.Attributes["name"].Value + ")", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
Folder folder = new Folder(folderData.Attributes["name"].Value, folderData.Attributes["message"].Value, Convert.ToInt32(folderData.Attributes["type"].Value), Convert.ToInt32(folderData.Attributes["purpose"].Value), Convert.ToInt32(folderData.Attributes["id"].Value), Convert.ToInt32(folderData.Attributes["mugshot"].Value));
TreeNode foldernode = new TreeNode(folder.name);
foldernode.Tag = folder;
//File
foreach (XmlNode fileData in folderData.ChildNodes)
{
if (!(new Regex(@"^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$").Match(fileData.Attributes["broadcast"].Value).Success))
{
//Software Channel
MessageBox.Show("Software Channel is invalid in file channel " + fileData.BaseURI + " (" + fileData.Attributes["name"].Value + ")", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (!(new Regex(@"^[0-9a-fA-F]{4}$").Match(fileData.Attributes["lci"].Value).Success))
{
//LCI
MessageBox.Show("Logical Channel LCI is invalid in file channel " + fileData.BaseURI + " (" + fileData.Attributes["name"].Value + ")", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (!(new Regex(@"^[0-9]+$").Match(fileData.Attributes["timeout"].Value).Success))
{
//Timeout
MessageBox.Show("Timeout is invalid in file channel " + fileData.BaseURI + " (" + fileData.Attributes["name"].Value + ")", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (!(new Regex(@"^[0-9]{12}$").Match(fileData.Attributes["price"].Value).Success))
{
//fountain
MessageBox.Show("Price is invalid in file channel " + fileData.BaseURI + " (" + fileData.Attributes["name"].Value + ")", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (!(new Regex(@"^(true|false)$").Match(fileData.Attributes["oneuse"].Value).Success))
{
//Timeout
MessageBox.Show("One Use is invalid in file channel " + fileData.BaseURI + " (" + fileData.Attributes["name"].Value + ")", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (!(new Regex(@"^[0-3]+$").Match(fileData.Attributes["autostart"].Value).Success))
{
//Timeout
MessageBox.Show("Autostart is invalid in file channel " + fileData.BaseURI + " (" + fileData.Attributes["name"].Value + ")", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (!(new Regex(@"^[0-3]+$").Match(fileData.Attributes["destination"].Value).Success))
{
//Timeout
MessageBox.Show("Destination is invalid in file channel " + fileData.BaseURI + " (" + fileData.Attributes["name"].Value + ")", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (!(new Regex(@"^(true|false)$").Match(fileData.Attributes["home"].Value).Success))
{
//Timeout
MessageBox.Show("Home is invalid in file channel " + fileData.BaseURI + " (" + fileData.Attributes["name"].Value + ")", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (!(new Regex(@"^(true|false)$").Match(fileData.Attributes["streamed"].Value).Success))
{
//Timeout
MessageBox.Show("Streamed is invalid in file channel " + fileData.BaseURI + " (" + fileData.Attributes["name"].Value + ")", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (!(new Regex(@"^(?:1[0-2]|[1-9]?)$").Match(fileData.Attributes["month"].Value).Success))
{
//fountain
MessageBox.Show("Month is invalid in file channel " + fileData.BaseURI + " (" + fileData.Attributes["name"].Value + ")", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (!(new Regex(@"^(?:3[0-1]|[1-2][0-9]|[1-9]?)$").Match(fileData.Attributes["day"].Value).Success))
{
//fountain
MessageBox.Show("Day is invalid in file channel " + fileData.BaseURI + " (" + fileData.Attributes["name"].Value + ")", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}