-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMSChecker.cpp
More file actions
80 lines (72 loc) · 1.79 KB
/
MSChecker.cpp
File metadata and controls
80 lines (72 loc) · 1.79 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
#include "StdAfx.h"
#include "MSChecker.h"
#include "EnumDisks.h"
using namespace DeviceDetectLibrary;
using namespace DeviceDetectLibrary::Connection;
CMSChecker::CMSChecker(ICollector& collector, const std::wstring& devicePath)
: collector_(collector)
, devicePath_(devicePath)
, thread_(ThreadFunction)
{
}
CMSChecker::~CMSChecker(void)
{
Stop();
}
void CMSChecker::Start(void)
{
stopEvent_.Reset();
thread_.Start(this);
}
void CMSChecker::Stop(void)
{
stopEvent_.Set();
thread_.Wait(INFINITE);
}
void CMSChecker::ThreadFunction(void* state)
{
CMSChecker* This = static_cast<CMSChecker *>(state);
if(This != NULL)
{
This->WorkThread();
}
}
void CMSChecker::WorkThread(void)
{
int tries = 60;
const int sleepTimeout = 1000;
Disk::Types::RemovableDeviceInfo_vt disks;
while((tries--) > 0)
{
try
{
Disk::Functions::SearchRemovalDisks(disks);
break;
}
catch(const std::exception& ex)
{
ex.what();
// EXCEPTION: Cannot found drives for (%S)", devicePath_.c_str());
if(stopEvent_.Wait(sleepTimeout))
{
return;
}
}
}
for(Disk::Types::RemovableDeviceInfo_vt_cit iter = disks.begin(); iter != disks.end(); ++iter)
{
if(devicePath_ == iter->wsPath)
{
CConnectionInfo::Pointer pConnectionInfo = CConnectionInfo::Create();
pConnectionInfo->Type = TypeUnknown;
pConnectionInfo->FriendlyName = iter->wsFriendlyName;
pConnectionInfo->DevicePath = iter->wsDevInterfaceVolume;
pConnectionInfo->HardwareID = iter->wsPath;
pConnectionInfo->PhysicalDeviceName = L"";
pConnectionInfo->DeviceDescription = iter->wsPath;
pConnectionInfo->ServiceName = iter->wsCompatibleIDs;
CDeviceInfo::Pointer pDeviceInfo = CDeviceInfo::Create(iter->wsPath, iter->wsFriendlyName, L"Mass Storage device", pConnectionInfo);
collector_.Found(pDeviceInfo);
}
}
}