-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainForm.cs
1690 lines (1647 loc) · 91.5 KB
/
MainForm.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.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Net.NetworkInformation;
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using Sunny.UI;
using AutoDialUp.Data;
using AutoDialUp.Crypt;
using AutoDialUp.Net;
using Newtonsoft.Json;
using Application = System.Windows.Forms.Application;
using System.Windows.Threading;
using static System.Net.Mime.MediaTypeNames;
using static AutoDialUp.Data.TimePlan;
using System.Drawing.Text;
using System.Web.UI.Design;
using Version = AutoDialUp.Data.Version;
namespace AutoDialUp
{
public enum CustomColor
{
Success,
Information,
Worring,
Error
}
public partial class MainForm : UIForm
{
RASDisplay ras = new RASDisplay();
DialUpAccount savedaccount = new DialUpAccount();
HotKeyConfig hotkeyconfig = new HotKeyConfig();
SoftwareConfig softwareConfig = null;
int _autoConnectTimerLocker = -1;
int _autoReConnectFlag = -1;//0是未联网,1是已联网
int successConnectCount = 0;
int _versionCheckLocker = 0;//获取网络上的版本信息只获取一次
Thread _timePlanEveryDayRefreshThread;
DateTime[] runTimeRecord = new DateTime[2];
List<string> timePlanSourceData = new List<string>();
OneDay Today = new OneDay(true);
Version versionData = new Version();
public MainForm()
{
InitializeComponent();
Control.CheckForIllegalCrossThreadCalls = false;
int pageIndex = 1000;
TreeNode parent = Aside.CreateNode("状态", 61668, 30, pageIndex);
parent = Aside.CreateNode("配置", 61573, 30, ++pageIndex);
Aside.CreateChildNode(parent,"拨号", 61612,12, ++pageIndex);
Aside.CreateChildNode(parent, "自动化", 61904, 12, ++pageIndex);
Aside.CreateChildNode(parent, "热键", 361957, 12, ++pageIndex);
Aside.CreateChildNode(parent, "时间段", 61463, 12, ++pageIndex);
parent = Aside.CreateNode("日志", 61747, 30, ++pageIndex);
parent = Aside.CreateNode("关于", 61638, 30, ++pageIndex);
tabControl.Region = new Region(new RectangleF(tabPage_Status.Left, tabPage_Status.Top + 5, tabPage_Status.Width, tabPage_Status.Height + 5)); //隐藏tabcontrol的选项卡
runTimeRecord[0] = DateTime.Now;//记录开始运行的时间
RegisterHotKey(Sunny.UI.ModifierKeys.None,Keys.Escape);
RegisterHotKey(Sunny.UI.ModifierKeys.Shift, Keys.F5);
RegisterHotKey(Sunny.UI.ModifierKeys.Shift, Keys.F7);
RegisterHotKey(Sunny.UI.ModifierKeys.Shift, Keys.F8);
Thread netCheckThread = new Thread(() =>
{
switch (GetInternetConStatus.GetNetConStatus("baidu.com"))//GetInternetConStatus.GetNetConStatus("baidu.com")
{
case 1:
{
//网络未连接
uiTitlePanel_NetStatus.TitleColor = Color.DarkOrange;
uiTitlePanel_NetStatus.RectColor = Color.DarkOrange;
uiAvatar_NetStatus.ForeColor = Color.DarkOrange;
uiSymbolLabel_ConnectCheck.ForeColor = Color.DarkOrange;
uiSymbolLabel_ConnectCheck.SymbolColor = Color.DarkOrange;
uiSymbolLabel_InternetDeviceType.ForeColor = Color.DarkOrange;
uiSymbolLabel_InternetDeviceType.SymbolColor = Color.DarkOrange;
uiSymbolLabel_PingOK.ForeColor = Color.DarkOrange;
uiSymbolLabel_PingOK.SymbolColor = Color.DarkOrange;
uiSymbolLabel_ConnectCheck.Symbol = 61453;//×,未通过
uiSymbolLabel_InternetDeviceType.Symbol = 61453;
uiSymbolLabel_PingOK.Symbol = 61453;
uiSymbolLabel_ConnectCheck.Text = "网络未连接";
uiSymbolLabel_InternetDeviceType.Text = "上网类型未知";
uiSymbolLabel_PingOK.Text = "Ping失败";
_autoReConnectFlag = 0;
LogAppend(CustomColor.Error, "[线程检测网络]网络未连接 - 1");
break;
}
case 2:
{
//采用调制解调器上网
uiTitlePanel_NetStatus.TitleColor = Color.FromArgb(80, 160, 255);
uiTitlePanel_NetStatus.RectColor = Color.FromArgb(80, 160, 255);
uiAvatar_NetStatus.ForeColor = Color.FromArgb(80, 160, 255);
//uiSymbolLabel_ConnectCheck.ForeColor = Color.FromArgb(80, 160, 255);
uiSymbolLabel_ConnectCheck.SymbolColor = Color.FromArgb(80, 160, 255);
//uiSymbolLabel_InternetDeviceType.ForeColor = Color.FromArgb(80, 160, 255);
uiSymbolLabel_InternetDeviceType.SymbolColor = Color.FromArgb(80, 160, 255);
//uiSymbolLabel_PingOK.ForeColor = Color.FromArgb(80, 160, 255);
uiSymbolLabel_PingOK.SymbolColor = Color.FromArgb(80, 160, 255);
uiSymbolLabel_ConnectCheck.Symbol = 61452;//钩,通过
uiSymbolLabel_InternetDeviceType.Symbol = 61452;
uiSymbolLabel_PingOK.Symbol = 61452;
uiSymbolLabel_ConnectCheck.Text = "网络已连接";
uiSymbolLabel_InternetDeviceType.Text = "调制解调器上网";
uiSymbolLabel_PingOK.Text = "Ping正常";
_autoReConnectFlag = 1;
LogAppend(CustomColor.Success, "[线程检测网络]网络已连接 - 2");
break;
}
case 3:
{
//采用网卡上网
uiTitlePanel_NetStatus.TitleColor = Color.FromArgb(80, 160, 255);
uiTitlePanel_NetStatus.RectColor = Color.FromArgb(80, 160, 255);
uiAvatar_NetStatus.ForeColor = Color.FromArgb(80, 160, 255);
//uiSymbolLabel_ConnectCheck.ForeColor = Color.FromArgb(80, 160, 255);
uiSymbolLabel_ConnectCheck.SymbolColor = Color.FromArgb(80, 160, 255);
//uiSymbolLabel_InternetDeviceType.ForeColor = Color.FromArgb(80, 160, 255);
uiSymbolLabel_InternetDeviceType.SymbolColor = Color.FromArgb(80, 160, 255);
//uiSymbolLabel_PingOK.ForeColor = Color.FromArgb(80, 160, 255);
uiSymbolLabel_PingOK.SymbolColor = Color.FromArgb(80, 160, 255);
uiSymbolLabel_ConnectCheck.Symbol = 61452;//钩,通过
uiSymbolLabel_InternetDeviceType.Symbol = 61452;
uiSymbolLabel_PingOK.Symbol = 61452;
uiSymbolLabel_ConnectCheck.Text = "网络已连接";
uiSymbolLabel_InternetDeviceType.Text = "使用网卡上网";
uiSymbolLabel_PingOK.Text = "Ping正常";
_autoReConnectFlag = 1;
LogAppend(CustomColor.Success, "[线程检测网络]网络已连接 - 3");
break;
}
case 4:
{
//采用调制解调器上网,但是联不通指定网络
uiTitlePanel_NetStatus.TitleColor = Color.DarkOrange;
uiTitlePanel_NetStatus.RectColor = Color.DarkOrange;
uiAvatar_NetStatus.ForeColor = Color.DarkOrange;
uiSymbolLabel_ConnectCheck.ForeColor = Color.DarkOrange;
uiSymbolLabel_ConnectCheck.SymbolColor = Color.DarkOrange;
uiSymbolLabel_InternetDeviceType.ForeColor = Color.DarkOrange;
uiSymbolLabel_InternetDeviceType.SymbolColor = Color.DarkOrange;
uiSymbolLabel_PingOK.ForeColor = Color.DarkOrange;
uiSymbolLabel_PingOK.SymbolColor = Color.DarkOrange;
uiSymbolLabel_ConnectCheck.Symbol = 61453;//×,未通过
uiSymbolLabel_InternetDeviceType.Symbol = 61453;
uiSymbolLabel_PingOK.Symbol = 61453;
uiSymbolLabel_ConnectCheck.Text = "网络未连接";
uiSymbolLabel_InternetDeviceType.Text = "调制解调器上网";
uiSymbolLabel_PingOK.Text = "Ping失败";
_autoReConnectFlag = 0;
LogAppend(CustomColor.Error, "[线程检测网络]网络未连接 - 4");
break;
}
case 5:
{
//采用网卡上网,但是联不通指定网络
uiTitlePanel_NetStatus.TitleColor = Color.DarkOrange;
uiTitlePanel_NetStatus.RectColor = Color.DarkOrange;
uiAvatar_NetStatus.ForeColor = Color.DarkOrange;
uiSymbolLabel_ConnectCheck.ForeColor = Color.DarkOrange;
uiSymbolLabel_ConnectCheck.SymbolColor = Color.DarkOrange;
uiSymbolLabel_InternetDeviceType.ForeColor = Color.DarkOrange;
uiSymbolLabel_InternetDeviceType.SymbolColor = Color.DarkOrange;
uiSymbolLabel_PingOK.ForeColor = Color.DarkOrange;
uiSymbolLabel_PingOK.SymbolColor = Color.DarkOrange;
uiSymbolLabel_ConnectCheck.Symbol = 61453;//×,未通过
uiSymbolLabel_InternetDeviceType.Symbol = 61453;
uiSymbolLabel_PingOK.Symbol = 61453;
uiSymbolLabel_ConnectCheck.Text = "网络未连接";
uiSymbolLabel_InternetDeviceType.Text = "使用网卡上网";
uiSymbolLabel_PingOK.Text = "Ping失败";
_autoReConnectFlag = 0;
LogAppend(CustomColor.Error, "[线程检测网络]网络未连接 - 5");
break;
}
}
});
netCheckThread.Start();
timer_AutoConnect.Enabled = true;
Thread configCheckThread = new Thread(() =>
{
if(File.Exists("Account.json") == true)
{
uiSymbolLabe_AccountConfigCheck.Text = "拨号配置正常";
savedaccount = JsonConvert.DeserializeObject<DialUpAccount>(File.ReadAllText(@"Account.json", Encoding.UTF8));
uiTextBox_DialUpName.Watermark = Decrypt.DES(savedaccount.Name, "latiaonb");
uiTextBox_DialUpAccount.Watermark = Decrypt.DES(savedaccount.Account, "latiaonb");
uiTextBox_DialUpPassword.Watermark = Decrypt.DES(savedaccount.Password, "latiaonb");
uiComboBox_DialUpType.SelectedIndex = uiComboBox_ConnectMethod.SelectedIndex = savedaccount.DialUpType;
uiSymbolButton_OneKeyConnect.Enabled = true;
LogAppend(CustomColor.Success, "账号配置文件解析完毕");
if (File.Exists("Config.json") == true)
{
uiSymbolLabel_SoftConfigCheck.Text = "软件配置正常";
softwareConfig = JsonConvert.DeserializeObject<SoftwareConfig>(File.ReadAllText(@"Config.json", Encoding.UTF8));
if (softwareConfig.AutoConnect == 1)
{
_autoConnectTimerLocker = 1;//时钟检测到值的变化后进行自动连接
uiCheckBox_AutoConnect.Checked = true;
}
else
_autoConnectTimerLocker = 0;
if (softwareConfig.AutoStart == 1)
uiCheckBox_AutoStart.Checked = true;
if (softwareConfig.AutoReConnect == 1)
uiCheckBox_AutoReConnect.Checked = true;
uiSymbolButton_ResetConfig.Enabled = true;//只有2个配置文件都存在才能重置
LogAppend(CustomColor.Success, "软件配置文件解析完毕");
}
else
{
uiTitlePanel_Config.TitleColor = Color.DarkOrange;
uiTitlePanel_Config.RectColor = Color.DarkOrange;
uiSymbolLabel_SoftConfigCheck.ForeColor = Color.DarkOrange;
uiSymbolLabel_SoftConfigCheck.SymbolColor = Color.DarkOrange;
uiSymbolLabel_SoftConfigCheck.Symbol = 61553;
uiSymbolLabel_SoftConfigCheck.Text = "软件配置不存在";
LogAppend(CustomColor.Worring, "软件配置文件不存在");
_autoConnectTimerLocker = 0;//时钟检测到值的变化后不进行自动连接
}
}
else
{
uiTitlePanel_Config.TitleColor = Color.DarkOrange;
uiTitlePanel_Config.RectColor = Color.DarkOrange;
uiSymbolLabel_SoftConfigCheck.ForeColor = Color.DarkOrange;
uiSymbolLabel_SoftConfigCheck.SymbolColor = Color.DarkOrange;
uiSymbolLabel_SoftConfigCheck.Symbol = 61553;
uiComboBox_ConnectMethod.SelectedIndex = 0;
uiSymbolLabel_SoftConfigCheck.Text = "拨号配置不存在";
LogAppend(CustomColor.Worring, "拨号配置文件不存在");
if (File.Exists("Config.json") == false)
{
uiTitlePanel_Config.TitleColor = Color.DarkOrange;
uiTitlePanel_Config.RectColor = Color.DarkOrange;
uiSymbolLabe_AccountConfigCheck.ForeColor = Color.DarkOrange;
uiSymbolLabe_AccountConfigCheck.SymbolColor = Color.DarkOrange;
uiSymbolLabe_AccountConfigCheck.Symbol = 61553;
uiSymbolLabe_AccountConfigCheck.Text = "软件配置不存在";
LogAppend(CustomColor.Worring, "软件配置文件不存在");
}
_autoConnectTimerLocker = 0;//时钟检测到值的变化后不进行自动连接
}
//热键配置文件是独立检查的
if(File.Exists(@"HotKey.json") == true)
{
hotkeyconfig = JsonConvert.DeserializeObject<HotKeyConfig>(File.ReadAllText(@"HotKey.json", Encoding.UTF8));
uiCheckBox_HotKey_Esc.Checked = hotkeyconfig.Esc ==1 ? true : false;
uiCheckBox_HotKey_ShiftF5.Checked = hotkeyconfig.ShiftF5 == 1 ? true : false;
uiCheckBox_HotKey_ShiftF6.Checked = hotkeyconfig.ShiftF6 == 1 ? true : false;
uiCheckBox_HotKey_ShiftF7.Checked = hotkeyconfig.ShiftF7 == 1 ? true : false;
uiCheckBox_HotKey_ShiftF8.Checked = hotkeyconfig.ShiftF8 == 1 ? true : false;
}
else
LogAppend(CustomColor.Worring, "热键配置文件不存在");
LogAppend(CustomColor.Success,"所有配置文件检查完毕");
});
configCheckThread.Start();
timer_NetChecker.Enabled = true;
Thread timePlanCheckThread = new Thread(() =>
{
if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "TimePlan\\Mon.json"))
{
DaysCollections.Mon = JsonConvert.DeserializeObject<OneDay>(File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "TimePlan\\Mon.json", Encoding.UTF8));
DaysCollections.Mon.Initialized = true;
timePlanSourceData.Add(String.Format("星期一 - 已设置 - {0} ~ {1}", DaysCollections.Mon.StartTime, DaysCollections.Mon.EndTime));
}
else
{
DaysCollections.Mon = new OneDay(false);
timePlanSourceData.Add("星期一 - 未设置");
}
if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "TimePlan\\Tues.json"))
{
DaysCollections.Tues = JsonConvert.DeserializeObject<OneDay>(File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "TimePlan\\Tues.json", Encoding.UTF8));
DaysCollections.Tues.Initialized = true;
timePlanSourceData.Add(String.Format("星期二 - 已设置 - {0} ~ {1}", DaysCollections.Tues.StartTime, DaysCollections.Tues.EndTime));
}
else
{
DaysCollections.Tues = new OneDay(false);
timePlanSourceData.Add("星期二 - 未设置");
}
if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "TimePlan\\Wed.json"))
{
DaysCollections.Wed = JsonConvert.DeserializeObject<OneDay>(File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "TimePlan\\Wed.json", Encoding.UTF8));
DaysCollections.Wed.Initialized = true;
timePlanSourceData.Add(String.Format("星期三 - 已设置 - {0} ~ {1}", DaysCollections.Wed.StartTime, DaysCollections.Wed.EndTime));
}
else
{
DaysCollections.Wed = new OneDay(false);
timePlanSourceData.Add("星期三 - 未设置");
}
if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "TimePlan\\Thur.json"))
{
DaysCollections.Thur = JsonConvert.DeserializeObject<OneDay>(File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "TimePlan\\Thur.json", Encoding.UTF8));
DaysCollections.Thur.Initialized = true;
timePlanSourceData.Add(String.Format("星期四 - 已设置 - {0} ~ {1}", DaysCollections.Thur.StartTime, DaysCollections.Thur.EndTime));
}
else
{
DaysCollections.Thur = new OneDay(false);
timePlanSourceData.Add("星期四 - 未设置");
}
if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "TimePlan\\Fri.json"))
{
DaysCollections.Fri = JsonConvert.DeserializeObject<OneDay>(File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "TimePlan\\Fri.json", Encoding.UTF8));
DaysCollections.Fri.Initialized = true;
timePlanSourceData.Add(String.Format("星期五 - 已设置 - {0} ~ {1}", DaysCollections.Fri.StartTime, DaysCollections.Fri.EndTime));
}
else
{
DaysCollections.Fri = new OneDay(false);
timePlanSourceData.Add("星期五 - 未设置");
}
if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "TimePlan\\Sat.json"))
{
DaysCollections.Sat = JsonConvert.DeserializeObject<OneDay>(File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "TimePlan\\Sat.json", Encoding.UTF8));
DaysCollections.Sat.Initialized = true;
timePlanSourceData.Add(String.Format("星期六 - 已设置 - {0} ~ {1}", DaysCollections.Sat.StartTime, DaysCollections.Sat.EndTime));
}
else
{
DaysCollections.Sat = new OneDay(false);
timePlanSourceData.Add("星期六 - 未设置");
}
if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "TimePlan\\Sun.json"))
{
DaysCollections.Sun = JsonConvert.DeserializeObject<OneDay>(File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "TimePlan\\Sun.json", Encoding.UTF8));
DaysCollections.Sun.Initialized = true;
timePlanSourceData.Add(String.Format("星期日 - 已设置 - {0} ~ {1}", DaysCollections.Sun.StartTime, DaysCollections.Sun.EndTime));
}
else
{
DaysCollections.Sun = new OneDay(false);
timePlanSourceData.Add("星期日 - 未设置");
}
if(timePlanSourceData.Count == 7)
{
uiComboBox_SelectWhichDay.DataSource = timePlanSourceData;
}
switch (TimePlan.WhichDay())
{
case 1:
{
Today = DaysCollections.Mon;
break;
}
case 2:
{
Today = DaysCollections.Tues;
break;
}
case 3:
{
Today = DaysCollections.Wed;
break;
}
case 4:
{
Today = DaysCollections.Thur;
break;
}
case 5:
{
Today = DaysCollections.Fri;
break;
}
case 6:
{
Today = DaysCollections.Sat;
break;
}
case 7:
{
Today = DaysCollections.Sun;
break;
}
}
//MessageBox.Show(Today.Check().ToString());
});
timePlanCheckThread.Start();
Thread timePlanEveryDayRefreshThread = new Thread(() =>
{
//此线程的目的旨在每到新的一天程序就会自杀并重启,省去校验日期的麻烦,后期也可能会改
for(; ; )
{
if(DateTime.Now.DayOfWeek != runTimeRecord[0].DayOfWeek)
{
//先写出日志再释放图标最后重启
runTimeRecord[1] = DateTime.Now;
TimeSpan ts = runTimeRecord[1] - runTimeRecord[0];
Start: if (Directory.Exists("Log"))
{
try
{
File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + "Log\\" + String.Format("{0}~{1}.txt", runTimeRecord[0].ToString("MM月dd日HH时mm分ss秒"), runTimeRecord[1].ToString("HH时mm分ss秒")), "此次总运行时间:" + ts.ToString() + Environment.NewLine + uiRichTextBox_Log.Text);
}
catch { }
}
else
{
try
{
Directory.CreateDirectory("Log");
goto Start;
}
catch { }
}
Thread.Sleep(500);
notifyIcon_MainForm.Dispose();
Application.Exit();
Process.Start(System.Reflection.Assembly.GetExecutingAssembly().Location);
}
Thread.Sleep(60000);
}
});
timePlanEveryDayRefreshThread.Start();
_timePlanEveryDayRefreshThread = timePlanEveryDayRefreshThread;
LogAppend(CustomColor.Information, "主窗口初始化事件处理完毕");
#region 测试功能区
/*OneDay testDay = new OneDay();
MessageBox.Show(testDay.StartTime.ToString());*/
#endregion
}
/// <summary>
/// 向日志框添加日志
/// </summary>
/// <param name="text"></param>
public void LogAppend(CustomColor customcolor,string text)
{
try
{
Color color = Color.Black;
switch (customcolor)
{
case CustomColor.Success:
{
color = Color.FromArgb(0, 139, 0);
break;
}
case CustomColor.Information:
{
color = Color.FromArgb(0, 46, 166);
break;
}
case CustomColor.Worring:
{
color = Color.FromArgb(255, 119, 15);
break;
}
case CustomColor.Error:
{
color = Color.FromArgb(215, 0, 15);
break;
}
}
uiRichTextBox_Log.SelectionColor = color;
uiRichTextBox_Log.AppendText(string.Format("[{0:T}]:", DateTime.Now) + text + Environment.NewLine);
//内容过多时防止内存溢出自动清理
if (uiRichTextBox_Log.Text.Length >= 20000)
{
uiRichTextBox_Log.Text = String.Empty;
LogAppend(CustomColor.Information, "由于日志内容过多,防止软件崩溃已自动清理");
}
}
catch { }
}
private void VersionDataCheck()
{
try
{
versionData = JsonConvert.DeserializeObject<Version>(GetMethod.Get("https://data.xn--e-5g8az75bbi3a.com/AutoDialUp/Version.json"));
uiLabel_SoftwareName.Text = versionData.SoftwareName;
uiSymbolLabel_VersionNumber.Text = versionData.VersionNumber.ToString();
uiSymbolButton_CheckUpdate.Enabled = true;
}
catch { }
}
/// <summary>
/// 选项卡切换的实现
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Aside_Click(object sender, EventArgs e)
{
//Console.WriteLine(Aside.SelectedNode.ToString());
switch (Aside.SelectedNode.ToString())
{
case "TreeNode: 状态":
{
tabControl.SelectedIndex = 0;
LogAppend(CustomColor.Information, "用户切换到了状态页面");
break;
}
case "TreeNode: 拨号":
{
tabControl.SelectedIndex = 1;
LogAppend(CustomColor.Information, "用户切换到了拨号设置页面");
break;
}
case "TreeNode: 自动化":
{
tabControl.SelectedIndex = 2;
LogAppend(CustomColor.Information, "用户切换到了自动化软件设置页面");
break;
}
case "TreeNode: 热键":
{
tabControl.SelectedIndex = 3;
LogAppend(CustomColor.Information, "用户切换到了热键设置页面");
break;
}
case "TreeNode: 时间段":
{
tabControl.SelectedIndex = 4;
LogAppend(CustomColor.Information, "用户切换到了时间段设置页面");
break;
}
case "TreeNode: 日志":
{
tabControl.SelectedIndex = 5;
LogAppend(CustomColor.Information, "用户切换到了日志页面");
break;
}
case "TreeNode: 关于":
{
tabControl.SelectedIndex = 6;
LogAppend(CustomColor.Information, "用户切换到了关于页面");
break;
}
default:
{
tabControl.SelectedIndex = 0;
LogAppend(CustomColor.Information, "用户切换到了未知页面,自动跳转到主页");
break;
}
}
}
/// <summary>
/// 判断是否为管理员运行
/// </summary>
private bool IsUserAnAdmin()
{
WindowsIdentity identity = WindowsIdentity.GetCurrent();
WindowsPrincipal principal = new WindowsPrincipal(identity);
return principal.IsInRole(WindowsBuiltInRole.Administrator);
}
/// <summary>
/// 拨号设置保存旁边的帮助按钮
/// </summary>
private void uiSymbolButton_AccountHelp_Click(object sender, EventArgs e)
{
UIMessageDialog.ShowMessageDialog("1.如何选择拨号方式\n校园普遍使用PPPoE的拨号方式,如果拿到的宽带信息中包含了账号密码信息则选择PPPoE方式。相反ADSL只需要填写宽带名\n\n2.宽带名要怎么填写\n一般填写为\"宽带连接\"即可,如果需要使用VPN则要将宽带名设置为英文\n\n3.无法连接\nA:可能需要在拨号设置里先新建一个拨号连接并成功连接一次,宽带名要和连接过的拨号连接名一样\nB:检查用户名或密码是否正确,以及拨号方式是否对应\n\n4.填写的账号密码安全吗\n信息只保存在电脑硬盘中,软件除手动检查更新外无任何联网行为且软件完全开源。保存在电脑中的信息采用目前业界主流DES加密方法,十分安全", "拨号设置帮助", false, Style);
}
/// <summary>
/// 保存账号设置
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void uiSymbolButton_SaveAccountConfig_Click(object sender, EventArgs e)
{
if(File.Exists("Account.json") == false)
{
switch (uiComboBox_DialUpType.SelectedIndex)
{
//PPPoE
case 0:
{
DialUpAccount saveaccount = new DialUpAccount(0, Encrypt.DES(uiTextBox_DialUpName.Text, "latiaonb"), Encrypt.DES(uiTextBox_DialUpAccount.Text, "latiaonb"), Encrypt.DES(uiTextBox_DialUpPassword.Text, "latiaonb"));
string json = JsonConvert.SerializeObject(saveaccount);
try
{
File.WriteAllText(@"Account.json", json);
}
catch(Exception ex)
{
ShowErrorDialog("异常捕获", string.Format("保存账号配置文件失败\n异常消息:\n{0}\n异常跟踪:\n{1}",ex.Message,ex.Source));
LogAppend(CustomColor.Error, "保存账号配置文件失败:写文件时异常");
}
finally
{
UIMessageDialog.ShowMessageDialog("已保存完毕,需要重启软件\n点击确认后软件自动重启", "提示", false, Style);
Application.Exit();
Process.Start(System.Reflection.Assembly.GetExecutingAssembly().Location);
}
break;
}
//ADSL
case 1:
{
DialUpAccount saveaccount = new DialUpAccount(1, Encrypt.DES(uiTextBox_DialUpName.Text, "latiaonb"), "none","none");
string json = JsonConvert.SerializeObject(saveaccount);
try
{
File.WriteAllText(@"Account.json", json);
}
catch (Exception ex)
{
ShowErrorDialog("异常捕获", string.Format("保存账号配置文件失败\n异常消息:\n{0}\n异常跟踪:\n{1}", ex.Message, ex.Source));
LogAppend(CustomColor.Error, "保存账号配置文件失败:写文件时异常");
}
finally
{
UIMessageDialog.ShowMessageDialog("已保存完毕,需要重启软件\n点击确认后软件自动重启", "提示", false, Style);
notifyIcon_MainForm.Dispose();
Application.Exit();
Process.Start(System.Reflection.Assembly.GetExecutingAssembly().Location);
}
break;
}
//没选
case -1:
{
ShowErrorDialog("错误","由于未选择拨号方式,保存账号配置失败\n请在选择拨号方式后重试");
break;
}
}
}
else
{
if (ShowAskDialog("账号配置文件已经存在,是否需要以当前配置覆盖旧的账号配置?\n如果覆盖,旧的配置将永久失去"))
{
switch (uiComboBox_DialUpType.SelectedIndex)
{
//PPPoE
case 0:
{
DialUpAccount saveaccount = new DialUpAccount(0, Encrypt.DES(uiTextBox_DialUpName.Text, "latiaonb"), Encrypt.DES(uiTextBox_DialUpAccount.Text, "latiaonb"), Encrypt.DES(uiTextBox_DialUpPassword.Text, "latiaonb"));
string json = JsonConvert.SerializeObject(saveaccount);
try
{
File.WriteAllText(@"Account.json", json);
}
catch (Exception ex)
{
ShowErrorDialog("异常捕获", string.Format("保存账号配置文件失败\n异常消息:\n{0}\n异常跟踪:\n{1}", ex.Message, ex.Source));
LogAppend(CustomColor.Error, "保存账号配置文件失败:写文件时异常");
}
finally
{
UIMessageDialog.ShowMessageDialog("已保存完毕,需要重启软件\n点击确认后软件自动重启", "提示", false, Style);
notifyIcon_MainForm.Dispose();
Application.Exit();
Process.Start(System.Reflection.Assembly.GetExecutingAssembly().Location);
}
break;
}
//ADSL
case 1:
{
DialUpAccount saveaccount = new DialUpAccount(1, Encrypt.DES(uiTextBox_DialUpName.Text, "latiaonb"), "none", "none");
string json = JsonConvert.SerializeObject(saveaccount);
try
{
File.WriteAllText(@"Account.json", json);
}
catch (Exception ex)
{
ShowErrorDialog("异常捕获", string.Format("保存账号配置文件失败\n异常消息:\n{0}\n异常跟踪:\n{1}", ex.Message, ex.Source));
LogAppend(CustomColor.Error, "保存账号配置文件失败:写文件时异常");
}
finally
{
UIMessageDialog.ShowMessageDialog("已保存完毕,需要重启软件\n点击确认后软件自动重启", "提示", false, Style);
Application.Exit();
Process.Start(System.Reflection.Assembly.GetExecutingAssembly().Location);
}
break;
}
//没选
case -1:
{
ShowErrorDialog("错误", "由于未选择拨号方式,保存账号配置失败\n请在选择拨号方式后重试");
break;
}
}
}
}
}
/// <summary>
/// 根据配置文件一键连接
/// </summary>
private void uiSymbolButton_OneKeyConnect_Click(object sender, EventArgs e)
{
timer_AutoReConnect.Enabled = false;
if (uiComboBox_ConnectMethod.SelectedIndex != -1)
{
if(savedaccount.DialUpType >= 0 && savedaccount.Name != "解密失败" && savedaccount.Account !="解密失败" && savedaccount.Password != "解密失败")
{
uiSymbolButton_OneKeyConnect.Enabled = false;
int tempNetChecker = GetInternetConStatus.GetNetConStatus("baidu.com");
if(tempNetChecker == 1 || tempNetChecker == 4 || tempNetChecker == 5)
{
uiProcessBar_ConectProcess.Visible = true;
LogAppend(CustomColor.Information, "开始一键连接");
switch (uiComboBox_ConnectMethod.SelectedIndex)
{
case 0:
{
Process p = new Process();//新建一个进程对象
uiProcessBar_ConectProcess.Value = 15;
p.StartInfo.FileName = "Rasdial.exe";//设置要启动的进程名字
uiProcessBar_ConectProcess.Value = 30;
p.StartInfo.Arguments = Decrypt.DES(savedaccount.Name, "latiaonb") + " " + Decrypt.DES(savedaccount.Account, "latiaonb") + " " + Decrypt.DES(savedaccount.Password, "latiaonb");//传递参数 格式 连接名字+空格+账号+空格+密码
uiProcessBar_ConectProcess.Value = 45;
//Console.WriteLine(p.StartInfo.Arguments);
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;//设置执行时的控制台为隐藏的
uiProcessBar_ConectProcess.Value = 60;
p.Start();//开始执行
uiProcessBar_ConectProcess.Value = 75;
p.WaitForExit();//等待连接后自动退出
uiProcessBar_ConectProcess.Value = 90;
if (p.ExitCode == 0)//通过退出返回的代码判断连接是否成功
{
Toast.ShowNotifiy("一键连接", String.Format("状态:宽带连接成功\n宽带名称:{0}\n宽带账号:{1}", Decrypt.DES(savedaccount.Name, "latiaonb"), Decrypt.DES(savedaccount.Account, "latiaonb")), Notifications.Wpf.NotificationType.Success);
LogAppend(CustomColor.Information, "一键连接成功");
}
else
{
Toast.ShowNotifiy("一键连接", String.Format("状态:宽带连接失败\n宽带名称:{0}\n宽带账号:{1}", Decrypt.DES(savedaccount.Name, "latiaonb"), Decrypt.DES(savedaccount.Account, "latiaonb")), Notifications.Wpf.NotificationType.Error);
LogAppend(CustomColor.Error, "一键连接失败");
}
uiProcessBar_ConectProcess.Value = 100;
uiProcessBar_ConectProcess.Visible = false;
break;
}
case 1:
{
MessageBox.Show("尚未实现PPPoE,请等待更新");
break;
}
}
}
else
ShowErrorDialog("错误", "由于网络已处于连接状态,无须一键连接");
uiSymbolButton_OneKeyConnect.Enabled = true;
}
else
{
ShowErrorDialog("错误", "拨号账号配置文件解密失败,请重置后重试");
LogAppend(CustomColor.Error, "一键连接失败:拨号账号配置文件解密失败");
}
}
else
{
ShowErrorDialog("错误", "由于未选择拨号方式,连接网络失败\n请在选择拨号方式后重试");
LogAppend(CustomColor.Error, "一键连接失败:未选择拨号方式");
}
timer_AutoReConnect.Enabled = true;
}
/// <summary>
/// 时钟循环检查网络状态
/// </summary>
private void timer_NetChecker_Tick(object sender, EventArgs e)
{
Thread netCheckThread = new Thread(() =>
{
switch (GetInternetConStatus.GetNetConStatus("baidu.com"))//GetInternetConStatus.GetNetConStatus("baidu.com")
{
case 1:
{
//网络未连接
uiTitlePanel_NetStatus.TitleColor = Color.DarkOrange;
uiTitlePanel_NetStatus.RectColor = Color.DarkOrange;
uiAvatar_NetStatus.ForeColor = Color.DarkOrange;
uiSymbolLabel_ConnectCheck.ForeColor = Color.DarkOrange;
uiSymbolLabel_ConnectCheck.SymbolColor = Color.DarkOrange;
uiSymbolLabel_InternetDeviceType.ForeColor = Color.DarkOrange;
uiSymbolLabel_InternetDeviceType.SymbolColor = Color.DarkOrange;
uiSymbolLabel_PingOK.ForeColor = Color.DarkOrange;
uiSymbolLabel_PingOK.SymbolColor = Color.DarkOrange;
uiSymbolLabel_ConnectCheck.Symbol = 61453;//×,未通过
uiSymbolLabel_InternetDeviceType.Symbol = 61453;
uiSymbolLabel_PingOK.Symbol = 61453;
uiSymbolLabel_ConnectCheck.Text = "网络未连接";
uiSymbolLabel_InternetDeviceType.Text = "上网类型未知";
uiSymbolLabel_PingOK.Text = "Ping失败";
_autoReConnectFlag = 0;
LogAppend(CustomColor.Error, "[时钟检测网络]网络未连接 - 1");
successConnectCount = 0;
break;
}
case 2:
{
//采用调制解调器上网
uiTitlePanel_NetStatus.TitleColor = Color.FromArgb(80, 160, 255);
uiTitlePanel_NetStatus.RectColor = Color.FromArgb(80, 160, 255);
uiAvatar_NetStatus.ForeColor = Color.FromArgb(80, 160, 255);
uiSymbolLabel_ConnectCheck.ForeColor = Color.FromArgb(80, 160, 255);
uiSymbolLabel_ConnectCheck.SymbolColor = Color.FromArgb(80, 160, 255);
uiSymbolLabel_InternetDeviceType.ForeColor = Color.FromArgb(80, 160, 255);
uiSymbolLabel_InternetDeviceType.SymbolColor = Color.FromArgb(80, 160, 255);
uiSymbolLabel_PingOK.ForeColor = Color.FromArgb(80, 160, 255);
uiSymbolLabel_PingOK.SymbolColor = Color.FromArgb(80, 160, 255);
uiSymbolLabel_ConnectCheck.Symbol = 61452;//钩,通过
uiSymbolLabel_InternetDeviceType.Symbol = 61452;
uiSymbolLabel_PingOK.Symbol = 61452;
uiSymbolLabel_ConnectCheck.Text = "网络已连接";
uiSymbolLabel_InternetDeviceType.Text = "调制解调器上网";
uiSymbolLabel_PingOK.Text = "Ping正常";
_autoReConnectFlag = 1;
if(_versionCheckLocker == 0)
{
Thread checker = new Thread(VersionDataCheck);
checker.Start();
_versionCheckLocker++;
}
if (successConnectCount < 10)
successConnectCount++;
else
{
LogAppend(CustomColor.Success, "[时钟检测网络]网络已连接 - 2");
successConnectCount = 0;
}
break;
}
case 3:
{
//采用网卡上网
uiTitlePanel_NetStatus.TitleColor = Color.FromArgb(80, 160, 255);
uiTitlePanel_NetStatus.RectColor = Color.FromArgb(80, 160, 255);
uiAvatar_NetStatus.ForeColor = Color.FromArgb(80, 160, 255);
uiSymbolLabel_ConnectCheck.ForeColor = Color.FromArgb(80, 160, 255);
uiSymbolLabel_ConnectCheck.SymbolColor = Color.FromArgb(80, 160, 255);
uiSymbolLabel_InternetDeviceType.ForeColor = Color.FromArgb(80, 160, 255);
uiSymbolLabel_InternetDeviceType.SymbolColor = Color.FromArgb(80, 160, 255);
uiSymbolLabel_PingOK.ForeColor = Color.FromArgb(80, 160, 255);
uiSymbolLabel_PingOK.SymbolColor = Color.FromArgb(80, 160, 255);
uiSymbolLabel_ConnectCheck.Symbol = 61452;//钩,通过
uiSymbolLabel_InternetDeviceType.Symbol = 61452;
uiSymbolLabel_PingOK.Symbol = 61452;
uiSymbolLabel_ConnectCheck.Text = "网络已连接";
uiSymbolLabel_InternetDeviceType.Text = "使用网卡上网";
uiSymbolLabel_PingOK.Text = "Ping正常";
_autoReConnectFlag = 1;
if (_versionCheckLocker == 0)
{
Thread checker = new Thread(VersionDataCheck);
checker.Start();
_versionCheckLocker++;
}
if (successConnectCount < 10)
successConnectCount++;
else
{
LogAppend(CustomColor.Success, "[时钟检测网络]网络已连接 - 3");
successConnectCount = 0;
}
break;
}
case 4:
{
//采用调制解调器上网,但是联不通指定网络
uiTitlePanel_NetStatus.TitleColor = Color.DarkOrange;
uiTitlePanel_NetStatus.RectColor = Color.DarkOrange;
uiAvatar_NetStatus.ForeColor = Color.DarkOrange;
uiSymbolLabel_ConnectCheck.ForeColor = Color.DarkOrange;
uiSymbolLabel_ConnectCheck.SymbolColor = Color.DarkOrange;
uiSymbolLabel_InternetDeviceType.ForeColor = Color.DarkOrange;
uiSymbolLabel_InternetDeviceType.SymbolColor = Color.DarkOrange;
uiSymbolLabel_PingOK.ForeColor = Color.DarkOrange;
uiSymbolLabel_PingOK.SymbolColor = Color.DarkOrange;
uiSymbolLabel_ConnectCheck.Symbol = 61453;//×,未通过
uiSymbolLabel_InternetDeviceType.Symbol = 61453;
uiSymbolLabel_PingOK.Symbol = 61453;
uiSymbolLabel_ConnectCheck.Text = "网络未连接";
uiSymbolLabel_InternetDeviceType.Text = "调制解调器上网";
uiSymbolLabel_PingOK.Text = "Ping失败";
_autoReConnectFlag = 0;
LogAppend(CustomColor.Error, "[时钟检测网络]网络未连接 - 4");
successConnectCount = 0;
break;
}
case 5:
{
//采用网卡上网,但是联不通指定网络
uiTitlePanel_NetStatus.TitleColor = Color.DarkOrange;
uiTitlePanel_NetStatus.RectColor = Color.DarkOrange;
uiAvatar_NetStatus.ForeColor = Color.DarkOrange;
uiSymbolLabel_ConnectCheck.ForeColor = Color.DarkOrange;
uiSymbolLabel_ConnectCheck.SymbolColor = Color.DarkOrange;
uiSymbolLabel_InternetDeviceType.ForeColor = Color.DarkOrange;
uiSymbolLabel_InternetDeviceType.SymbolColor = Color.DarkOrange;
uiSymbolLabel_PingOK.ForeColor = Color.DarkOrange;
uiSymbolLabel_PingOK.SymbolColor = Color.DarkOrange;
uiSymbolLabel_ConnectCheck.Symbol = 61453;//×,未通过
uiSymbolLabel_InternetDeviceType.Symbol = 61453;
uiSymbolLabel_PingOK.Symbol = 61453;
uiSymbolLabel_ConnectCheck.Text = "网络未连接";
uiSymbolLabel_InternetDeviceType.Text = "使用网卡上网";
uiSymbolLabel_PingOK.Text = "Ping失败";
_autoReConnectFlag = 0;
LogAppend(CustomColor.Error, "[时钟检测网络]网络未连接 - 5");
successConnectCount = 0;
break;
}
}
});
netCheckThread.Start();
}
/// <summary>
/// 保存软件设置
/// 如果此前已有配置文件,那么看之前的配置文件的开机自启是开还是关,然后设置反,故与第一次设置不同
/// </summary>
private void uiSymbolButton_SaveSoftwareConfig_Click(object sender, EventArgs e)
{
if (File.Exists("Config.json") == false)
{
SoftwareConfig newSoftwareConfig = new SoftwareConfig()
{
AutoStart = uiCheckBox_AutoStart.Checked == true ? 1 : 0,
AutoConnect = uiCheckBox_AutoConnect.Checked == true ? 1 : 0,
AutoReConnect = uiCheckBox_AutoReConnect.Checked == true ? 1 : 0,
ReConnectCount = uiIntegerUpDown_ReConnectCount.Value
};
string json = JsonConvert.SerializeObject(newSoftwareConfig);
//MessageBox.Show(json);
try
{
if(uiCheckBox_AutoStart.Checked == true)//此处不用写日志,因为保存完成后会重启,所以只需要写保存失败的日志
{
ShowWaitForm("正在设置开机自动启动...");
AutoStart start = new AutoStart();
start.SetMeAutoStart(true);
SetWaitFormDescription("开机自动启动设置成功");
Thread.Sleep(1000);
SetWaitFormDescription("正在保存配置文件...");
Thread.Sleep(1000);
File.WriteAllText(@"Config.json", json);
HideWaitForm();
}
else//不用设置开机自启 所以只需要写配置文件就好
{
File.WriteAllText(@"Config.json", json);
LogAppend(CustomColor.Success, "保存软件配置文件成功");
}
}
catch (Exception ex)
{
ShowErrorDialog("异常捕获", string.Format("保存软件配置文件失败\n异常消息:\n{0}\n异常跟踪:\n{1}", ex.Message, ex.Source));
LogAppend(CustomColor.Error, "保存软件配置文件失败:写文件时异常");
}
finally
{
UIMessageDialog.ShowMessageDialog("已保存完毕,需要重启软件\n点击确认后软件自动重启", "提示", false, Style);
notifyIcon_MainForm.Dispose();
Application.Exit();
Process.Start(System.Reflection.Assembly.GetExecutingAssembly().Location);
}
}
else
{
if (ShowAskDialog("软件配置文件已经存在,是否需要以当前配置覆盖旧的账号配置?\n如果覆盖,旧的配置将永久失去"))
{
if(softwareConfig != null)
{
SoftwareConfig newSoftwareConfig = new SoftwareConfig()
{
AutoStart = uiCheckBox_AutoStart.Checked == true ? 1 : 0,
AutoConnect = uiCheckBox_AutoConnect.Checked == true ? 1 : 0,
AutoReConnect = uiCheckBox_AutoReConnect.Checked == true ? 1 : 0,
ReConnectCount = uiIntegerUpDown_ReConnectCount.Value
};
string json = JsonConvert.SerializeObject(newSoftwareConfig);
try
{
File.Delete(@"Config.json");//先前已存在配置文件,需要先删除再重新写
File.WriteAllText(@"Config.json", json);
}
catch(Exception ex)
{
UIMessageDialog.ShowMessageDialog("软件无法覆盖先前保存的配置文件\n尝试将软件目录下的\"Config\"文件手动删除后进行保存配置\n点击确定后软件自动打开软件所在目录并定位配置文件", "提示", false, Style);