使用soui开发的mbc,只支持windows版本
w1146869587
2022-01-24 4905e2e7537d507f218e8e9595485e09d9f3a2b4
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
#include "StdAfx.h"
#include "MBDownloadMgr.h"
 
///////////////////////////////////
CMBDownFileInfo::CMBDownFileInfo()
{
    m_bGetDocInfo  = false;     
    m_nFileSize    = 0 ; 
    m_nType        = DOWNFILE_NONE;
    m_nIsDir = 0;
}
 
CMBDownFileInfo::~CMBDownFileInfo()
}
 
CMBDownFileInfo::CMBDownFileInfo(const CMBDownFileInfo &downFileInfo)
{
    m_nType             = downFileInfo.m_nType;
    m_strID             = downFileInfo.m_strID;
    m_strName        = downFileInfo.m_strName;
    m_strFileName     = downFileInfo.m_strFileName;   
    m_strFileType    = downFileInfo.m_strFileType;        
    m_strServerFlag  = downFileInfo.m_strServerFlag;  
    m_strParentDir   = downFileInfo.m_strParentDir;       
    m_strCanDownload = downFileInfo.m_strCanDownload;
    m_strFileID      = downFileInfo.m_strFileID;    
    m_nFileSize      = downFileInfo.m_nFileSize;    
    m_nIsDir         = downFileInfo.m_nIsDir;
 
    m_strCatalogPath = downFileInfo.m_strCatalogPath;    
    m_strCabinetID   = downFileInfo.m_strCabinetID;    
    m_strCabinetName = downFileInfo.m_strCabinetName;        
    m_bGetDocInfo    = downFileInfo.m_bGetDocInfo; 
}
 
CMBDownFileInfo& CMBDownFileInfo::operator=(const CMBDownFileInfo &downFileInfo)
{
    if( this == &downFileInfo )
        return *this;
 
    m_nType             = downFileInfo.m_nType;
    m_strID             = downFileInfo.m_strID;
    m_strName        = downFileInfo.m_strName;
    m_strFileName     = downFileInfo.m_strFileName;   
    m_strFileType    = downFileInfo.m_strFileType;        
    m_strServerFlag  = downFileInfo.m_strServerFlag;  
    m_strParentDir   = downFileInfo.m_strParentDir;               
    m_strCanDownload = downFileInfo.m_strCanDownload;
    m_strFileID      = downFileInfo.m_strFileID;    
    m_nFileSize      = downFileInfo.m_nFileSize;    
    m_nIsDir         = downFileInfo.m_nIsDir;
 
    m_strCatalogPath = downFileInfo.m_strCatalogPath;    
    m_strCabinetID   = downFileInfo.m_strCabinetID;    
    m_strCabinetName = downFileInfo.m_strCabinetName;        
    m_bGetDocInfo    = downFileInfo.m_bGetDocInfo; 
    return *this;
}
 
CString CMBDownFileInfo::GetDownloadFileName()
{  
    CString strName;
    CString strFileName;
    // ÏÈ´´½¨Îļþ
    CStrFileUtils::CreateDir(m_strParentDir); 
    strFileName.Format(_T("%s\\%s"),m_strParentDir,m_strFileName);
    if( !CStrFileUtils::IsExist(strFileName) )
    { 
        return strFileName;
    }
 
    int nPos = m_strFileName.Find(_T("."));
    strName = m_strFileName.Mid(0,nPos);
 
    int nIndex = 1;
    while( true )
    {
        strFileName.Format(_T("%s\\%s(%d)%s"),m_strParentDir,strName,nIndex,m_strFileType);
        if( !CStrFileUtils::IsExist(strFileName) )
        {
            return strFileName;
        }
        nIndex++;
    }
    return strFileName;
}
 
