drives.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. #include "main.h"
  2. #include <Windows.h>
  3. #include "resource.h"
  4. #include "drives.h"
  5. #include <strsafe.h>
  6. //
  7. // UNIT TYPES AND MEDIA TYPES
  8. //
  9. #define PRIMOSDK_CDROM 0x00000201
  10. #define PRIMOSDK_CDR 0x00000202
  11. #define PRIMOSDK_CDRW 0x00000203
  12. #define PRIMOSDK_DVDR 0x00000204
  13. #define PRIMOSDK_DVDROM 0x00000205
  14. #define PRIMOSDK_DVDRAM 0x00000206
  15. #define PRIMOSDK_DVDRW 0x00000207
  16. #define PRIMOSDK_ROBOTICS 0x00000208
  17. #define PRIMOSDK_DVDPRW 0x00000209
  18. #define PRIMOSDK_DVDPR 0x00000210
  19. #define PRIMOSDK_DDCDROM 0x00000211
  20. #define PRIMOSDK_DDCDR 0x00000212
  21. #define PRIMOSDK_DDCDRW 0x00000213
  22. #define PRIMOSDK_DVDPR9 0x00000214
  23. #define PRIMOSDK_DVDR9 0x00000215
  24. //
  25. #define PRIMOSDK_OTHER 0x00000220
  26. // bus type
  27. #define PRIMOSDK_UNKNOWN 0
  28. #define PRIMOSDK_ATAPI 1
  29. #define PRIMOSDK_SCSI 2
  30. #define PRIMOSDK_1394 3
  31. #define PRIMOSDK_USB 4
  32. #define PRIMOSDK_USB2 5
  33. const wchar_t *typeText[] = {L"UNKNOWN", L"CD-ROM", L"CD-R", L"CD-RW", L"DVD-ROM", L"DVD-R", L"DVD-RW", L"DVD+R", L"DVD+RW", L"DVD-RAM", L"DDCD", L"DDCD-R", L"DDCD-RW", L"DL DVD+R", L"DL DVD-R"};
  34. const wchar_t *busText[] = {L"UNKNOWN", L"ATAPI", L"SCSI", L"1394", L"USB", L"USB2"};
  35. Drives::Drives(void)
  36. {
  37. }
  38. Drives::~Drives(void)
  39. {
  40. Clear();
  41. }
  42. void Drives::AddDrive(wchar_t letter, unsigned int typeCode, wchar_t* description, const wchar_t *extInfo)
  43. {
  44. OPTICAL_DRIVE drive;
  45. drive.letter = (wchar_t)CharUpperW((wchar_t*)letter);
  46. drive.typeCode = typeCode;
  47. drive.modelInfo = (NULL == description) ? NULL : _wcsdup(description);
  48. drive.busType = 0;
  49. drive.disc = NULL;
  50. if (extInfo)
  51. { // extInfo format: bysType;typeCode1;typeCode2;...;typeCoden
  52. const wchar_t *desc = extInfo;
  53. drive.nTypeList = 0;
  54. while(desc[0] != 0x00) {desc = CharNextW(desc); if (desc[0] == ';') drive.nTypeList ++;}
  55. if (drive.nTypeList) drive.nTypeList;
  56. drive.pTypeList = (int*) malloc(sizeof(int) * drive.nTypeList);
  57. int *list = drive.pTypeList;
  58. const wchar_t *start = extInfo;
  59. const wchar_t *end = extInfo;
  60. BOOL cont;
  61. do
  62. {
  63. while(end[0] != ';' && end[0] != 0x00) end = CharNextW(end);
  64. cont = (end[0] == ';') ;
  65. if (start == extInfo)
  66. drive.busType = _wtoi(start);
  67. else
  68. {
  69. *list = _wtoi(start);
  70. list++;
  71. }
  72. if(cont)
  73. {
  74. end = CharNextW(end);
  75. start = end;
  76. }
  77. }
  78. while(cont);
  79. }
  80. else
  81. {
  82. drive.nTypeList = 1;
  83. drive.pTypeList = (int*) malloc(sizeof(int) * drive.nTypeList);
  84. drive.pTypeList[0] = typeCode;
  85. }
  86. Map<wchar_t, OPTICAL_DRIVE>::MapPair insert_pair(drive.letter, drive);
  87. driveList.insert(insert_pair);
  88. }
  89. void Drives::Clear(void)
  90. {
  91. for (c_iter = driveList.begin(); c_iter != driveList.end(); c_iter++)
  92. {
  93. if (c_iter->second.modelInfo) free(c_iter->second.modelInfo);
  94. if (c_iter->second.pTypeList) free(c_iter->second.pTypeList);
  95. if (c_iter->second.disc) delete(c_iter->second.disc);
  96. }
  97. driveList.clear();
  98. }
  99. unsigned int Drives::GetCount(void)
  100. {
  101. return (unsigned int)driveList.size();
  102. }
  103. const OPTICAL_DRIVE* Drives::GetFirst(void)
  104. {
  105. c_iter = driveList.begin();
  106. return (c_iter == driveList.end()) ? NULL : &c_iter->second;
  107. }
  108. const OPTICAL_DRIVE* Drives::GetNext(void)
  109. {
  110. return (++c_iter == driveList.end()) ? NULL : &c_iter->second;
  111. }
  112. BOOL Drives::IsRecorder(const OPTICAL_DRIVE *drive)
  113. {
  114. BOOL recorder = FALSE;
  115. switch (drive->typeCode)
  116. {
  117. case PRIMOSDK_CDR:
  118. case PRIMOSDK_CDRW:
  119. case PRIMOSDK_DVDR:
  120. case PRIMOSDK_DVDRW:
  121. case PRIMOSDK_DVDPR:
  122. case PRIMOSDK_DVDPRW:
  123. case PRIMOSDK_DVDRAM:
  124. case PRIMOSDK_DDCDR:
  125. case PRIMOSDK_DDCDRW:
  126. case PRIMOSDK_DVDPR9:
  127. case PRIMOSDK_DVDR9:
  128. recorder = TRUE;
  129. break;
  130. }
  131. return recorder;
  132. }
  133. const wchar_t* Drives::GetTypeString(int typeCode)
  134. {
  135. int index = 0;
  136. switch (typeCode)
  137. {
  138. case PRIMOSDK_CDROM:
  139. index = 1;
  140. break;
  141. case PRIMOSDK_CDR:
  142. index = 2;
  143. break;
  144. case PRIMOSDK_CDRW:
  145. index = 3;
  146. break;
  147. case PRIMOSDK_DVDROM:
  148. index = 4;
  149. break;
  150. case PRIMOSDK_DVDR:
  151. index = 5;
  152. break;
  153. case PRIMOSDK_DVDRW:
  154. index = 6;
  155. break;
  156. case PRIMOSDK_DVDPR:
  157. index = 7;
  158. break;
  159. case PRIMOSDK_DVDPRW:
  160. index = 8;
  161. break;
  162. case PRIMOSDK_DVDRAM:
  163. index = 9;
  164. break;
  165. case PRIMOSDK_DDCDROM:
  166. index = 10;
  167. break;
  168. case PRIMOSDK_DDCDR:
  169. index = 11;
  170. break;
  171. case PRIMOSDK_DDCDRW:
  172. index = 12;
  173. break;
  174. case PRIMOSDK_DVDPR9:
  175. index = 13;
  176. break;
  177. case PRIMOSDK_DVDR9:
  178. index = 14;
  179. break;
  180. default:
  181. static wchar_t tmp2[64];
  182. return WASABI_API_LNGSTRINGW_BUF(plugin.hDllInstance,IDS_UNKNOWN,tmp2,64);
  183. }
  184. return typeText[index];
  185. }
  186. const wchar_t* Drives::GetBusString(int busCode)
  187. {
  188. int index = 0;
  189. switch (busCode)
  190. {
  191. case PRIMOSDK_ATAPI:
  192. index = 1;
  193. break;
  194. case PRIMOSDK_SCSI:
  195. index = 2;
  196. break;
  197. case PRIMOSDK_1394:
  198. index = 3;
  199. break;
  200. case PRIMOSDK_USB:
  201. index = 4;
  202. break;
  203. case PRIMOSDK_USB2:
  204. index = 5;
  205. break;
  206. default:
  207. static wchar_t tmp3[64];
  208. return WASABI_API_LNGSTRINGW_BUF(plugin.hDllInstance,IDS_UNKNOWN,tmp3,64);
  209. }
  210. return busText[index];
  211. }
  212. const wchar_t* Drives::GetFormatedString(const OPTICAL_DRIVE *drv, wchar_t *buffer, size_t size, BOOL useFullName)
  213. {
  214. StringCchPrintfW(buffer, size, WASABI_API_LNGSTRINGW(plugin.hDllInstance,IDS_X_DRIVE_BRACKET_X),
  215. GetTypeString(drv->typeCode), drv->letter);
  216. if (useFullName && drv->modelInfo)
  217. {
  218. StringCchPrintfW(buffer, size, L"%s - %s", buffer, drv->modelInfo);
  219. }
  220. return buffer;
  221. }