-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmainwindow.cpp
1879 lines (1676 loc) · 62.1 KB
/
mainwindow.cpp
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
#include "mainwindow.h"
#include "ui_mainwindow.h"
//引入库文件,位置必须是绝对地址,有改变务必改动
#pragma comment(lib, "E:/QtProject/CSGO Toolbox/CSGO-Toolbox/libShareCodeToURLcs.lib" )
__declspec(dllimport) int api_Urlstring(const char* a);
//全局变量
QString steamPath = "";
QString launcherPath = "";
QString csgoPath = "";
QString steamID = "";
QString userName = "";
QString launchOption1 = "";
QString launchOption2 = "";
bool autoClip = false;
bool autoDownload = false;
bool backupdataZipped = false;
bool useTray = true;
bool launchFirst = true;
short cpuType = 0;
//TODO: 加载过程的文字显示在Loading界面上
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
setupUI();
createTray();
readSetting();
getSteamPath();
getCsgoPath();
refreshBackup();
if( SteamIDList.length() == 0 )
getSteamID();
else
setupUserdata();
}
MainWindow::~MainWindow()
{
if( useTray == true )
writeSetting();
delete ui;
}
/**
* 程序的核心模块,是完成其他实际功能的基础
* 1. 程序启动/关闭时调用
* 2. 获取各种路径
* 3. 获取SteamID
*/
/* 1. 程序启动/关闭时调用 */
//设置UI样式
void MainWindow::setupUI()
{
QFont font, font1, font2, font6, font60;
font.setFamily("微软雅黑");
qApp->setFont(font);
font1.setPixelSize(14);
font2.setPixelSize(17);
font6.setPixelSize(20);
font60.setPixelSize(60);
ui->centralwidget->setFont(font1);
ui->tabWidget->setFont(font2);
ui->TabMain->setFont(font2);
ui->backupSetting->setFont(font2);
ui->backupdata->setFont(font1);
ui->checkCsgoPath->setFont(font1);
ui->checkLauncherPath->setFont(font1);
ui->checkSteamID->setFont(font1);
ui->checkSteamPath->setFont(font1);
ui->getLauncherPathBtn->setFont(font2);
ui->getUserDataBtn->setFont(font2);
ui->manualBtn->setFont(font2);
ui->openBackupLoc->setFont(font2);
ui->openCNlocalcfg->setFont(font2);
ui->opencsgoDir->setFont(font2);
ui->opencsgocfg->setFont(font2);
ui->openlocalcfg->setFont(font2);
ui->userdata->setFont(font2);
ui->zipBackupdata->setFont(font2);
ui->TabSetting->setFont(font2);
ui->ManualSteamID->setFont(font2);
ui->manualCsgoBtn->setFont(font2);
ui->antiHarmony->setFont(font2);
ui->debug->setFont(font2);
ui->reloadHarmony->setFont(font2);
ui->solveVAC->setFont(font2);
ui->textID->setFont(font6);
ui->TabDemo->setFont(font2);
ui->autoClip->setFont(font2);
ui->autoDownload->setFont(font2);
ui->clipURL->setFont(font2);
ui->dispURL->setFont(font2);
ui->downURL->setFont(font2);
//ui->dragArea->setFont(font40);
ui->labelDispURL->setFont(font2);
ui->labelDragArea->setFont(font60);
ui->labelSharecode->setFont(font2);
ui->textEdit->setFont(font6);
ui->PCconfig->setFont(font2);
ui->labelDragArea->setAttribute(Qt::WA_TransparentForMouseEvents,true);
ui->checkSteamPath->setAttribute(Qt::WA_TransparentForMouseEvents,true);
ui->checkCsgoPath->setAttribute(Qt::WA_TransparentForMouseEvents,true);
ui->checkLauncherPath->setAttribute(Qt::WA_TransparentForMouseEvents,true);
}
//读取设置
void MainWindow::readSetting()
{
bool t;
QSettings *iniRead = new QSettings("./config.ini", QSettings::IniFormat);
iniRead->setIniCodec("utf-8"); //解决乱码问题
iniRead->beginGroup("Paths");
steamPath = iniRead->value("steamPath").toString();
launcherPath = iniRead->value("launcherPath").toString();
csgoPath = iniRead->value("csgoPath").toString();
iniRead->endGroup();
iniRead->beginGroup("User");
userName = iniRead->value("userName").toString();
steamID = iniRead->value("steamID").toString();
SteamIDList = iniRead->value("SteamIDList").toStringList();
PersonaNameList = iniRead->value("PersonaNameList").toStringList();
iniRead->endGroup();
iniRead->beginGroup("Auto");
autoClip = iniRead->value("autoClip").toBool();
autoDownload = iniRead->value("autoDownload").toBool();
iniRead->endGroup();
iniRead->beginGroup("Powerplan");
cpuType = iniRead->value("cpuType").toUInt();
iniRead->endGroup();
iniRead->beginGroup("LaunchOption");
launchOption1 = iniRead->value("launchOption1").toString();
launchOption2 = iniRead->value("launchOption2").toString();
t = iniRead->value("launchFirst").toBool();
if( iniRead->value("launchFirst").toString().isEmpty() )
launchFirst = true;
else
launchFirst = t;
iniRead->endGroup();
iniRead->beginGroup("Tray");
useTray = iniRead->value("useTray").toBool();
iniRead->endGroup();
//iniRead->beginGroup(" ");
// = iniRead->value(" ").toString();
//iniRead->endGroup();
//读入完成后删除指针
delete iniRead;
//检查如果路径不存在则置空
if( !isSteamExisted() )
steamPath = "";
if( !isLauncherExisted() )
launcherPath = "";
if( !isCsgoExisted() )
csgoPath = "";
//改变路径、iD相关的checkbox状态
onSteamPathChanged();
onCsgoPathChanged();
onLauncherPathChanged();
onSteamIDChanged();
//设置ui中的checkbox状态
if(autoClip == true)
ui->autoClip->setCheckState(Qt::Checked);
else
ui->autoClip->setCheckState(Qt::Unchecked);
if(autoDownload == true)
ui->autoDownload->setCheckState(Qt::Checked);
else
ui->autoDownload->setCheckState(Qt::Unchecked);
//设置电源计划radiobutton
switch(cpuType){
case 1:ui->Ryzen3000->setChecked(true);on_Ryzen3000_clicked(); break;
case 2:ui->RyzenEtc->setChecked(true);on_RyzenEtc_clicked();break;
case 3:ui->allPlatform->setChecked(true);on_allPlatform_clicked();break;
default:break;
}
//设置启动项
ui->LaunchOpt1->setText( launchOption1 );
ui->LaunchOpt2->setText( launchOption2 );
ui->sliderLaunchFirst->setValue( launchFirst );
//设置托盘
if( useTray == true )
ui->checkboxTray->setCheckState(Qt::Checked);
else
ui->checkboxTray->setCheckState(Qt::Unchecked);
}
//写入设置
void MainWindow::writeSetting()
{
//判断当前路径变量是否正确,否则置空
if( !isSteamExisted() )
steamPath = "";
if( !isLauncherExisted() )
launcherPath = "";
if( !isCsgoExisted() )
csgoPath = "";
//判断powerplan相关变量是否正确
if( cpuType > 3 || cpuType < 0 )
cpuType = 0;
//读取启动项
launchOption1 = ui->LaunchOpt1->text();
launchOption2 = ui->LaunchOpt2->text();
launchFirst = ui->sliderLaunchFirst->value();
//读取托盘设置
useTray = ui->checkboxTray->checkState();
//写设置
QSettings *IniWrite = new QSettings("./config.ini", QSettings::IniFormat);
IniWrite->setIniCodec("utf-8"); //解决乱码问题
IniWrite->beginGroup("AppInfo");
IniWrite->setValue("Name", qAppName());
IniWrite->setValue("Version", APP_VERSION);
IniWrite->endGroup();
IniWrite->beginGroup("Paths");
IniWrite->setValue("steamPath", steamPath);
IniWrite->setValue("launcherPath", launcherPath);
IniWrite->setValue("csgoPath", csgoPath);
IniWrite->endGroup();
IniWrite->beginGroup("User");
IniWrite->setValue("userName", userName);
IniWrite->setValue("steamID", steamID);
IniWrite->setValue("SteamIDList", SteamIDList);
IniWrite->setValue("PersonaNameList", PersonaNameList);
IniWrite->endGroup();
IniWrite->beginGroup("Auto");
IniWrite->setValue("autoClip", autoClip);
IniWrite->setValue("autoDownload", autoDownload);
IniWrite->endGroup();
IniWrite->beginGroup("Powerplan");
IniWrite->setValue("cpuType", cpuType);
IniWrite->endGroup();
IniWrite->beginGroup("LaunchOption");
IniWrite->setValue("launchOption1", launchOption1);
IniWrite->setValue("launchOption2", launchOption2);
IniWrite->setValue("launchFirst", launchFirst);
IniWrite->endGroup();
IniWrite->beginGroup("Tray");
IniWrite->setValue("useTray", useTray);
IniWrite->endGroup();
//IniWrite->beginGroup(" ");
//IniWrite->setValue(" ", );
//IniWrite->endGroup();
//写入完成后删除指针
delete IniWrite;
}
//关闭主界面时保存设置
void MainWindow::closeEvent(QCloseEvent *e)
{
if(useTray == true){
e->ignore();//忽略关闭事件
hide();//隐藏窗口
}
else{
writeSetting();
e->accept();
}
}
//右下角托盘相关
void MainWindow::createTray()
{
menu = new QMenu( this );//托盘菜单
menuLaunchOpt = new QMenu( this );
QAction *changeOpt = new QAction( this );
QAction *LaunchPwrd = new QAction( this );
QAction *LaunchWwd = new QAction( this );
QAction *killcsgoproc = new QAction( this );
//QAction *reset = new QAction( this );//菜单实现功能:恢复窗口
QAction *quit = new QAction( this );//菜单实现功能:退出程序
/****托盘*** */
tray = new QSystemTrayIcon( this );
tray->setIcon( QIcon( QPixmap( ":/file/logo.png" ) ) );
tray->show();
tray->setToolTip("CSGO工具箱");
QObject::connect( tray, SIGNAL( activated( QSystemTrayIcon::ActivationReason ) ), this, SLOT( TrayIconAction( QSystemTrayIcon::ActivationReason ) ) );
/****初始化托盘菜单及功能****/
if(launchFirst == true)
menuLaunchOpt->setTitle("当前启动项 ①");
else
menuLaunchOpt->setTitle("当前启动项 ②");
changeOpt->setText("切换");
QObject::connect( changeOpt, SIGNAL( triggered() ), this, SLOT( changeLaunchOpt() ) );
LaunchWwd->setText("启动国际服");
LaunchPwrd->setText("启动国服");
QObject::connect( LaunchWwd, SIGNAL( triggered() ), this, SLOT( launchWwd() ) );
QObject::connect( LaunchPwrd, SIGNAL( triggered() ), this, SLOT( launchPwrd() ) );
killcsgoproc->setText("关闭CSGO");
QObject::connect( killcsgoproc, SIGNAL( triggered() ), this, SLOT( killcsgo() ) );
//reset->setText( "打开主面板" );
//QObject::connect( reset, SIGNAL( triggered() ), this, SLOT( dispForm() ) );
quit->setText( "退出" );
QObject::connect( quit, SIGNAL( triggered() ), qApp, SLOT( quit() ) );
menu->setStyleSheet("QMenu::item {padding: 2px 22px 2px 12px;}QMenu::item:selected {"
"background-color: rgb(145, 201, 247);color: rgb(0, 0, 0);}");
menuLaunchOpt->setStyleSheet("QMenu::item {padding: 2px 22px 2px 12px;}QMenu::item:selected {"
"background-color: rgb(145, 201, 247);color: rgb(0, 0, 0);}");
tray->setContextMenu( menu );
menu->addMenu( menuLaunchOpt );
menuLaunchOpt->addAction( changeOpt );
menu->addSeparator();
menu->addAction( LaunchWwd );
//menu->addSeparator();
menu->addAction( LaunchPwrd );
menu->addSeparator();
menu->addAction( killcsgoproc );
menu->addSeparator();
//menu->addAction( reset );
menu->addAction( quit );
}
void MainWindow::dispForm()
{
this->showNormal();
this->activateWindow();
this->setWindowState( (this->windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
}
void MainWindow::TrayIconAction(QSystemTrayIcon::ActivationReason reason)
{ /* 如果对图标进行单击,则显示正常大小的窗口 */
if ( reason == QSystemTrayIcon::Trigger ){
QPoint mspos = cursor().pos();//获取鼠标位置
menu->show();
menu->move(mspos.rx(), mspos.ry() - 140 );
}
else if ( reason == QSystemTrayIcon::DoubleClick )
dispForm();
}
void MainWindow::on_checkboxTray_stateChanged(int arg1)
{
if(arg1 == Qt::Checked )
useTray = true;
else
useTray = false;
}
void MainWindow::killcsgo()
{
cmd("taskkill /F /IM csgo.exe");
}
void MainWindow::launchWwd()
{
if(launchFirst == true)
on_LaunchWwd1_clicked();
else
on_LaunchWwd2_clicked();
}
void MainWindow::launchPwrd()
{
if(launchFirst == true)
on_LaunchPwrd1_clicked();
else
on_LaunchPwrd2_clicked();
}
/* 2. 获取各种路径 */
//获取Steam路径
bool MainWindow::getSteamPath()
{
#define STEAM_KEY "HKEY_CURRENT_USER\\SOFTWARE\\Valve\\Steam" //注册表SteamExe项所在位置
//第一步 读取设置中的steamPath 已经在main()中调用 readSetting()
QString tPath = steamPath;
//第二步 尝试默认路径
if( !isSteamExisted(tPath) ){
QStringList defSteamPath;
defSteamPath
<< QStringLiteral("C:/Program Files (x86)/steam/Steam.exe")
<< QStringLiteral("C:/Steam/Steam.exe")
<< QStringLiteral("D:/Steam/Steam.exe")
<< QStringLiteral("E:/Steam/Steam.exe")
<< QStringLiteral("G:/Steam/Steam.exe")
<< QStringLiteral("H:/Steam/Steam.exe")
;
for(int i = 0; i< defSteamPath.size(); i++)
{
if( isSteamExisted( defSteamPath.at(i) ) ){
tPath = defSteamPath.at(i);
break;
}
}
}
//第三步 读取注册表中路径 //HKEY_CURRENT_USER\SOFTWARE\Valve\Steam 查询SteamExe
if( !isSteamExisted(tPath) ){
QSettings *pReg = new QSettings(STEAM_KEY, QSettings::NativeFormat);
tPath = pReg->value("SteamExe").toString(); //读取注册表值
//pReg->setValue("key", "value"); //设置注册表值
delete pReg;
}
//第四步 读取进程列表 要打开steam
if( !isSteamExisted(tPath) ){
QUrl url( "steam://rungame" );
QDesktopServices::openUrl(url);
tPath = getProcessPath("steam.exe");
for(int count = 10; count >0 && !QFile::exists( tPath ) ; count-- ){
stall(100);
tPath = getProcessPath("steam.exe");
}
}
//第五步 自动获取路径失败 提示用户手动选择路径
if( isSteamExisted(tPath) ){
steamPath = tPath;
onSteamPathChanged();
return true;
}
else{
QMessageBox::warning(this, "提示", "自动获取Steam路径失败,请手动选择!");
return false;
}
}
//获取国服启动器csgoLauncher路径
bool MainWindow::getLauncherPath()
{
#define Launcher_KEY "HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\Valve\\Steam\\NSIS" //注册表CSGO项所在位置 TODO:
//第一步 读取设置中的launcherPath 已经在main()中调用 readSetting()
QString tPath = launcherPath;
//第二步 读取注册表中路径
if( !isLauncherExisted(tPath) ){
QSettings *pReg = new QSettings(Launcher_KEY, QSettings::NativeFormat);
tPath = pReg->value("Path").toString(); //读取注册表值
delete pReg;
if( !tPath.isEmpty() )
tPath = tPath.append("\\csgolauncher.exe");
}
//第三步 读取进程列表 要打开国服启动器
if( !isLauncherExisted(tPath) ){
QUrl url( "steam://rungame" );
QDesktopServices::openUrl(url);
tPath = getProcessPath("csgolauncher.exe");
for(int count = 10; count >0 && !QFile::exists( tPath ) ; count-- ){
stall(100);
tPath = getProcessPath("csgolauncher.exe");
}
}
//第四步 自动获取路径失败 提示用户手动选择路径
if( isLauncherExisted(tPath) ){
launcherPath = tPath;
onLauncherPathChanged();
return true;
}
else{
QMessageBox::warning(this, "提示", "自动获取国服客户端路径失败,请手动选择!");
tPath = QFileDialog::getOpenFileName(this, "选择国服启动器csgolauncher.exe的位置", tPath, "csgolauncher.exe");
if( !isLauncherExisted(tPath) ){
return false;
}
launcherPath = tPath;
return false;
}
}
//获取国服启动器路径的槽函数
void MainWindow::on_getLauncherPathBtn_clicked()
{
getLauncherPath();
}
//获取CSGO路径
bool MainWindow::getCsgoPath()
{
//第一步 读取设置中的csgoPath 已经在main()中调用 readSetting()
QString tPath = csgoPath;
//第二步 尝试默认路径
if( !isCsgoExisted(tPath) ){
QStringList defCsgoPath;
defCsgoPath
<< QStringLiteral("C:/Program Files (x86)/Steam/steamapps/common/Counter-Strike Global Offensive/csgo.exe")
<< QStringLiteral("C:/steam/steamapps/common/Counter-Strike Global Offensive/csgo.exe")
<< QStringLiteral("D:/SteamLibrary/steamapps/common/Counter-Strike Global Offensive/csgo.exe")
<< QStringLiteral("E:/SteamLibrary/steamapps/common/Counter-Strike Global Offensive/csgo.exe")
<< QStringLiteral("F:/SteamLibrary/steamapps/common/Counter-Strike Global Offensive/csgo.exe")
<< QStringLiteral("G:/SteamLibrary/steamapps/common/Counter-Strike Global Offensive/csgo.exe")
<< QStringLiteral("H:/SteamLibrary/steamapps/common/Counter-Strike Global Offensive/csgo.exe")
;
for(int i = 0; i< defCsgoPath.size(); i++)
{
if( QFile::exists( defCsgoPath.at(i) ) ){
tPath = defCsgoPath.at(i);
break;
}
}
}
//第三步 根据Steam或国服启动器获得路径
if( !isCsgoExisted(tPath) ){
if( isSteamExisted() ){
tPath = steamPath;
tPath = tPath.replace("steam.exe", "steamapps/common/Counter-Strike Global Offensive/csgo.exe", Qt::CaseInsensitive);
}
else if( isCsgoExisted() ){
tPath = steamPath;
tPath = tPath.replace("steam.exe", "steamapps/common/Counter-Strike Global Offensive/csgo.exe", Qt::CaseInsensitive);
}
}
//第四步 读取进程列表 要打开steam和csgo 会强制关闭CSGO
if( !isCsgoExisted(tPath) ){
QUrl url( "steam://rungameid/730" );
QDesktopServices::openUrl(url);
tPath = getProcessPath("csgo.exe");
for(int count = 10; count >0 && !QFile::exists( tPath ) ; count-- ){
stall(100);
tPath = getProcessPath("csgo.exe");
cmd("taskkill /F /IM csgo.exe");
}
}
//第五步 自动获取路径失败 提示用户手动选择路径
if( isCsgoExisted(tPath) ){
csgoPath = tPath;
onCsgoPathChanged();
return true;
}
else{
QMessageBox::warning(this, "提示", "自动获取CSGO路径失败,请手动选择!");
return false;
}
}
//手动设置路径
void MainWindow::on_manualBtn_clicked()
{
QString tPath = "";
if( !isSteamExisted() ){
tPath = QFileDialog::getOpenFileName(this, "选择steam.exe的位置", tPath, "steam.exe");
if( !isSteamExisted(tPath) ){
return;
}
steamPath = tPath;
}
if( !isCsgoExisted()){
tPath = QFileDialog::getOpenFileName(this, "选择csgo.exe的位置", tPath, "csgo.exe");
if( !isCsgoExisted(tPath) ){
return;
}
csgoPath = tPath;
}
//已有路径的处理 TODO: 路径设置好后直接enabled 0
if( isSteamExisted() && isCsgoExisted() ){
QMessageBox::warning(this, "提示", "路径已有,无需手动选择!");
}
}
//手动选择csgo位置
void MainWindow::on_manualCsgoBtn_clicked()
{
QString tPath = "";
tPath = QFileDialog::getOpenFileName(this, "选择csgo.exe的位置", tPath, "csgo.exe");
if( !isCsgoExisted(tPath) ){
return;
}
csgoPath = tPath;
}
/* 3. 获取SteamID */
//获取SteamID32,32比特,一般9位数字 TODO: 改进算法
void MainWindow::getSteamID()
{
QString fileName = "";
if( isSteamExisted() ){
fileName = steamPath;
fileName.replace("steam.exe" ,"userdata/", Qt::CaseInsensitive );
}
else if( isLauncherExisted() ){
fileName = launcherPath;
fileName.replace("csgolauncher.exe" ,"userdata/", Qt::CaseInsensitive );
}
else{
QMessageBox::warning(this, "提示", "没有获得Steam或国服客户端路径!");
return;
}
//读取userdata下所有包含数字的文件名得到SteamID
QDir *dir=new QDir(fileName);
QStringList filter;
QString temp;
QList<QFileInfo> *fileInfo=new QList<QFileInfo>(dir->entryInfoList(filter));
for(int i = 0; i < fileInfo->count(); i++)
{
temp = QString::fromStdString( ( fileInfo->at(i).fileName().toStdString() ) );
if( isDigitStr( temp ) == true && !SteamIDList.contains( temp ))
SteamIDList << temp;
}
for(int i = 0 ; i < SteamIDList.length() ; i++){
temp = fileName + SteamIDList.at(i) + "/config/localconfig.vdf";
QFile f( temp );
if ( !f.exists() ) //文件不存在
return;
if ( !f.open(QIODevice::ReadOnly | QIODevice::Text) )
return;
QTextStream fStream(&f); //用文本流读取文件
fStream.setCodec("utf-8"); //解决乱码问题
QString content = fStream.readAll();
f.close();
//去除无用字符 查找昵称
content = get_until(content, "communitypreferences");
search_and_cut(content , "PersonaName");
content.remove("\n");
content.remove("\"");
content.remove("\t");
if( !PersonaNameList.contains( content ) )
PersonaNameList << content;
}
//单用户时直接确定ID
if(SteamIDList.length() == 1){
steamID = SteamIDList.at(0);
userName = PersonaNameList.at(0);
onSteamIDChanged();
QMessageBox::warning(this, "提示", "检测到只有一个用户ID,已设置好SteamID!\n SteamID = " + steamID);
}
//显示在tabview上 用户按一次按钮完成选择 //TODO: debug
setupUserdata();
}
void MainWindow::setupUserdata()
{
QFont font;
font.setPixelSize(17);
short n = SteamIDList.length();
ui->userdata->setColumnCount(4);
ui->userdata->setRowCount(n);
ui->userdata->setColumnWidth(0,98);
ui->userdata->setColumnWidth(1,180);
ui->userdata->setColumnWidth(2,65);
ui->userdata->setColumnWidth(3,65);
QStringList header;
header << "SteamID" << "昵称" << "" << "";
ui->userdata->setHorizontalHeaderLabels(header);
for(short i = 0; i < n; i++){
ui->userdata->setRowHeight(i, 35);
ui->userdata->setItem(i, 0, new QTableWidgetItem(SteamIDList.at(i)));
ui->userdata->item(i,0)->setTextAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
ui->userdata->setItem(i, 1, new QTableWidgetItem(PersonaNameList.at(i)));
ui->userdata->item(i,1)->setTextAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
QPushButton *chooseBtn = new QPushButton();
connect(chooseBtn, SIGNAL(clicked()), this, SLOT(onChooseBtnClicked()));
QPushButton *DeleteBtn = new QPushButton();
connect(DeleteBtn, SIGNAL(clicked()), this, SLOT(onUserDeleteBtnClicked()));
//在QTableWidget中添加控件:删除按钮
ui->userdata->setCellWidget(i, 2, DeleteBtn);
DeleteBtn->setProperty("id", i);
DeleteBtn->setProperty("text", "删除");
DeleteBtn->setProperty("status", "normal");
DeleteBtn->setFont(font);
//选择按钮
ui->userdata->setCellWidget(i, 3, chooseBtn);
chooseBtn->setProperty("id", i);
chooseBtn->setProperty("text", "选择");
chooseBtn->setProperty("status", "normal");
chooseBtn->setFont(font);
}
ui->userdata->setEditTriggers(QAbstractItemView::NoEditTriggers);
}
//选择按钮按下时切换SteamID
void MainWindow::onChooseBtnClicked()
{
QPushButton *senderObj=qobject_cast<QPushButton*>(sender());
if(senderObj == nullptr){
return;
}
QModelIndex idx = ui->userdata->indexAt(QPoint(senderObj->frameGeometry().x(),senderObj->frameGeometry().y()));
int row = idx.row();
steamID = ui->userdata->item(row, 0)->text();
userName = ui->userdata->item(row, 1)->text();
onSteamIDChanged();
}
//删除按钮按下时删除对应用户信息
void MainWindow::onUserDeleteBtnClicked()
{
QPushButton *senderObj=qobject_cast<QPushButton*>(sender());
if(senderObj == nullptr){
return;
}
QModelIndex idx = ui->userdata->indexAt(QPoint(senderObj->frameGeometry().x(),senderObj->frameGeometry().y()));
int row = idx.row();
QString temp = ui->userdata->item(row, 0)->text();
ui->userdata->removeRow(row);
row = SteamIDList.indexOf( temp );
if( SteamIDList.contains( temp ) ){
SteamIDList.removeAt( row );
PersonaNameList.removeAt( row );
}
if( temp == steamID )
steamID = "";
onSteamIDChanged();
}
//手动输入SteamID TODO: 进一步加强
void MainWindow::on_ManualSteamID_clicked()
{
QString tID = ui->textID->toPlainText();
if( tID.isEmpty() )
return;
else if( !isDigitStr(tID) || tID.length() < 8 || tID.length() > 10 ){
ui->debug->appendPlainText("ID格式有误!");
return;
}
QString tPath = "";
if( isSteamExisted() ){
tPath = steamPath;
tPath.replace("Steam.exe", "userdata/" +tID, Qt::CaseInsensitive);
if( QFile::exists( tPath ) ){
steamID = tID;
onSteamIDChanged();
ui->debug->appendPlainText("成功!");
ui->textID->setText("");
return;
}
else
ui->debug->appendPlainText("userdata目录下检测不到该ID对应的文件夹,注意检测ID正误");
}
else if( isLauncherExisted() ){
tPath = launcherPath;
tPath.replace("csgolauncher.exe", "userdata/" +tID, Qt::CaseInsensitive);
if( QFile::exists( tPath ) ){
steamID = tID;
onSteamIDChanged();
ui->debug->appendPlainText("成功!");
ui->textID->setText("");
return;
}
else
ui->debug->appendPlainText("userdata目录下检测不到该ID对应的文件夹,注意检测ID正误");
}
else{
ui->debug->appendPlainText("无Steam或国服启动器路径,无法识别,注意检测ID正误");
}
}
//按钮槽函数
void MainWindow::on_getUserDataBtn_clicked()
{
getSteamID();
}
/**
* 拓展功能,基于核心模块和封装好的功能模块,完成具体的功能
* 包括:
* 1. 转换DEMO分享代码 获得真实下载链接
* 2. 修复VAC验证问题
* 3. 备份和还原设置(个人cfg文件夹)
* 4. 国服反和谐和反和谐恢复
* 5. 打开各种cfg文件夹和csgo位置
*/
/*------------------------------------------------------------------------------------*/
// 转换DEMO分享代码 获得真实下载链接 注意这里不可对dragArea赋非空值否则会死循环
void MainWindow::sharecodeTransform()
{
const QString ShareCodePattern = "^CSGO(-?[\\w]{5}){5}$";
QRegExp reg( ShareCodePattern ); //正则表达式
//显示提示
ui->dispURL->setText("正在转换链接。。。");
//1. 读入分享代码(参照之前的项目)
QString ShareCode = ui->dragArea->toPlainText();
if( !QString(ShareCode).isEmpty() )
ui->dragArea->setText("");
else
return;
//2. 去掉分享代码的无用信息(得到标准格式) "CSGO-xxx"的长度为34
ShareCode = ShareCode.remove(0, ShareCode.lastIndexOf("CSGO-") ).left(34);
//3. 正则表达式匹配
if( !reg.exactMatch( ShareCode )){
ui->dispURL->setText("分享链接格式不正确!");
return; //TODO: 链接格式不正确的处理
}
//4. 标准格式转换成获取3个id需要的字符串格式(20个字符)
ShareCode.replace("CSGO-","");
ShareCode.replace("-", "");
//5. 调用@Yellowfisher编译的DLL库(核心代码源于github.com/akiver/CSGO-Demos-Manager)
// 获得URL(需要DLL+boiler.exe+steam_api.dll+steam_appid.txt)
//6. 打开Steam 关闭CSGO
cmd("explorer.exe \"steam://rungame\"");
cmd("taskkill /f /t /im csgo.exe");
do{
stall(100);
}while( getProcessPath("csgo.exe").endsWith("exe") );
//调用DLL库中函数 因为限制只能传进去char数组 故此处转换
QByteArray ba=ShareCode.toLatin1();
char *c = ba.data();
QString retValue = QString::number( api_Urlstring( c ) );
if( retValue != "0" ){
ui->dispURL->setText( " 转换失败!错误代码:" + retValue );
return;
}
QFile f("URL.txt");
if ( !f.exists() ) //文件不存在
return;
if ( !f.open(QIODevice::ReadOnly | QIODevice::Text) )
return;
QTextStream fStream(&f); //用文本流读取文件
fStream.setCodec("utf-8"); //解决乱码问题
QString URL = fStream.readAll();
URL.replace("\n", "");
URL.replace("\r", "");
f.close();
if ( QFile::exists("matches.dat") )
QFile::remove("matches.dat");
if ( QFile::exists("URL.txt") )
QFile::remove("URL.txt");
if( URL.startsWith("http://") )
ui->dispURL->setText(URL);
if( autoDownload == true )
on_downURL_clicked();
if( autoClip == true )
on_clipURL_clicked();
}
//开始下载DEMO
void MainWindow::on_downURL_clicked()
{
QString URL = ui->dispURL->toPlainText();
if( URL.startsWith("http://") ){
QUrl url( URL );
QDesktopServices::openUrl(url);
}
else
return;
}
//复制DEMO下载链接
void MainWindow::on_clipURL_clicked()
{
QString URL = ui->dispURL->toPlainText();
if( URL.startsWith("http://") ){
QClipboard *clipboard = QApplication::clipboard(); //获取系统剪贴板指针
clipboard->setText(URL); //设置剪贴板内容</span>
}
else
return;
}
//自动下载checkbox按下
void MainWindow::on_autoDownload_stateChanged(int arg1)
{
if(arg1 == Qt::Checked )
autoDownload = true;
else
autoDownload = false;
}
//自动复制checkbox按下
void MainWindow::on_autoClip_stateChanged(int arg1)
{
if(arg1 == Qt::Checked )
autoClip = true;
else
autoClip = false;
}
//拖拽区域文字发生改变时调用 注意这里不可对dragArea赋非空值否则会死循环
void MainWindow::on_dragArea_textChanged()
{
sharecodeTransform();
}
/*------------------------------------------------------------------------------------*/
//修复VAC验证问题 TODO:
void MainWindow::solveVacIssue()
{
//检查路径是否正确
QString tPath;
if( isSteamExisted() ){
tPath = steamPath;
tPath.replace("steam.exe", "", Qt::CaseInsensitive);
}
else if( isLauncherExisted() ){
tPath = launcherPath;
tPath.replace("csgolauncher.exe", "", Qt::CaseInsensitive);
}
else{
QMessageBox::warning(this, "提示", "未获得Steam或国服路径!");
return;
}
//检查用到的批处理脚本
if( !QFile::exists( QCoreApplication::applicationDirPath() + "/SolveVAC.bat" ) ){
QMessageBox::warning(this, "提示", "SolveVAC.bat文件丢失!");
return;
}
QString command = "\"" + QCoreApplication::applicationDirPath() + "/SolveVAC.bat\" " + tPath;
QString output = cmd( command );
QMessageBox::warning(this, "提示", "已调出批处理脚本,如果不好使请到QQ群反馈,见'关于'");
}
//槽函数
void MainWindow::on_solveVAC_clicked()
{
solveVacIssue();
}
/*------------------------------------------------------------------------------------*/
//备份设置
void MainWindow::on_backupSetting_clicked()
{
if( steamID.isEmpty() )
return;
QString tPath = "";
if( isSteamExisted() ){
tPath = steamPath;
tPath.replace("steam.exe", "userdata/" + steamID + "/730/local/cfg", Qt::CaseInsensitive);
}
else if ( isLauncherExisted() ){
tPath = launcherPath;
tPath.replace("csgolauncher.exe", "userdata/" + steamID + "/730/local/cfg", Qt::CaseInsensitive);
}
else return;
QDateTime current_date_time = QDateTime::currentDateTime();
QString zipName = current_date_time.toString("yyyy-MM-dd_hh-mm-ss_%1").arg(userName.left(6)) + ".zip";
QString zipPath = QCoreApplication::applicationDirPath() + "/备份/";
QDir dir;
//如果路径不存在则创建
if (!dir.exists(zipPath)) dir.mkpath(zipPath);
if (!dir.exists(tPath)) dir.mkpath(tPath);
//压缩
JlCompress::compressDir(zipPath + zipName, tPath);
//TODO: 压缩后的操作
QMessageBox::warning(this, "提示", "备份成功!");
refreshBackup();
}
//刷新备份backupdata域
void MainWindow::refreshBackup()
{ //显示在tablewidget上 用户按一次按钮完成选择
QString tPath = "";
if( isSteamExisted() ){