-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
867 lines (763 loc) · 32.3 KB
/
main.cpp
File metadata and controls
867 lines (763 loc) · 32.3 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
#include "./include/adb.hpp"
#include "./include/data.h"
#include "./include/file.hpp"
#include "./include/hexreader.hpp"
#include "./include/hexwriter.hpp"
#include "./include/setting.hpp"
#include "include/tools.hpp"
#include "include/winruntime.hpp"
#include "wx/app.h"
#include "wx/dynarray.h"
#include "wx/event.h"
#include "wx/language.h"
#include "wx/msgdlg.h"
#include "wx/string.h"
#include <algorithm>
#include <cstdio>
#include <format>
#include <fstream>
#include <memory>
#include <string>
#include <thread>
#include <wx/filename.h>
#include <wx/listctrl.h>
#include <wx/wxprec.h>
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
std::vector<FileManager::FileList> init();
class MyApp : public wxApp {
public:
virtual bool OnInit();
private:
wxLocale m_locale;
};
enum { ID_Export = 1001, ID_Import, ID_Setting };
class MyFrame : public wxFrame {
public:
MyFrame();
private:
std::vector<FileManager::FileList> lists;
wxListBox *deviceList;
wxListCtrl *fileList;
void OnDeviceSelected(wxCommandEvent &event);
void OnExit(wxCommandEvent &event);
void OnAbout(wxCommandEvent &event);
void OnADBWirelessDebugHelper(wxCommandEvent &event);
void OnSettingExportPath(wxCommandEvent &event);
void OnImportFromComputer(wxCommandEvent &event);
void OnRefresh(wxCommandEvent &event);
void OnFileSelected(wxListEvent &event);
void OnFileListRightClick(wxMouseEvent &event);
void OnExport(wxCommandEvent &event);
void OnDelete(wxCommandEvent &event);
void OnEditOwnership(wxCommandEvent &event);
void OnSendToDynamicDevice(wxCommandEvent &event);
void OnClose(wxCloseEvent &event);
};
wxIMPLEMENT_APP(MyApp);
bool MyApp::OnInit() {
m_locale.AddCatalogLookupPathPrefix("locale");
m_locale.Init(wxLANGUAGE_CHINESE_SIMPLIFIED);
m_locale.AddCatalog("wxstd");
MyFrame *frame = new MyFrame();
frame->Show(true);
return true;
}
MyFrame::MyFrame()
: wxFrame(NULL, wxID_ANY,
wxString::FromUTF8("火影忍者手游录像管理器 TPPPP开发"),
wxDefaultPosition, wxSize(1024, 768)) {
// UI初始化
SetIcon(wxICON(NarutoRecordManager));
// 工具栏
wxMenu *controlMenu = new wxMenu;
// controlMenu->Append(wxID_ADD, wxString::FromUTF8("ADB无线调试辅助"));
controlMenu->Append(wxID_REFRESH, wxString::FromUTF8("刷新\tF5"));
controlMenu->Append(ID_Import, wxString::FromUTF8("从电脑导入"));
wxMenu *helpMenu = new wxMenu;
helpMenu->Append(wxID_ABOUT, wxString::FromUTF8("关于"));
wxMenu *settingMenu = new wxMenu;
settingMenu->Append(ID_Setting, wxString::FromUTF8("导出路径"));
wxMenuBar *menuBar = new wxMenuBar;
menuBar->Append(controlMenu, wxString::FromUTF8("操作"));
menuBar->Append(settingMenu, wxString::FromUTF8("设置"));
menuBar->Append(helpMenu, wxString::FromUTF8("帮助"));
SetMenuBar(menuBar);
CreateStatusBar();
// 设备列表
wxBoxSizer *topSizer = new wxBoxSizer(wxHORIZONTAL);
wxStaticText *deviceLabel =
new wxStaticText(this, wxID_ANY, wxString::FromUTF8("设备列表"),
wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER);
deviceList = new wxListBox(this, wxID_ANY, wxDefaultPosition, wxDefaultSize);
wxBoxSizer *leftSizer = new wxBoxSizer(wxVERTICAL);
leftSizer->Add(deviceLabel, 0, wxALIGN_CENTER_HORIZONTAL | wxTOP | wxBOTTOM,
10);
leftSizer->Add(deviceList, 1, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 10);
// 文件列表
wxStaticText *fileLabel =
new wxStaticText(this, wxID_ANY, wxString::FromUTF8("文件列表"),
wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER);
fileList = new wxListCtrl(this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
wxLC_REPORT);
fileList->InsertColumn(0, wxString::FromUTF8("文件名"), wxLIST_FORMAT_LEFT,
140);
fileList->InsertColumn(1, "1P", wxLIST_FORMAT_LEFT, 90);
fileList->InsertColumn(2, "2P", wxLIST_FORMAT_LEFT, 90);
fileList->InsertColumn(3, wxString::FromUTF8("胜负"), wxLIST_FORMAT_LEFT, 50);
fileList->InsertColumn(4, wxString::FromUTF8("所有权"), wxLIST_FORMAT_LEFT,
150);
wxBoxSizer *rightSizer = new wxBoxSizer(wxVERTICAL);
rightSizer->Add(fileLabel, 0, wxALIGN_CENTER_HORIZONTAL | wxTOP | wxBOTTOM,
10);
rightSizer->Add(fileList, 1, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 10);
topSizer->Add(leftSizer, 1, wxEXPAND | wxALL, 5);
topSizer->Add(rightSizer, 1, wxEXPAND | wxALL, 5);
SetSizer(topSizer);
Layout();
deviceList->Bind(wxEVT_LISTBOX, &MyFrame::OnDeviceSelected, this);
fileList->Bind(wxEVT_LIST_ITEM_SELECTED, &MyFrame::OnFileSelected, this);
fileList->Bind(wxEVT_LIST_ITEM_DESELECTED, &MyFrame::OnFileSelected, this);
fileList->Bind(wxEVT_RIGHT_DOWN, &MyFrame::OnFileListRightClick, this);
// Bind(wxEVT_MENU, &MyFrame::OnADBWirelessDebugHelper, this, wxID_ADD);
Bind(wxEVT_MENU, &MyFrame::OnSettingExportPath, this, ID_Setting);
Bind(wxEVT_MENU, &MyFrame::OnAbout, this, wxID_ABOUT);
Bind(wxEVT_MENU, &MyFrame::OnImportFromComputer, this, ID_Import);
Bind(wxEVT_MENU, &MyFrame::OnExit, this, wxID_EXIT);
Bind(wxEVT_MENU, &MyFrame::OnRefresh, this, wxID_REFRESH);
Bind(wxEVT_CLOSE_WINDOW, &MyFrame::OnClose, this);
// 程序初始化
SetStatusText(wxString::FromUTF8("初始化中......"));
lists = init();
for (const auto &i : lists) {
deviceList->Append(i.device_id);
}
SetStatusText(wxString::FromUTF8("初始化完成!"));
}
void MyFrame::OnExit(wxCommandEvent &event) { Close(true); }
void MyFrame::OnAbout(wxCommandEvent &event) {
wxMessageBox(
wxString::FromUTF8("该程序基于Android Debug "
"Bridge,实现火影忍者手游录像的管理迁移等功能\n开发者"
":TPPPP\nBilibili:https://space.bilibili.com/"
"358783831\nGithub:https://github.com/TPPPP72/"
"NarutoRecordManager\n\n版本号:1.0"),
wxString::FromUTF8("关于该软件"), wxOK | wxICON_INFORMATION);
}
void MyFrame::OnADBWirelessDebugHelper(wxCommandEvent &event) {}
void MyFrame::OnSettingExportPath(wxCommandEvent &event) {
wxDirDialog dirDialog(this, wxString::FromUTF8("选择导出的文件夹"), "",
wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST);
if (dirDialog.ShowModal() == wxID_OK) {
Setting::WriteData(Setting::Data{dirDialog.GetPath().ToUTF8().data()});
SetStatusText(wxString::FromUTF8("设置导出文件夹为:") +
dirDialog.GetPath());
} else {
wxMessageBox(wxString::FromUTF8("未选择文件夹"), wxString::FromUTF8("错误"),
wxOK | wxICON_ERROR);
}
}
void MyFrame::OnRefresh(wxCommandEvent &event) {
deviceList->SetSelection(wxNOT_FOUND);
deviceList->Clear();
long item = -1;
while ((item = fileList->GetNextItem(item, wxLIST_NEXT_ALL,
wxLIST_STATE_SELECTED)) != -1) {
fileList->SetItemState(item, 0, wxLIST_STATE_SELECTED);
}
fileList->DeleteAllItems();
lists = init();
for (const auto &item : lists) {
deviceList->Append(item.device_id);
}
std::thread([this]() {
FileManager::local_system_clear();
wxTheApp->CallAfter(
[this]() { SetStatusText(wxString::FromUTF8("刷新完成!")); });
}).detach();
}
void MyFrame::OnImportFromComputer(wxCommandEvent &event) {
if (deviceList->GetSelection() == wxNOT_FOUND) {
wxMessageBox(wxString::FromUTF8("请先在设备列表选择一个设备"),
wxString::FromUTF8("错误"), wxOK | wxICON_ERROR);
return;
}
const std::string selected_device_id =
deviceList->GetString(deviceList->GetSelection()).ToStdString();
wxFileDialog openFileDialog(
this, wxString::FromUTF8("选择文件"),
wxFileName::DirName(wxString::FromUTF8(Setting::GetData().Export_Path))
.GetAbsolutePath(),
"", wxString::FromUTF8("所有文件 (*.*)|*.*"),
wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE);
if (openFileDialog.ShowModal() == wxID_OK) {
wxArrayString paths;
openFileDialog.GetPaths(paths);
std::thread([=, this]() {
int success_cnt = 0;
int total = paths.size();
for (const auto &path : paths) {
wxTheApp->CallAfter([=, this]() {
std::string notify = std::format(
"正在导入文件:{} 当前进度:{:.1f}%",
wxString(path.substr(path.rfind("\\") + 1)).ToStdString(),
static_cast<double>(success_cnt) / total * 100);
SetStatusText(wxString::FromUTF8(notify));
});
if (ADB::PushRemoteFile_Full(
FileManager::GetListByDeviceID(lists, selected_device_id),
path.ToStdString())) {
++success_cnt;
fileList->InsertItem(fileList->GetItemCount(),
wxString(path.substr(path.rfind("\\") + 1)));
}
}
wxTheApp->CallAfter([=, this]() {
std::string notify = std::format("导入完成! {} 成功,{} 失败",
success_cnt, total - success_cnt);
SetStatusText(wxString::FromUTF8(notify));
wxCommandEvent dummy;
dummy.SetInt(deviceList->GetSelection());
OnDeviceSelected(dummy);
});
}).detach();
} else {
wxMessageBox(wxString::FromUTF8("未选择文件"), wxString::FromUTF8("错误"),
wxOK | wxICON_ERROR);
return;
}
}
void MyFrame::OnDeviceSelected(wxCommandEvent &event) {
long item = -1;
while ((item = fileList->GetNextItem(item, wxLIST_NEXT_ALL,
wxLIST_STATE_SELECTED)) != -1) {
fileList->SetItemState(item, 0, wxLIST_STATE_SELECTED);
}
fileList->DeleteAllItems();
std::string selected_device_id =
deviceList->GetString(event.GetSelection()).ToStdString();
SetStatusText(wxString::FromUTF8("选择设备:" + selected_device_id));
if (FileManager::Is_Local_Device_MAP_TEMP_Exists(selected_device_id)) {
std::thread([selected_device_id, this]() {
auto datas = FileManager::Get_File_List_Json(selected_device_id)
.get<std::vector<FileManager::FileData>>();
int total = datas.size();
if (total == FileManager::GetListByDeviceID(lists, selected_device_id)
.record.size()) {
wxTheApp->CallAfter([this, datas = std::move(datas), total]() {
int cnt = 0;
for (const auto &item : datas) {
long index = fileList->InsertItem(fileList->GetItemCount(),
wxString::FromUTF8(item.file));
fileList->SetItem(index, 1, wxString::FromUTF8(item.data.p1));
fileList->SetItem(index, 2, wxString::FromUTF8(item.data.p2));
fileList->SetItem(index, 3, wxString::FromUTF8(item.data.statu));
fileList->SetItem(index, 4, wxString::FromUTF8(item.data.belong));
std::string notify = std::format(
"获取到已构建的文件列表,加载中...... 当前进度:{:.1f}%",
static_cast<double>(++cnt) / total * 100);
SetStatusText(wxString::FromUTF8(notify));
}
});
} else {
std::thread([=, this]() {
auto &list =
FileManager::GetListByDeviceID(lists, selected_device_id);
std::map<std::string, std::string> mapping;
int sum = list.recordlist.size() + list.record.size();
int cnt = 0;
std::vector<FileManager::FileData> datas;
for (const auto &item : list.recordlist) {
std::string temp_path =
FileManager::Get_Local_Device_TEMP_Path(list.device_id);
ADB::PullRemoteFile(list, item, temp_path);
auto recordlist = hexreader::Get_Record_List(temp_path + item);
for (const auto &recorditem : recordlist) {
mapping[recorditem.datetime] = item.substr(item.rfind("_") + 1);
}
FileManager::local_system_clear(list.device_id);
std::string notify =
std::format("正在构建文件列表中...... 当前进度:{:.1f}%",
static_cast<double>(++cnt) / sum * 100);
wxTheApp->CallAfter(
[=, this]() { SetStatusText(wxString::FromUTF8(notify)); });
}
for (const auto &item : list.record) {
std::string temp_path =
FileManager::Get_Local_Device_TEMP_Path(list.device_id);
ADB::PullRemoteFile(list, item, temp_path);
auto record = hexreader::Get_Record(temp_path + item);
FileManager::FileData filedata;
filedata.file = item;
int playerIndex = 0;
for (const auto &playeritem : record.information.inner.players) {
if (playerIndex == 0)
filedata.data.p1 = playeritem.userdata.nickname;
else if (playerIndex == 1)
filedata.data.p2 = playeritem.userdata.nickname;
++playerIndex;
}
int result = record.settle_information.inner.statu;
if (result == 1)
filedata.data.statu = "平";
else if (result == 2)
filedata.data.statu = "负";
else
filedata.data.statu = "胜";
if (mapping.find(item) != mapping.end())
filedata.data.belong = mapping.at(item);
else
filedata.data.belong = "无";
datas.emplace_back(std::move(filedata));
std::string notify =
std::format("正在构建文件列表中...... 当前进度:{:.1f}%",
static_cast<double>(++cnt) / sum * 100);
wxTheApp->CallAfter(
[=, this]() { SetStatusText(wxString::FromUTF8(notify)); });
}
{
std::ofstream output(
FileManager::Get_Local_Device_MAP_TEMP(selected_device_id));
nlohmann::json j = datas;
output << j.dump(4);
output.close();
}
wxTheApp->CallAfter([this, datas = std::move(datas)]() {
for (const auto &filedata : datas) {
long index = fileList->InsertItem(
fileList->GetItemCount(), wxString::FromUTF8(filedata.file));
fileList->SetItem(index, 1, wxString::FromUTF8(filedata.data.p1));
fileList->SetItem(index, 2, wxString::FromUTF8(filedata.data.p2));
fileList->SetItem(index, 3,
wxString::FromUTF8(filedata.data.statu));
fileList->SetItem(index, 4,
wxString::FromUTF8(filedata.data.belong));
}
SetStatusText(wxString::FromUTF8("文件列表构建完毕!"));
});
}).detach();
}
}).detach();
return;
}
std::thread([=, this]() {
auto list = FileManager::GetListByDeviceID(lists, selected_device_id);
std::map<std::string, std::string> mapping;
int sum = list.recordlist.size() + list.record.size();
int cnt = 0;
std::vector<FileManager::FileData> datas;
for (const auto &item : list.recordlist) {
std::string temp_path =
FileManager::Get_Local_Device_TEMP_Path(list.device_id);
ADB::PullRemoteFile(list, item, temp_path);
auto recordlist = hexreader::Get_Record_List(temp_path + item);
for (const auto &recorditem : recordlist) {
mapping[recorditem.datetime] = item.substr(item.rfind("_") + 1);
}
FileManager::local_system_clear(list.device_id);
std::string notify =
std::format("正在构建文件列表中...... 当前进度:{:.1f}%",
static_cast<double>(++cnt) / sum * 100);
wxTheApp->CallAfter(
[=, this]() { SetStatusText(wxString::FromUTF8(notify)); });
}
for (const auto &item : list.record) {
std::string temp_path =
FileManager::Get_Local_Device_TEMP_Path(list.device_id);
ADB::PullRemoteFile(list, item, temp_path);
auto record = hexreader::Get_Record(temp_path + item);
FileManager::FileData filedata;
filedata.file = item;
int playerIndex = 0;
for (const auto &playeritem : record.information.inner.players) {
if (playerIndex == 0)
filedata.data.p1 = playeritem.userdata.nickname;
else if (playerIndex == 1)
filedata.data.p2 = playeritem.userdata.nickname;
++playerIndex;
}
int result = record.settle_information.inner.statu;
if (result == 1)
filedata.data.statu = "平";
else if (result == 2)
filedata.data.statu = "负";
else
filedata.data.statu = "胜";
if (mapping.find(item) != mapping.end())
filedata.data.belong = mapping.at(item);
else
filedata.data.belong = "无";
datas.emplace_back(std::move(filedata));
std::string notify =
std::format("正在构建文件列表中...... 当前进度:{:.1f}%",
static_cast<double>(++cnt) / sum * 100);
wxTheApp->CallAfter(
[=, this]() { SetStatusText(wxString::FromUTF8(notify)); });
}
{
std::ofstream output(
FileManager::Get_Local_Device_MAP_TEMP(selected_device_id));
nlohmann::json j = datas;
output << j.dump(4);
output.close();
}
wxTheApp->CallAfter([this, datas = std::move(datas)]() {
for (const auto &filedata : datas) {
long index = fileList->InsertItem(fileList->GetItemCount(),
wxString::FromUTF8(filedata.file));
fileList->SetItem(index, 1, wxString::FromUTF8(filedata.data.p1));
fileList->SetItem(index, 2, wxString::FromUTF8(filedata.data.p2));
fileList->SetItem(index, 3, wxString::FromUTF8(filedata.data.statu));
fileList->SetItem(index, 4, wxString::FromUTF8(filedata.data.belong));
}
SetStatusText(wxString::FromUTF8("文件列表构建完毕!"));
});
}).detach();
}
void MyFrame::OnFileSelected(wxListEvent &event) {
int index = event.GetIndex();
if (index == wxNOT_FOUND)
return;
wxString selected_file = fileList->GetItemText(index);
long state = fileList->GetItemState(index, wxLIST_STATE_SELECTED);
if (state & wxLIST_STATE_SELECTED) {
SetStatusText(wxString::FromUTF8("选择文件:" + selected_file));
} else {
SetStatusText(wxString::FromUTF8("取消选择:" + selected_file));
}
}
void MyFrame::OnFileListRightClick(wxMouseEvent &event) {
wxPoint pos_in_list = event.GetPosition();
wxPoint pos_on_screen = fileList->ClientToScreen(pos_in_list);
wxPoint pos_in_frame = this->ScreenToClient(pos_on_screen);
int flag = 0;
long file_list_index = fileList->HitTest(pos_in_list, flag);
if (file_list_index != wxNOT_FOUND) {
fileList->SetItemState(file_list_index, wxLIST_STATE_SELECTED,
wxLIST_STATE_SELECTED);
SetStatusText(wxString::FromUTF8("选择文件:" +
fileList->GetItemText(file_list_index)));
}
std::unique_ptr<wxMenu> menu = std::make_unique<wxMenu>();
menu->Append(ID_Export, wxString::FromUTF8("导出到电脑"));
if (lists.size() >= 2) {
wxMenu *sendSubMenu = new wxMenu;
auto device_list_index = deviceList->GetSelection();
for (int item = 0; item < lists.size(); item++) {
if (lists[item].device_id !=
deviceList->GetString(device_list_index).ToStdString()) {
sendSubMenu->Append(2000 + item, lists[item].device_id);
Bind(wxEVT_MENU, &MyFrame::OnSendToDynamicDevice, this, 2000 + item);
}
}
menu->AppendSubMenu(sendSubMenu, wxString::FromUTF8("发送到其他设备"));
}
menu->Append(wxID_DELETE, wxString::FromUTF8("删除"));
menu->Append(wxID_EDIT, wxString::FromUTF8("编辑所有权"));
menu->Bind(wxEVT_MENU, &MyFrame::OnExport, this, ID_Export);
menu->Bind(wxEVT_MENU, &MyFrame::OnDelete, this, wxID_DELETE);
menu->Bind(wxEVT_MENU, &MyFrame::OnEditOwnership, this, wxID_EDIT);
PopupMenu(menu.get(), pos_in_frame);
}
void MyFrame::OnExport(wxCommandEvent &event) {
const std::string selected_device_id =
deviceList->GetString(deviceList->GetSelection()).ToStdString();
wxArrayInt selections;
long item = -1;
while ((item = fileList->GetNextItem(item, wxLIST_NEXT_ALL,
wxLIST_STATE_SELECTED)) != -1) {
selections.Add(item);
}
std::thread([=, this]() {
int success_cnt = 0;
int total = selections.size();
auto &list = FileManager::GetListByDeviceID(lists, selected_device_id);
std::string export_path = Setting::GetData().Export_Path;
if (export_path.back() != '\\')
export_path += '\\';
for (size_t i = 0; i < selections.size(); ++i) {
long index = selections[i];
std::string file = fileList->GetItemText(index, 0).ToStdString();
auto file_ptr = std::make_shared<std::string>(std::move(file));
wxTheApp->CallAfter([=, this]() {
std::string notify =
std::format("正在导出文件:{} 当前进度:{:.1f}%", *file_ptr,
static_cast<double>(success_cnt) / total * 100);
SetStatusText(wxString::FromUTF8(notify));
});
if (FileManager::Copy(list, *file_ptr, utf8_to_gbk(export_path)))
++success_cnt;
}
wxTheApp->CallAfter([=, this]() {
std::string notify =
std::format("导出完成!目录:{} {} 成功,{} 失败", export_path,
success_cnt, total - success_cnt);
SetStatusText(wxString::FromUTF8(notify));
});
}).detach();
}
void MyFrame::OnDelete(wxCommandEvent &event) {
const std::string selected_device_id =
deviceList->GetString(deviceList->GetSelection()).ToStdString();
wxArrayInt selections;
long item = -1;
while ((item = fileList->GetNextItem(item, wxLIST_NEXT_ALL,
wxLIST_STATE_SELECTED)) != -1) {
selections.Add(item);
}
std::thread([=, this]() {
int success_cnt = 0;
int total = selections.size();
auto &list = FileManager::GetListByDeviceID(lists, selected_device_id);
std::vector<std::string> DelSuccess;
for (size_t i = 0; i < selections.size(); ++i) {
long index = selections[i];
std::string file = fileList->GetItemText(index, 0).ToStdString();
auto file_ptr = std::make_shared<std::string>(std::move(file));
wxTheApp->CallAfter([=, this]() {
std::string notify =
std::format("正在删除文件:{} 当前进度:{:.1f}%", *file_ptr,
static_cast<double>(success_cnt) / total * 100);
SetStatusText(wxString::FromUTF8(notify));
});
if (ADB::DeleteRemoteFile(list, *file_ptr)) {
DelSuccess.emplace_back(*file_ptr);
++success_cnt;
}
}
wxTheApp->CallAfter([=, this]() {
for (const auto &item : DelSuccess) {
long itemIndex = -1;
while ((itemIndex = fileList->GetNextItem(itemIndex)) != -1) {
wxString filename = fileList->GetItemText(itemIndex, 0);
if (filename == wxString(item)) {
fileList->DeleteItem(itemIndex);
break;
}
}
}
std::string notify = std::format("删除完成! {} 成功,{} 失败",
success_cnt, total - success_cnt);
SetStatusText(wxString::FromUTF8(notify));
});
}).detach();
}
void MyFrame::OnEditOwnership(wxCommandEvent &event) {
wxString input =
wxGetTextFromUser(wxString::FromUTF8("请输入游戏 ID"),
wxString::FromUTF8("编辑所有权"), "", this);
if (input.IsEmpty()) {
SetStatusText(wxString::FromUTF8("开始清除所选文件的所有权"));
std::thread([=, this]() {
const std::string selected_device_id =
deviceList->GetString(deviceList->GetSelection()).ToStdString();
wxArrayInt selections;
std::map<std::string, std::vector<std::string>> map;
std::vector<std::string> Change_List;
long item = -1;
while ((item = fileList->GetNextItem(item, wxLIST_NEXT_ALL)) != -1) {
bool isSelected = fileList->GetItemState(item, wxLIST_STATE_SELECTED) &
wxLIST_STATE_SELECTED;
wxString colText = fileList->GetItemText(item, 4);
if (isSelected) {
map[colText.ToStdString()].emplace_back(
fileList->GetItemText(item, 0));
Change_List.emplace_back(fileList->GetItemText(item, 0));
}
}
for (auto [game_id, files] : map) {
std::string path = std::format(
"{}LocalRecordList_JueDou_{}",
FileManager::Get_Local_Device_TEMP_Path(selected_device_id),
game_id);
if (!std::filesystem::exists(path)) {
ADB::PullRemoteFile(
FileManager::GetListByDeviceID(lists, selected_device_id),
std::format("LocalRecordList_JueDou_{}", game_id),
FileManager::Get_Local_Device_TEMP_Path(selected_device_id));
}
auto records = hexreader::Get_Record_List(path);
std::cout << "records.size():" << records.size() << std::endl;
for (auto &item : files) {
std::erase_if(records, [&](const auto &record) {
return record.datetime == item;
});
}
if (!records.empty()) {
hexwriter::Write_Record_List(
records, std::format("{}LocalRecordList_JueDou_{}",
FileManager::Get_Local_Device_TEMP_Path(
selected_device_id),
game_id));
ADB::PushRemoteFile_Full(
FileManager::GetListByDeviceID(lists, selected_device_id),
std::format(
"{}LocalRecordList_JueDou_{}",
FileManager::Get_Local_Device_TEMP_Path(selected_device_id),
game_id));
} else {
ADB::DeleteRemoteFile(
FileManager::GetListByDeviceID(lists, selected_device_id),
std::format("LocalRecordList_JueDou_{}", game_id));
}
}
wxTheApp->CallAfter([=, this]() {
for (const auto &item : Change_List) {
long itemIndex = -1;
while ((itemIndex = fileList->GetNextItem(itemIndex)) != -1) {
wxString filename = fileList->GetItemText(itemIndex, 0);
if (filename == wxString(item)) {
fileList->SetItem(itemIndex, 4, wxString::FromUTF8("无"));
break;
}
}
}
SetStatusText(wxString::FromUTF8("清除完成"));
});
}).detach();
return;
}
try {
std::string game_id = input.ToStdString();
long long temp = std::stoll(game_id);
if (temp < 0) {
throw std::invalid_argument("负数不合法");
}
const std::string selected_device_id =
deviceList->GetString(deviceList->GetSelection()).ToStdString();
wxArrayInt selections;
std::vector<std::string> Change_List;
long item = -1;
while ((item = fileList->GetNextItem(item, wxLIST_NEXT_ALL)) != -1) {
bool isSelected = fileList->GetItemState(item, wxLIST_STATE_SELECTED) &
wxLIST_STATE_SELECTED;
wxString colText = fileList->GetItemText(item, 4);
bool matchDeviceId = colText.ToStdString() == game_id;
if (isSelected) {
Change_List.emplace_back(fileList->GetItemText(item, 0));
}
if (isSelected || matchDeviceId) {
selections.Add(item);
}
}
SetStatusText(wxString::FromUTF8("正在修改选中文件的所有权"));
std::thread([=, this]() {
std::vector<ManagerData::Player_Record> records;
for (size_t i = 0; i < selections.size(); ++i) {
long index = selections[i];
std::string file = fileList->GetItemText(index, 0).ToStdString();
auto record = hexreader::Get_Record(std::format(
"{}{}", FileManager::Get_Local_Device_TEMP_Path(selected_device_id),
file));
ManagerData::User_Data select;
for (const auto &item : record.information.inner.players) {
select = item.userdata;
if (std::to_string(item.userdata.user_id) != game_id)
break;
}
std::vector<int> ninja_number, fashion_number;
for (const auto &item : select.game.ninja) {
// ninja_number.emplace_back(item.basic.ninja_id);
// fashion_number.emplace_back(item.basic.ninja_resource.fashion_resource
// % 10);
ninja_number.emplace_back(90001001);
fashion_number.emplace_back(0);
}
ManagerData::Player_Record new_record;
new_record.timestamp = to_timestamp(file);
new_record.statu = record.settle_information.inner.statu;
new_record.datetime = file;
new_record.info = {select.nickname,
select.avatar_url,
select.private_info.area_code - 400000 + 2000,
select.area_name,
ninja_number,
select.rank,
fashion_number,
select.dynamic_avatar};
if (new_record.info.area_code >= 5000 ||
new_record.info.area_code <= 2000)
new_record.info.area_code = 2001;
new_record.is_temp = false;
records.emplace_back(new_record);
}
hexwriter::Write_Record_List(
records, std::format("{}LocalRecordList_JueDou_{}",
FileManager::Get_Local_Device_TEMP_Path(
selected_device_id),
game_id));
ADB::PushRemoteFile_Full(
FileManager::GetListByDeviceID(lists, selected_device_id),
std::format(
"{}LocalRecordList_JueDou_{}",
FileManager::Get_Local_Device_TEMP_Path(selected_device_id),
game_id));
wxTheApp->CallAfter([=, this]() {
for (const auto &item : Change_List) {
long itemIndex = -1;
while ((itemIndex = fileList->GetNextItem(itemIndex)) != -1) {
wxString filename = fileList->GetItemText(itemIndex, 0);
if (filename == wxString(item)) {
fileList->SetItem(itemIndex, 4, wxString::FromUTF8(game_id));
break;
}
}
}
SetStatusText(wxString::FromUTF8("修改完成"));
});
}).detach();
} catch (const std::exception &e) {
wxMessageBox(wxString::FromUTF8("输入的不是合法的数字,请重新尝试"),
wxString::FromUTF8("格式错误"), wxOK | wxICON_ERROR);
}
}
void MyFrame::OnSendToDynamicDevice(wxCommandEvent &event) {
const std::string selected_device_id =
deviceList->GetString(deviceList->GetSelection()).ToStdString();
wxArrayInt selections;
long item = -1;
while ((item = fileList->GetNextItem(item, wxLIST_NEXT_ALL,
wxLIST_STATE_SELECTED)) != -1) {
selections.Add(item);
}
std::thread([=, this]() {
int success_cnt = 0;
int total = selections.size();
auto &list = FileManager::GetListByDeviceID(lists, selected_device_id);
std::string export_path = Setting::GetData().Export_Path;
for (size_t i = 0; i < selections.size(); ++i) {
long index = selections[i];
std::string file = fileList->GetItemText(index, 0).ToStdString();
auto file_ptr = std::make_shared<std::string>(std::move(file));
wxTheApp->CallAfter([=, this]() {
std::string notify =
std::format("正在发送文件:{} 当前进度:{:.1f}%", *file_ptr,
static_cast<double>(success_cnt) / total * 100);
SetStatusText(wxString::FromUTF8(notify));
});
if (ADB::PushRemoteFile(lists[event.GetId() - 2000], list.device_id,
*file_ptr))
++success_cnt;
}
wxTheApp->CallAfter([=, this]() {
std::string notify = std::format("发送完成! {} 成功,{} 失败",
success_cnt, total - success_cnt);
SetStatusText(wxString::FromUTF8(notify));
});
}).detach();
}
void MyFrame::OnClose(wxCloseEvent &event) {
RunCommand("taskkill /f /im adb.exe");
Destroy();
}
std::vector<FileManager::FileList> init() {
FileManager::local_system_init();
FileManager::local_system_clear();
auto devicelist = ADB::GetDevices();
std::vector<FileManager::FileList> lists;
std::for_each(devicelist.begin(), devicelist.end(), [&](const auto &item) {
lists.emplace_back(FileManager::FileList{ADB::GetRecordFiles(item), item});
});
return lists;
}