BurnProgress.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6. using System.Runtime.InteropServices;
  7. using NEROLib;
  8. namespace NeroFiddlesCOM.NET
  9. {
  10. /// <summary>
  11. /// Summary description for BurnProgress.
  12. /// </summary>
  13. public class BurnProgressForm : System.Windows.Forms.Form
  14. {
  15. private NeroDrive m_drive;
  16. private Nero m_nero;
  17. private DateTime m_timeStart;
  18. private System.Timers.Timer m_timer;
  19. private WaitCDForm m_frmWaitCD;
  20. private bool m_bAborted;
  21. private _INeroDriveEvents_OnDoneBurnEventHandler m_evOnDoneBurn;
  22. private _INeroDriveEvents_OnProgressEventHandler m_evOnProgress;
  23. private _INeroDriveEvents_OnSubTaskProgressEventHandler m_evOnSubTaskProgress;
  24. private _INeroDriveEvents_OnAbortedEventHandler m_evOnAborted;
  25. private _INeroDriveEvents_OnAddLogLineEventHandler m_evOnAddLogLine;
  26. private _INeroDriveEvents_OnSetPhaseEventHandler m_evOnSetPhase;
  27. private _INeroDriveEvents_OnDisableAbortEventHandler m_evOnDisableAbort;
  28. private _INeroEvents_OnFileSelImageEventHandler m_evOnFileSelImage;
  29. private _INeroEvents_OnWaitCDEventHandler m_evOnWaitCD;
  30. private _INeroEvents_OnWaitCDDoneEventHandler m_evOnWaitCDDone;
  31. private _INeroEvents_OnWaitCDMediaInfoEventHandler m_evOnWaitCDMediaInfo;
  32. private _INeroEvents_OnNonEmptyCDRWEventHandler m_evOnNonEmptyCDRW;
  33. private System.Windows.Forms.ListView c_Events;
  34. private System.Windows.Forms.ColumnHeader columnHeader1;
  35. private System.Windows.Forms.ColumnHeader columnHeader2;
  36. private System.Windows.Forms.Label label1;
  37. private System.Windows.Forms.Label c_TimeElapsed;
  38. private System.Windows.Forms.ProgressBar c_SubTask;
  39. private System.Windows.Forms.ProgressBar c_Task;
  40. private System.Windows.Forms.Label c_SubTaskPercent;
  41. private System.Windows.Forms.Label c_TaskPercent;
  42. private System.Windows.Forms.Button c_Done;
  43. private System.Windows.Forms.Button c_Cancel;
  44. private System.Windows.Forms.Label label2;
  45. private System.Windows.Forms.Label c_Phase;
  46. private System.Windows.Forms.Button c_SaveLog;
  47. /// <summary>
  48. /// Required designer variable.
  49. /// </summary>
  50. private System.ComponentModel.Container components = null;
  51. public BurnProgressForm(NeroDrive drive, Nero nero)
  52. {
  53. //
  54. // Required for Windows Form Designer support
  55. //
  56. InitializeComponent();
  57. m_drive = drive;
  58. m_nero = nero;
  59. m_bAborted = false;
  60. }
  61. /// <summary>
  62. /// Clean up any resources being used.
  63. /// </summary>
  64. protected override void Dispose( bool disposing )
  65. {
  66. if( disposing )
  67. {
  68. if(components != null)
  69. {
  70. components.Dispose();
  71. }
  72. }
  73. base.Dispose( disposing );
  74. }
  75. protected override void OnLoad(EventArgs e)
  76. {
  77. base.OnLoad (e);
  78. // Upon loading, create a new WaitCD form and subscribe to its
  79. // OnCancel event that we will use to abort the burning process.
  80. //
  81. m_frmWaitCD = new WaitCDForm ();
  82. m_frmWaitCD.OnCancel += new EventHandler(m_frmWaitCD_OnCancel);
  83. }
  84. #region Windows Form Designer generated code
  85. /// <summary>
  86. /// Required method for Designer support - do not modify
  87. /// the contents of this method with the code editor.
  88. /// </summary>
  89. private void InitializeComponent()
  90. {
  91. this.c_Events = new System.Windows.Forms.ListView();
  92. this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
  93. this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
  94. this.label1 = new System.Windows.Forms.Label();
  95. this.c_TimeElapsed = new System.Windows.Forms.Label();
  96. this.c_SubTask = new System.Windows.Forms.ProgressBar();
  97. this.c_Task = new System.Windows.Forms.ProgressBar();
  98. this.c_SubTaskPercent = new System.Windows.Forms.Label();
  99. this.c_TaskPercent = new System.Windows.Forms.Label();
  100. this.c_Done = new System.Windows.Forms.Button();
  101. this.c_Cancel = new System.Windows.Forms.Button();
  102. this.label2 = new System.Windows.Forms.Label();
  103. this.c_Phase = new System.Windows.Forms.Label();
  104. this.c_SaveLog = new System.Windows.Forms.Button();
  105. this.SuspendLayout();
  106. //
  107. // c_Events
  108. //
  109. this.c_Events.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
  110. this.columnHeader1,
  111. this.columnHeader2});
  112. this.c_Events.Location = new System.Drawing.Point(8, 8);
  113. this.c_Events.Name = "c_Events";
  114. this.c_Events.Size = new System.Drawing.Size(552, 168);
  115. this.c_Events.TabIndex = 8;
  116. this.c_Events.View = System.Windows.Forms.View.Details;
  117. //
  118. // columnHeader1
  119. //
  120. this.columnHeader1.Text = "Time";
  121. this.columnHeader1.Width = 69;
  122. //
  123. // columnHeader2
  124. //
  125. this.columnHeader2.Text = "Events";
  126. this.columnHeader2.Width = 458;
  127. //
  128. // label1
  129. //
  130. this.label1.Location = new System.Drawing.Point(392, 184);
  131. this.label1.Name = "label1";
  132. this.label1.Size = new System.Drawing.Size(80, 16);
  133. this.label1.TabIndex = 2;
  134. this.label1.Text = "Time elapsed:";
  135. //
  136. // c_TimeElapsed
  137. //
  138. this.c_TimeElapsed.Location = new System.Drawing.Point(480, 184);
  139. this.c_TimeElapsed.Name = "c_TimeElapsed";
  140. this.c_TimeElapsed.Size = new System.Drawing.Size(80, 16);
  141. this.c_TimeElapsed.TabIndex = 3;
  142. this.c_TimeElapsed.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
  143. //
  144. // c_SubTask
  145. //
  146. this.c_SubTask.Location = new System.Drawing.Point(48, 208);
  147. this.c_SubTask.Name = "c_SubTask";
  148. this.c_SubTask.Size = new System.Drawing.Size(512, 23);
  149. this.c_SubTask.TabIndex = 5;
  150. //
  151. // c_Task
  152. //
  153. this.c_Task.Location = new System.Drawing.Point(48, 240);
  154. this.c_Task.Name = "c_Task";
  155. this.c_Task.Size = new System.Drawing.Size(512, 23);
  156. this.c_Task.TabIndex = 7;
  157. //
  158. // c_SubTaskPercent
  159. //
  160. this.c_SubTaskPercent.Location = new System.Drawing.Point(8, 208);
  161. this.c_SubTaskPercent.Name = "c_SubTaskPercent";
  162. this.c_SubTaskPercent.Size = new System.Drawing.Size(40, 24);
  163. this.c_SubTaskPercent.TabIndex = 4;
  164. this.c_SubTaskPercent.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
  165. //
  166. // c_TaskPercent
  167. //
  168. this.c_TaskPercent.Location = new System.Drawing.Point(8, 240);
  169. this.c_TaskPercent.Name = "c_TaskPercent";
  170. this.c_TaskPercent.Size = new System.Drawing.Size(40, 24);
  171. this.c_TaskPercent.TabIndex = 6;
  172. this.c_TaskPercent.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
  173. //
  174. // c_Done
  175. //
  176. this.c_Done.DialogResult = System.Windows.Forms.DialogResult.OK;
  177. this.c_Done.Enabled = false;
  178. this.c_Done.Location = new System.Drawing.Point(408, 272);
  179. this.c_Done.Name = "c_Done";
  180. this.c_Done.TabIndex = 10;
  181. this.c_Done.Text = "Done";
  182. //
  183. // c_Cancel
  184. //
  185. this.c_Cancel.Location = new System.Drawing.Point(488, 272);
  186. this.c_Cancel.Name = "c_Cancel";
  187. this.c_Cancel.TabIndex = 11;
  188. this.c_Cancel.Text = "Cancel";
  189. this.c_Cancel.Click += new System.EventHandler(this.c_Cancel_Click);
  190. //
  191. // label2
  192. //
  193. this.label2.Location = new System.Drawing.Point(8, 184);
  194. this.label2.Name = "label2";
  195. this.label2.Size = new System.Drawing.Size(40, 16);
  196. this.label2.TabIndex = 0;
  197. this.label2.Text = "Phase:";
  198. //
  199. // c_Phase
  200. //
  201. this.c_Phase.Location = new System.Drawing.Point(56, 184);
  202. this.c_Phase.Name = "c_Phase";
  203. this.c_Phase.Size = new System.Drawing.Size(320, 16);
  204. this.c_Phase.TabIndex = 1;
  205. //
  206. // c_SaveLog
  207. //
  208. this.c_SaveLog.Enabled = false;
  209. this.c_SaveLog.Location = new System.Drawing.Point(328, 272);
  210. this.c_SaveLog.Name = "c_SaveLog";
  211. this.c_SaveLog.TabIndex = 9;
  212. this.c_SaveLog.Text = "Save Log";
  213. this.c_SaveLog.Click += new System.EventHandler(this.c_SaveLog_Click);
  214. //
  215. // BurnProgressForm
  216. //
  217. this.AcceptButton = this.c_Done;
  218. this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  219. this.ClientSize = new System.Drawing.Size(568, 302);
  220. this.Controls.Add(this.label2);
  221. this.Controls.Add(this.c_Done);
  222. this.Controls.Add(this.c_SubTask);
  223. this.Controls.Add(this.label1);
  224. this.Controls.Add(this.c_Events);
  225. this.Controls.Add(this.c_TimeElapsed);
  226. this.Controls.Add(this.c_Task);
  227. this.Controls.Add(this.c_SubTaskPercent);
  228. this.Controls.Add(this.c_TaskPercent);
  229. this.Controls.Add(this.c_Cancel);
  230. this.Controls.Add(this.c_Phase);
  231. this.Controls.Add(this.c_SaveLog);
  232. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
  233. this.MaximizeBox = false;
  234. this.Name = "BurnProgressForm";
  235. this.ShowInTaskbar = false;
  236. this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
  237. this.Text = "BurnProgress";
  238. this.ResumeLayout(false);
  239. }
  240. #endregion
  241. // This is the function for burning an image.
  242. //
  243. public void BurnImage (string sImageFilename, NERO_BURN_FLAGS burnFlags, int iSpeedInKBS, NERO_MEDIA_TYPE mediaType, System.Windows.Forms.IWin32Window owner)
  244. {
  245. try
  246. {
  247. // First subscribe to all events of interest.
  248. //
  249. SubscribeToEvents (true);
  250. // Now, start burning.
  251. //
  252. m_drive.BurnImage2 (sImageFilename,
  253. (NERO_BURN_FLAGS) ((uint) burnFlags | (uint) NERO_BURN_FLAGS.NERO_BURN_FLAG_SPEED_IN_KBS),
  254. iSpeedInKBS,
  255. mediaType);
  256. this.ShowDialog (owner);
  257. }
  258. catch (COMException ex)
  259. {
  260. SubscribeToEvents (false);
  261. MessageBox.Show (this, ex.Message);
  262. }
  263. }
  264. public void BurnIsoAudio (string sArtist, string sTitle, NeroISOTrack isoTrack, NeroAudioTracks audioTracks, NeroCDStamp cdStamp, NERO_BURN_FLAGS nbf, int iSpeedInKBS, NERO_MEDIA_TYPE mediaType, System.Windows.Forms.IWin32Window owner)
  265. {
  266. try
  267. {
  268. // First subscribe to all events of interest.
  269. //
  270. SubscribeToEvents (true);
  271. // If the iso track passed in has neither files nor folders,
  272. // don't use it.
  273. //
  274. if (isoTrack.RootFolder.Files.Count == 0 &&
  275. isoTrack.RootFolder.Folders.Count == 0)
  276. {
  277. isoTrack = null;
  278. }
  279. // Just pass on all the gathered parameters.
  280. //
  281. m_drive.BurnIsoAudioCD (sArtist, sTitle, false,
  282. isoTrack, audioTracks, cdStamp,
  283. (NERO_BURN_FLAGS) ((uint) nbf | (uint) NERO_BURN_FLAGS.NERO_BURN_FLAG_SPEED_IN_KBS),
  284. iSpeedInKBS,
  285. mediaType);
  286. this.ShowDialog (owner);
  287. }
  288. catch (COMException ex)
  289. {
  290. SubscribeToEvents (false);
  291. MessageBox.Show (this, ex.Message);
  292. }
  293. }
  294. private void m_drive_OnDoneBurn(ref NERO_BURN_ERROR StatusCode)
  295. {
  296. // When burning is over, make sure to unsubscribe from all
  297. // events.
  298. //
  299. SubscribeToEvents (false);
  300. // Show the appropriate message for success and failure.
  301. //
  302. if (StatusCode == NERO_BURN_ERROR.NERO_BURN_OK)
  303. {
  304. MessageBox.Show (this, "Burn process completed successfully!");
  305. }
  306. else
  307. {
  308. MessageBox.Show (this, "Burn process failed!\n" + StatusCode.ToString ());
  309. }
  310. // Disable the Cancel button and enable the Done
  311. // button.
  312. //
  313. c_Cancel.Enabled = false;
  314. c_Done.Enabled = true;
  315. c_SaveLog.Enabled = true;
  316. }
  317. private void c_Cancel_Click(object sender, System.EventArgs e)
  318. {
  319. // When a Cancel button is clicked, make sure to abort.
  320. //
  321. m_bAborted = true;
  322. m_nero.Abort ();
  323. }
  324. private void SubscribeToEvents (bool bSubscribe)
  325. {
  326. if (bSubscribe)
  327. {
  328. // Subscribe to NeroDrive events.
  329. //
  330. m_evOnDoneBurn = new _INeroDriveEvents_OnDoneBurnEventHandler(m_drive_OnDoneBurn);
  331. m_drive.OnDoneBurn += m_evOnDoneBurn;
  332. m_evOnProgress = new _INeroDriveEvents_OnProgressEventHandler(m_drive_OnProgress);
  333. m_drive.OnProgress += m_evOnProgress;
  334. m_evOnSubTaskProgress = new _INeroDriveEvents_OnSubTaskProgressEventHandler(m_drive_OnSubTaskProgress);
  335. m_drive.OnSubTaskProgress += m_evOnSubTaskProgress;
  336. m_evOnAborted = new _INeroDriveEvents_OnAbortedEventHandler(m_drive_OnAborted);
  337. m_drive.OnAborted += m_evOnAborted;
  338. m_evOnAddLogLine = new _INeroDriveEvents_OnAddLogLineEventHandler(m_drive_OnAddLogLine);
  339. m_drive.OnAddLogLine += m_evOnAddLogLine;
  340. m_evOnSetPhase = new _INeroDriveEvents_OnSetPhaseEventHandler(m_drive_OnSetPhase);
  341. m_drive.OnSetPhase += m_evOnSetPhase;
  342. m_evOnDisableAbort = new _INeroDriveEvents_OnDisableAbortEventHandler(m_drive_OnDisableAbort);
  343. m_drive.OnDisableAbort += m_evOnDisableAbort;
  344. // Subscribe to Nero events.
  345. //
  346. m_evOnFileSelImage = new _INeroEvents_OnFileSelImageEventHandler(m_nero_OnFileSelImage);
  347. m_nero.OnFileSelImage += m_evOnFileSelImage;
  348. m_evOnWaitCD = new _INeroEvents_OnWaitCDEventHandler(m_nero_OnWaitCD);
  349. m_nero.OnWaitCD += m_evOnWaitCD;
  350. m_evOnWaitCDDone = new _INeroEvents_OnWaitCDDoneEventHandler(m_nero_OnWaitCDDone);
  351. m_nero.OnWaitCDDone += m_evOnWaitCDDone;
  352. m_evOnWaitCDMediaInfo = new _INeroEvents_OnWaitCDMediaInfoEventHandler(m_nero_OnWaitCDMediaInfo);
  353. m_nero.OnWaitCDMediaInfo += m_evOnWaitCDMediaInfo;
  354. m_evOnNonEmptyCDRW = new _INeroEvents_OnNonEmptyCDRWEventHandler(m_nero_OnNonEmptyCDRW);
  355. m_nero.OnNonEmptyCDRW += m_evOnNonEmptyCDRW;
  356. // Start the timer that is responsible for displaying
  357. // the elapsed time during burning.
  358. //
  359. m_timeStart = DateTime.Now;
  360. m_timer = new System.Timers.Timer (500);
  361. m_timer.Elapsed += new System.Timers.ElapsedEventHandler(m_timer_Elapsed);
  362. m_timer.Start ();
  363. }
  364. else
  365. {
  366. // Stop the elapsed time timer.
  367. //
  368. m_timer.Stop ();
  369. // Unsubscribe from NeroDrive events.
  370. //
  371. m_drive.OnDoneBurn -= m_evOnDoneBurn;
  372. m_drive.OnProgress -= m_evOnProgress;
  373. m_drive.OnSubTaskProgress -= m_evOnSubTaskProgress;
  374. m_drive.OnAborted -= m_evOnAborted;
  375. m_drive.OnAddLogLine -= m_evOnAddLogLine;
  376. m_drive.OnSetPhase -= m_evOnSetPhase;
  377. m_drive.OnDisableAbort -= m_evOnDisableAbort;
  378. // Unsubscribe from Nero events.
  379. //
  380. m_nero.OnFileSelImage -= m_evOnFileSelImage;
  381. m_nero.OnWaitCD -= m_evOnWaitCD;
  382. m_nero.OnWaitCDDone -= m_evOnWaitCDDone;
  383. m_nero.OnWaitCDMediaInfo -= m_evOnWaitCDMediaInfo;
  384. m_nero.OnNonEmptyCDRW -= m_evOnNonEmptyCDRW;
  385. }
  386. }
  387. private void m_nero_OnFileSelImage(ref string Filename)
  388. {
  389. // This events asks us to supply the image filename to
  390. // save to if the chose recorder is "Image Recorder".
  391. //
  392. SaveFileDialog dlg = new SaveFileDialog ();
  393. dlg.DefaultExt = ".nrg";
  394. dlg.Filter = "NRG files (*.nrg)|*.nrg|All files (*.*)|*.*";
  395. // To cancel, assign empty string.
  396. //
  397. if (DialogResult.OK == dlg.ShowDialog (this))
  398. {
  399. Filename = dlg.FileName;
  400. }
  401. else
  402. {
  403. Filename = "";
  404. }
  405. }
  406. private void m_drive_OnProgress(ref int ProgressInPercent, ref bool Abort)
  407. {
  408. // This events gives us an opportunity to show progress
  409. // as well as abort if needed.
  410. //
  411. Abort = m_bAborted;
  412. c_Task.Value = ProgressInPercent;
  413. c_TaskPercent.Text = ProgressInPercent.ToString () + "%";
  414. }
  415. private void m_drive_OnSubTaskProgress(ref int ProgressInPercent, ref bool Abort)
  416. {
  417. // This event gives us the other task's progress.
  418. //
  419. Abort = m_bAborted;
  420. c_SubTask.Value = ProgressInPercent;
  421. c_SubTaskPercent.Text = ProgressInPercent.ToString () + "%";
  422. }
  423. private void m_drive_OnAborted(ref bool Abort)
  424. {
  425. // This is a general aborted event that is called
  426. // more frequently than other events that might
  427. // also give us a chance to abort.
  428. //
  429. Abort = m_bAborted;
  430. }
  431. private void m_drive_OnAddLogLine(ref NERO_TEXT_TYPE TextType, ref string Text)
  432. {
  433. // This one informs us of the important events during
  434. // the burn process. We simply add a line to the list
  435. // view with the current time beside it.
  436. //
  437. DateTime time = DateTime.Now;
  438. ListViewItem lvi = c_Events.Items.Add (time.ToLongTimeString ());
  439. lvi.SubItems.Add (Text);
  440. }
  441. private void m_timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  442. {
  443. // When the timer ticks, we should update the elapsed
  444. // time.
  445. //
  446. TimeSpan ts = System.DateTime.Now - m_timeStart;
  447. c_TimeElapsed.Text = ts.Hours.ToString ("00") + ":" + ts.Minutes.ToString ("00") + ":" + ts.Seconds.ToString ("00");
  448. }
  449. private void m_drive_OnSetPhase(ref string Text)
  450. {
  451. // When a new phase comes in, display it.
  452. //
  453. c_Phase.Text = Text;
  454. }
  455. private void m_nero_OnWaitCD(ref NERO_WAITCD_TYPE WaitCD, ref string WaitCDLocalizedText)
  456. {
  457. // Ok, so now we need to wait on a disc. Let's pass
  458. // the WaitCD form the text and show it (if not already
  459. // shown). Make sure to disable the parent (this window)
  460. // so that a modal behavior is simulated.
  461. //
  462. m_frmWaitCD.c_WaitCDText.Text = WaitCDLocalizedText;
  463. m_frmWaitCD.Owner = this;
  464. m_frmWaitCD.Show ();
  465. this.Enabled = false;
  466. }
  467. private void m_nero_OnWaitCDDone()
  468. {
  469. // When waiting on a disc is done, make sure to
  470. // enable us and hide the WaitCD form.
  471. //
  472. this.Enabled = true;
  473. m_frmWaitCD.Hide ();
  474. }
  475. private void m_nero_OnWaitCDMediaInfo(ref NERO_MEDIA_TYPE LastDetectedMedia, ref string LastDetectedMediaName, ref NERO_MEDIA_TYPE RequestedMedia, ref string RequestedMediaName)
  476. {
  477. // When this event is fired, we need to update the
  478. // information on the WaitCD form. Also, sometimes
  479. // this event can come before the actual OnWaitCD so
  480. // make sure that either of them is prepared to
  481. // show the WaitCD form.
  482. //
  483. m_frmWaitCD.c_LastDetectedMedia.Text = LastDetectedMediaName;
  484. m_frmWaitCD.c_RequestedMedia.Text = RequestedMediaName;
  485. m_frmWaitCD.Owner = this;
  486. m_frmWaitCD.Show ();
  487. this.Enabled = false;
  488. }
  489. private void m_frmWaitCD_OnCancel(object sender, EventArgs e)
  490. {
  491. // This handler is called when WaitCD form's Cancel button is
  492. // clicked. Make sure to abort.
  493. //
  494. m_bAborted = true;
  495. m_nero.Abort ();
  496. }
  497. private void m_nero_OnNonEmptyCDRW(ref NERO_RESPONSE Response)
  498. {
  499. // This event will be fired only if the proper conditions
  500. // are met AND if NERO_BURN_FLAGS.NERO_BURN_FLAG_DETECT_NON_EMPTY_CDRW
  501. // was specified to the burn fucntion. Ask if we should erase
  502. // the rewritable.
  503. //
  504. if (DialogResult.Yes != MessageBox.Show (this, "The rewritable disc is not empty. It needs to be erased in order to continue. Do you want to erase the disc?", "Erase?", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
  505. {
  506. // If the answer was NO, ask for a new disc.
  507. //
  508. Response = NERO_RESPONSE.NERO_RETURN_RESTART;
  509. }
  510. else
  511. {
  512. // If YES, then do erase the disc and continue burning
  513. // afterwards.
  514. //
  515. EraseProgressForm frm = new EraseProgressForm (m_drive, true, false);
  516. frm.ShowDialog (this);
  517. Response = NERO_RESPONSE.NERO_RETURN_CONTINUE;
  518. }
  519. }
  520. private void m_drive_OnDisableAbort(ref bool EnableAbort)
  521. {
  522. // This event will be fired at appropriate moments
  523. // only if NERO_BURN_FLAGS.NERO_BURN_FLAG_DISABLE_ABORT
  524. // was specified to the burning function. Make sure to
  525. // update the state of the Cancel button accordingly.
  526. //
  527. c_Cancel.Enabled = EnableAbort;
  528. }
  529. // This function burns a copy of a disc in source drive.
  530. //
  531. public void BurnDiscCopy (NeroDrive sourceDrive, bool bOnTheFly, string sImageFilepath, bool bDeleteImage, int iReadSpeed, int iNumberOfRetries, bool bIgnoreDataReadErrors, bool bIgnoreAudioReadErrors, bool bReadISRCAndMediaCatalogNumber, bool bRAWReadMode, NERO_BURN_FLAGS burnFlags, int iWriteSpeed, NERO_MEDIA_TYPE mediaType, System.Windows.Forms.IWin32Window owner)
  532. {
  533. try
  534. {
  535. // Subscribe to events and then pass all parameters to
  536. // the burning function.
  537. //
  538. SubscribeToEvents (true);
  539. m_drive.BurnDiscCopy (sourceDrive,
  540. bOnTheFly,
  541. sImageFilepath,
  542. bDeleteImage,
  543. iReadSpeed,
  544. iNumberOfRetries,
  545. bIgnoreDataReadErrors,
  546. bIgnoreAudioReadErrors,
  547. bReadISRCAndMediaCatalogNumber,
  548. bRAWReadMode,
  549. burnFlags,
  550. iWriteSpeed,
  551. mediaType);
  552. this.ShowDialog (owner);
  553. }
  554. catch (COMException ex)
  555. {
  556. SubscribeToEvents (false);
  557. MessageBox.Show (this, ex.Message);
  558. }
  559. }
  560. private void c_SaveLog_Click(object sender, System.EventArgs e)
  561. {
  562. // Ask for a filename to save to and then write the whole
  563. // log to the file.
  564. //
  565. SaveFileDialog dlg = new SaveFileDialog ();
  566. dlg.DefaultExt = ".log";
  567. dlg.Filter = "Log files (*.log)|*.log|All files (*.*)|*.*";
  568. if (DialogResult.OK == dlg.ShowDialog (this))
  569. {
  570. System.IO.StreamWriter fs = new System.IO.StreamWriter (dlg.FileName);
  571. fs.Write (m_nero.ErrorLog);
  572. }
  573. }
  574. public void BurnNeroBurnContext (NeroVisionAPI.INeroBurnContext pBurnContext, NERO_BURN_FLAGS burnFlags, int iWriteSpeed, System.Windows.Forms.IWin32Window owner)
  575. {
  576. try
  577. {
  578. // Subscribe to events and then pass all parameters to
  579. // the burning function.
  580. //
  581. SubscribeToEvents (true);
  582. m_drive.BurnNVAPI (pBurnContext,
  583. burnFlags,
  584. iWriteSpeed);
  585. this.ShowDialog (owner);
  586. }
  587. catch (COMException ex)
  588. {
  589. SubscribeToEvents (false);
  590. MessageBox.Show (this, ex.Message);
  591. }
  592. }
  593. }
  594. }