CString CMBDownFileInfo::GetFullFileName()
{
    CString strName;
    CString strFileName;
    CStrFileUtils::CreateDir(m_strParentDir); 
    strFileName.Format(_T("%s\\%s"),m_strParentDir,m_strFileName);
    return strFileName;
}
// ÅжÏÊÇ·ñ»ñµÃ¹ýÎĵµÐÅÏ¢
bool CMBDownFileInfo::IsGetDocInfo()
{
    CSingleLock        lock( &m_cs, true );
 
    return m_bGetDocInfo;
}
 
// ÉèÖÃÒѵõ½¹ýÎĵµÐÅÏ¢
void CMBDownFileInfo::SetIsGetDocInfo()
{
    CSingleLock        lock( &m_cs, true );
 
    m_bGetDocInfo = true;
}
 
bool CMBDownFileInfo::ParseXML(CString &strXML,CString &strErrInfo)
{
    if( strXML.IsEmpty() )
    {  
        return true;
    }
    pugi::xml_document    xmlDoc;    
    if (!xmlDoc.load(strXML))   
    {   
        return false;
    }   
    //CString strSecretLvl;  // Ãܼ¶
 
    pugi::xml_node form  = xmlDoc.child(_T("Doc")); 
    pugi::xml_node node = form; 
    m_strCanDownload     = node.attribute(_T("CanDownload")).value(); 
    m_strFileID          = node.attribute(_T("FileID")).value();
    m_strServerFlag      = node.attribute(_T("FileServer")).value();
    CString strFileSize        = node.attribute(_T("FileSize")).value(); 
    m_nFileSize = _ttol(strFileSize);
    m_strFileName        = node.child_value(_T("FileName"));  
    m_strCatalogPath     = node.child_value(_T("CatalogPath")); // Ä¿Â¼Â·¾¶
    m_strCabinetID       = node.attribute(_T("CabinetID")).value();   // Îĵµ¹ñid
    m_strCabinetName     = node.attribute(_T("CabinetName")).value();; // ÎĵµÃû³Æ
    
    return true; 
}
 
///////////////////////////////////
CMBDownDirInfo::CMBDownDirInfo()
{
    m_pDownloadFileMgr = NULL;
    m_pDownloadFileMgr = new CMBDownloadFileMgr();
    m_bGetDocList = false;
    m_nType       = DOWNDIR_NONE;
}
 
CMBDownDirInfo::~CMBDownDirInfo()
{
    if( m_pDownloadFileMgr )
    {
        delete m_pDownloadFileMgr;
        m_pDownloadFileMgr = NULL;
    }
}
 
bool CMBDownDirInfo::IsGetDocList()
{
    CSingleLock        lock( &m_cs, true );
    return m_bGetDocList;
}
 
void CMBDownDirInfo::SetIsGetDocList()
{
    CSingleLock        lock( &m_cs, true );
    m_bGetDocList = true;
}
 
CMBDownloadFileMgr *CMBDownDirInfo::GetChildFileMgr()
{
    return m_pDownloadFileMgr;
}
 
void CMBDownDirInfo::CreateDir()
    CString strDir;
    strDir.Format(_T("%s\\%s"),m_strParentDir,m_strName);
    if( !CStrFileUtils::IsDirExit(strDir) )
    {
        // ´´½¨Ä¿Â¼
        CStrFileUtils::CreateDir(strDir);
        m_strCurDir = strDir;
        return ;
    }
    int nIndex = 1;
    while( true )
    {
        strDir.Format(_T("%s\\%s(%d)"),m_strParentDir,m_strName,nIndex);
        if( !CStrFileUtils::IsDirExit(strDir) )
        {  
            CStrFileUtils::CreateDir(strDir);
            m_strCurDir = strDir;
            return ;
        } 
        nIndex++;
    }
}
/////////////////////////////////// 
CMBDownloadFileMgr::CMBDownloadFileMgr(void)
{
    RemoveAllDownloadDirInfo();
    RemoveAllDownloadFileInfo();
    m_nState = State_NoTraversing;    
}
 
 
CMBDownloadFileMgr::~CMBDownloadFileMgr(void)
{
    RemoveAllDownloadDirInfo();
    RemoveAllDownloadFileInfo(); 
}
 
