| 1 |
/*! |
| 2 |
\file |
| 3 |
\brief URG の USB 接続ポートかを判断する |
| 4 |
|
| 5 |
\author Satofumi KAMIMURA |
| 6 |
|
| 7 |
$Id$ |
| 8 |
*/ |
| 9 |
|
| 10 |
#include "IsUsbUrgCom.h" |
| 11 |
#include "DetectOS.h" |
| 12 |
#ifdef WINDOWS_OS |
| 13 |
#include <windows.h> |
| 14 |
#include <string> |
| 15 |
#endif |
| 16 |
|
| 17 |
#ifdef WINDOWS_OS |
| 18 |
static bool existRegValue(HKEY hkey, LPCSTR subkey, const char* find_value) { |
| 19 |
|
| 20 |
HKEY next_hkey; |
| 21 |
if (RegOpenKeyExA(hkey, subkey, 0, KEY_READ, &next_hkey) != ERROR_SUCCESS) { |
| 22 |
return false; |
| 23 |
} |
| 24 |
enum { MaxLength = 255 }; |
| 25 |
|
| 26 |
// find_value が存在するかを探索 |
| 27 |
CHAR device[MaxLength]; |
| 28 |
char name[MaxLength]; |
| 29 |
|
| 30 |
DWORD ret = ERROR_SUCCESS; |
| 31 |
for (int i = 0; ret == ERROR_SUCCESS; ++i) { |
| 32 |
DWORD dl = MaxLength, nl = MaxLength; |
| 33 |
ret = RegEnumValueA(hkey, i, device, &dl, NULL, NULL, (BYTE*)name, &nl); |
| 34 |
if (! strcmp(name, find_value)) { |
| 35 |
RegCloseKey(next_hkey); |
| 36 |
return true; |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
// find_value が存在しなければ、再帰探索を行う |
| 41 |
char next_subkey[MaxLength]; |
| 42 |
FILETIME filetime; |
| 43 |
|
| 44 |
ret = ERROR_SUCCESS; |
| 45 |
for (int i = 0; ret == ERROR_SUCCESS; ++i) { |
| 46 |
DWORD dl = MaxLength, nl = MaxLength; |
| 47 |
ret = RegEnumKeyExA(next_hkey, i, next_subkey, |
| 48 |
&dl, NULL, NULL, &nl, &filetime); |
| 49 |
|
| 50 |
bool value_exist = existRegValue(next_hkey, next_subkey, find_value); |
| 51 |
if (value_exist) { |
| 52 |
RegCloseKey(next_hkey); |
| 53 |
return true; |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
RegCloseKey(next_hkey); |
| 58 |
return false; |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
bool beego::isUsbUrgCom(const char* com_port) { |
| 63 |
|
| 64 |
// "URG Series USB Device Driver (COMx)" が Value に含まれているか検索 |
| 65 |
std::string value_pattern = |
| 66 |
std::string("URG Series USB Device Driver (") + com_port + ")"; |
| 67 |
|
| 68 |
bool ret = existRegValue(HKEY_LOCAL_MACHINE, |
| 69 |
"SYSTEM\\CurrentControlSet\\Enum\\USB", |
| 70 |
value_pattern.c_str()); |
| 71 |
if (ret) { |
| 72 |
// 見つかったら戻る |
| 73 |
return ret; |
| 74 |
} |
| 75 |
|
| 76 |
// "URG-X002 USB Device Driver (COMx)" が Value に含まれているか検索 |
| 77 |
value_pattern = std::string("URG-X002 USB Device Driver (") + com_port + ")"; |
| 78 |
|
| 79 |
return existRegValue(HKEY_LOCAL_MACHINE, |
| 80 |
"SYSTEM\\CurrentControlSet\\Enum\\USB", |
| 81 |
value_pattern.c_str()); |
| 82 |
} |
| 83 |
#else |
| 84 |
|
| 85 |
bool beego::isUsbUrgCom(const char* com_port) { |
| 86 |
return false; |
| 87 |
} |
| 88 |
#endif |