1
0

discInfo.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. #include "main.h"
  2. #include "discinfo.h"
  3. #include "resource.h"
  4. #include <strsafe.h>
  5. // indices
  6. #define DD_PARSED 0x0000
  7. #define DD_INDEX_MEDIUM_TYPE 0x0001
  8. #define DD_INDEX_MEDIUM_FORMAT 0x0002
  9. #define DD_INDEX_MEDIUM 0x0003
  10. #define DD_INDEX_PROTECTED_DVD 0x0004
  11. #define DD_INDEX_ERASABLE 0x0005
  12. #define DD_INDEX_TRACKS_NUM 0x0006
  13. #define DD_INDEX_SECTOR_USED 0x0007
  14. #define DD_INDEX_SECTOR_FREE 0x0008
  15. #define TEXT_UNKNOWN L"Unknown"
  16. #define TEXT_TRUE L"Yes"
  17. #define TEXT_FALSE L"No"
  18. // MediumType Values
  19. #define PRIMOSDK_SILVER 0x00000301 /* A disc that is not recordable. It may be a stamped (silver) disc or a gold (recordable) disc that has been recorded Disc-At-Once. */
  20. #define PRIMOSDK_COMPLIANTGOLD 0x00000302 /* A gold disc or rewritable disc that contains data but remains open, allowing the appending of additional data. */
  21. #define PRIMOSDK_OTHERGOLD 0x00000303 /* A gold disc to which it is not possible for PrimoSDK to append additional data. */
  22. #define PRIMOSDK_BLANK 0x00000304 /* A blank gold disc or blank rewritable disc. */
  23. // MediumFormat Values
  24. #define PRIMOSDK_B1 0x000000B1 /* Blank disc */
  25. #define PRIMOSDK_D1 0x000000D1 /* Data Mode 1 DAO (e.g. most data CD-ROMs or typical DOS games) */
  26. #define PRIMOSDK_D2 0x000000D2 /* Kodak Photo CD: Data multisession Mode 2 TAO */
  27. #define PRIMOSDK_D3 0x000000D3 /* Gold Data Mode 1: Data multisession Mode 1, closed */
  28. #define PRIMOSDK_D4 0x000000D4 /* Gold Data Mode 2: Data multisession Mode 2, closed */
  29. #define PRIMOSDK_D5 0x000000D5 /* Data Mode 2 DAO (silver mastered from Corel or Toast gold) */
  30. #define PRIMOSDK_D6 0x000000D6 /* CDRFS: Fixed packet (from Sony packet-writing solution) */
  31. #define PRIMOSDK_D7 0x000000D7 /* Packet writing */
  32. #define PRIMOSDK_D8 0x000000D8 /* Gold Data Mode 1: Data multisession Mode 1, open */
  33. #define PRIMOSDK_D9 0x000000D9 /* Gold Data Mode 2: Data multisession Mode 2, open */
  34. #define PRIMOSDK_A1 0x000000A1 /* Audio DAO/SAO/TAO (like most silver music discs) or closed gold audio */
  35. #define PRIMOSDK_A2 0x000000A2 /* Audio Gold disc with session not closed (TAO or SAO) */
  36. #define PRIMOSDK_A3 0x000000A3 /* First type of Enhanced CD (aborted) */
  37. #define PRIMOSDK_A4 0x000000A4 /* CD Extra, Blue Book standard */
  38. #define PRIMOSDK_A5 0x000000A5 /* Audio TAO with session not written (in-progress compilation) */
  39. #define PRIMOSDK_M1 0x000000E1 /* First track data, others audio */
  40. #define PRIMOSDK_M2 0x000000E2 /* Mixed-mode made TAO */
  41. #define PRIMOSDK_M3 0x000000E3 /* Kodak Portfolio (as per the Kodak standard) */
  42. #define PRIMOSDK_M4 0x000000E4 /* Video CD (as the White Book standard) */
  43. #define PRIMOSDK_M5 0x000000E5 /* CD-i (as the Green Book standard) */
  44. #define PRIMOSDK_M6 0x000000E6 /* PlayStation (Sony games) */
  45. #define PRIMOSDK_F1 0x000000F1 /* Obsolete */
  46. #define PRIMOSDK_F2 0x000000F2 /* Obsolete for restricted overwrite DVD (DLA DVD-RW) */
  47. #define PRIMOSDK_F3 0x000000F3 /* Completed (non-appendable) DVD (DVD-ROM or closed recordable) */
  48. #define PRIMOSDK_F4 0x000000F4 /* Incremental DVD with appendable zone (DLA DVD-R and DVD+RW) */
  49. #define PRIMOSDK_F8 0x000000F8 /* Appendable DVD of any type (single border or multiborder) */
  50. #define PRIMOSDK_FA 0x000000FA /* DVD-RAM cartridge */
  51. #define PRIMOSDK_GENERICCD 0x000000C1 /* Other type of CD. */
  52. // Medium and Unit Values
  53. #define PRIMOSDK_CDROM 0x00000201 /* CD-ROM */
  54. #define PRIMOSDK_CDR 0x00000202 /* CD-R */
  55. #define PRIMOSDK_CDRW 0x00000203 /* CD-RW */
  56. #define PRIMOSDK_DVDR 0x00000204 /* DVD-R */
  57. #define PRIMOSDK_DVDROM 0x00000205 /* DVD-ROM (any type) */
  58. #define PRIMOSDK_DVDRAM 0x00000206 /* DVD-RAM */
  59. #define PRIMOSDK_DVDRW 0x00000207 /* DVD-RW */
  60. #define PRIMOSDK_DVDPRW 0x00000209 /* DVD+RW */
  61. #define PRIMOSDK_DVDPR 0x00000210 /* DVD+R */
  62. #define PRIMOSDK_DDCDROM 0x00000211 /* Double-density CD-ROM */
  63. #define PRIMOSDK_DDCDR 0x00000212 /* Double-density CD-R */
  64. #define PRIMOSDK_DDCDRW 0x00000213 /* Double-density CD-RW */
  65. #define PRIMOSDK_DVDPR9 0x00000214 /* dual-layer DVD+R */
  66. #define PRIMOSDK_OTHER 0x00000220 /* other types */
  67. int mediumTypeText[] = {IDS_STAMPED_DISC_OR_RECORDABLE_THAT_HAS_BEEN_RECORDED,
  68. IDS_REWRITEABLE_DISC_HAS_DATA_BUT_KEPT_OPEN_FOR_APPEND,
  69. IDS_REWRITEABLE_DISC_NOT_POSSIBLE_TO_APPEND_DATA,
  70. IDS_BLANK_REWRITEABLE_DISC,
  71. };
  72. const wchar_t *mediumText[] = {L"CD-ROM", L"CD-R", L"CD-RW", L"DVD-ROM",
  73. L"DVD-R",L"DVD-RW", L"DVD+R", L"DVD+RW", L"DVD-RAM",
  74. L"DDCD-ROM", L"DDCD-R", L"DDCD-RW", L"DL DVD+R"};
  75. int mediumFormatText[] = { IDS_MEDIA_BLANK_DISC,
  76. IDS_MEDIA_DATA_MODE_1_DAO,
  77. IDS_MEDIA_KODAK_PHOTO_CD,
  78. IDS_MEDIA_DATA_MULTISESSION_MODE_1_CLOSED,
  79. IDS_MEDIA_DATA_MULTISESSION_MODE_2_CLOSED,
  80. IDS_MEDIA_DATA_MODE_2_DAO,
  81. IDS_MEDIA_CDRFS,
  82. IDS_MEDIA_PACKET_WRITING,
  83. IDS_MEDIA_DATA_MULTISESSION_MODE_1_OPEN,
  84. IDS_MEDIA_DATA_MULTISESSION_MODE_2_OPEN,
  85. IDS_MEDIA_AUDIO_DAO_SAO_TAO,
  86. IDS_MEDIA_AUDIO_REWRITEABLE_DISC_WITH_SESSION_NOT_CLOSED,
  87. IDS_MEDIA_FIRST_TYPE_OF_ENHANCED_CD_ABORTED,
  88. IDS_MEDIA_CD_EXTRA,
  89. IDS_MEDIA_AUDIO_TAO_WITH_SESSION_NOT_WRITTEN,
  90. IDS_MEDIA_FIRST_TRACK_DATA_OTHERS_AUDIO,
  91. IDS_MEDIA_MIXED_MODE_MADE_TAO,
  92. IDS_MEDIA_KODAK_PORTFOLIO,
  93. IDS_MEDIA_VIDEO_CD,
  94. IDS_MEDIA_CDi,
  95. IDS_MEDIA_PLAYSTATION_SONY_GAMES,
  96. IDS_MEDIA_OBSOLETE,
  97. IDS_MEDIA_OBSOLETE_FOR_RESTRICTED_OVERWRITE_DVD,
  98. IDS_MEDIA_DVDROM_OR_CLOSED_RECORDABLE,
  99. IDS_MEDIA_INCREMENTAL_DVD_WITH_APPENDABLE_ZONE,
  100. IDS_MEDIA_APPENDABLE_DVD_OF_ANY_TYPE,
  101. IDS_MEDIA_DVDRAM_CARTRIDGE,
  102. IDS_MEDIA_CD_OTHER_TYPE
  103. };
  104. DiscInfo::DiscInfo(void)
  105. {
  106. serialNum = 0;
  107. memset(buffer, 0, sizeof(buffer));
  108. strData = NULL;
  109. ResetData();
  110. }
  111. DiscInfo::DiscInfo(const wchar_t *info)
  112. {
  113. serialNum = 0;
  114. memset(buffer, 0, sizeof(buffer));
  115. strData = NULL;
  116. SetStringInfo(info);
  117. }
  118. DiscInfo::~DiscInfo(void)
  119. {
  120. ResetData();
  121. }
  122. void DiscInfo::ResetData(void)
  123. {
  124. if (strData) free(strData);
  125. strData = NULL;
  126. data[DD_PARSED]= FALSE;
  127. for (int i = 1; i < DISC_DATA_COUNT; i++) data[i] = -1;
  128. }
  129. BOOL DiscInfo::SetStringInfo(const wchar_t *info)
  130. {
  131. ResetData();
  132. int strLen = lstrlenW(info) + 1;
  133. strData = (wchar_t*) malloc(strLen * sizeof(wchar_t));
  134. StringCchCopyW(strData, strLen, info);
  135. const wchar_t *start = info;
  136. const wchar_t *end = info;
  137. BOOL cont;
  138. int i = 1;
  139. do
  140. {
  141. while(end[0] != L';' && end[0] != 0x00) end = CharNextW(end);
  142. cont = (end[0] == L';');
  143. data[i++] = _wtoi(start);
  144. if(cont)
  145. {
  146. end = CharNextW(end);
  147. start = end;
  148. }
  149. }
  150. while(cont && i < DISC_DATA_COUNT);
  151. data[DD_PARSED] = (i == DISC_DATA_COUNT);
  152. return data[DD_PARSED];
  153. }
  154. const wchar_t* DiscInfo::GetStringInfo(void)
  155. {
  156. return strData;
  157. }
  158. DWORD DiscInfo::GetMedium(void)
  159. {
  160. return data[DD_INDEX_MEDIUM];
  161. }
  162. DWORD DiscInfo::GetMediumType(void)
  163. {
  164. return data[DD_INDEX_MEDIUM_TYPE];
  165. }
  166. DWORD DiscInfo::GetMediumFormat(void)
  167. {
  168. return data[DD_INDEX_MEDIUM_FORMAT];
  169. }
  170. BOOL DiscInfo::GetProtectedDVD(void)
  171. {
  172. return data[DD_INDEX_PROTECTED_DVD];
  173. }
  174. BOOL DiscInfo::GetErasable(void)
  175. {
  176. return data[DD_INDEX_ERASABLE];
  177. }
  178. DWORD DiscInfo::GetTracksNumber(void)
  179. {
  180. return data[DD_INDEX_TRACKS_NUM];
  181. }
  182. DWORD DiscInfo::GetSectorsUsed(void)
  183. {
  184. return data[DD_INDEX_SECTOR_USED];
  185. }
  186. DWORD DiscInfo::GetSectorsFree(void)
  187. {
  188. return data[DD_INDEX_SECTOR_FREE];
  189. }
  190. BOOL DiscInfo::GetRecordable(void)
  191. {
  192. return (data[DD_INDEX_MEDIUM_TYPE] == PRIMOSDK_COMPLIANTGOLD || data[DD_INDEX_MEDIUM_TYPE] == PRIMOSDK_BLANK);
  193. }
  194. int DiscInfo::GetSerialNumber(void)
  195. {
  196. return serialNum;
  197. }
  198. void DiscInfo::SetSerialNumber(int serialNumber)
  199. {
  200. serialNum = serialNumber;
  201. }
  202. const wchar_t* DiscInfo::GetMediumText(void)
  203. {
  204. int index = -1;
  205. switch(data[DD_INDEX_MEDIUM])
  206. {
  207. case PRIMOSDK_CDROM: index = 0; break;
  208. case PRIMOSDK_CDR: index = 1; break;
  209. case PRIMOSDK_CDRW: index = 2; break;
  210. case PRIMOSDK_DVDR: index = 4; break;
  211. case PRIMOSDK_DVDROM: index = 3; break;
  212. case PRIMOSDK_DVDRAM: index = 8; break;
  213. case PRIMOSDK_DVDRW: index = 5; break;
  214. case PRIMOSDK_DVDPRW: index = 7; break;
  215. case PRIMOSDK_DVDPR: index = 6; break;
  216. case PRIMOSDK_DDCDROM: index = 9; break;
  217. case PRIMOSDK_DDCDR: index = 10; break;
  218. case PRIMOSDK_DDCDRW: index = 11; break;
  219. case PRIMOSDK_DVDPR9: index = 12; break;
  220. default: return TEXT_UNKNOWN;
  221. }
  222. return mediumText[index];
  223. }
  224. const wchar_t* DiscInfo::GetMediumTypeText(void)
  225. {
  226. static wchar_t tmp[256];
  227. int index = -1;
  228. switch(data[DD_INDEX_MEDIUM_TYPE])
  229. {
  230. case PRIMOSDK_SILVER: index = 0; break;
  231. case PRIMOSDK_COMPLIANTGOLD: index = 1; break;
  232. case PRIMOSDK_OTHERGOLD: index = 2; break;
  233. case PRIMOSDK_BLANK: index = 3; break;
  234. default: return WASABI_API_LNGSTRINGW_BUF(plugin.hDllInstance,IDS_UNKNOWN,tmp,256);
  235. }
  236. return WASABI_API_LNGSTRINGW_BUF(plugin.hDllInstance,mediumTypeText[index],tmp,256);
  237. }
  238. const wchar_t* DiscInfo::GetMediumFormatText(void)
  239. {
  240. static wchar_t tmpM[256];
  241. int index = -1;
  242. switch(data[DD_INDEX_MEDIUM_FORMAT])
  243. {
  244. case PRIMOSDK_B1: index = 0; break;
  245. case PRIMOSDK_D1: index = 1; break;
  246. case PRIMOSDK_D2: index = 2; break;
  247. case PRIMOSDK_D3: index = 3; break;
  248. case PRIMOSDK_D4: index = 4; break;
  249. case PRIMOSDK_D5: index = 5; break;
  250. case PRIMOSDK_D6: index = 6; break;
  251. case PRIMOSDK_D7: index = 7; break;
  252. case PRIMOSDK_D8: index = 8; break;
  253. case PRIMOSDK_D9: index = 9; break;
  254. case PRIMOSDK_A1: index = 10; break;
  255. case PRIMOSDK_A2: index = 11; break;
  256. case PRIMOSDK_A3: index = 12; break;
  257. case PRIMOSDK_A4: index = 13; break;
  258. case PRIMOSDK_A5: index = 14; break;
  259. case PRIMOSDK_M1: index = 15; break;
  260. case PRIMOSDK_M2: index = 16; break;
  261. case PRIMOSDK_M3: index = 17; break;
  262. case PRIMOSDK_M4: index = 18; break;
  263. case PRIMOSDK_M5: index = 19; break;
  264. case PRIMOSDK_M6: index = 20; break;
  265. case PRIMOSDK_F1: index = 21; break;
  266. case PRIMOSDK_F2: index = 22; break;
  267. case PRIMOSDK_F3: index = 23; break;
  268. case PRIMOSDK_F4: index = 24; break;
  269. case PRIMOSDK_F8: index = 25; break;
  270. case PRIMOSDK_FA: index = 26; break;
  271. case PRIMOSDK_GENERICCD: index = 27; break;
  272. default: return WASABI_API_LNGSTRINGW_BUF(plugin.hDllInstance,IDS_UNKNOWN,tmpM,256);
  273. }
  274. return WASABI_API_LNGSTRINGW_BUF(plugin.hDllInstance,mediumFormatText[index],tmpM,256);
  275. }
  276. const wchar_t* DiscInfo::GetProtectedDVDText(void)
  277. {
  278. return data[DD_INDEX_PROTECTED_DVD] ? TEXT_TRUE : TEXT_FALSE ;
  279. }
  280. const wchar_t* DiscInfo::GetErasableText(void)
  281. {
  282. return data[DD_INDEX_ERASABLE] ? TEXT_TRUE: TEXT_FALSE ;
  283. }
  284. const wchar_t* DiscInfo::GetTracksNumberText(void)
  285. {
  286. StringCchPrintfW(buffer, TEXT_BUFFER_SIZE, L"%d", data[DD_INDEX_TRACKS_NUM]);
  287. return buffer;
  288. }
  289. const wchar_t* DiscInfo::GetSectorsUsedText(void)
  290. {
  291. StringCchPrintfW(buffer, TEXT_BUFFER_SIZE, L"%d", data[DD_INDEX_SECTOR_USED]);
  292. return buffer;
  293. }
  294. const wchar_t* DiscInfo::GetSectorsFreeText(void)
  295. {
  296. StringCchPrintfW(buffer, TEXT_BUFFER_SIZE, L"%d", data[DD_INDEX_SECTOR_FREE]);
  297. return buffer;
  298. }
  299. const wchar_t* DiscInfo::GetRecordableText(void)
  300. {
  301. return GetRecordable() ? TEXT_TRUE : TEXT_FALSE;
  302. }