int  CMBDownloadFileMgr::GetFileInfoCount()
    return m_mapDownloadFileInfo.size();
}
 
int  CMBDownloadFileMgr::GetDownloadDirCount()
{
    return m_mapDownloadDirInfo.size();
}
 
int  CMBDownloadFileMgr::GetState()
{
    CSingleLock        lock( &m_cs, true );
 
    return m_nState;
}
 
void CMBDownloadFileMgr::SetState( int nState )
{
    CSingleLock        lock( &m_cs, true );
 
    m_nState = nState;
}
 
bool CMBDownloadFileMgr::AddDownloadFileInfo(CMBDownFileInfo *pDownFileInfo)
{
    if( NULL ==  pDownFileInfo || pDownFileInfo->m_strID.IsEmpty() )
        return false;
 
    CMBDownloadFileInfoMap::iterator    it;
    CString strID;
 
    strID = pDownFileInfo->m_strID;
    it = m_mapDownloadFileInfo.find(strID);
 
    // Èç¹ûÕҵõ½ ·µ»Ø
    if( it != m_mapDownloadFileInfo.end() )
        return false; 
 
    m_mapDownloadFileInfo[strID] = pDownFileInfo; 
 
    return true;       
}
 
CMBDownFileInfo*  CMBDownloadFileMgr::GetDownloadFileInfo( CString strID )
{
    if( strID.IsEmpty() )
    {
        return NULL;
    }
 
    CMBDownloadFileInfoMap::iterator    it;
    CMBDownFileInfo *pDownFileInfo = NULL;
 
    it = m_mapDownloadFileInfo.find(strID);
     
    if( it!= m_mapDownloadFileInfo.end() )
        pDownFileInfo = it->second;
 
    return pDownFileInfo;  
}
 
bool  CMBDownloadFileMgr::RemoveAllDownloadFileInfo()
{
    CMBDownloadFileInfoMap::iterator    it;
    CMBDownFileInfo *pDownFileInfo = NULL;
     
    for( it = m_mapDownloadFileInfo.begin();it != m_mapDownloadFileInfo.end();it++ )
    {
        pDownFileInfo = it->second;
        delete pDownFileInfo;
        pDownFileInfo = NULL;        
    }
    m_mapDownloadFileInfo.clear();     
    return true;  
}
 
bool CMBDownloadFileMgr::AddDownloadDirInfo(CMBDownDirInfo *pDownDirInfo)
{
    if( NULL ==  pDownDirInfo || pDownDirInfo->m_strID.IsEmpty() )
        return false;
 
    CMBDownloadDirInfoMap::iterator    it;
    CString strID;
 
    strID = pDownDirInfo->m_strID;
    it = m_mapDownloadDirInfo.find(strID);
 
    // Èç¹ûÕҵõ½ ·µ»Ø
    if( it != m_mapDownloadDirInfo.end() )
        return false; 
 
    m_mapDownloadDirInfo[strID] = pDownDirInfo; 
 
    return true;       
}
 
CMBDownDirInfo*  CMBDownloadFileMgr::GetDownloadDirInfo( CString strID )
{
    if( strID.IsEmpty() )
    {
        return NULL;
    }
 
    CMBDownloadDirInfoMap::iterator    it;
    CMBDownDirInfo *pDownDirInfo = NULL;
 
    it = m_mapDownloadDirInfo.find(strID);
     
    if( it!= m_mapDownloadDirInfo.end() )
        pDownDirInfo = it->second;
 
    return pDownDirInfo;  
}
 
