Burnhelper.cpp 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. #include "BurnCore.h"
  2. #include <assert.h>
  3. NERO_SETTINGS CWriteToDVD::s_NeroSettings =
  4. {
  5. NULL,
  6. "ahead", "Nero - Burning Rom",
  7. "Nero.txt",
  8. {IdleCallback, &s_NeroSettings},
  9. {UserDialog, &s_NeroSettings}
  10. };
  11. CBurnContextProgress::CBurnContextProgress ()
  12. {
  13. if (m_pNeroProgress != NULL)
  14. {
  15. m_pNeroProgress->npAbortedCallback = CWriteToDVD::AbortedCallback;
  16. m_pNeroProgress->npAddLogLineCallback = CWriteToDVD::AddLogLine;
  17. m_pNeroProgress->npDisableAbortCallback = CWriteToDVD::DisableAbortCallback;
  18. m_pNeroProgress->npProgressCallback = CWriteToDVD::ProgressCallback;
  19. m_pNeroProgress->npSetMajorPhaseCallback = CWriteToDVD::SetMajorPhaseCallback;
  20. m_pNeroProgress->npSetPhaseCallback = CWriteToDVD::SetPhaseCallback;
  21. m_pNeroProgress->npSubTaskProgressCallback = NULL; // Write buffer fill level callback (we don't use this as it is complicated to visualize)
  22. m_pNeroProgress->npUserData = &CWriteToDVD::s_NeroSettings;
  23. }
  24. }
  25. void NERO_CALLBACK_ATTR CWriteToDVD::DisableAbortCallback (void *pUserData, BOOL enableAbort)
  26. {
  27. // Just print out one or the other string.
  28. //
  29. puts ((!enableAbort)? "[i] The current process cannot be interrupted": "[i] The process can be interrupted again");
  30. }
  31. DWORD NERO_CALLBACK_ATTR CWriteToDVD::WriteIOCallback (void *pUserData, BYTE *pBuffer, DWORD dwLen)
  32. {
  33. // NeroAPI provides a file handle and a buffer of data, containing dwLen bytes
  34. return fwrite (pBuffer, 1, dwLen, (FILE *)pUserData);
  35. }
  36. BOOL NERO_CALLBACK_ATTR CWriteToDVD::EOFCallback (void *pUserData)
  37. {
  38. return feof ((FILE *)pUserData);
  39. }
  40. BOOL NERO_CALLBACK_ATTR CWriteToDVD::ErrorCallback (void *pUserData)
  41. {
  42. return ferror ((FILE *)pUserData);
  43. }
  44. // ReadIOCallback will be used when PCM is written to CD
  45. DWORD NERO_CALLBACK_ATTR CWriteToDVD::ReadIOCallback (void *pUserData, BYTE *pBuffer, DWORD dwLen)
  46. {
  47. // Read dwLen number of bytes from the file into pBuffer
  48. return fread (pBuffer, 1, dwLen, (FILE *)pUserData);
  49. }
  50. void NERO_CALLBACK_ATTR CWriteToDVD::AddLogLine (void *pUserData, NERO_TEXT_TYPE type, const char *text)
  51. {
  52. const char *header;
  53. const char *start;
  54. // Evaluate the type of log entry that should be added
  55. // and assign the line header accordingly.
  56. switch (type)
  57. {
  58. case NERO_TEXT_INFO: // informative text
  59. header = "[i]";
  60. break;
  61. case NERO_TEXT_STOP: // some operation stopped prematurely
  62. header = "[#]";
  63. break;
  64. case NERO_TEXT_EXCLAMATION: // important information
  65. header = "[!]";
  66. break;
  67. case NERO_TEXT_QUESTION: // a question which requires an answer
  68. header = "[?]";
  69. break;
  70. case NERO_TEXT_DRIVE: // a message concerning a CD-ROM drive or recorder
  71. header = "[-]";
  72. break;
  73. default:
  74. header = "";
  75. }
  76. // Step through the message text, considering newline characters
  77. // and inserting a line break every 76 characters if the line is longer
  78. start = text;
  79. while (*start)
  80. {
  81. // search for newline NL(LF) and set a pointer to the
  82. // next newline character. If no newline is found end becomes NULL.
  83. char *end = (char*)strchr (start, '\n');
  84. // Determine the length of the string part to be printed.
  85. // If a newline character was found the length is the difference between end and start
  86. // Otherwise there is no newline between the current position of start in the string
  87. // and the end of the string. So the length can be determined by a simple call to strlen.
  88. int len;
  89. if (NULL != end)
  90. {
  91. len = end - start;
  92. // replace newline character with 0 to not print parts of the following line
  93. *end = 0;
  94. }
  95. else
  96. {
  97. len = strlen (start);
  98. }
  99. // We also make sure that no more than 76 characters are printed
  100. // no matter how long the current string part really is.
  101. if (len > 76)
  102. {
  103. len = 76;
  104. }
  105. // The formatted output:
  106. printf ("%-4.4s%-76.76s", header, start);
  107. header = ""; // we print the header only in the first line
  108. // Shift the start pointer right by the amount of bytes just printed.
  109. start += len;
  110. // If newline characters were found start has to be set to the next character
  111. // If end contains NULL this means that either no newlines were found or
  112. // the end of the string has been reached.
  113. if (NULL != end)
  114. {
  115. ++start;
  116. }
  117. }
  118. printf("\n");
  119. }
  120. BOOL NERO_CALLBACK_ATTR CWriteToDVD::ProgressCallback (void *pUserData, DWORD dwProgressInPercent)
  121. {
  122. // print the numerical value
  123. printf ("%03d%% ", dwProgressInPercent);
  124. // print the progress meter
  125. int i;
  126. int w = (74*dwProgressInPercent)/100;
  127. for ( i = w; i > 0; i --)
  128. {
  129. printf ("#");
  130. }
  131. for (i = 74 - w; i > 0; i --)
  132. {
  133. printf (".");
  134. }
  135. // carriage return
  136. printf ("\r");
  137. fflush (stdout);
  138. // We simply return the aborted flag
  139. return s_bAborted;
  140. }
  141. struct PHASE_MAPPING
  142. {
  143. NERO_MAJOR_PHASE m_phase;
  144. LPCSTR m_psDescription;
  145. };
  146. static PHASE_MAPPING s_PhaseMapping[] = {
  147. {NERO_PHASE_UNSPECIFIED , "Unspecified"},
  148. {NERO_PHASE_START_CACHE , "Start cache"},
  149. {NERO_PHASE_DONE_CACHE , "Done cache"},
  150. {NERO_PHASE_FAIL_CACHE , "Fail cache"},
  151. {NERO_PHASE_ABORT_CACHE , "Abort cache"},
  152. {NERO_PHASE_START_TEST , "Start test"},
  153. {NERO_PHASE_DONE_TEST , "Done test"},
  154. {NERO_PHASE_FAIL_TEST , "Fail test"},
  155. {NERO_PHASE_ABORT_TEST , "Abort test"},
  156. {NERO_PHASE_START_SIMULATE , "Start simulate"},
  157. {NERO_PHASE_DONE_SIMULATE , "Done simulate"},
  158. {NERO_PHASE_FAIL_SIMULATE , "Fail simulate"},
  159. {NERO_PHASE_ABORT_SIMULATE , "Abort simulate"},
  160. {NERO_PHASE_START_WRITE , "Start write"},
  161. {NERO_PHASE_DONE_WRITE , "Done write"},
  162. {NERO_PHASE_FAIL_WRITE , "Fail write"},
  163. {NERO_PHASE_ABORT_WRITE , "Abort write"},
  164. {NERO_PHASE_START_SIMULATE_NOSPD , "Start simulate nospd"},
  165. {NERO_PHASE_DONE_SIMULATE_NOSPD , "Done simulate nospd"},
  166. {NERO_PHASE_FAIL_SIMULATE_NOSPD , "Fail simulate nospd"},
  167. {NERO_PHASE_ABORT_SIMULATE_NOSPD , "Abort simulate nospd"},
  168. {NERO_PHASE_START_WRITE_NOSPD , "Start write nospd"},
  169. {NERO_PHASE_DONE_WRITE_NOSPD , "Done write nospd"},
  170. {NERO_PHASE_FAIL_WRITE_NOSPD , "Fail write nospd"},
  171. {NERO_PHASE_ABORT_WRITE_NOSPD , "Abort write nospd"},
  172. {NERO_PHASE_PREPARE_ITEMS , "Prepare items"},
  173. {NERO_PHASE_VERIFY_COMPILATION , "Verify compilation"},
  174. {NERO_PHASE_VERIFY_ABORTED , "Verify aborted"},
  175. {NERO_PHASE_VERIFY_END_OK , "Verify end ok"},
  176. {NERO_PHASE_VERIFY_END_FAIL , "Verify end fail"},
  177. {NERO_PHASE_ENCODE_VIDEO , "Encode video"},
  178. {NERO_PHASE_SEAMLESSLINK_ACTIVATED , "Seamlesslink activated"},
  179. {NERO_PHASE_BUP_ACTIVATED , "BUP activated"},
  180. {NERO_PHASE_START_FORMATTING , "Start formatting"},
  181. {NERO_PHASE_CONTINUE_FORMATTING , "Continue formatting"},
  182. {NERO_PHASE_FORMATTING_SUCCESSFUL , "Formatting successful"},
  183. {NERO_PHASE_FORMATTING_FAILED , "Formatting failed"},
  184. {NERO_PHASE_PREPARE_CD , "Prepare CD"},
  185. {NERO_PHASE_DONE_PREPARE_CD , "Done prepare CD"},
  186. {NERO_PHASE_FAIL_PREPARE_CD , "Fail prepare CD"},
  187. {NERO_PHASE_ABORT_PREPARE_CD , "Abort prepare CD"},
  188. {NERO_PHASE_DVDVIDEO_DETECTED , "Dvdvideo detected"},
  189. {NERO_PHASE_DVDVIDEO_REALLOC_STARTED , "Dvdvideo realloc started"},
  190. {NERO_PHASE_DVDVIDEO_REALLOC_COMPLETED , "Dvdvideo realloc completed"},
  191. {NERO_PHASE_DVDVIDEO_REALLOC_NOTNEEDED , "Dvdvideo realloc not needed"},
  192. {NERO_PHASE_DVDVIDEO_REALLOC_FAILED , "Dvdvideo realloc failed"},
  193. {NERO_PHASE_DRM_CHECK_FAILURE , "DRM check failure"},
  194. };
  195. void NERO_CALLBACK_ATTR CWriteToDVD::SetMajorPhaseCallback (void *pUserData, NERO_MAJOR_PHASE phase, void * reserved)
  196. {
  197. // Declare the buffer variable and set it to a default message.
  198. //
  199. char sBuffer[100] = "PHASE: unknown";
  200. // Search for the appropriate phase mapping description string.
  201. //
  202. for (int i = 0; i < sizeof (s_PhaseMapping)/sizeof (s_PhaseMapping[0]); i ++)
  203. {
  204. if (phase == s_PhaseMapping[i].m_phase)
  205. {
  206. // If the phase was found in the phase mapping table then
  207. // use it and break the for loop. We don't need to check
  208. // for buffer overflow as we "know" all our messages are short
  209. // enough to fit in the buffer.
  210. //
  211. sprintf (sBuffer, "PHASE: %s", s_PhaseMapping[i].m_psDescription);
  212. break;
  213. }
  214. }
  215. printf (" %-76s\n", sBuffer);
  216. }
  217. void NERO_CALLBACK_ATTR CWriteToDVD::SetPhaseCallback (void *pUserData, const char *text)
  218. {
  219. printf (" %-76s\n", text);
  220. }
  221. BOOL NERO_CALLBACK_ATTR CWriteToDVD::IdleCallback (void* pUserData)
  222. {
  223. assert(pUserData!=0);
  224. //CWriteToDVD* ptr=(CWriteToDVD*)pUserData;
  225. //block here!
  226. /*static MSG msg;
  227. if(ptr->IsBurning()){
  228. while (PeekMessage(&msg,NULL,NULL,NULL,PM_NOREMOVE))
  229. {
  230. TranslateMessage(&msg);
  231. DispatchMessage(&msg);
  232. }
  233. }*/
  234. return s_bAborted;
  235. }
  236. BOOL NERO_CALLBACK_ATTR CWriteToDVD::AbortedCallback(void *pUserData)
  237. {
  238. // do not ask the user if he really wants to abort
  239. // just return the aborted flag
  240. return s_bAborted;
  241. }