Repository navigation
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
3698 lines (3440 loc) · 187 KB
/
Copy pathmainwindow.cpp
File metadata and controls
3698 lines (3440 loc) · 187 KB
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 "qnetworkreply.h"
#include "ui_mainwindow.h"
//#include "ui_dialog_deviceList.h"
#include <QFileInfoList>
#include <QDesktopServices>
#include <QProcess>
#include <QFile>
#include <QCursor>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QCryptographicHash>
#include <QStack>
#include <QThread>
#include <QElapsedTimer>
#include <QMessageBox>
#include <QFileIconProvider>
#ifdef Q_OS_WIN
#include <windows.h>
#include <shlobj.h>
#endif
#include <QScreen>
#include <QInputDialog>
#ifdef Q_OS_WIN
#include <winuser.h>
#include <dwmapi.h>
#endif
#include <QSysInfo>
#include <QUrlQuery>
#include <QSystemTrayIcon>
#include <QClipboard>
#include <QBuffer>
#include <QPainter>
#include <QUuid>
#include <QMetaEnum>
#include <qcachedbytearray.h>
#include <passport.h>
#include <QFileDialog>
#include <QShortcut>
#ifdef Q_OS_ANDROID
// #include <QAndroidJniEnvironment>
// #include <QAndroidJniObject>
// #include <QtAndroid>
#endif
//#define process_events_without_useript QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents)
////#define idToString(id) #id
////调试定义
////#define DEBUG_NO_ENCRYPTION
//using namespace std;
//MainWindow::MainWindow(BusinessLogic *bl,QWidget *parent, std::function<void(QString)> func_update, bool bShow)
// : QMainWindow(parent)
// , businesslogic(bl)
// , ui(new Ui::MainWindow)
// , settings("config/settings.ini",QSettings::IniFormat)
//{
// //对象创建
// m_communication = new Communication;
// m_signalling = new Signalling;
// m_storage = new Storage;
// m_transmissionengine = nullptr;
// label_status = new QLabel(this);
// process_proxy = new QProcess(this);
// process_proxy_ui = new QProcess(this);
// line_ackloop = new QLineSeries(this);
// line_delay = new QLineSeries(this);
// line_speed = new QLineSeries(this);
//// dialog_remoteFile = new Dialog_remoteFile(this);
// logFile = new QFile(QString("logs/%1.log").arg(QDateTime::currentDateTime().toString("yyyyMMdd-hhmmss")).toStdString().c_str(),this);
// //安卓平台设置
//#ifdef Q_OS_ANDROID
// /*QString currentWorkPath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
// ninfo<<"工作目录信息配置正确。"<<currentWorkPath;
// if(!currentWorkPath.contains("Android/data")){
// ninfo<<"工作目录:"<<currentWorkPath;
// QString ph = "/storage/emulated/0/Android/data/com.nnpyro.SyncTunnel/";
//// ui->statusBar->showMessage("成功配置了工作目录",1);
// QDir dir(ph);
// if(!dir.exists())dir.mkpath(".");
// QDir::setCurrent(ph);
// }*/
// QAndroidJniObject context = QtAndroid::androidContext();
// if(!context.isValid()){
// ncritical<<"context 无效";
// QMessageBox::critical(this,tr("SyncTunnel 错误"),tr("无法设置运行目录。将使用私有目录,功能受限。\ncontext无效"));
// }
// else{
// QAndroidJniObject fileObj = context.callObjectMethod("getExternalFilesDir","(Ljava/lang/String;)Ljava/io/File;",nullptr);
// if(!fileObj.isValid()){
// ncritical<<"fileObj 无效";
// QMessageBox::critical(this,tr("SyncTunnel 错误"),tr("无法设置运行目录。将使用私有目录,功能受限。\nfileObj无效"));
// }
// else{
// QAndroidJniObject o = fileObj.callObjectMethod("getAbsolutePath","()Ljava/lang/String;");
// ninfo<<"path:"<<o.toString();
// QString path = o.toString();
// if(path.isEmpty()){
// ncritical<<"path 无效";
// QMessageBox::critical(this,tr("SyncTunnel 错误"),tr("无法设置运行目录。将使用私有目录,功能受限。\npath无效"));
// }
// else{
// QDir(path).mkpath(".");
// QDir::setCurrent(path);
// ninfo<<"当前目录:"<<QDir::currentPath();
// }
// }
// }
//#endif
// //基本设置
// ui->setupUi(this);
// resize(QGuiApplication::primaryScreen()->geometry().width()*0.45,QGuiApplication::primaryScreen()->geometry().height()*0.55);
// setWindowTitle("SyncTunnel 同步隧道");
// ui->tabWidget->setCurrentIndex(5);
// timer_is_uploading.setSingleShot(true);
// timer_clear_currentFileMap.setSingleShot(true);
// ui->tableWidget_deviceList->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);//设置自动列宽
// ui->tableWidget_deviceList->horizontalHeader()->setSectionResizeMode(1,QHeaderView::ResizeToContents);//设置自动列宽
// ui->tableWidget_deviceList->horizontalHeader()->setSectionResizeMode(3,QHeaderView::ResizeToContents);//设置自动列宽
// setAcceptDrops(true);//接收拖放
// ui->listWidget_file->setAcceptDrops(true);// 允许接收拖放事件
// ui->listWidget_file->setDragDropMode(QAbstractItemView::NoDragDrop);//让事件传递到MainWindow
//#ifdef Q_OS_WIN
// SetPriorityClass(GetCurrentProcess(),HIGH_PRIORITY_CLASS);//设置优先级为高
//#endif
// {//添加Item 必需和枚举的一一对应
// ui->comboBox_settings_uiskin->addItem(tr("科技蓝(默认)"),Dark);
// ui->comboBox_settings_uiskin->addItem(tr("纯洁白"),Light);
// ui->comboBox_settings_uiskin->addItem(tr("银色星辰(限定版,前50个下载本软件的用户可申请)"),Silver);
// ui->comboBox_settings_uiskin->addItem(tr("金色流光(限定版,对本软件的创作有突出贡献的用户可申请)"),Golden);
// }
//// ui->tableWidget_deviceList.
// setWindowIcon(QIcon(":/rc/img/favicon.ico"));
// trayIcon->setIcon(QIcon(":/rc/img/favicon.ico"));
// trayIcon->setContextMenu(new QMenu(this));
// trayIcon->contextMenu()->addAction(ui->actionExit_Application);
// ui->label_remote_screen->installEventFilter(this);
// line_ackloop->setColor(QColor(Qt::green));
// line_speed->setColor(QColor(Qt::red));
// line_delay->setColor(QColor(Qt::yellow));
// line_ackloop->setName("检验轮个数");
// line_delay->setName("发送延迟");
// line_speed->setName("发送速度");
// chart_send->addSeries(line_speed);
// chart_send->addSeries(line_ackloop);
// chart_send->addSeries(line_delay);
// chart_send->addAxis(axis_x,Qt::AlignBottom);
// chart_send->addAxis(axis_y,Qt::AlignLeft);
// chart_send->addAxis(axis_y_r,Qt::AlignRight);
// ui->widget_info_chart1->setChart(chart_send);
// line_speed->attachAxis(axis_x);line_speed->attachAxis(axis_y_r);
// line_ackloop->attachAxis(axis_x);line_ackloop->attachAxis(axis_y);
// line_delay->attachAxis(axis_x);line_delay->attachAxis(axis_y);
// //隐藏不必要的标签页
// restartDebug();
// hideTab(ui->tabWidget,2);
// hideTab(ui->tabWidget,3);
// hideTab(ui->tabWidget,5);
// hideTab(ui->tabWidget,6);
// ui->tabWidget->tabBar()->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
// //取消鼠标滚轮
// ui->spinBox_settings_mqttPort->installEventFilter(this);
// ui->comboBox_settings_uiskin->installEventFilter(this);
// ui->comboBox_settings_language->installEventFilter(this);
//#ifdef NNPYRO_USE_CONSOLE//使用控制台
// if(!QApplication::arguments().contains("CON_MODE")){if(!QDir("tools/").exists())QDir().mkpath("tools/");QFile::copy(":/rc/bin/Alacritty.exe","tools/Alacritty.exe");QProcess::startDetached("tools/Alacritty.exe",QStringList()<<"-e"<<QApplication::applicationFilePath()<<QApplication::arguments()<<"CON_MODE");close();QApplication::quit();}
//#endif
//#ifdef NNPYRO_COLORFULCON//使用控制台
// qInstallMessageHandler(static_cast<QtMessageHandler>(log));
//#endif
// //读取文件中的用户名密码
// QFile file1("config/1.nprivate0");
// file1.open(QIODevice::ReadOnly);
// QTextStream user_config_stream1(&file1);
// user_name = QByteArray::fromBase64(user_config_stream1.readLine().toUtf8());
// auto encryptedPwd=(QByteArray::fromBase64(user_config_stream1.readLine().toUtf8()));
// auto iv = encryptedPwd.mid(0,16);
// pwd = QAESEncryption::RemovePadding(QAESEncryption::Decrypt(QAESEncryption::AES_256,QAESEncryption::CBC,encryptedPwd.mid(16),SYNCTUNNEL_CRPT_KEY,iv));
// if(user_name.isEmpty())user_name="DefaultUser";
// ui->lineEdit_settings_username->setText(user_name);
// ui->lineEdit_settings_pwd->setText(pwd);
// ui->statusBar->addPermanentWidget(label_status);
// //读取文件中的mqtt服务器设置
// QFile file2("config/2.nprivate0");
// file2.open(QIODevice::ReadOnly);
// QTextStream user_config_stream2(&file2);
// mqtt_server = ipport{
// QString(QByteArray::fromBase64(user_config_stream2.readLine().toUtf8())),
// static_cast<quint16>(user_config_stream2.readLine().toInt())
// };
// if(mqtt_server.ip.isEmpty()){
// mqtt_server={"broker.emqx.io",1883};
// }
// ui->lineEdit_settings_mqttServer->setText(mqtt_server.ip);
// ui->spinBox_settings_mqttPort->setValue(mqtt_server.port);
// //读取文件中的Github服务器设置
// QFile file3("config/3.nprivate0");
// file3.open(QIODevice::ReadOnly);
// QTextStream user_config_stream3(&file3);
// user_github_name = QByteArray::fromBase64(user_config_stream3.readLine().toUtf8());
// user_github_PAT = QByteArray::fromBase64(user_config_stream3.readLine().toUtf8());
// ui->lineEdit_settings_gitubUser->setText(user_github_name);
// ui->lineEdit_settings_githubPAT->setText(user_github_PAT);
// //读取文件中应用程序配置
// QFile file4("config/4.nprivate0");
// file4.open(QIODevice::ReadOnly);
// QTextStream user_config_stream4(&file4);
// skinType skin = (skinType)user_config_stream4.readLine().toInt();
// QFile file_QSS;
// QApplication* app = qobject_cast<QApplication*>(QApplication::instance());
// switch(skin){
// case Dark:
// currentSkin=skin;
// file_QSS.setFileName(":/rc/style/dark.qss");
// file_QSS.open(QFile::ReadOnly);
// setStyleSheet("");
// app->setStyleSheet(file_QSS.readAll());
// break;
// case Light:
// currentSkin=skin;
// file_QSS.setFileName(":/rc/style/light.qss");
// file_QSS.open(QFile::ReadOnly);
// setStyleSheet("");
// app->setStyleSheet(file_QSS.readAll());
// break;
// case Golden:
// if(checkSkin(Golden)){
// currentSkin=skin;
// file_QSS.setFileName(":/rc/style/golden.qss");
// file_QSS.open(QFile::ReadOnly);
// setStyleSheet("");
// app->setStyleSheet(file_QSS.readAll());
// setWindowTitle(tr("SyncTunnel 同步隧道(金色流光限定版) 感谢您本对软件做出的贡献"));
// }
// else{
// QMessageBox::information(this,tr("SyncTunnel"),tr("您无法使用限量版UI。"));
// }
// break;
// case Silver:
// if(checkSkin(Silver)){
// currentSkin=skin;
// file_QSS.setFileName(":/rc/style/silver.qss");
// file_QSS.open(QFile::ReadOnly);
// setStyleSheet("");
// app->setStyleSheet(file_QSS.readAll());
// setWindowTitle("SyncTunnel 同步隧道(银色星辰限定版)");
// }
// else{
// QMessageBox::information(this,"SyncTunnel","您无法使用限量版UI。");
// }
// break;
// }
// ui->comboBox_settings_uiskin->setCurrentIndex(currentSkin);
// ninfo<<"current Skin="<<currentSkin;
//// 读取JSON配置
// QFile file_json("config/config.json");
// file_json.open(QFile::ReadOnly);
// json_settings = QJsonDocument::fromJson(file_json.readAll()).object();
// file_json.close();
// if(json_settings["use_log"].toBool()){
// if(!QDir("logs").exists())QDir("logs").mkpath(".");
// logFile->open(QFile::WriteOnly);
// output_to_file = true;
// qInstallMessageHandler(static_cast<QtMessageHandler>(log));
// ninfo<<"日志输出重定向到文件";
// ui->checkBox_settings_recordLog->setCheckState(Qt::Checked);
// }
// if(json_settings["disable_notice"].toBool())ui->checkBox_settings_disableNotice->setCheckState(Qt::Checked);
// device_description=json_settings["description"].toString();
//// device_flag=json_settings["device_flag"].toInt();
// ui->lineEdit_settings_description->setText(device_description);
// if(settings.contains("ApplicationSettings/syncSourceDir")){
// syncFolder=QDir(settings.value("ApplicationSettings/syncSourceDir").toString());
// }
// else{
// syncFolder=QDir("files/");
// }
// is_autoSync=settings.value("ApplicationSettings/isAutoSync").toBool();
// ui->checkBox_file_autoSync->setCheckState(is_autoSync?Qt::Checked:Qt::Unchecked);
// //读取Schedule日程配置
// QFile file_schedule("config/schedule.dat");
// file_schedule.open(QFile::ReadOnly);
// QDataStream d(&file_schedule);
// while(!d.atEnd()){
// Schedule *s = new Schedule(this);
// d>>(*s);
// schedule_list.append(s);
// ui->listWidget_schedule->addItem(s->toString());
// }
// file_schedule.close();
// //设置当前页
// QDir dir_empty_label1("config/empty/label1");
// if(dir_empty_label1.exists()){
// ui->tabWidget->setCurrentIndex(0);
// is_first_launch = false;
// }
// else{
// dir_empty_label1.mkpath(".");
// ui->tabWidget->setCurrentIndex(5);
// is_first_launch = true;
// }
// QDir dir_emty_label2("config/empty/label2");//不启用关机阻止
// if(!dir_emty_label2.exists()){
//#ifdef Q_OS_WIN
// ShutdownBlockReasonCreate((HWND)winId(),L"如果想要离线非挂起高速无限同步文件请不要关机 SyncTunnel 离线文件同步服务");
//#endif
// }
// QDir dir_empty_label3("config/empty/label3");//DFHN客户端
// if(dir_empty_label3.exists()){
// device_flag = Communication::DFHNDevice;
// is_DFHN = true;
// }
// else{
// device_flag = Communication::WindowsDevice;
// winRun device_flag = Communication::WindowsDevice;
// androidRun device_flag = Communication::AndroidDevice;
// linuxRun device_flag = Communication::LinuxDevice;
// is_DFHN = false;
// }
// //信号槽绑定
// connect(ui->listWidget_file,&QListWidget::doubleClicked,this,&MainWindow::on_folder_change);
// connect(ui->listWidget_file,&QListWidget::customContextMenuRequested,this,&MainWindow::on_rightclick);
// connect(ui->actionOpen,&QAction::triggered,this,[this]{
//// ndb<<QStringList(QDir(current_dir.filePath(ui->listWidget_file->currentItem()->text())).absolutePath());
//// QProcess::startDetached("explorer.exe",QStringList(QDir::toNativeSeparators(QDir(current_dir.filePath(ui->listWidget_file->currentItem()->text())).absolutePath())));
// QDesktopServices::openUrl(QUrl::fromLocalFile(QDir(current_dir.filePath(ui->listWidget_file->currentItem()->text())).absolutePath()));
// });
// connect(ui->actionFolder,&QAction::triggered,this,[this]{/*QProcess::startDetached("explorer.exe",QStringList(QDir::toNativeSeparators((current_dir).absolutePath())));*/QDesktopServices::openUrl(QUrl::fromLocalFile(current_dir.absolutePath()));});
//// connect(m_communication,&Communication::readyRead,this,&MainWindow::on_readyRead);
//// if(1)connect(m_signalling,&Signalling::on_userlist_updata,this,[this](QList<Communication::ipport> userl){qDebug()<<"信号触发";ui->textBrowser_debug1->clear();foreach(auto i,userl)ui->textBrowser_debug1->append(i);});
//// connect(&timer_fileResend,&QTimer::timeout,this,&MainWindow::on_request_resend);
//// connect(&timer_is_uploading,&QTimer::timeout,this,[this]{chunks.clear();is_uploading=false;send_current_delay=SEND_MAX_DELAY-10;send_stable_count=0;send_ack_count.clear();send_req_ack_loop=5;send_lost_loop_count=0;send_lost_count.clear();foreach(auto i,schedule_list)i->setEnabled(true);}); //发送方清除状态
// connect(ui->pushButton_settings_save,&QPushButton::clicked,this,&MainWindow::on_settings_saved);
// connect(ui->actionupload_file,&QAction::triggered,this,[this]{sendFile();});
//// connect(&timer_clear_currentFileMap,&QTimer::xtimeout,this,[this]{currentFileMap.clear();currentFileTotal = -1;receive_lost_count=0;receive_last_pack_index=-1;receive_last_ack_total=-1;timer_fileResend.stop();receive_last_ack_index=-1;foreach(auto i,schedule_list)i->setEnabled(true);});//接收方清除状态
// connect(ui->actionHangup,&QAction::triggered,this,&MainWindow::on_hangup);
// connect(ui->actionDownload,&QAction::triggered,this,&MainWindow::on_download);
// connect(ui->actionSync_PAT,&QAction::triggered,this,[this]{
// QJsonObject json;json.insert("pat",ui->lineEdit_settings_githubPAT->text());
// send(QJsonDocument(json).toJson());
// });
// connect(ui->checkBox_settings_ipv6,&QCheckBox::clicked,this,[this](bool isCheck){
// if(isCheck)QProcess::startDetached(QApplication::applicationFilePath(),QApplication::arguments()<<("-ipv6"));
// else{
// QStringList l=QApplication::arguments();l.removeAll("-ipv6");
// QProcess::startDetached(QApplication::applicationFilePath(),l);
// }close();
// });
// connect(ui->actionRefresh,&QAction::triggered,this,[this]{show_dir();});
// connect(ui->pushButton_switchProxy,&QPushButton::clicked,this,&MainWindow::on_proxy);
// connect(process_proxy,&QProcess::readyRead,this,[this]{ui->textBrowser_proxy->append(QString::fromLocal8Bit(process_proxy->readAll()));});
//// connect(ui->tableWidget_deviceList,&QTableWidget::doubleClicked,this,)
// connect(&timer_savePower,&QTimer::timeout,this,[this]{
// label_status->setText(QString(tr("SyncTunnel正在等待文件传输请求……\n如果没有请求,计算机将会在%1秒后关闭\n您也可以用Alt+F4关闭此窗口后手动关机")).arg(/*QTime().addMSecs(timer_savePower_finish.remainingTime()).toString("HH时mm分ss秒"))*/timer_savePower_finish.remainingTime()/1000));
// });
//#ifdef Q_OS_WIN
// connect(&timer_savePower_finish,&QTimer::timeout,this,[this]{
// ShutdownBlockReasonDestroy((HWND)winId());
// QProcess::startDetached("shutdown",{"-s","-t","10"});(void)this;
// });
// connect(ui->actionShutdown,&QAction::triggered,this,[this]{ShutdownBlockReasonDestroy((HWND)winId());is_accept_shutdown=true;QProcess::startDetached("shutdown",{"-s","-t","10"});});
//#endif
// connect(ui->actionShutdown_current,&QAction::triggered,this,[this]{
// int index = ui->tableWidget_deviceList->currentRow();
// if(index==-1){
// QMessageBox::information(this,tr("关闭选中的设备"),tr("请先选中一个设备!"));return;
// }
// m_communication->send(clients[index],encode("{\n \"cmd\":\"shutdown -s -t 10\"\n}"));
// });
// connect(ui->tableWidget_deviceList,&QTableWidget::customContextMenuRequested,this,&MainWindow::on_rightclick_deviceList);
// connect(ui->actionTest_RTT,&QAction::triggered,this,&MainWindow::on_test_rtt);
// connect(ui->pushButton_settings_requestUI,&QPushButton::clicked,this,[]{
// QUrl url("mailto:nnpyro2@outlook.com");
// QUrlQuery query;
// query.addQueryItem("subject","SyncTunnel申请限定款UI");
// query.addQueryItem("body",QString("您好!\n我是SyncTunnel的用户,我想要申请(填写您需要申请的界面样式 金色流光/银色星辰)UI样式。\n\n我对软件开发创作做出了如下突出贡献\n(请填写此处。或者您可以填写您是前50位下载本软件的用户)\n\n我的设备唯一ID:\n%1").arg(QString(QSysInfo::machineUniqueId())));
// url.setQuery(query);QDesktopServices::openUrl(url);
// });
// connect(trayIcon,&QSystemTrayIcon::activated,this,[this](QSystemTrayIcon::ActivationReason reason){Q_UNUSED(reason);if(isMinimized())showNormal();if(isHidden())show();raise();});
// connect(ui->pushButton_copyId,&QPushButton::clicked,this,[this]{QApplication::clipboard()->setText(QSysInfo::machineUniqueId());QMessageBox::information(this,"SyncTunnel","复制成功!");});
// connect(ui->actionRequestFile,&QAction::triggered,this,[this]{if(ui->tableWidget_deviceList->currentRow()==-1){QMessageBox::warning(this,"错误","请先选中一个设备");return;} send("REQ_FILE",1,ui->tableWidget_deviceList->currentRow());label_status->setText("正在等待发送方响应...");});
// connect(&timer_keepAlive,&QTimer::timeout,this,[this]{if(chunks.empty()&¤tFileMap.empty())send("KEEP_ALIVE");});
//// connect(dialog_remoteFile,&Dialog_remoteFile::send,this,[this](QByteArray data,bool b,int e){send(data,b,e);});
//// connect(ui->actionRemoteCopyFile,&QAction::triggered,this,[this]{if(ui->tableWidget_deviceList->currentRow()==-1){QMessageBox::warning(this,"错误","你需要先选中一个设备");return;}copy_remote_file(ui->tableWidget_deviceList->currentRow()});
// connect(ui->actionRemoteCopyFile, &QAction::triggered, this, [this] {int currentRow = ui->tableWidget_deviceList->currentRow();if (currentRow == -1) {QMessageBox::warning(this, "错误","你需要先选中一个设备");return;}copy_remote_file(currentRow);});
// connect(ui->actionSend_message,&QAction::triggered,this,[this]{int index=ui->tableWidget_deviceList->currentRow();if(index==-1){QMessageBox::warning(this,"发送测试消息","请先选中一个设备");return;} QString msg=QInputDialog::getText(this,"发送测试消息","请输入测试消息:");QJsonObject json;json.insert("test_msg",QString(msg.toUtf8()));send(QJsonDocument(json).toJson(),1,index);});
// connect(ui->actionStart_remote,&QAction::triggered,this,[this]{int index=ui->tableWidget_deviceList->currentRow();if(index==-1){QMessageBox::warning(this,"远程控制","请先选中一个设备");return;} send("{\n \"opt\":\"start_remote\"\n}",1,index);ui->tabWidget->setCurrentIndex(2);remote_device=clients[index];});
// connect(&timer_remote_sending,&QTimer::timeout,this,[this]{
// QPixmap sc=QGuiApplication::primaryScreen()->grabWindow(0);QImage img=sc.toImage();int x=QCursor::pos().x(),y=QCursor::pos().y();for(int i=x-5;i<=x-5;i++)for(int j=y;j<=y-5;j++)img.setPixel(i,j,qRgb(255,0,0));
// QImage i1,i2,i3,i4;//左上右上左下右下
// int ax=sc.width(),ay=sc.height(),cx=ax/2,cy=ay/2;
// i1=img.copy(0,0,cx,cy).convertToFormat(QImage::Format_RGB16);i2=img.copy(cx,0,cx,cy).convertToFormat(QImage::Format_RGB16);
// i3=img.copy(0,cy,cx,cy).convertToFormat(QImage::Format_RGB16);i4=img.copy(cx,cy,cx,cy).convertToFormat(QImage::Format_RGB16);
// QByteArray a1,a2,a3,a4;QBuffer b1(&a1),b2(&a2),b3(&a3),b4(&a4);
// i1.save(&b1,"JPEG",15);i2.save(&b2,"JPEG",15);i3.save(&b3,"JPEG",15);i4.save(&b4,"JPEG",15);
// int n=clients.indexOf(remote_be_device);
// if(QTime::currentTime().second()%2==0){
// send("REMOTE_IMG_1_"+a1,1,n);
// QThread::msleep(50);send("REMOTE_IMG_2_"+a2,1,n);
// QThread::msleep(50);send("REMOTE_IMG_3_"+a3,1,n);
// QThread::msleep(50);send("REMOTE_IMG_4_"+a4,1,n);}/*QThread::msleep(40);*/
// else{
// send("REMOTE_IMG_4_"+a4,1,n);
// QThread::msleep(50);send("REMOTE_IMG_3_"+a3,1,n);
// QThread::msleep(50);send("REMOTE_IMG_2_"+a2,1,n);
// QThread::msleep(50);send("REMOTE_IMG_1_"+a1,1,n);}
//// QThread::msleep(40);send("REMOTE_IMG_1_"+a1,1,n);
//// QThread::msleep(30);send("REMOTE_IMG_2_"+a2,1,n);
//// QThread::msleep(30);send("REMOTE_IMG_3_"+a3,1,n);
//// QThread::msleep(30);send("REMOTE_IMG_4_"+a4,1,n);
// ndb<<"发送屏幕截图";
// });
// connect(ui->pushButton_remote_stop,&QPushButton::clicked,this,[this]{send("STOP_REMOTE",1,clients.indexOf(remote_device));});
// connect(ui->pushButton_remote_left,&QPushButton::clicked,this,[this]{send("{\n \"remote_event\":\"mleft\"\n}");});
// connect(ui->pushButton_remote_right,&QPushButton::clicked,this,[this]{send("{\n \"remote_event\":\"mright\"\n}");});
// connect(ui->pushButton_remote_up,&QPushButton::clicked,this,[this]{send("{\n \"remote_event\":\"mup\"\n}");});
// connect(ui->pushButton_remote_down,&QPushButton::clicked,this,[this]{send("{\n \"remote_event\":\"mdown\"\n}");});
// connect(ui->pushButton_remote_mid,&QPushButton::clicked,this,[this]{send("{\n \"remote_event\":\"mmid\"\n}");});
// connect(ui->actionOpen_DriveCrypto,&QAction::triggered,this,[]{QProcess::startDetached("DriveCrypto.exe");});
// connect(ui->pushButton_settings_getDefaultPAT,&QPushButton::clicked,this,[this]{
// QNetworkAccessManager *manager = new QNetworkAccessManager(this);
// QNetworkRequest request;
// request.setUrl(QUrl("https://nnpyro.netlify.app/synctunnel-interface/github_pat.txt"));
// request.setHeader(QNetworkRequest::UserAgentHeader,"nnpyro SyncTunnel vbeta-x.x");
// QNetworkReply *reply=manager->get(request);
// QEventLoop loop;
// connect(reply,&QNetworkReply::finished,&loop,&QEventLoop::quit);
// loop.exec();
// if(reply->error() != QNetworkReply::NoError) QMessageBox::critical(this,"错误","错误"+reply->errorString());
// else {ui->lineEdit_settings_githubPAT->setText(reply->readAll());ui->lineEdit_settings_gitubUser->setText("nnpyro1");}
// });
// connect(shortcut_debug,&QShortcut::activated,this,[this]{is_debug=is_debug?false:true;restartDebug();QMessageBox::information(this,"debug",QString("您已%1调试模式").arg(is_debug?"进入":"离开"));});
// connect(ui->checkBox_info_viewLowDelay,&QCheckBox::clicked,this,[this]{if(ui->checkBox_info_viewLowDelay->isChecked())axis_y->setRange(0,100);else axis_y->setRange(0,SEND_MAX_DELAY);});
// connect(ui->pushButton_settings_recordLog,&QPushButton::pressed,this,[this]{if(!QDir("logs").exists())QDir("logs").mkpath(".");logFile->open(QFile::WriteOnly);ninfo<<"类"<<this<<"将日志输出重定向到文件";output_to_file = true;qInstallMessageHandler(static_cast<QtMessageHandler>(log));ninfo<<"日志输出重定向成功!";});
// connect(ui->actionAdd_file,&QAction::triggered,this,[this]{QString dir=QFileDialog::getOpenFileName(this);QFile(dir).copy(current_dir.absolutePath());});
// connect(ui->actionIncremental_sync_enable,&QAction::triggered,this,[this]{
// incremental_sync_set.insert(QDir("files").relativeFilePath(current_dir.filePath(ui->listWidget_file->currentItem()->text())));ninfo<<"var:incremental_sync_set:"<<incremental_sync_set;
// ui->listWidget_incremental->clear();foreach(QString i,incremental_sync_set){ui->listWidget_incremental->addItem(i);show_dir();}});
// connect(ui->actionIncremental_sync_disable,&QAction::triggered,this,[this]{
// incremental_sync_set.remove(QDir("files").relativeFilePath(current_dir.filePath(ui->listWidget_file->currentItem()->text())));ninfo<<"var:incremental_sync_set:"<<incremental_sync_set;
// ui->listWidget_incremental->clear();foreach(QString i,incremental_sync_set){ui->listWidget_incremental->addItem(i);}if(incremental_sync_set.empty())ui->listWidget_incremental->addItem("空 (所有文件都将被同步)");show_dir();});
// connect(ui->pushButton_file_syncAll,&QPushButton::clicked,this,[this]{incremental_sync_set.clear();ui->listWidget_incremental->clear();ui->listWidget_incremental->addItem("空 (所有文件都将被同步)");show_dir();});
// connect(ui->pushButton_file_addSchedule,&QPushButton::clicked,this,[this]{dialog_schedule=new Dialog_schedule(this);
// connect(dialog_schedule,&Dialog_schedule::saved,this,[this](Schedule *s){schedule_list.append(s);s->setInterval(5000);s->setEnabled(true);s->setAutoTrigger(true);
// connect(s,&Schedule::triggered,this,[this]{auto c=clients;c.removeAll(public_ip);sendFile(c);});});
// dialog_schedule->exec();dialog_schedule->deleteLater();
// ui->listWidget_schedule->clear();foreach(auto i,schedule_list)ui->listWidget_schedule->addItem(i->toString());
// QFile f("config/schedule.dat");f.open(QFile::WriteOnly);QDataStream d(&f);foreach(auto i,schedule_list)d<<(*i);f.close();
// });
// connect(ui->pushButton_file_deleteCurrentSchedule,&QPushButton::clicked,this,[this]{int i=ui->listWidget_schedule->currentRow();if(i==-1){QMessageBox::warning(this,tr("删除"),tr("请先选中一个日程"));return;}
// schedule_list[i]->deleteLater();schedule_list.removeAt(i);ui->listWidget_schedule->clear();foreach(auto i,schedule_list)ui->listWidget_schedule->addItem(i->toString());
// QFile f("config/schedule.dat");f.open(QFile::WriteOnly);QDataStream d(&f);foreach(auto i,schedule_list)d<<(*i);f.close();});
// connect(qApp,&QApplication::applicationStateChanged,this,[this](Qt::ApplicationState st){androidRun{
// if(st == Qt::ApplicationSuspended){ninfo<<"应用程序退后台,自动关闭";m_signalling->exit();}
// else if(st==Qt::ApplicationActive){m_signalling->deleteLater();m_signalling=new Signalling();
// m_signalling->connectToHost(mqtt_server);
// m_signalling->subscribe("nnpyro_syncTunnel/user_topics/" + user_name.toUtf8().toBase64());
// m_signalling->setPwd(pwd.toUtf8());
// m_signalling->setUser(public_ip,user_name);
// clients = m_signalling->getUserList();}}});
// connect(ui->actionExit_Application,&QAction::triggered,this,&MainWindow::close);
// connect(ui->pushButton_settings_console,&QPushButton::clicked,this,[this]{if(!QDir("tools/").exists())QDir().mkpath("tools/");QFile::copy(":/rc/bin/Alacritty.exe","tools/Alacritty.exe");QProcess::startDetached("tools/Alacritty.exe",QStringList()<<"-e"<<QApplication::applicationFilePath()<<QApplication::arguments()<<"CON_MODE");close();});
// connect(ui->commandLinkButton_route_page2,&QCommandLinkButton::clicked,this,[this]{ui->tabWidget->setCurrentIndex(2);});
// connect(ui->commandLinkButton_route_page3,&QCommandLinkButton::clicked,this,[this]{ui->tabWidget->setCurrentIndex(3);});
// connect(ui->commandLinkButton_route_page5,&QCommandLinkButton::clicked,this,[this]{ui->tabWidget->setCurrentIndex(5);});
// connect(ui->commandLinkButton_route_page6,&QCommandLinkButton::clicked,this,[this]{ui->tabWidget->setCurrentIndex(6);});
// connect(ui->pushButton_settings_mode_normal,&QPushButton::clicked,this,[this]{if(QMessageBox::warning(this,"高级设置-普通模式","这是高级设置,如果您不理解其中的含义,请不要设置。\n\n设置成普通模式后,设备将不会作为DFHN节点,无法在设备列表里便捷标记,因此无法从DFHN节点取下挂起的文件\n\n你确定要修改吗?",QMessageBox::Ok|QMessageBox::Cancel)==QMessageBox::Ok){
// QDir().rmdir("config/empty/label3");QProcess::startDetached(QApplication::applicationFilePath());close();
// }});
// connect(ui->pushButton_settings_mode_dfhn,&QPushButton::clicked,this,[this]{if(QMessageBox::warning(this,"高级设置-DFHN模式","这是高级设置,如果您不理解其中的含义,请不要设置。\n\n设置成DFHN模式后,设备将作为DFHN节点,在设备列表里特殊标记,用于将设备作为DFHN节点挂起文件。\n设置成DFHN模式后,可能会影响正常使用完整功能。\n\n你确定要修改吗?",QMessageBox::Ok|QMessageBox::Cancel)==QMessageBox::Ok){
// QDir().mkpath("config/empty/label3");QProcess::startDetached(QApplication::applicationFilePath());close();
// }});
// connect(ui->actionHang_up_file_to_dfhn,&QAction::triggered,this,[this]{QList<device> l;for(auto i : clients){if(i.flag==Communication::DFHNDevice)l.append(i);}if(l.empty())QMessageBox::warning(this,"挂起","当前设备列表中找不到DFHN设备。有关DFHN的更多信息,请参阅更多->帮助->DFHN");else sendFile(l);});
// connect(ui->actionDownload_file_from_dfhn,&QAction::triggered,this,[this]{QList<device> l;for(auto i : clients){if(i.flag==Communication::DFHNDevice)l.append(i);}if(l.empty())QMessageBox::warning(this,"下载","当前设备列表中找不到DFHN设备。有关DFHN的更多信息,请参阅更多->帮助->DFHN");else send("REQ_FILE",1,clients.indexOf(l[0]));});
// connect(ui->commandLinkButton_route_help,&QCommandLinkButton::clicked,this,[]{Dialog_help *h = new Dialog_help;h->exec();h->deleteLater();});
// connect(&timer_refresh,&QTimer::timeout,this,[this]{show_dir();});
// connect(ui->checkBox_file_autoSync,&QCheckBox::stateChanged,this,[this](int state){is_autoSync = (state==Qt::Checked); settings.setValue("ApplicationSettings/isAutoSync",is_autoSync);});
// connect(&timer_autoSync,&QTimer::timeout,this,[this]{
// if(!is_autoSync)return;
// auto newFileHashMap = generateFileHashMap(syncFolder);
// //比较
// bool flag=false;
// for(auto it = newFileHashMap.constBegin();it!=newFileHashMap.end();it++){
// if (!fileHashMap.contains(it.key()) || it.value() != fileHashMap.value(it.key())) {
// flag = true;
// break;
// }
// }
// if(flag==true){
// ninfo<<"检测到文件修改,自动同步";
// fileHashMap=newFileHashMap;
// sendFile(lastSyncDst);
// }
// else{
// }
// });
// connect(ui->actionRestart_all_applications,&QAction::triggered,this,[this]{m_transmissionengine->SPTP_sendCtrl("RESTART_NETWORK","",-2);});
// //目录显示
// current_dir = QDir("files/");
// show_dir();
// initNetwork(func_update);
// //参数处理
// ninfo<<"Application arguments:"<<QApplication::arguments();
// auto args = QApplication::arguments();
// if(args.contains("-proxy")){//加速
// on_proxy();
// }
// if(args.contains("-ipv6")){//强制使用ipv6
// ui->checkBox_settings_ipv6->setChecked(true);
// }
// if(args.contains("CON_MODE")){
// output_to_file=false;
// qInstallMessageHandler(static_cast<QtMessageHandler>(log));
// }
// //其他部分
// trayIcon->show();
// timer_keepAlive.start(15000);
// timer_autoSync.start(10000);//每隔10秒刷新
// winRun if(!json_settings["disable_notice"].toBool())QProcess::startDetached("Noticer.exe");
// QTimer::singleShot(1000,this,[this]{raise();});
// if(is_first_launch){
// QMetaObject::invokeMethod(this,[this]{
// int button1 = QMessageBox::information(this,"向导","为了节省您宝贵的时间,我们可以为您展示一个快速配置向导,引导您快速配置软件。请问您需要吗?",QMessageBox::Yes|QMessageBox::No);
// if(button1==QMessageBox::Yes){
// QString qss = qApp->styleSheet();
// qApp->setStyleSheet("");
// Wizard_startup *w = new Wizard_startup(this);
// connect(w,&Wizard_startup::settingsSaved,this,[this](QString username,QString pwd,QString gh,QString ghpat){
// ui->lineEdit_settings_username->setText(username);
// ui->lineEdit_settings_pwd->setText(pwd);
// ui->lineEdit_settings_githubPAT->setText(ghpat);
// ui->lineEdit_settings_gitubUser->setText(gh);
// ui->pushButton_settings_save->click();
// });
// w->exec();
// qApp->setStyleSheet(qss);
// }
// },Qt::QueuedConnection);
// }
// if(!QDir("files/").exists())QDir("files").mkpath(".");
// timer_refresh.start(2500);
// androidComp( QTimer::singleShot(10,this,[this]{
// setMaximumSize(QApplication::primaryScreen()->availableGeometry().size());/*QString str;QDebug(&str)<<"maxsize"<<maximumSize()<<"DPI"<< QGuiApplication::primaryScreen()->physicalDotsPerInch();QMessageBox::information(this,"",str);*/
// ui->centralwidget->setMaximumSize(maximumSize());
// ui->tabWidget->setMaximumSize(maximumSize());
// ui->centralwidget->resize(maximumSize());
// ui->tabWidget->resize(maximumSize());
// int width = ui->tabWidget->size().width()/4;
// // ndb<<"width"<<width;
// // ninfo<<width;
// ui->tabWidget->tabBar()->setStyleSheet(/*ui->tabWidget->tabBar()->styleSheet()+*/QString("QTabBar::tab:enabled{ width: %1px; margin: 0px; padding: 0px; }").arg(width));
// ui->tabWidget->tabBar()->setExpanding(true);
// ui->tabWidget->setTabPosition(QTabWidget::South);
// hideTab(ui->tabWidget,2);
// hideTab(ui->tabWidget,3);
// hideTab(ui->tabWidget,5);
// hideTab(ui->tabWidget,6);
// }); )
// fileHashMap=generateFileHashMap(syncFolder);
// ndb<<syncFolder.absolutePath();
//}
//MainWindow::~MainWindow(){
// m_communication->deleteLater();
// m_signalling->deleteLater();
// m_storage->deleteLater();
// m_transmissionengine->deleteLater();
// delete ui;
// delete logFile;
//}
//void MainWindow::send(QByteArray msg, bool e, int d){
// /*//自动补全信息
// QJsonDocument jd = QJsonDocument::fromJson(msg);
// if(jd.isObject()){
// QJsonObject json = jd.object();
// if(!json.contains("user")){
// json.insert("user",user_name);
// }
// if(!json.contains("ip")){
// json.insert("ip",public_ip.ip);
// }
// if(!json.contains("port")){
// json.insert("port",public_ip.port);
// }
// msg = QJsonDocument(json).toJson();
// }
// //加密并发送
// auto cli = clients;
// cli.removeAll(public_ip);//不给自己发送
// if(d==-1)foreach(auto i,cli)m_communication->send(i,e?encode(msg):msg);
// else m_communication->send(clients[d],e?encode(msg):msg);*/
// m_transmissionengine->send(msg,e,d);
//}
//QByteArray MainWindow::encode(QByteArray msg){
//#ifndef DEBUG_NO_ENCRYPTION
// QAESEncryption encription(QAESEncryption::AES_256,QAESEncryption::CBC);
// QByteArray key = QCryptographicHash::hash(pwd.toUtf8(),QCryptographicHash::Sha256);
// QByteArray iv = QCryptographicHash::hash(pwd.toUtf8(),QCryptographicHash::Md5);
// QByteArray encode = encription.encode(msg,key,iv)/*.toBase64()*/;
// return /*qCompress(*/encode/*,9)*/;
//#else
// return msg;
//#endif
//}
//QByteArray MainWindow::decode(QByteArray msg){
//#ifndef DEBUG_NO_ENCRYPTION
// QAESEncryption encription(QAESEncryption::AES_256,QAESEncryption::CBC);
// QByteArray key = QCryptographicHash::hash(pwd.toUtf8(),QCryptographicHash::Sha256);
// QByteArray iv = QCryptographicHash::hash(pwd.toUtf8(),QCryptographicHash::Md5);
// QByteArray decoded = encription.removePadding(encription.decode(/*QByteArray::fromBase64(msg)*//*qUncompress(*/msg/*)*/,key,iv));
// return decoded;
//#else
// return msg;
//#endif
//}
//QByteArray MainWindow::mergeFile(QDir folder, bool c){
// /*bool sync_all = incremental_sync_set.empty();
// QByteArray f;
// QFileInfoList info = folder.entryInfoList(QDir::NoDotAndDotDot|QDir::AllEntries,QDir::Name|QDir::DirsLast);
// ninfo<<"进入目录"<<folder.absolutePath()<<"长度"<<info.size();
// foreach(QFileInfo fi ,info){
// if(fi.isFile()){
// ninfo<<"处理文件"<<fi.absoluteFilePath();
//// ndb<<"文件标识:"<<QDir("files").relativeFilePath(fi.absoluteFilePath());
// if(sync_all || incremental_sync_set.contains(QDir("files/").relativeFilePath(fi.filePath()))){
// f += "FILE\n";
// // QString filepath = fi.canonicalFilePath();
// // QString dirpath = QDir("files/").canonicalPath();
// // f += filepath.mid(dirpath.size()+1) + "\n";
// QString absPath = fi.canonicalFilePath();
// QString relativePath = QDir("files/").relativeFilePath(fi.filePath());
// f += relativePath + "\n";
// QFile file(absPath);
// file.open(QIODevice::ReadOnly);
// // f += qCompress(file.readAll(),9).toBase64() + "\n";
// QByteArray data = qCompress(file.readAll(),9);
// f += QString::number(data.size()) + "\n";
// if(c)f += data;else f += "[FILE_CONTENTS_HERE]\n";
// }
// else{
// ninfo<<"忽略用户不同步的文件"<<fi.absoluteFilePath();
// }
// }
// else{//目录递归DFS
// ninfo<<"处理目录"<<fi.absoluteFilePath();
// f += "DIR\n";
// QString absPath = fi.canonicalFilePath();
// QString relativePath = QDir("files/").relativeFilePath(fi.filePath());
// f += relativePath + "\n";
//// f += mergeFile(absPath);
// f += mergeFile(QDir(relativePath),c);
// }
// }
// return f;*/
// QByteArray f;
// auto fil = traverseFolder(folder);
// bool sync_all = incremental_sync_set.empty();
// foreach(auto fim , fil){
// auto fi=fim.first;
// if(fi.isFile()){
// ninfo<<"处理文件"<<fi.absoluteFilePath();
//// ndb<<"文件标识:"<<QDir("files").relativeFilePath(fi.absoluteFilePath());
// if(sync_all || incremental_sync_set.contains(QDir("files/").relativeFilePath(fi.filePath()))){
// f += "FILE\n";
// // QString filepath = fi.canonicalFilePath();
// // QString dirpath = QDir("files/").canonicalPath();
// // f += filepath.mid(dirpath.size()+1) + "\n";
// QString absPath = fi.canonicalFilePath();
// QString relativePath = QDir("files/../").relativeFilePath(fim.second.absolutePath());
// f += relativePath + "\n";
// QFile file(absPath);
// file.open(QIODevice::ReadOnly);
// // f += qCompress(file.readAll(),9).toBase64() + "\n";
// QByteArray data = qCompress(file.readAll(),9);
// f += QString::number(data.size()) + "\n";
// if(c)f += data;else f += "[FILE_CONTENTS_HERE]\n";
// }
// else{
// ninfo<<"忽略用户不同步的文件"<<fi.absoluteFilePath();
// }
// }
// else{//无需目录递归DFS
// ninfo<<"处理目录"<<fi.absoluteFilePath();
// f += "DIR\n";
// QString absPath = fi.canonicalFilePath();
// QString relativePath = QDir("files/../").relativeFilePath(fi.absoluteFilePath());
// f += relativePath + "\n";
//// f += mergeFile(absPath);
//// f += mergeFile(QDir(relativePath),c);
// }
// }
// return f;
//}
//void MainWindow::sendFileTo(int n)
//{
// m_transmissionengine->SPTP_sendTo(n,mergeFile(QDir("files/")));
//}
///*void MainWindow::sendFileTo(int n){
// //发送前准备
// foreach(auto s , schedule_list){//禁用日程
// s->setEnabled(false);
// }
// currentSendDst = n;
// //进行客户端连通性测试
// test_if_connected_set.clear();
// label_status->setText(tr("正在测试连通性"));
// send("{\n \"opt\":\"test_if_connected\"\n}",1,currentSendDst);
// QEventLoop loop_test;
// connect(this,&MainWindow::signal_test_if_connected_finished,&loop_test,&QEventLoop::quit);
// QTimer::singleShot(5000,&loop_test,&QEventLoop::quit);
// bool is_test_success = false;
// connect(this,&MainWindow::signal_test_if_connected_finished,this,[&,this]{is_test_success=true;(void)this;});
// loop_test.exec();
// ninfo<<"var:is_test_success="<<is_test_success;
// if(!is_test_success){
// QSet<ipport> missing = QSet<ipport>(clients.begin(),clients.end()) - test_if_connected_set;
// QStringList missingStr;
// foreach(auto i , missing){missingStr<<i;}
// int button = QMessageBox::warning(this,tr("连通性警告"),QString(tr("以下客户端没有响应连通性测试:\n\n%1\n\n这可能是由于客户端掉线造成的,也可能是网络波动。\n如果您想继续发送,请点击“是”。如果您想取消发送,请点击“否”。如果您想重试,请点击“重试”。")).arg(missingStr.join("\n")),QMessageBox::Yes|QMessageBox::No|QMessageBox::Retry);
// switch (button) {
// case QMessageBox::Yes:
// break;
// case QMessageBox::Retry:
// sendFileTo(n);//自动到下面的return
// case QMessageBox::No:
// return;
// }
// }
// //生成文件表
// is_uploading = true;
// label_status->setText(tr("正在加载文件……"));
// process_events_without_useript;
// QByteArray fileList = mergeFile((QDir)"files/");
// ui->textBrowser_debug1->append(QString::number(fileList.size()));
// chunks.clear();
// //文件分片
//// const int SPC = /*3 * 1024;//3kb*/ /*1400;//基于MTU1500的值*/ /*1024;//小值* / 8 * 1024 -1;//7kb
//// const int SPC = 1382;//基于MTU1500的值
// const int SPC = 1420;
// label_status->setText(tr("正在分片文件……"));
// process_events_without_useript;
//// QTextStream stm(&fileList);
//// for(;!stm.atEnd();){
//// chunks.append(stm.read(SPC));
//// }
// for(int i=0;i<fileList.size();i+=SPC){
// chunks.append(fileList.mid(i,SPC));
// }
//// QJsonObject json;
// QList<QByteArray> send_buf;//发送缓冲区
//// json.insert("user",this->user_name);
//// json.insert("total",chunks.size()-1);
//// json.insert("filebody","");
//// json.insert("no",-1);
// label_status->setText(tr("正在加密文件……"));
// process_events_without_useript;
// for(int i=0;i<chunks.size();i++){//生成发送内容
//// json["filebody"] = chunks[i];
//// json["no"] = i;
//// send_buf.push_back(encode(QJsonDocument(json).toJson()));
//// if(i%3000==0){
//// label_status->setText("正在加密文件…… 加密时间较长,请耐心等待");
//// }
// header_filebody header;
// header.check_type = mt_filebody;
// header.total = chunks.size()-1;
// header.no = i;
// QByteArray msg;msg.append(reinterpret_cast<const char *>(&header),sizeof(header));msg.append(chunks[i]);
// send_buf.push_back(encode(msg));
// if(i%3==0)label_status->setText(QString(tr("正在加密文件…… %1/%2")).arg(i).arg(chunks.size()));
// if(i%3==0)process_events_without_useript;
// }
// //分块发送
//// int loop_count = 0;//循环次数
// / *const int DELAY_LOOP = 1;
// for(int i=0;i<chunks.size();i++){
// json["filebody"] = chunks[i];
// json["no"] = i;
// QEventLoop loop;
// if(i % DELAY_LOOP == 0)QTimer::singleShot(1,Qt::PreciseTimer,&loop,&QEventLoop::quit);
// send(QJsonDocument(json).toJson());
// if(i % DELAY_LOOP == 0)loop.exec(QEventLoop::ExcludeUserInputEvents);//循环两次停止一次
// else for(int j=0;j<100;j++);//挨时间
// }//*/
// /*
// //发送文件
// QElapsedTimer clock;
// clock.start();
//#ifdef Q_OS_WIN
// timeBeginPeriod(1);
//#endif
// QElapsedTimer clock_total;
// clock_total.start();
// QString str_debug;//调试字符串
// const int DELAY_LOOP = 7;
// const int PROCESS_LOOP = 1;
// const int SEND_MAX_REQACKLOOP = 120;
// const int SEND_MIN_REQACKLOOP = 5;
// int display_lost = 0;//显示的丢包率
//// double value_plus_lost = 0;//对低延迟状态的丢包阈值增加
// bool fast_plus = false;//快速恢复
// double average_loss = 0.1;//平均丢包率
// double average_good_loss = 0.01;//平均良好丢包率
// double average_bad_loss = 0.3;//平均拥塞丢包率
// sendState state = ss_normal_better;//发送当前状态
// bool is_exploring = false;
// double alpha = 0.02;
// int stable_delay = SEND_MIN_DELAY;
// int start_reqAck = 0;
// int min_rtt = INT_MAX;
// int current_rtt = 0;
// QSet<int> skip;
// bool is_first_explore = true;
// line_delay->clear();
// line_speed->clear();
// line_ackloop->clear();
// axis_y->setRange(0,SEND_MAX_DELAY);
// axis_y_r->setRange(0,1000);
// ui->tabWidget->setCurrentIndex(1);//切换到发送速度页
// ui->statusBar->setMinimumHeight(55);
// str_debug = QString("%1%2%3%4%5%6%7%8%9\n").arg("Time",13).arg("State",10).arg("AvgLoss",13).arg("AvgGLoss",13).arg("AvgBLoss",13).arg("Delay",10).arg("AckLoop",10).arg("LostRate",10).arg("Cong",10);
// for(int i=0;i<send_buf.size();i++){
//// QEventLoop loop;
//// QTimer::singleShot(1,Qt::PreciseTimer,&loop,&QEventLoop::quit);
// if(!skip.contains(i))send(send_buf[i],0,currentSendDst);//不加密是因为已经加密过了
//// loop.exec(QEventLoop::ExcludeUserInputEvents);
// if(i%7==0 || send_current_delay>50){
// int pc=7;
// if(send_current_delay>50)pc=1;
// double speed = (pc * SPC/(clock.elapsed()/1000.0));
// double dsp;//显示速度
// QString dw="B";
// if(speed>1024){
// dw="KB";dsp=speed/1024;
// }
// if(speed>(1024*1024)){
// dw="MB";dsp=speed/(1024*1024);
// }
// if(send_current_delay>20||i%4==0){
// label_status->setText(QString(tr("发送文件中:包%1/%2 显示%3毫秒 速度%4%5/s \n本轮丢包%6% 延迟%7ms 验证轮%8个 累计%9 稳定%10\nGAB%12:%11:%13 状态%14 探索%15")).arg(i).arg(send_buf.size()-1).arg(clock.elapsed()).arg(dsp,0,'f',4).arg(dw).arg(display_lost).arg(send_current_delay).arg(send_req_ack_loop).arg(send_lost_loop_count).arg(stable_delay).arg(average_loss,0,'f',3).arg(average_good_loss,0,'f',3).arg(average_bad_loss,0,'f',3).arg(state).arg(is_exploring));
// line_delay->append(i,send_current_delay);
// line_ackloop->append(i,send_req_ack_loop);
// line_speed->append(i,speed/1024.);//KB/s
// axis_x->setRange(0,i+5);
// if(speed > axis_y_r->max()) axis_y_r->setRange(0,speed+15);
// chart_send->update();
// ui->widget_info_chart1->update();
// ui->label_info_time->setText(QString("共记录%1s").arg(clock_total.elapsed()/1000.));
// }
// clock.restart();
// }
// if(i%PROCESS_LOOP==0){
// QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents,1);
// }
//// if(elapsed_lase_ack.elapsed() > send_current_delay + 80){
//// send_current_delay += 30;//强力降速
//// if(send_current_delay > SEND_MAX_DELAY){
//// send_current_delay = SEND_MAX_DELAY;
//// }
//// ndb<<"强力降速"<<send_current_delay;
//// }
//// if(i%2==0)send_current_delay+=1;
// if(!skip.contains(i)){
// if((i&DELAY_LOOP)==0)/*QThread::msleep(send_current_delay);* /multiDelay(send_current_delay);
// else if(i%send_req_ack_loop == 0)/*QThread::msleep(2);* /multiDelay(2);//为了防止拥塞
// }
// //进行ACK请求
// if(i%send_req_ack_loop == 0){
// send_lost_count.clear();
// ninfo<<"于包"<<i;
// send_req_ack_uuid = QUuid::createUuid();
// bool flag = false;
// QEventLoop loop;
// QTimer timer;
// connect(&timer,&QTimer::timeout,&loop,&QEventLoop::quit);
// connect(this,&MainWindow::signal_reqAck_finished,&loop,&QEventLoop::quit);
// connect(this,&MainWindow::signal_reqAck_finished,this,[&,this]{flag=true;(void)this;});
// timer.start(650);
// send_current_reqAck = i;
// ninfo<<"请求接收统计:从"<<start_reqAck<<"到"<<i;
// QElapsedTimer clock1;clock1.start();
// for(int ii=0;ii<3;ii++)send(QString("{\n \"req_ack\":%1,\"start_req_ack\":%2,\n\"uuid\":\"%3\"\n}").arg(i).arg(start_reqAck).arg(send_req_ack_uuid.toString()).toUtf8(),1,currentSendDst);
//// send(QString("{\n \"req_ack\":%1,\"start_req_ack\":%2,\n\"uuid\":\"%3\"\n}").arg(i).arg(start_reqAck).arg(send_req_ack_uuid.toString()).toUtf8());//防止丢包
// int overdrop_cnt = 0;//透支包计数
// QElapsedTimer clock_overdrop;clock_overdrop.start();
// if(send_lost_loop_count > 2 && send_current_delay < 20){//网络条件好的时候 开始透支
// for(;;){
// if(flag==true)break;
// if(clock_overdrop.elapsed()>min_rtt)break;
// if(overdrop_cnt >= qMin(send_req_ack_loop/2,5)) break;
// overdrop_cnt++;
// send(send_buf[i+overdrop_cnt],0,currentSendDst);
// skip.insert(i+overdrop_cnt);
// multiDelay(send_current_delay);
// }
// ninfo<<"透支了从"<<i+1<<"开始的"<<overdrop_cnt<<"个包";
// }
// if(!flag)loop.exec(QEventLoop::ExcludeUserInputEvents);
// if(clock.elapsed()>10)ndb<<"请求所用时间>10ms:"<<clock.elapsed()<<"ms";
// current_rtt = clock.elapsed();
// if(current_rtt < min_rtt)min_rtt = current_rtt;
// loop.deleteLater();
// //开始计算条件
// bool retry_flag = true;
// bool congestion = false;
// int last_lost_pack_index = -1;
// int fat_cnt = 0;;
// for(auto it=send_current_fastresend_map.rbegin();it!=send_current_fastresend_map.rend();it++,fat_cnt++){//检测是否因为缓冲区膨胀导致的丢包
// if(last_lost_pack_index==-1)last_lost_pack_index=*it;
// else if(abs(last_lost_pack_index-*it)>2){
// if(fat_cnt<3)retry_flag=false;
// break;
// }
// }
// if(send_current_fastresend_map.size()<3)retry_flag=false;
// QSet<int> old_fastresend = send_current_fastresend_map;
// if(retry_flag && !send_current_fastresend_map.empty()){//重试
// multiDelay(2);
// send_lost_count.clear();
// send_current_fastresend_map.clear();
// ninfo<<"于包"<<i<<"开始重新请求统计信息";
// send_req_ack_uuid = QUuid::createUuid();
// bool flag = false;
// QEventLoop loop;
// QTimer timer;
// connect(&timer,&QTimer::timeout,&loop,&QEventLoop::quit);
// connect(this,&MainWindow::signal_reqAck_finished,&loop,&QEventLoop::quit);
// connect(this,&MainWindow::signal_reqAck_finished,this,[&,this]{flag=true;(void)this;});
// timer.start(600);
// send_current_reqAck = i;
// send(QString("{\n \"req_ack\":%1,\"start_req_ack\":%2,\n\"uuid\":\"%3\"\n}").arg(i).arg(start_reqAck).arg(send_req_ack_uuid.toString()).toUtf8(),1,currentSendDst);
// loop.exec(QEventLoop::ExcludeUserInputEvents);
// loop.deleteLater();
// if(old_fastresend.size() - send_current_fastresend_map.size() < 2)congestion=true;//如果丢包集中在尾部且重新请求ACK无用就认为拥塞
// }
// float lost = 0;//平均丢包率
// for(int i : send_lost_count){
// lost += i;
// }
// ninfo<<"丢包数量"<<lost;
// lost /= send_lost_count.size();
// lost = lost / send_req_ack_loop;
// ninfo<<"丢包率"<<lost;
// ninfo<<"拥塞状态"<<congestion;
// display_lost = lost * 100;//百分数
// if(flag && lost <= 1.001){