bool   CMBDownloadFileMgr::RemoveAllDownloadDirInfo()
{
    CMBDownloadDirInfoMap::iterator    it;
    CMBDownDirInfo *pDownDirInfo = NULL;
     
    for( it = m_mapDownloadDirInfo.begin();it != m_mapDownloadDirInfo.end();it++ )
    {
        pDownDirInfo = it->second;
        delete pDownDirInfo;
        pDownDirInfo = NULL;        
    }
    m_mapDownloadDirInfo.clear();     
    return true;  
}
 
 
// ½âÎöxmlÊý¾Ý
bool    CMBDownloadFileMgr::ParseUnitOrDepartXml( CString &strXml,CString strFrom,CString strCabinetID,CString strPath,CString &strErrInfo )
{
    if( strXml.IsEmpty() )
    { 
        strErrInfo = _T("CMBDownloadFileMgr::ParseUnitOrDepartXml,²ÎÊýstrXmlΪ¿Õ£¡");
        return false;
    }
 
    CString               strFileSize;
    pugi::xml_document    xmlDoc;
 
    if (!xmlDoc.load(strXml))   
    {  
        return false;
    }   
    pugi::xml_node form  = xmlDoc.child(_T("Body")).child(_T("Catalog")); 
    for(pugi::xml_node node = form; node; node = node.next_sibling(_T("Catalog")))
    {  
        CMBDownDirInfo *pDownDirInfo = new CMBDownDirInfo();    
        pDownDirInfo->m_nType        = CMBDownDirInfo::DOWNDIR_UNITORDEPART; 
        pDownDirInfo->m_strID        = node.attribute(_T("ID")).value();  // Ä¿Â¼id
        pDownDirInfo->m_strName      = node.child_value(_T("Name")); 
        pDownDirInfo->m_strParentDir = strPath; // ÏÂÔØÎļþĿ¼            
        pDownDirInfo->m_strCabinetID = strCabinetID; // Îĵµ¹ñid 
        pDownDirInfo->m_strPermit    = node.attribute(_T("Permit")).value();
        pDownDirInfo->m_strFrom      = strFrom;
        if( !AddDownloadDirInfo(pDownDirInfo) )
        {
            delete pDownDirInfo;
            pDownDirInfo = NULL;
        } 
    } 
 
    form  = xmlDoc.child(_T("Body")).child(_T("Doc")); 
    for(pugi::xml_node node = form; node; node = node.next_sibling(_T("Doc")))
    { 
        CMBDownFileInfo *pDownFileInfo = new CMBDownFileInfo();
        pDownFileInfo->m_nType         = CMBDownFileInfo::DOWNFILE_UNITORDEPART;         
        pDownFileInfo->m_strID         = node.attribute(_T("ID")).value();
        pDownFileInfo->m_strName       = node.child_value(_T("Name")); 
        pDownFileInfo->m_strFileID     = node.attribute(_T("FileID")).value();
        pDownFileInfo->m_strFileName   = node.attribute(_T("FileName")).value();
        pDownFileInfo->m_strServerFlag = node.attribute(_T("FileServer")).value();;
        pDownFileInfo->m_strParentDir  = strPath;  
        pDownFileInfo->m_strCanDownload =  node.attribute(_T("CanDownload")).value();
        pDownFileInfo->m_strFileType    = node.attribute(_T("FileType")).value();;
        pDownFileInfo->m_strFrom      = strFrom;
        if( !AddDownloadFileInfo(pDownFileInfo) )
        {
            delete pDownFileInfo;
            pDownFileInfo = NULL;
        } 
    } 
 
    return true;
}
 
