-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdowntask.cpp
More file actions
867 lines (807 loc) · 27.1 KB
/
downtask.cpp
File metadata and controls
867 lines (807 loc) · 27.1 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 "stdafx.h"
namespace local {
TaskNode::TaskNode(const TypeID& task_id) :
ITaskCommonData(task_id),
m_pTaskResult(new TaskResult())
{
Global::LibcurlGet()->CreateRequest(task_id);
}
TaskNode::~TaskNode() {
}
void TaskNode::Release() const {
Global::LibcurlGet()->DestoryRequest(m_ID);
delete this;
}
void TaskNode::LocalResDir(const std::string& path) {
std::lock_guard<std::mutex> lock{ *m_Mutex };
m_LocalResDir = path;
}
const std::string& TaskNode::LocalResDir() const {
std::lock_guard<std::mutex> lock{ *m_Mutex };
return m_LocalResDir;
}
void TaskNode::DownLimitSpeed(const long long& speed_b/*b*/) {
std::lock_guard<std::mutex> lock{ *m_Mutex };
m_DownLimitSpeed = speed_b;
auto pDownReqObj = Global::LibcurlGet()->GetRequest(m_ID);
if (pDownReqObj)
pDownReqObj->MaxRecvSpeedLarge(m_DownLimitSpeed);
}
void* TaskNode::RoutePtr() const {
std::lock_guard<std::mutex> lock{ *m_Mutex };
return m_RoutePtr;
}
void TaskNode::BindUI2(void* bindui2) {
std::lock_guard<std::mutex> lock{ *m_Mutex };
m_BindUI2 = bindui2;
}
void* TaskNode::BindUI2() const {
std::lock_guard<std::mutex> lock{ *m_Mutex };
return m_BindUI2;
}
void TaskNode::BindPtr(void* ptr) {
std::lock_guard<std::mutex> lock{ *m_Mutex };
m_BindPtr = ptr;
}
void* TaskNode::BindPtr() const {
std::lock_guard<std::mutex> lock{ *m_Mutex };
return m_BindPtr;
}
void* TaskNode::BindUI() const {
std::lock_guard<std::mutex> lock{ *m_Mutex };
return m_BindUI;
}
void TaskNode::BindUI(void* bind_ui) {
std::lock_guard<std::mutex> lock{ *m_Mutex };
m_BindUI = bind_ui;
}
void TaskNode::RoutePtr(void* route_ptr) {
std::lock_guard<std::mutex> lock{ *m_Mutex };
m_RoutePtr = route_ptr;
}
void TaskResult::operator<<(const libcurlpp::IProgressInfo* info) {
std::lock_guard<std::mutex> lock{ *m_Mutex };
do {
if (!info)
break;
m_down_total = info->total();
m_down_current = info->current();
m_down_percentage = info->percentage();
auto time_s = info->time_s();
auto speed_s = info->speed_s();
if (time_s > 0)
m_down_time_s = time_s;
if (speed_s > 0)
m_down_speed_s = speed_s;
} while (0);
}
void TaskResult::operator<<(const libcurlpp::IResponse* res) {
std::lock_guard<std::mutex> lock{ *m_Mutex };
do {
if (!res)
break;
} while (0);
}
const std::string& TaskResult::FinishPath() const {
std::lock_guard<std::mutex> lock{ *m_Mutex };
return m_FinishPath;
}
const std::string& TaskResult::FinishPathname() const {
std::lock_guard<std::mutex> lock{ *m_Mutex };
return m_FinishPathname;
}
const double& TaskResult::down_total() const {
std::lock_guard<std::mutex> lock{ *m_Mutex };
return m_down_total;
}
const double& TaskResult::down_current() const {
std::lock_guard<std::mutex> lock{ *m_Mutex };
return m_down_current;
}
const double& TaskResult::down_speed_s() const {
std::lock_guard<std::mutex> lock{ *m_Mutex };
return m_down_speed_s;
}
const double& TaskResult::down_percentage() const {
std::lock_guard<std::mutex> lock{ *m_Mutex };
return m_down_percentage;
}
const long long& TaskResult::down_time_s() const {
std::lock_guard<std::mutex> lock{ *m_Mutex };
return m_down_time_s;
}
const long long& TaskResult::extract_total() const {
std::lock_guard<std::mutex> lock{ *m_Mutex };
return m_extract_total;
}
void TaskResult::operator<<(const tagTaskmanMsg::tagDetails& details) {
std::lock_guard<std::mutex> lock{ *m_Mutex };
m_FinishPath = shared::Win::GetPathByPathnameA(details.StartupPEPathname);
m_FinishPathname = details.StartupPEPathname;
}
void TaskResult::operator<<(const EXTRACTPROGRESSINFO& extract_progress_info) {
std::lock_guard<std::mutex> lock{ *m_Mutex };
m_extract_total = extract_progress_info.extract_total;
m_extract_current = extract_progress_info.extract_current;
m_extract_time_s = extract_progress_info.extract_time_s;
m_extract_percentage = extract_progress_info.extract_percentage;
}
const long long& TaskResult::extract_current() const {
std::lock_guard<std::mutex> lock{ *m_Mutex };
return m_extract_current;
}
const long long& TaskResult::extract_percentage() const {
std::lock_guard<std::mutex> lock{ *m_Mutex };
return m_extract_percentage;
}
const long long& TaskResult::extract_time_s() const {
std::lock_guard<std::mutex> lock{ *m_Mutex };
return m_extract_time_s;
}
void TaskNode::TaskType(const EnTaskType& task_type) {
std::lock_guard<std::mutex> lock{ *m_Mutex };
m_TaskType.store(task_type);
}
ITaskResultStatus* TaskNode::Result() const {
std::lock_guard<std::mutex> lock{ *m_Mutex };
return dynamic_cast<ITaskResultStatus*>(m_pTaskResult);
}
const std::string& TaskNode::DownCacheFilePathname() const {
std::lock_guard<std::mutex> lock{ *m_Mutex };
return m_DownCacheFilePathname;
}
void TaskNode::DownCacheFilePathname(const std::string& pathname) {
std::lock_guard<std::mutex> lock{ *m_Mutex };
m_DownCacheFilePathname = shared::Win::PathFixedA(pathname);
}
void TaskNode::OpenCommandLine(const std::string& commandline) {
std::lock_guard<std::mutex> lock{ *m_Mutex };
m_OpenCommandLine = commandline;
}
const std::string& TaskNode::Name() const {
std::lock_guard<std::mutex> lock{ *m_Mutex };
return m_Name;
}
void TaskNode::Name(const std::string& name) {
std::lock_guard<std::mutex> lock{ *m_Mutex };
m_Name = name;
}
void TaskNode::operator<<(const tagTaskmanMsg::tagDetails& details) {
std::lock_guard<std::mutex> lock{ *m_Mutex };
if (m_pTaskResult)
*m_pTaskResult << details;
}
void TaskNode::operator<<(const EXTRACTPROGRESSINFO& progress_info) {
std::lock_guard<std::mutex> lock{ *m_Mutex };
if (m_pTaskResult)
*m_pTaskResult << progress_info;
}
const TypeID& TaskNode::ID() const {
std::lock_guard<std::mutex> lock{ *m_Mutex };
return m_ID;
}
bool TaskNode::Verify() const {
bool result = false;
std::lock_guard<std::mutex> lock{ *m_Mutex };
do {
if (m_ID <= 0)
break;
if (m_Url.empty())
break;
/*if (!m_pRequestObj)
break;*/
result = true;
} while (0);
return result;
}
void TaskNode::Url(const std::string& url) {
std::lock_guard<std::mutex> lock{ *m_Mutex };
m_Url = url;
}
const std::string& TaskNode::LogoUrl() const {
std::lock_guard<std::mutex> lock{ *m_Mutex };
return m_LogoUrl;
}
void TaskNode::LogoUrl(const std::string& url) {
std::lock_guard<std::mutex> lock{ *m_Mutex };
m_LogoUrl = url;
}
const std::string& TaskNode::Url() const {
std::lock_guard<std::mutex> lock{ *m_Mutex };
return m_Url;
}
const unsigned int& TaskNode::VipLevel() const {
std::lock_guard<std::mutex> lock{ *m_Mutex };
return m_VipLevel;
}
void TaskNode::VipLevel(const unsigned int& level) {
std::lock_guard<std::mutex> lock{ *m_Mutex };
m_VipLevel = level;
}
const std::string& TaskNode::LogoPathname() const {
std::lock_guard<std::mutex> lock{ *m_Mutex };
return m_LogoPathname;
}
void TaskNode::LogoPathname(const std::string& logo_buffer) {
std::lock_guard<std::mutex> lock{ *m_Mutex };
m_LogoPathname = logo_buffer;
}
EnActionType TaskNode::Action() const {
std::lock_guard<std::mutex> lock{ *m_Mutex };
return m_ActionType.load();
}
EnActionType TaskNode::ActionPrev() const {
std::lock_guard<std::mutex> lock{ *m_Mutex };
return m_ActionTypePrev.load();
}
EnActionType TaskNode::StatusPrev() const {
std::lock_guard<std::mutex> lock{ *m_Mutex };
return m_ActionTypePrev.load();
}
EnActionType TaskNode::Status() const {
std::lock_guard<std::mutex> lock{ *m_Mutex };
return m_ActionType.load();
}
void TaskNode::FinishPathname(const std::string& pathname) {
std::lock_guard<std::mutex> lock{ *m_Mutex };
m_FinishPathname = pathname;
}
const std::string& TaskNode::FinishPathname() const {
std::lock_guard<std::mutex> lock{ *m_Mutex };
return m_FinishPathname;
}
void TaskNode::FinishPath(const std::string& path) {
std::lock_guard<std::mutex> lock{ *m_Mutex };
m_FinishPath = path;
}
const std::string& TaskNode::FinishPath() const {
std::lock_guard<std::mutex> lock{ *m_Mutex };
return m_FinishPath;
}
void TaskNode::Action(const EnActionType& set_action) {
std::lock_guard<std::mutex> lock{ *m_Mutex };
m_ActionTypePrev.store(m_ActionType.load());
m_ActionType.store(set_action);
}
bool TaskNode::IsPost() {
bool result = false;
std::lock_guard<std::mutex> lock{ *m_Mutex };
if (m_ActionType == EnActionType::DownBeworking) {
result = true;
}
else if (m_ActionType == EnActionType::InstallBeworking) {
result = true;
}
else {
auto found = m_ActionPostedQ.find(m_ActionType);
if (found == m_ActionPostedQ.end()) {
m_ActionPostedQ.emplace(m_ActionType);
result = true;
}
}
return result;
}
bool TaskNode::Install() {
bool result = false;
std::lock_guard<std::mutex> lock{ *m_Mutex };
#if 0//!@ 因当前不涉及该业务而禁用
do {
//!@ 创建安装进程
//!
//!
std::string process_pathname;
std::string commandline;
commandline
.append(componects_taskman::mapCommandLineIdentify.at(componects_taskman::EnCmdType::Verify))
.append("=").append(componects_taskman::STARUP_VERIFY)
.append(" ");
commandline
.append(componects_taskman::mapCommandLineIdentify.at(componects_taskman::EnCmdType::TaskId))
.append("=").append(std::to_string(m_ID))
.append(" ");
commandline
.append(componects_taskman::mapCommandLineIdentify.at(componects_taskman::EnCmdType::IPAddr))
.append("=").append(Global::PCHackerGet()->ConfigureGet()->LocalServiceTcpAddr())
.append(" ");
process_pathname = shared::Win::PathFixedA(Global::PCHackerGet()->ConfigureGet()->ProjectCurrentPath() + R"(\Taskman.exe)");
if (!shared::Win::AccessA(process_pathname))
break;
#if 1 // 发行算法
if (Global::PCHackerGet()->m_TaskmanPtrQ.search(m_ID))
break;
shared::Win::Process::CreateA(
process_pathname,
commandline,
[&](const HANDLE&, const DWORD& create_pid) {
auto pTaskman = new Taskman(m_ID);
pTaskman->InPathname(m_DownCacheFilePathname);
pTaskman->OutPath(m_FinishPath.empty() ? shared::Win::GetPathByPathnameA(m_FinishPathname) : m_FinishPath);
Global::PCHackerGet()->m_TaskmanPtrQ.push(m_ID, pTaskman);
result = true;
}, false, false, 0);
#else //!@ 调试算法
auto pTaskman = new Taskman(m_ID);
pTaskman->InPathname(m_DownCacheFilePathname);
pTaskman->OutPath(shared::Win::GetPathByPathnameA(m_FinishPathname) + std::to_string(m_ID) + "\\");
Global::PCHackerGet()->m_TaskmanPtrQ.push(m_ID, pTaskman);
#endif
} while (0);
#endif
return result;
}
bool TaskNode::Perform() {
bool result = false;
std::lock_guard<std::mutex> lock{ *m_Mutex };
do {
if (m_ActionType.load() == EnActionType::DownBeworking) {
result = true;
break;
}
m_ActionTypePrev.store(m_ActionType.load());
m_ActionType.store(EnActionType::DownBeworking);
auto pDownReqObj = Global::LibcurlGet()->GetRequest(m_ID);
if (!pDownReqObj)
break;
pDownReqObj->RequestUrl(m_Url);
pDownReqObj->Header(false);
pDownReqObj->EnableWriteStream(false);
pDownReqObj->RequestType(libcurlpp::EnRequestType::REQUEST_TYPE_GET);
if (!pDownReqObj->CachePathname(m_DownCacheFilePathname)) {
std::cout << "Create cache file failed." << std::endl;
break;
}
pDownReqObj->ProgressCb(
[&](const libcurlpp::IProgressInfo* pDownProgressInfo, const libcurlpp::IProgressInfo*)->libcurlpp::ProgressActionType {
libcurlpp::ProgressActionType result = libcurlpp::ProgressActionType::Break;
do {
if (!pDownProgressInfo)
break;
if (m_pTaskResult)
*m_pTaskResult << pDownProgressInfo;
result = libcurlpp::ProgressActionType::Continue;
} while (0);
if (m_ActionType.load() == EnActionType::DownStop)
result = libcurlpp::ProgressActionType::Break;
return result;
});
pDownReqObj->FinishCb(
[&](const libcurlpp::IResponse* resObj) {
if (m_pTaskResult) {
*m_pTaskResult << resObj;
}
if (resObj->HttpCode() == 200 && resObj->CurlCode() == 42) {
m_ActionTypePrev.store(m_ActionType.load());
m_ActionType.store(EnActionType::DownStopd);
}
else if ((resObj->HttpCode() == 200 || resObj->HttpCode() == 206) && resObj->CurlCode() == 0) {
m_ActionTypePrev.store(m_ActionType.load());
m_ActionType.store(EnActionType::DownFinished);
}
else {
m_ActionTypePrev.store(m_ActionType.load());
m_ActionType.store(EnActionType::DownFailed);
}
});
pDownReqObj->Action(libcurlpp::EnRequestAction::Start);
result = true;
} while (0);
if (!result) {
m_ActionTypePrev.store(m_ActionType.load());
m_ActionType.store(EnActionType::DownFailed);
}
return result;
}
bool TaskNode::FinalResult() const {
std::lock_guard<std::mutex> lock{ *m_Mutex };
return m_FinalResult.load();
}
#if 0
IDownTaskElement* TaskNode::UIDownTaskElementCreate() {
std::lock_guard<std::mutex> lock{ *m_Mutex };
CDialogBuilder builder;
m_pUIDownTaskElement = builder.Create<IDownTaskElement>(LR"(nodes\uidwontasknode.xml)");
if (!m_Name.empty())
m_pUIDownTaskElement->SetName(shared::IConv::MBytesToWString(m_Name));
return m_pUIDownTaskElement;
}
IDownTaskElement* TaskNode::UIDownTaskElementGet() const {
std::lock_guard<std::mutex> lock{ *m_Mutex };
return m_pUIDownTaskElement;
}
DownActionType TaskNode::Action() const {
std::lock_guard<std::mutex> lock{ *m_Mutex };
return m_ActionType.load();
}
bool TaskNode::Pause() {
return Stop();
}
bool TaskNode::Start() {
bool result = false;
std::lock_guard<std::mutex> lock{ *m_Mutex };
#if 0
do {
if (m_ActionType != EnDownActionType::Start)
break;
if (!m_IsOpenThread.load()) {
m_IsOpenThread.store(true);
m_Threads.emplace_back([this]() {OnProgressChanged(); });
}
//!@ 任务节点开始下载
auto pReqObj = Global::PCDownGet()->HttpObj()->RouteCreate();
if (!pReqObj)
break;
pReqObj->Push(
[&](shared::http::RequestObj* reqObj) {
do {
auto fixUrl = shared::Win::UrlFixedByDowntool(m_Url);
reqObj->Url(fixUrl);
reqObj->Type(shared::http::EnRequestType::EN_REQUEST_TYPE_DOWN);
reqObj->Header(false);
if (m_VipLevel <= 0)
reqObj->MaxRecvSpeedLarge(NormalUserLimitDownSpeedValue);
reqObj->TimeoutResponseMS(10 * 1000);//!@ 超时
reqObj->DownCacheFilePathname(m_DownCacheFilePathname);
reqObj->ResultCb(
[&](const shared::http::RequestObj* reqObj, const shared::http::ResponseObj* resObj) {
auto sk = 0;
});
//!@ dltotal + ResumeFromLarge, dlnow + ResumeFromLarge, ultotal, ulnow, nullptr
reqObj->ProgressCb(
[&](
const __int64& dltotal/*+ ResumeFromLarge*/,
const __int64& dlnow/*+ ResumeFromLarge*/,
const __int64& ultotal,
const __int64& ulnow,
void*)->int {
int result = static_cast<int>(shared::http::EnDownProgressStatus::EN_DOWN_PROGRESS_STATUS_ON);
do {
m_ProgressRouteQ.push(ProgressRoute(dltotal, dlnow, ultotal, ulnow));
} while (0);
return result;
});
} while (0);
return true;
});
if (!Global::PCDownGet()->HttpObj()->Perform(pReqObj))
break;
if (!m_pUIDownTaskElement)
break;
m_pUIDownTaskElement->StartingSwitch(true);
m_ActionType = EnDownActionType::Running;
m_pUIDownTaskElement->StatusTextSet(CommonStringMap.at(CommonStringType::Downing));
result = true;
} while (0);
#endif
return result;
}
bool TaskNode::Stop() {
bool result = false;
std::lock_guard<std::mutex> lock{ *m_Mutex };
do {
if (m_ActionType != EnDownActionType::Stop && m_ActionType != EnDownActionType::Pause)
break;
if (!m_pUIDownTaskElement)
break;
m_pUIDownTaskElement->StartingSwitch(false);
m_pUIDownTaskElement->SetDownDownTimeRemain(0, 0);
m_pUIDownTaskElement->StatusTextSet(CommonStringMap.at(CommonStringType::DownTaskStop));
m_ActionType = EnDownActionType::Stop;
result = true;
} while (0);
m_IsOpenThread.store(false);
for (auto& t : m_Threads)
t.join();
m_Threads.clear();
return result;
}
bool TaskNode::Preparation() {
bool result = false;
std::lock_guard<std::mutex> lock{ *m_Mutex };
do {
if (m_ID <= 0)
break;
if (m_Url.empty())
break;
std::string file_name;
std::string file_format;
shared::Win::GetFileNameAndFormat(m_LogoUrl, file_name, file_format);
m_LogoPathname = shared::Win::PathFixedA(Global::PCHackerGet()->SystemDirectoryA() + "\\logos\\" + std::to_string(m_ID) + file_format);
//!@ 初始化最终下载文件名
shared::Win::GetFileNameAndFormat(m_Url, file_name, file_format);
m_FinishPathname = shared::Win::PathFixedA(Global::PCHackerGet()->SystemDirectoryA() + "\\finishs\\" + std::to_string(m_ID) + file_format);
//!@ 初始化下载缓冲文件路径名
m_DownCacheFilePathname = shared::Win::PathFixedA(Global::PCHackerGet()->SystemDirectoryA() + "\\caches\\" + std::to_string(m_ID) + file_format);
#if 0
auto reqHead = Global::HttpGet()->CreateRequest();
reqHead->RequestUrl(m_Url);
reqHead->Header(true);
reqHead->RequestType(malware::http::EnRequestType::REQUEST_TYPE_HEAD);
reqHead->FinishCb(
[&](const malware::http::IResponse* resObj) {
result = true;
});
auto reqLogo = Global::HttpGet()->CreateRequest();
reqLogo->RequestUrl(m_LogoUrl);
reqLogo->RequestType(malware::http::EnRequestType::REQUEST_TYPE_GET);
//reqLogo->HeadersAdd(R"(content-type: application/x-www-form-urlencoded)");
reqLogo->FinishCb(
[&](const malware::http::IResponse* resObj) {
auto sk = 0;
});
Global::HttpGet()->PerformM({ reqLogo,reqHead });
Global::HttpGet()->DestoryRequest({ reqLogo,reqHead });
#endif
#if 0
auto pReqObj = Global::PCDownGet()->HttpObj()->RouteCreate();
if (!pReqObj)
break;
if (!m_LogoUrl.empty() && !shared::Win::AccessA(m_LogoPathname)) {
pReqObj->Push(
[this](shared::http::RequestObj* reqObj) {
auto fixUrl = shared::Win::UrlFixedByDowntool(shared::IConv::MBytesToUTF8(m_LogoUrl));
reqObj->Url(fixUrl);
reqObj->HttpHeaderAppend({ {"content-type", "application/x-www-form-urlencoded"} });
reqObj->Type(shared::http::EnRequestType::EN_REQUEST_TYPE_GET);
reqObj->ResultCb(
[&](const shared::http::RequestObj* reqObj, const shared::http::ResponseObj* resObj) {
do {
if (resObj->HttpCode() != 200)
break;
shared::Win::File::Write(m_LogoPathname, resObj->ContentBody());
} while (0);
});
return true;
});
}
pReqObj->Push(
[&](shared::http::RequestObj* reqObj) {
auto fixUrl = shared::Win::UrlFixedByDowntool(shared::IConv::MBytesToUTF8(m_Url));
reqObj->Url(fixUrl);
reqObj->Type(shared::http::EnRequestType::EN_REQUEST_TYPE_HEAD);
reqObj->ResultCb(
[this, &result](const shared::http::RequestObj* reqObj, const shared::http::ResponseObj* resObj) {
do {
if (!resObj)
break;
if (resObj->HttpCode() != 200)
break;
m_ResourceTotalSize = resObj->ContentLength();
result = m_ResourceTotalSize > 0;
} while (0);
if (!result) {
m_Status = EnTaskStatus::Error;
m_ActionType = EnDownActionType::Pause;
}
});
return true;
});
Global::PCDownGet()->HttpObj()->Perform(pReqObj);
} while (0);
do {
if (!m_pUIDownTaskElement)
break;
//!@ 设置资源(游戏)Logo
if (shared::Win::AccessA(m_LogoPathname))
m_pUIDownTaskElement->SetLogo(shared::IConv::MBytesToWString(m_LogoPathname));
if (!result)
break;
//!@ 设置资源大小
m_pUIDownTaskElement->ResourceSizeTextSet(static_cast<size_t>(m_ResourceTotalSize), 0);
//!@ 初始化进度条数值
m_pUIDownTaskElement->SetProgressValue(0, 0);
//!@ 初始化实时下载速度
m_pUIDownTaskElement->SetDownSpeedValue(0);
//!@ 初始化VIP加速度
m_pUIDownTaskElement->SetDownSpeedValueVip(0);
//!@ 初始化[预测下载时间]
m_pUIDownTaskElement->SetDownDownTimeRemain(static_cast<size_t>(m_ResourceTotalSize), \
NormalUserLimitDownSpeedValue);
#endif
} while (0);
return result;
}
void TaskNode::SetStatusText(const std::wstring& text, const DWORD& color /*= CommonColorMap.at(CommonColorType::White)*/) {
std::lock_guard<std::mutex> lock{ *m_Mutex };
do {
if (!m_pUIDownTaskElement)
break;
m_pUIDownTaskElement->StatusTextSet(text, color);
} while (0);
}
void TaskNode::SetResourceSizeText(const size_t& total, const size_t& current, const DWORD& color /*= CommonColorMap.at(CommonColorType::White)*/) {
std::lock_guard<std::mutex> lock{ *m_Mutex };
do {
if (!m_pUIDownTaskElement)
break;
m_pUIDownTaskElement->ResourceSizeTextSet(total, current, color);
} while (0);
}
void TaskNode::OnProgressChanged() {
const time_t calc_down_speed_interval = 500;
volatile time_t prev_time_mark = shared::Win::Time::TimeStamp<std::chrono::milliseconds>();
volatile __int64 prev_down_total = 0;//!@ 前一次下载量
volatile __int64 prev_down_current = 0;
do {
do {
if (m_ProgressRouteQ.empty())
break;
auto routes = m_ProgressRouteQ.pops();
for (auto it = routes.begin(); it != routes.end(); ++it) {
const auto current_time_ms = shared::Win::Time::TimeStamp<std::chrono::milliseconds>();
do {
if (it->dlnow == prev_down_total)
break;
if (!m_pUIDownTaskElement)
break;
m_pUIDownTaskElement->SetDownloadCompletionRate(static_cast<size_t>(it->dltotal), static_cast<size_t>(it->dlnow));
m_pUIDownTaskElement->SetDownDownTimeRemain(static_cast<size_t>(it->dltotal) - static_cast<size_t>(it->dlnow));
m_pUIDownTaskElement->ResourceSizeTextSet(static_cast<size_t>(it->dltotal), static_cast<size_t>(it->dlnow));
m_pUIDownTaskElement->SetProgressValue(static_cast<size_t>(it->dltotal), static_cast<size_t>(it->dlnow));
do {//!@ 计算下载速度
if (current_time_ms - prev_time_mark < calc_down_speed_interval)
break;
if (it->dlnow < prev_down_total)
break;
if (m_VipLevel > 0) {
size_t noVip = static_cast<size_t>((it->dlnow - prev_down_current) / 3 * 1);
size_t Vip = static_cast<size_t>((it->dlnow - prev_down_current) / 3 * 2);
m_pUIDownTaskElement->SetDownSpeedValue(noVip);
m_pUIDownTaskElement->SetDownSpeedValueVip(Vip);
}
else
{
m_pUIDownTaskElement->SetDownSpeedValue(static_cast<size_t>(it->dlnow - prev_down_current));
}
prev_time_mark = current_time_ms;
prev_down_current = it->dlnow;
} while (0);
prev_down_total = it->dlnow;
} while (0);
}
} while (0);
if (!m_IsOpenThread.load())
break;
std::this_thread::sleep_for(std::chrono::milliseconds(100));
prev_time_mark += 100;
} while (1);
}
#endif
#if 0
///////////////////////////////////////////////////////////////////////////////////////////////////////////
void IDownTaskElement::SetDownDownTimeRemain(const size_t& size_remain,
const size_t& current_down_speed_value /*= NormalUserLimitDownSpeedValue*/, const DWORD& color /*= 0*/) {
do {
auto ui = GetSubCtrl<CLabelUI>(L"D1C4FD362124");
if (!ui)
break;
std::wstring time_text = L"--:--:--";
if (size_remain > 0 && current_down_speed_value > 0) {
time_t total_s = size_remain / current_down_speed_value;
time_text = shared::IConv::MBytesToWString(shared::Win::Time::TimePeriodUnMade(static_cast<UINT>(total_s)));
}
ui->SetText(time_text.c_str());
if (color)
ui->SetTextColor(color);
} while (0);
}
void IDownTaskElement::SetDownloadCompletionRate(const size_t& total, const size_t& current) {
std::wstring text = L"0.0%";
CLabelUI* ui_label = nullptr;
CProgressUI* ui_progress = nullptr;
do {
ui_progress = GetSubCtrl<CProgressUI>(L"90352B27A442");
ui_label = GetSubCtrl<CLabelUI>(L"56E157AE72A8");
if (!ui_progress || !ui_label)
break;
if (total <= 0 || current <= 0)
break;
const auto max = ui_progress->GetMaxValue();
double current_progress = (current * 1.0) / (total * 1.0);
int value = static_cast<int>(current_progress * max);
double RatioProgress = current_progress * max / 100.0;
text = std::format(L"{:.2f}%", RatioProgress);
} while (0);
if (ui_label)
ui_label->SetText(text.c_str());
}
void IDownTaskElement::StartingSwitch(const bool& status) {
do {
auto ui = GetSubCtrl<COptionUI>(L"06A057E7350B");
if (!ui)
break;
auto current_status = ui->IsSelected();
if (current_status == status)
break;
ui->Selected(status);
} while (0);
}
void IDownTaskElement::SetLogo(const std::wstring& logo_pathname) {
do {
if (!shared::Win::AccessW(logo_pathname))
break;
auto ui = GetSubCtrl<CLabelUI>(L"CCB822F77204");
if (!ui)
break;
ui->SetBkImage(logo_pathname.c_str());
} while (0);
}
void IDownTaskElement::SetDownSpeedValueVip(const size_t& real_speed/*-NormalUserLimitDownSpeedValue*/) {
do {
auto ui = GetSubCtrl<CLabelUI>(L"F5E1F8FAD133");
if (!ui)
break;
auto speed = shared::Win::RealtimeSpeed(real_speed);
ui->SetText(shared::IConv::MBytesToWString(speed).c_str());
} while (0);
}
void IDownTaskElement::SetDownSpeedValue(const size_t& value) {
do {
auto ui = GetSubCtrl<CLabelUI>(L"76E1ED97A767");
if (!ui)
break;
auto speed = shared::Win::RealtimeSpeed(value);
ui->SetText(shared::IConv::MBytesToWString(speed).c_str());
} while (0);
}
void IDownTaskElement::SetProgressValue(const size_t& total, const size_t& current) {
do {
if (total <= 0 || current <= 0)
break;
auto ui = GetSubCtrl<CProgressUI>(L"90352B27A442");
if (!ui)
break;
const auto max = ui->GetMaxValue();
double current_progress = (current * 1.0) / (total * 1.0);
int value = static_cast<int>(current_progress * max);
ui->SetValue(static_cast<int>(value));
} while (0);
}
void IDownTaskElement::SetName(const std::wstring& name, const DWORD& color) {
do {
auto ui = GetSubCtrl<CLabelUI>(L"DD0FB204BE1D");
if (!ui)
break;
ui->SetText(name.c_str());
if (color)
ui->SetTextColor(color);
} while (0);
}
void IDownTaskElement::StatusTextSet(const std::wstring& text, const DWORD& color) {
do {
auto ui = GetSubCtrl<CLabelUI>(L"E509EB1128BD");
if (!ui)
break;
ui->SetText(text.c_str());
if (color)
ui->SetTextColor(color);
} while (0);
}
void IDownTaskElement::ResourceSizeTextSet(const size_t& total, const size_t& current, const DWORD& color) {
do {
auto ui = GetSubCtrl<CLabelUI>(L"E4BD5BC33011");
if (!ui)
break;
if (total <= 0 && current <= 0) {
ui->SetText(L"--/--");
break;
}
auto realTotal = shared::Win::RealtimeSpeed(total);
auto realCurrent = shared::Win::RealtimeSpeed(current);
ui->SetText(std::format(L"{}/{}", shared::IConv::MBytesToWString(realCurrent), shared::IConv::MBytesToWString(realTotal)).c_str());
if (color)
ui->SetTextColor(color);
} while (0);
}
void IDownTaskElement::DownTotalTimeTextSet(const std::wstring& text, const DWORD& color) {
do {
auto ui = GetSubCtrl<CLabelUI>(L"D1C4FD362124");
if (!ui)
break;
ui->SetText(text.c_str());
if (color)
ui->SetTextColor(color);
} while (0);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////
#endif
}///namespace lcoal