1
0

common.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. #include "./main.h"
  2. #include "./resource.h"
  3. #include "./primosdk.h"
  4. #include <strsafe.h>
  5. DWORD BeginBurn(obj_primo *primoSDK, DWORD drive, WABURNSTRUCT *burnstruct)
  6. {
  7. burnstruct->primoSDK = primoSDK;
  8. burnstruct->drive = drive;
  9. DWORD rc[3] = { PRIMOSDK_ERROR, PRIMOSDK_ERROR, PRIMOSDK_ERROR};
  10. burnstruct->blocker = (PBYTE)("WINAMPBURNER v1.0");
  11. DWORD retCode = PRIMOSDK_OK;
  12. // init Sonic PrimoSDK
  13. if (!primoSDK)
  14. return PRIMOSDK_NOTLOADED;
  15. // block drive
  16. rc[0] = primoSDK->UnitVxBlock(&burnstruct->drive, PRIMOSDK_LOCK, burnstruct->blocker);
  17. if (PRIMOSDK_OK != rc[0]) retCode = rc[0];
  18. else
  19. {
  20. rc[1] = primoSDK->UnitAIN(&burnstruct->drive, PRIMOSDK_LOCK);
  21. if (PRIMOSDK_OK != rc[1]) retCode = rc[1];
  22. else
  23. {
  24. rc[2] = primoSDK->UnitLock(&burnstruct->drive, PRIMOSDK_LOCK);
  25. if (PRIMOSDK_OK != rc[2]) retCode = rc[2];
  26. }
  27. }
  28. if (PRIMOSDK_OK != retCode)
  29. {
  30. if (PRIMOSDK_OK == rc[2]) primoSDK->UnitLock(&burnstruct->drive, PRIMOSDK_UNLOCK);
  31. if (PRIMOSDK_OK == rc[1]) primoSDK->UnitAIN(&burnstruct->drive, PRIMOSDK_UNLOCK);
  32. if (PRIMOSDK_OK == rc[0]) primoSDK->UnitVxBlock(&burnstruct->drive, PRIMOSDK_UNLOCK, burnstruct->blocker);
  33. burnstruct->drive = 0x0000;
  34. burnstruct->blocker = NULL;
  35. burnstruct->primoSDK = NULL;
  36. }
  37. return retCode;
  38. }
  39. DWORD EndBurn(WABURNSTRUCT *burnstruct)
  40. {
  41. if (!burnstruct) return PRIMOSDK_ERROR;
  42. if (0x0000 == burnstruct->drive) return PRIMOSDK_OK;
  43. DWORD rc[4];
  44. rc[0] = burnstruct->primoSDK->UnitLock(&burnstruct->drive, PRIMOSDK_UNLOCK);
  45. rc[1] = burnstruct->primoSDK->MoveMedium(&burnstruct->drive,
  46. PRIMOSDK_IMMEDIATE | ((burnstruct->eject) ? PRIMOSDK_OPENTRAYEJECT : 0));
  47. if (0 == burnstruct->eject)
  48. rc[1] = PRIMOSDK_OK;
  49. rc[2] = burnstruct->primoSDK->UnitAIN(&burnstruct->drive, PRIMOSDK_UNLOCK);
  50. rc[3] = burnstruct->primoSDK->UnitVxBlock(&burnstruct->drive, PRIMOSDK_UNLOCK, burnstruct->blocker);
  51. burnstruct->drive = 0x0000;
  52. burnstruct->blocker = NULL;
  53. int len = sizeof(rc)/sizeof(DWORD);
  54. for (int i = 0; i < len; i++) { if (PRIMOSDK_OK != rc[i]) return rc[i]; }
  55. return PRIMOSDK_OK;
  56. }
  57. DWORD GetMediumInfo(obj_primo *primoSDK, DWORD *drive, WAMEDIUMINFO *info)
  58. {
  59. DWORD retCode(PRIMOSDK_OK), erasable(0);
  60. if (MAXDWORD != info->mediumType || MAXDWORD != info->mediumFormat || MAXDWORD != info->erasable ||
  61. MAXDWORD != info->tracks || MAXDWORD != info->usedSectors || MAXDWORD != info->freeSectors || MAXDWORD != info->recordable)
  62. {
  63. retCode = primoSDK->DiscInfoEx(drive, 0,(MAXDWORD == info->mediumType && MAXDWORD == info->recordable) ? NULL : &info->mediumType,
  64. (MAXDWORD == info->mediumFormat) ? NULL : &info->mediumFormat,
  65. &erasable,
  66. (MAXDWORD == info->tracks) ? NULL : &info->tracks,
  67. (MAXDWORD == info->usedSectors) ? NULL : &info->usedSectors,
  68. (MAXDWORD == info->freeSectors) ? NULL : &info->freeSectors);
  69. if (MAXDWORD != info->erasable) info->erasable = (TRUE == erasable);
  70. if (MAXDWORD != info->recordable) info->recordable = (PRIMOSDK_COMPLIANTGOLD == info->mediumType || PRIMOSDK_BLANK == info->mediumType);
  71. if (PRIMOSDK_OK != retCode) return retCode;
  72. }
  73. DWORD medium, rfu3;
  74. BOOL needMediumInfo = (MAXDWORD != info->medium || MAXDWORD != info->isCD || MAXDWORD != info->isDCD || MAXDWORD != info->isDVD || MAXDWORD != info->isDLDVD);
  75. if (MAXDWORD != info->protectedDVD || needMediumInfo)
  76. {
  77. retCode = primoSDK->DiscInfo2(drive, !needMediumInfo ? NULL : &medium,
  78. (MAXDWORD == info->protectedDVD) ? NULL : &info->protectedDVD,
  79. NULL,
  80. !needMediumInfo ? NULL : &info->medium,
  81. &rfu3);
  82. }
  83. if (MAXDWORD != info->isCD) info->isCD = (PRIMOSDK_CDROM == info->medium || PRIMOSDK_CDR == info->medium || PRIMOSDK_CDRW == info->medium);
  84. if (MAXDWORD != info->isDCD) info->isDCD = (PRIMOSDK_DDCDR == info->medium || PRIMOSDK_DDCDRW == info->medium);
  85. if (MAXDWORD != info->isDVD) info->isDVD = (PRIMOSDK_DDCDROM == info->medium || PRIMOSDK_DVDR == info->medium || PRIMOSDK_DVDROM == info->medium || PRIMOSDK_DVDRAM == info->medium ||
  86. PRIMOSDK_DVDRW == info->medium || PRIMOSDK_DVDPRW == info->medium || PRIMOSDK_DVDPR == info->medium);
  87. if (MAXDWORD != info->isDLDVD) info->isDLDVD = (PRIMOSDK_DVDPR9 == info->medium);
  88. return retCode;
  89. }
  90. wchar_t* GetMediumText(wchar_t *buffer, unsigned int cchBuffer,DWORD medium)
  91. {
  92. UINT uid = IDS_UNKNOWN;
  93. switch(medium)
  94. {
  95. case PRIMOSDK_CDROM: uid = IDS_MEDIUM_CD; break;
  96. case PRIMOSDK_CDR: uid = IDS_MEDIUM_CDR; break;
  97. case PRIMOSDK_CDRW: uid = IDS_MEDIUM_CDRW; break;
  98. case PRIMOSDK_DVDR: uid = IDS_MEDIUM_DVDR; break;
  99. case PRIMOSDK_DVDROM: uid = IDS_MEDIUM_DVD; break;
  100. case PRIMOSDK_DVDRAM: uid = IDS_MEDIUM_DVDRAM; break;
  101. case PRIMOSDK_DVDRW: uid = IDS_MEDIUM_DVDRW; break;
  102. case PRIMOSDK_DVDPRW: uid = IDS_MEDIUM_DVDPRW; break;
  103. case PRIMOSDK_DVDPR: uid = IDS_MEDIUM_DVDPR; break;
  104. case PRIMOSDK_DDCDROM: uid = IDS_MEDIUM_DDCD; break;
  105. case PRIMOSDK_DDCDR: uid = IDS_MEDIUM_DDCDR; break;
  106. case PRIMOSDK_DDCDRW: uid = IDS_MEDIUM_DDCDRW; break;
  107. case PRIMOSDK_DVDPR9: uid = IDS_MEDIUM_DVDPR9; break;
  108. case PRIMOSDK_DVDR9: uid = IDS_MEDIUM_DVDR9; break;
  109. case PRIMOSDK_BDR: uid = IDS_MEDIUM_BDR; break;
  110. case PRIMOSDK_BDRE: uid = IDS_MEDIUM_BDRE; break;
  111. }
  112. LoadStringW(hResource, uid, buffer, cchBuffer);
  113. return buffer;
  114. }
  115. wchar_t*GetMediumTypeText(wchar_t *buffer, unsigned int cchBuffer, DWORD type)
  116. {
  117. UINT uid = IDS_UNKNOWN;
  118. switch(type)
  119. {
  120. case PRIMOSDK_SILVER: uid = IDS_MEDIUMTYPE_SILVER; break;
  121. case PRIMOSDK_COMPLIANTGOLD: uid = IDS_MEDIUMTYPE_COMPILATIONGOLD; break;
  122. case PRIMOSDK_OTHERGOLD: uid = IDS_MEDIUMTYPE_OTHERGOLD; break;
  123. case PRIMOSDK_BLANK: uid = IDS_MEDIUMTYPE_BLANK; break;
  124. }
  125. LoadStringW(hResource, uid, buffer, cchBuffer);
  126. return buffer;
  127. }
  128. wchar_t* GetMediumFormatText(wchar_t *buffer, unsigned int cchBuffer, DWORD format)
  129. {
  130. UINT uid = IDS_UNKNOWN;
  131. switch(format)
  132. {
  133. case PRIMOSDK_B1: uid = IDS_MEDIUMFORMAT_B1; break;
  134. case PRIMOSDK_D1: uid = IDS_MEDIUMFORMAT_D1; break;
  135. case PRIMOSDK_D2: uid = IDS_MEDIUMFORMAT_D2; break;
  136. case PRIMOSDK_D3: uid = IDS_MEDIUMFORMAT_D3; break;
  137. case PRIMOSDK_D4: uid = IDS_MEDIUMFORMAT_D4; break;
  138. case PRIMOSDK_D5: uid = IDS_MEDIUMFORMAT_D5; break;
  139. case PRIMOSDK_D6: uid = IDS_MEDIUMFORMAT_D6; break;
  140. case PRIMOSDK_D7: uid = IDS_MEDIUMFORMAT_D7; break;
  141. case PRIMOSDK_D8: uid = IDS_MEDIUMFORMAT_D8; break;
  142. case PRIMOSDK_D9: uid = IDS_MEDIUMFORMAT_D9; break;
  143. case PRIMOSDK_A1: uid = IDS_MEDIUMFORMAT_A1; break;
  144. case PRIMOSDK_A2: uid = IDS_MEDIUMFORMAT_A2; break;
  145. case PRIMOSDK_A3: uid = IDS_MEDIUMFORMAT_A3; break;
  146. case PRIMOSDK_A4: uid = IDS_MEDIUMFORMAT_A4; break;
  147. case PRIMOSDK_A5: uid = IDS_MEDIUMFORMAT_A5; break;
  148. case PRIMOSDK_M1: uid = IDS_MEDIUMFORMAT_M1; break;
  149. case PRIMOSDK_M2: uid = IDS_MEDIUMFORMAT_M2; break;
  150. case PRIMOSDK_M3: uid = IDS_MEDIUMFORMAT_M3; break;
  151. case PRIMOSDK_M4: uid = IDS_MEDIUMFORMAT_M4; break;
  152. case PRIMOSDK_M5: uid = IDS_MEDIUMFORMAT_M5; break;
  153. case PRIMOSDK_M6: uid = IDS_MEDIUMFORMAT_M6; break;
  154. case PRIMOSDK_F1: uid = IDS_MEDIUMFORMAT_F1; break;
  155. case PRIMOSDK_F2: uid = IDS_MEDIUMFORMAT_F2; break;
  156. case PRIMOSDK_F3: uid = IDS_MEDIUMFORMAT_F3; break;
  157. case PRIMOSDK_F4: uid = IDS_MEDIUMFORMAT_F4; break;
  158. case PRIMOSDK_F5: uid = IDS_MEDIUMFORMAT_F5; break;
  159. case PRIMOSDK_F8: uid = IDS_MEDIUMFORMAT_F8; break;
  160. case PRIMOSDK_FA: uid = IDS_MEDIUMFORMAT_FA; break;
  161. case PRIMOSDK_GENERICCD: uid = IDS_MEDIUMFORMAT_GENERICCD; break;
  162. }
  163. LoadStringW(hResource, uid, buffer, cchBuffer);
  164. return buffer;
  165. }
  166. wchar_t* GetPrimoCodeText(wchar_t *buffer, unsigned int cchBuffer, DWORD primoCode)
  167. {
  168. UINT uid = IDS_UNKNOWN;
  169. switch(primoCode)
  170. {
  171. case PRIMOSDK_OK: uid = IDS_PRIMOCODE_OK; break;
  172. case PRIMOSDK_CMDSEQUENCE: uid = IDS_PRIMOCODE_CMDSEQUENCE; break;
  173. case PRIMOSDK_NOASPI: uid = IDS_PRIMOCODE_NOASPI; break; //PRIMOSDK_NO_DRIVER - is the same code
  174. case PRIMOSDK_INTERR: uid = IDS_PRIMOCODE_INTERR; break;
  175. case PRIMOSDK_BADPARAM: uid = IDS_PRIMOCODE_BADPARAM; break;
  176. case PRIMOSDK_ALREADYEXIST: uid = IDS_PRIMOCODE_ALREADYEXIST; break;
  177. case PRIMOSDK_NOTREADABLE: uid = IDS_PRIMOCODE_NOTREADABLE; break;
  178. case PRIMOSDK_NOSPACE: uid = IDS_PRIMOCODE_NOSPACE; break;
  179. case PRIMOSDK_INVALIDMEDIUM: uid = IDS_PRIMOCODE_INVALIDMEDIUM; break;
  180. case PRIMOSDK_RUNNING: uid = IDS_PRIMOCODE_RUNNING; break;
  181. case PRIMOSDK_BUR: uid = IDS_PRIMOCODE_BUR; break;
  182. case PRIMOSDK_SCSIERROR: uid = IDS_PRIMOCODE_SCSIERROR; break;
  183. case PRIMOSDK_UNITERROR: uid = IDS_PRIMOCODE_UNITERROR; break;
  184. case PRIMOSDK_NOTREADY: uid = IDS_PRIMOCODE_NOTREADY; break;
  185. case PRIMOSDK_INVALIDSOURCE: uid = IDS_PRIMOCODE_INVALIDSOURCE; break;
  186. case PRIMOSDK_INCOMPATIBLE: uid = IDS_PRIMOCODE_INCOMPATIBLE; break;
  187. case PRIMOSDK_FILEERROR: uid = IDS_PRIMOCODE_FILEERROR; break;
  188. case PRIMOSDK_ITSADEMO: uid = IDS_PRIMOCODE_ITSADEMO; break;
  189. case PRIMOSDK_USERABORT: uid = IDS_PRIMOCODE_USERABORT; break;
  190. case PRIMOSDK_BADHANDLE: uid = IDS_PRIMOCODE_BADHANDLE; break;
  191. case PRIMOSDK_BADUNIT: uid = IDS_PRIMOCODE_BADUNIT; break;
  192. case PRIMOSDK_ERRORLOADING: uid = IDS_PRIMOCODE_ERRORLOADING; break;
  193. case PRIMOSDK_NOAINCONTROL: uid = IDS_PRIMOCODE_NOAINCONTROL; break;
  194. case PRIMOSDK_READERROR: uid = IDS_PRIMOCODE_READERROR; break;
  195. case PRIMOSDK_WRITEERROR: uid = IDS_PRIMOCODE_WRITEERROR; break;
  196. case PRIMOSDK_TMPOVERFLOW: uid = IDS_PRIMOCODE_TMPOVERFLOW; break;
  197. case PRIMOSDK_DVDSTRUCTERROR: uid = IDS_PRIMOCODE_DVDSTRUCTERROR; break;
  198. case PRIMOSDK_FILETOOLARGE: uid = IDS_PRIMOCODE_FILETOOLARGE; break;
  199. case PRIMOSDK_CACHEFULL: uid = IDS_PRIMOCODE_CACHEFULL; break;
  200. case PRIMOSDK_FEATURE_NOT_SUPPORTED: uid = IDS_PRIMOCODE_FEATURE_NOT_SUPPORTED; break;
  201. case PRIMOSDK_FEATURE_DISABLED: uid = IDS_PRIMOCODE_FEATURE_DISABLED; break;
  202. case PRIMOSDK_CALLBACK_ERROR: uid = IDS_PRIMOCODE_CALLBACK_ERROR; break;
  203. case PRIMOSDK_PROTECTEDWMA: uid = IDS_PRIMOCODE_PROTECTEDWMA; break;
  204. }
  205. LoadStringW(hResource, uid, buffer, cchBuffer);
  206. return buffer;
  207. }
  208. wchar_t* GetBussText(wchar_t *buffer, unsigned int cchBuffer, DWORD bussType)
  209. {
  210. UINT uid = IDS_UNKNOWN;
  211. switch(bussType)
  212. {
  213. case PRIMOSDK_ATAPI: uid = IDS_BUSSTYPE_ATAPI; break;
  214. case PRIMOSDK_SCSI: uid = IDS_BUSSTYPE_SCSI; break;
  215. case PRIMOSDK_1394: uid = IDS_BUSSTYPE_1394; break;
  216. case PRIMOSDK_USB: uid = IDS_BUSSTYPE_USB; break;
  217. case PRIMOSDK_USB2: uid = IDS_BUSSTYPE_USB2; break;
  218. }
  219. LoadStringW(hResource, uid, buffer, cchBuffer);
  220. return buffer;
  221. }
  222. wchar_t* GetTrackTypeText(wchar_t *buffer, unsigned int cchBuffer, DWORD trackType)
  223. {
  224. UINT uid = IDS_UNKNOWN;
  225. switch(trackType)
  226. {
  227. case PRIMOSDK_AUDIO_TRACK: uid = IDS_TRACKTYPE_AUDIO; break;
  228. case PRIMOSDK_MODE1_TRACK: uid = IDS_TRACKTYPE_TRACK2; break;
  229. case PRIMOSDK_MODE2_TRACK: uid = IDS_TRACKTYPE_TRACK2; break;
  230. }
  231. LoadStringW(hResource, uid, buffer, cchBuffer);
  232. return buffer;
  233. }
  234. wchar_t* GetTimeString(wchar_t *string, unsigned int cchLen, unsigned int timesec)
  235. {
  236. unsigned int min = timesec / 60;
  237. if (min > 0) timesec = timesec % 60;
  238. unsigned int hour = min / 60;
  239. if (hour > 0) min = min % 60;
  240. StringCchPrintfW(string, cchLen, L"%02d:%02d:%02d", hour, min, timesec);
  241. return string;
  242. }