bool   CMBDownloadFileMgr::ParsePsnXml( CString &strXml,CString strFrom,CString strCabinetID,CString strPath,CString &strErrInfo )
{
    if( strXml.IsEmpty() )
    { 
        strErrInfo = _T("CMBDownloadFileMgr::ParsePsnXml,²ÎÊýstrXmlΪ¿Õ£¡");
        return false;
    }
 
    CString               strFileSize;
    pugi::xml_document    xmlDoc;
 
    if (!xmlDoc.load(strXml))   
    {  
        return false;
    }   
    pugi::xml_node form  = xmlDoc.child(_T("Body")).child(_T("Catalog")); 
    for(pugi::xml_node node = form; node; node = node.next_sibling(_T("Catalog")))
    { 
        CMBDownDirInfo *pDownDirInfo = new CMBDownDirInfo();
        pDownDirInfo->m_nType        = CMBDownDirInfo::DOWNDIR_PSN;
        pDownDirInfo->m_strID        = node.attribute(_T("ID")).value();  // Ä¿Â¼id
        pDownDirInfo->m_strName      = node.child_value(_T("Name")); 
        pDownDirInfo->m_strParentDir = strPath; // ÏÂÔØÎļþĿ¼            
        pDownDirInfo->m_strCabinetID = strCabinetID; // Îĵµ¹ñid 
        pDownDirInfo->m_strPermit    = node.attribute(_T("Permit")).value();
        pDownDirInfo->m_strFrom      = strFrom;
        if( !AddDownloadDirInfo(pDownDirInfo) )
        {
            delete pDownDirInfo;
            pDownDirInfo = NULL;
        } 
    }  
    form  = xmlDoc.child(_T("Body")).child(_T("Doc")); 
    for(pugi::xml_node node = form; node; node = node.next_sibling(_T("Doc")))
    {
        CMBDownFileInfo *pDownFileInfo = new CMBDownFileInfo();
        pDownFileInfo->m_nType         = CMBDownFileInfo::DOWNFILE_PSN;     
        pDownFileInfo->m_strID         = node.attribute(_T("ID")).value();
        pDownFileInfo->m_strName       = node.child_value(_T("Name")); 
        pDownFileInfo->m_strFileID     = node.attribute(_T("FileID")).value();
        pDownFileInfo->m_strFileName   = node.attribute(_T("FileName")).value();
        pDownFileInfo->m_strServerFlag = node.attribute(_T("FileServer")).value();;
        pDownFileInfo->m_strParentDir  = strPath;  
        pDownFileInfo->m_strCanDownload =  node.attribute(_T("CanDownload")).value();
        pDownFileInfo->m_strFileType    = node.attribute(_T("FileType")).value();;
        pDownFileInfo->m_strFrom      = strFrom;
        if( !AddDownloadFileInfo(pDownFileInfo) )
        {
            delete pDownFileInfo;
            pDownFileInfo = NULL;
        } 
    }  
 
    return true;
}
 
bool  CMBDownloadFileMgr::ParseVaultXml( CString &strXml,CString strFrom,CString strPath,CString &strErrInfo )
{
    if( strXml.IsEmpty() )
    { 
        strErrInfo = _T("CMBDownloadFileMgr::ParseUnitOrDepartXml,²ÎÊýstrXmlΪ¿Õ£¡");
        return false;
    }
 
    CString               strFileSize;
    pugi::xml_document    xmlDoc;
 
    if (!xmlDoc.load(strXml))   
    {  
        return false;
    }   
    pugi::xml_node form  = xmlDoc.child(_T("ObjList")).child(_T("Obj"));  
  //<Obj ID='%s' FileServer='%s' FileID='%s' FileType='%s' FileSize='%s' FileMD5='%s'><FileName><![CDATA[%s]]></FileName></Obj>
    for(pugi::xml_node node = form; node; node = node.next_sibling(_T("Obj")))
    { 
        CMBDownFileInfo *pDownFileInfo = new CMBDownFileInfo();
        pDownFileInfo->m_nType         = CMBDownFileInfo::DOWNFILE_NONE;         
        pDownFileInfo->m_strID         = node.attribute(_T("ID")).value();
        pDownFileInfo->m_strName       = node.child_value(_T("FileName")); 
        pDownFileInfo->m_strFileID     = node.attribute(_T("FileID")).value();
        pDownFileInfo->m_strFileName   = node.child_value(_T("FileName")); 
        pDownFileInfo->m_strServerFlag = node.attribute(_T("FileServer")).value();;
        pDownFileInfo->m_strParentDir  = strPath;  
        pDownFileInfo->m_strFileType    = node.attribute(_T("FileType")).value();;
        pDownFileInfo->m_strFrom       = strFrom;
        if( !AddDownloadFileInfo(pDownFileInfo) )
        {
            delete pDownFileInfo;
            pDownFileInfo = NULL;
        } 
    } 
 
    return true;
}
 
 
bool  CMBDownloadFileMgr::ParseFireXml( CString &strXml,CString strFrom,CString strPath,CString &strErrInfo )
{
    if( strXml.IsEmpty() )
    { 
        strErrInfo = _T("CMBDownloadFileMgr::ParseUnitOrDepartXml,²ÎÊýstrXmlΪ¿Õ£¡");
        return false;
    }
 
    CString               strFileSize,strDirName;
    pugi::xml_document    xmlDoc;
 
    if (!xmlDoc.load(strXml))   
    {  
        return false;
    }   
    pugi::xml_node form  = xmlDoc.child(_T("ObjList")).child(_T("Obj"));  
  //<Obj ID='%s' FileServer='%s' FileID='%s' FileType='%s' FileSize='%s' FileMD5='%s'><FileName><![CDATA[%s]]></FileName></Obj>
    for(pugi::xml_node node = form; node; node = node.next_sibling(_T("Obj")))
    { 
        CMBDownFileInfo *pDownFileInfo = new CMBDownFileInfo();
        pDownFileInfo->m_nType         = CMBDownFileInfo::DOWNFILE_NONE;         
        pDownFileInfo->m_strID         = node.attribute(_T("ID")).value();
        pDownFileInfo->m_strName       = node.child_value(_T("FileName")); 
        pDownFileInfo->m_strFileID     = node.attribute(_T("FileID")).value();
        pDownFileInfo->m_strFileName   = node.child_value(_T("FileName")); 
        pDownFileInfo->m_strServerFlag = node.attribute(_T("FileServer")).value(); 
 
        strDirName = CStrFileUtils::GetDirName( pDownFileInfo->m_strFileID ); 
 
        pDownFileInfo->m_strParentDir  = strPath + _T("\\") + strDirName;  
        pDownFileInfo->m_strFileType   = node.attribute(_T("FileType")).value();
        pDownFileInfo->m_strFrom       = strFrom;
        if( !AddDownloadFileInfo(pDownFileInfo) )
        {
            delete pDownFileInfo;
            pDownFileInfo = NULL;
        } 
    } 
 
    return true;
}
 
///////////////////////////////////////
CMBDownloadRootMgr::CMBDownloadRootMgr()
{
    RemoveAllDownloadFileMgr();    
}
 
CMBDownloadRootMgr::~CMBDownloadRootMgr()
{
    RemoveAllDownloadFileMgr();    
}
 
bool   CMBDownloadRootMgr::AddDownloadFileMgr(CMBDownloadFileMgr *pDownloadFileMgr)
{
    if( NULL ==  pDownloadFileMgr )
        return false;
    if( pDownloadFileMgr->GetFileInfoCount() > 0  || pDownloadFileMgr->GetDownloadDirCount() > 0 )
    {
        m_listDownloadFileMgr.push_back(pDownloadFileMgr); 
    }else
    {
        return false;
    }
    return true;
}
 
bool   CMBDownloadRootMgr::RemoveAllDownloadFileMgr()
{
    CMBDownloadFileMgrList::iterator    it;
    CMBDownloadFileMgr *pDownloadFileMgr = NULL;
     
    for( it = m_listDownloadFileMgr.begin();it != m_listDownloadFileMgr.end();it++ )
    {
        pDownloadFileMgr = *it;
        delete pDownloadFileMgr;
        pDownloadFileMgr = NULL;        
    }
    m_listDownloadFileMgr.clear(); 
     
    return true;
}
 
///////////////////////////////////////
CMBDownloadMgr::CMBDownloadMgr()
{
    RemoveAllDownloadRootMgr();    
}
 
CMBDownloadMgr::~CMBDownloadMgr()
{
    RemoveAllDownloadRootMgr();    
}
 
bool   CMBDownloadMgr::AddDownloadRootMgr(CMBDownloadRootMgr *pDownloadRootMgr,bool bEvent)
{
    CSingleLock        lock( &m_cs, true );
 
    if( NULL ==  pDownloadRootMgr || pDownloadRootMgr->m_strRootPath.IsEmpty() )
        return false;
 
     
    //CString strRootPath;
 
    m_vectorDownloadRootMgr.push_back(pDownloadRootMgr);
    if( bEvent )
        m_eventExe.Set();
 
    //m_vectorDownloadRootMgr[strRootPath] = pDownloadRootMgr; 
 
    return true;   
}
 
 
//CMBDownloadRootMgr*  CMBDownloadMgr::GetDownloadRootMgr( CString strRootPath )
//{
//    if( strRootPath.IsEmpty() )
//    {
//        return NULL;
//    }
//
//    CMBDownloadRootMgrVector::iterator    it;
//    CMBDownloadRootMgr *pDownloadRootMgr = NULL;
//
//    it = m_mapDownloadRootMgr.find(strRootPath);
//     
//    if( it!= m_mapDownloadRootMgr.end() )
//        pDownloadRootMgr = it->second;
//
//    return pDownloadRootMgr;  
//}
 
bool     CMBDownloadMgr::RemoveAllDownloadRootMgr()
{
    CSingleLock        lock( &m_cs, true );
 
    CMBDownloadRootMgrVector::iterator    it;
    CMBDownloadRootMgr *pDownloadRootMgr = NULL;
     
    for( it = m_vectorDownloadRootMgr.begin();it != m_vectorDownloadRootMgr.end();it++ )
    {
        pDownloadRootMgr = *it;
        delete pDownloadRootMgr;
        pDownloadRootMgr = NULL;        
    }
    m_vectorDownloadRootMgr.clear();     
    return true;  
}
 
 
bool   CMBDownloadMgr::AttachThreadDownloadRoogMgr(CMBDownloadRootMgrVector &vectorDownloadRootMgr)
{
    CSingleLock        lock( &m_cs, true );
 
    vectorDownloadRootMgr.clear();
    vectorDownloadRootMgr = m_vectorDownloadRootMgr;
 
    return true;
}
 
 
bool  CMBDownloadMgr::RemoveDownloadRootMgr( CMBDownloadRootMgr *pDownloadRootMgr )
{
    CSingleLock        lock( &m_cs, true );
    
    if( NULL == pDownloadRootMgr )
        return false;
 
    CMBDownloadRootMgrVector::iterator    it = std::find(m_vectorDownloadRootMgr.begin( ), m_vectorDownloadRootMgr.end( ), pDownloadRootMgr); //²éÕÒ
    if( it != m_vectorDownloadRootMgr.end( ) ){
         
        m_vectorDownloadRootMgr.erase(it);
        if( NULL != pDownloadRootMgr )
        {
            delete pDownloadRootMgr;
            pDownloadRootMgr = NULL;
        }
    }  
 
    return true;
}
 
 
void CMBDownloadMgr::SetEventExe()
{
    CSingleLock        lock( &m_cs, true );
 
    m_eventExe.Set();
}
 
void CMBDownloadMgr::SetEventShutdown()
{
    CSingleLock        lock( &m_cs, true );
    m_eventShutdown.Set();
}
 
void CMBDownloadMgr::ResetEventExe()
{
    CSingleLock        lock( &m_cs, true );
    m_eventExe.Reset();
}
 
void CMBDownloadMgr::ResetEventShutdown()
{
    CSingleLock        lock( &m_cs, true );
    m_eventShutdown.Reset();
}
 
HANDLE CMBDownloadMgr::GetEventShutdownHandle()
{
    CSingleLock        lock( &m_cs, true );
    return m_eventShutdown.GetEvent();
}
 
HANDLE CMBDownloadMgr::GetEventExeHandle()
    CSingleLock        lock( &m_cs, true );
    return m_eventExe.GetEvent();
}