BurnProgress.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  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 LYFZ.NeroDiscBurn.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. // //加载后,创建一个新的手表形态和订阅,我们将用它来中止刻录过程的OnCancel事件。
  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 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
  93. this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(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(10, 9);
  113. this.c_Events.Name = "c_Events";
  114. this.c_Events.Size = new System.Drawing.Size(662, 181);
  115. this.c_Events.TabIndex = 8;
  116. this.c_Events.UseCompatibleStateImageBehavior = false;
  117. this.c_Events.View = System.Windows.Forms.View.Details;
  118. //
  119. // columnHeader1
  120. //
  121. this.columnHeader1.Text = "Time";
  122. this.columnHeader1.Width = 69;
  123. //
  124. // columnHeader2
  125. //
  126. this.columnHeader2.Text = "Events";
  127. this.columnHeader2.Width = 458;
  128. //
  129. // label1
  130. //
  131. this.label1.Location = new System.Drawing.Point(470, 198);
  132. this.label1.Name = "label1";
  133. this.label1.Size = new System.Drawing.Size(96, 17);
  134. this.label1.TabIndex = 2;
  135. this.label1.Text = "进度:";
  136. //
  137. // c_TimeElapsed
  138. //
  139. this.c_TimeElapsed.Location = new System.Drawing.Point(576, 198);
  140. this.c_TimeElapsed.Name = "c_TimeElapsed";
  141. this.c_TimeElapsed.Size = new System.Drawing.Size(96, 17);
  142. this.c_TimeElapsed.TabIndex = 3;
  143. this.c_TimeElapsed.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
  144. //
  145. // c_SubTask
  146. //
  147. this.c_SubTask.Location = new System.Drawing.Point(58, 224);
  148. this.c_SubTask.Name = "c_SubTask";
  149. this.c_SubTask.Size = new System.Drawing.Size(614, 25);
  150. this.c_SubTask.TabIndex = 5;
  151. //
  152. // c_Task
  153. //
  154. this.c_Task.Location = new System.Drawing.Point(58, 258);
  155. this.c_Task.Name = "c_Task";
  156. this.c_Task.Size = new System.Drawing.Size(614, 25);
  157. this.c_Task.TabIndex = 7;
  158. //
  159. // c_SubTaskPercent
  160. //
  161. this.c_SubTaskPercent.Location = new System.Drawing.Point(10, 224);
  162. this.c_SubTaskPercent.Name = "c_SubTaskPercent";
  163. this.c_SubTaskPercent.Size = new System.Drawing.Size(48, 26);
  164. this.c_SubTaskPercent.TabIndex = 4;
  165. this.c_SubTaskPercent.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
  166. //
  167. // c_TaskPercent
  168. //
  169. this.c_TaskPercent.Location = new System.Drawing.Point(10, 258);
  170. this.c_TaskPercent.Name = "c_TaskPercent";
  171. this.c_TaskPercent.Size = new System.Drawing.Size(48, 26);
  172. this.c_TaskPercent.TabIndex = 6;
  173. this.c_TaskPercent.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
  174. //
  175. // c_Done
  176. //
  177. this.c_Done.DialogResult = System.Windows.Forms.DialogResult.OK;
  178. this.c_Done.Enabled = false;
  179. this.c_Done.Location = new System.Drawing.Point(490, 293);
  180. this.c_Done.Name = "c_Done";
  181. this.c_Done.Size = new System.Drawing.Size(90, 25);
  182. this.c_Done.TabIndex = 10;
  183. this.c_Done.Text = "Done";
  184. //
  185. // c_Cancel
  186. //
  187. this.c_Cancel.Location = new System.Drawing.Point(586, 293);
  188. this.c_Cancel.Name = "c_Cancel";
  189. this.c_Cancel.Size = new System.Drawing.Size(90, 25);
  190. this.c_Cancel.TabIndex = 11;
  191. this.c_Cancel.Text = "Cancel";
  192. this.c_Cancel.Click += new System.EventHandler(this.c_Cancel_Click);
  193. //
  194. // label2
  195. //
  196. this.label2.Location = new System.Drawing.Point(10, 198);
  197. this.label2.Name = "label2";
  198. this.label2.Size = new System.Drawing.Size(48, 17);
  199. this.label2.TabIndex = 0;
  200. this.label2.Text = "执行阶段:";
  201. //
  202. // c_Phase
  203. //
  204. this.c_Phase.Location = new System.Drawing.Point(67, 198);
  205. this.c_Phase.Name = "c_Phase";
  206. this.c_Phase.Size = new System.Drawing.Size(384, 17);
  207. this.c_Phase.TabIndex = 1;
  208. //
  209. // c_SaveLog
  210. //
  211. this.c_SaveLog.Enabled = false;
  212. this.c_SaveLog.Location = new System.Drawing.Point(394, 293);
  213. this.c_SaveLog.Name = "c_SaveLog";
  214. this.c_SaveLog.Size = new System.Drawing.Size(90, 25);
  215. this.c_SaveLog.TabIndex = 9;
  216. this.c_SaveLog.Text = "Save Log";
  217. this.c_SaveLog.Click += new System.EventHandler(this.c_SaveLog_Click);
  218. //
  219. // BurnProgressForm
  220. //
  221. this.AcceptButton = this.c_Done;
  222. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  223. this.ClientSize = new System.Drawing.Size(712, 346);
  224. this.Controls.Add(this.label2);
  225. this.Controls.Add(this.c_Done);
  226. this.Controls.Add(this.c_SubTask);
  227. this.Controls.Add(this.label1);
  228. this.Controls.Add(this.c_Events);
  229. this.Controls.Add(this.c_TimeElapsed);
  230. this.Controls.Add(this.c_Task);
  231. this.Controls.Add(this.c_SubTaskPercent);
  232. this.Controls.Add(this.c_TaskPercent);
  233. this.Controls.Add(this.c_Cancel);
  234. this.Controls.Add(this.c_Phase);
  235. this.Controls.Add(this.c_SaveLog);
  236. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
  237. this.MaximizeBox = false;
  238. this.Name = "BurnProgressForm";
  239. this.ShowInTaskbar = false;
  240. this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
  241. this.Text = "BurnProgress";
  242. this.ResumeLayout(false);
  243. }
  244. #endregion
  245. // This is the function for burning an image.
  246. //
  247. public void BurnImage (string sImageFilename, NERO_BURN_FLAGS burnFlags, int iSpeedInKBS, NERO_MEDIA_TYPE mediaType, System.Windows.Forms.IWin32Window owner)
  248. {
  249. try
  250. {
  251. // First subscribe to all events of interest.
  252. //
  253. SubscribeToEvents (true);
  254. // Now, start burning.
  255. //
  256. m_drive.BurnImage2 (sImageFilename,
  257. (NERO_BURN_FLAGS) ((uint) burnFlags | (uint) NERO_BURN_FLAGS.NERO_BURN_FLAG_SPEED_IN_KBS),
  258. iSpeedInKBS,
  259. mediaType);
  260. this.ShowDialog (owner);
  261. }
  262. catch (COMException ex)
  263. {
  264. SubscribeToEvents (false);
  265. MessageBox.Show (this, ex.Message);
  266. }
  267. }
  268. 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)
  269. {
  270. try
  271. {
  272. // First subscribe to all events of interest.
  273. //首先订阅感兴趣的所有事件。
  274. //
  275. SubscribeToEvents (true);
  276. // If the iso track passed in has neither files nor folders,
  277. // don't use it.
  278. //
  279. if (isoTrack.RootFolder.Files.Count == 0 &&
  280. isoTrack.RootFolder.Folders.Count == 0)
  281. {
  282. isoTrack = null;
  283. }
  284. // Just pass on all the gathered parameters.
  285. //
  286. m_drive.BurnIsoAudioCD (sArtist, sTitle, false,
  287. isoTrack, audioTracks, cdStamp,
  288. (NERO_BURN_FLAGS) ((uint) nbf | (uint) NERO_BURN_FLAGS.NERO_BURN_FLAG_SPEED_IN_KBS),
  289. iSpeedInKBS,
  290. mediaType);
  291. this.ShowDialog (owner);
  292. }
  293. catch (COMException ex)
  294. {
  295. SubscribeToEvents (false);
  296. MessageBox.Show (this, ex.Message);
  297. }
  298. }
  299. private void m_drive_OnDoneBurn(ref NERO_BURN_ERROR StatusCode)
  300. {
  301. // When burning is over, make sure to unsubscribe from all
  302. // events.
  303. //
  304. SubscribeToEvents (false);
  305. // Show the appropriate message for success and failure.
  306. //
  307. if (StatusCode == NERO_BURN_ERROR.NERO_BURN_OK)
  308. {
  309. MessageBox.Show (this, "Burn process completed successfully!");
  310. }
  311. else
  312. {
  313. MessageBox.Show (this, "Burn process failed!\n" + StatusCode.ToString ());
  314. }
  315. // Disable the Cancel button and enable the Done
  316. // button.
  317. //
  318. c_Cancel.Enabled = false;
  319. c_Done.Enabled = true;
  320. c_SaveLog.Enabled = true;
  321. }
  322. private void c_Cancel_Click(object sender, System.EventArgs e)
  323. {
  324. // When a Cancel button is clicked, make sure to abort.
  325. //
  326. m_bAborted = true;
  327. m_nero.Abort ();
  328. }
  329. private void SubscribeToEvents (bool bSubscribe)
  330. {
  331. if (bSubscribe)
  332. {
  333. // Subscribe to NeroDrive events.
  334. //
  335. m_evOnDoneBurn = new _INeroDriveEvents_OnDoneBurnEventHandler(m_drive_OnDoneBurn);
  336. m_drive.OnDoneBurn += m_evOnDoneBurn;
  337. m_evOnProgress = new _INeroDriveEvents_OnProgressEventHandler(m_drive_OnProgress);
  338. m_drive.OnProgress += m_evOnProgress;
  339. m_evOnSubTaskProgress = new _INeroDriveEvents_OnSubTaskProgressEventHandler(m_drive_OnSubTaskProgress);
  340. m_drive.OnSubTaskProgress += m_evOnSubTaskProgress;
  341. m_evOnAborted = new _INeroDriveEvents_OnAbortedEventHandler(m_drive_OnAborted);
  342. m_drive.OnAborted += m_evOnAborted;
  343. m_evOnAddLogLine = new _INeroDriveEvents_OnAddLogLineEventHandler(m_drive_OnAddLogLine);
  344. m_drive.OnAddLogLine += m_evOnAddLogLine;
  345. m_evOnSetPhase = new _INeroDriveEvents_OnSetPhaseEventHandler(m_drive_OnSetPhase);
  346. m_drive.OnSetPhase += m_evOnSetPhase;
  347. m_evOnDisableAbort = new _INeroDriveEvents_OnDisableAbortEventHandler(m_drive_OnDisableAbort);
  348. m_drive.OnDisableAbort += m_evOnDisableAbort;
  349. // Subscribe to Nero events.
  350. //
  351. m_evOnFileSelImage = new _INeroEvents_OnFileSelImageEventHandler(m_nero_OnFileSelImage);
  352. m_nero.OnFileSelImage += m_evOnFileSelImage;
  353. m_evOnWaitCD = new _INeroEvents_OnWaitCDEventHandler(m_nero_OnWaitCD);
  354. m_nero.OnWaitCD += m_evOnWaitCD;
  355. m_evOnWaitCDDone = new _INeroEvents_OnWaitCDDoneEventHandler(m_nero_OnWaitCDDone);
  356. m_nero.OnWaitCDDone += m_evOnWaitCDDone;
  357. m_evOnWaitCDMediaInfo = new _INeroEvents_OnWaitCDMediaInfoEventHandler(m_nero_OnWaitCDMediaInfo);
  358. m_nero.OnWaitCDMediaInfo += m_evOnWaitCDMediaInfo;
  359. m_evOnNonEmptyCDRW = new _INeroEvents_OnNonEmptyCDRWEventHandler(m_nero_OnNonEmptyCDRW);
  360. m_nero.OnNonEmptyCDRW += m_evOnNonEmptyCDRW;
  361. // Start the timer that is responsible for displaying
  362. // the elapsed time during burning.
  363. //
  364. m_timeStart = DateTime.Now;
  365. m_timer = new System.Timers.Timer (500);
  366. m_timer.Elapsed += new System.Timers.ElapsedEventHandler(m_timer_Elapsed);
  367. m_timer.Start ();
  368. }
  369. else
  370. {
  371. // Stop the elapsed time timer.
  372. //
  373. m_timer.Stop ();
  374. // Unsubscribe from NeroDrive events.
  375. //
  376. m_drive.OnDoneBurn -= m_evOnDoneBurn;
  377. m_drive.OnProgress -= m_evOnProgress;
  378. m_drive.OnSubTaskProgress -= m_evOnSubTaskProgress;
  379. m_drive.OnAborted -= m_evOnAborted;
  380. m_drive.OnAddLogLine -= m_evOnAddLogLine;
  381. m_drive.OnSetPhase -= m_evOnSetPhase;
  382. m_drive.OnDisableAbort -= m_evOnDisableAbort;
  383. // Unsubscribe from Nero events.
  384. //
  385. m_nero.OnFileSelImage -= m_evOnFileSelImage;
  386. m_nero.OnWaitCD -= m_evOnWaitCD;
  387. m_nero.OnWaitCDDone -= m_evOnWaitCDDone;
  388. m_nero.OnWaitCDMediaInfo -= m_evOnWaitCDMediaInfo;
  389. m_nero.OnNonEmptyCDRW -= m_evOnNonEmptyCDRW;
  390. }
  391. }
  392. /// <summary>
  393. /// 映像刻录时设置文件保存位置
  394. /// </summary>
  395. /// <param name="Filename"></param>
  396. private void m_nero_OnFileSelImage(ref string Filename)
  397. {
  398. // This events asks us to supply the image filename to
  399. // save to if the chose recorder is "Image Recorder".
  400. // //这个事件要求我们提供的图像文件名//保存到如果选择的刻录机“映像刻录”。
  401. SaveFileDialog dlg = new SaveFileDialog ();
  402. dlg.DefaultExt = ".nrg";
  403. dlg.Filter = "NRG files (*.nrg)|*.nrg|All files (*.*)|*.*";
  404. // To cancel, assign empty string.
  405. //
  406. if (DialogResult.OK == dlg.ShowDialog (this))
  407. {
  408. Filename = dlg.FileName;
  409. }
  410. else
  411. {
  412. Filename = "";
  413. }
  414. }
  415. private void m_drive_OnProgress(ref int ProgressInPercent, ref bool Abort)
  416. {
  417. // This events gives us an opportunity to show progress
  418. // as well as abort if needed.
  419. //
  420. Abort = m_bAborted;
  421. c_Task.Value = ProgressInPercent;
  422. c_TaskPercent.Text = ProgressInPercent.ToString () + "%";
  423. }
  424. private void m_drive_OnSubTaskProgress(ref int ProgressInPercent, ref bool Abort)
  425. {
  426. // This event gives us the other task's progress.
  427. //
  428. Abort = m_bAborted;
  429. c_SubTask.Value = ProgressInPercent;
  430. c_SubTaskPercent.Text = ProgressInPercent.ToString () + "%";
  431. }
  432. /// <summary>
  433. /// 一个中止
  434. /// </summary>
  435. /// <param name="Abort"></param>
  436. private void m_drive_OnAborted(ref bool Abort)
  437. {
  438. // This is a general aborted event that is called
  439. // more frequently than other events that might
  440. // also give us a chance to abort.
  441. //
  442. Abort = m_bAborted;
  443. }
  444. private void m_drive_OnAddLogLine(ref NERO_TEXT_TYPE TextType, ref string Text)
  445. {
  446. // This one informs us of the important events during
  447. // the burn process. We simply add a line to the list
  448. // view with the current time beside it.
  449. //
  450. DateTime time = DateTime.Now;
  451. ListViewItem lvi = c_Events.Items.Add (time.ToLongTimeString ());
  452. lvi.SubItems.Add (Text);
  453. }
  454. private void m_timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  455. {
  456. // When the timer ticks, we should update the elapsed
  457. // time.
  458. //
  459. TimeSpan ts = System.DateTime.Now - m_timeStart;
  460. if (this.InvokeRequired)
  461. {
  462. this.Invoke(new UpdateControl(delegate()
  463. {
  464. c_TimeElapsed.Text = ts.Hours.ToString("00") + ":" + ts.Minutes.ToString("00") + ":" + ts.Seconds.ToString("00");
  465. }));
  466. }
  467. else
  468. {
  469. c_TimeElapsed.Text = ts.Hours.ToString("00") + ":" + ts.Minutes.ToString("00") + ":" + ts.Seconds.ToString("00");
  470. }
  471. }
  472. private void m_drive_OnSetPhase(ref string Text)
  473. {
  474. // When a new phase comes in, display it.
  475. //
  476. c_Phase.Text = Text;
  477. }
  478. private void m_nero_OnWaitCD(ref NERO_WAITCD_TYPE WaitCD, ref string WaitCDLocalizedText)
  479. {
  480. // Ok, so now we need to wait on a disc. Let's pass
  481. // the WaitCD form the text and show it (if not already
  482. // shown). Make sure to disable the parent (this window)
  483. // so that a modal behavior is simulated.
  484. //
  485. m_frmWaitCD.c_WaitCDText.Text = WaitCDLocalizedText;
  486. m_frmWaitCD.Owner = this;
  487. m_frmWaitCD.Show ();
  488. this.Enabled = false;
  489. }
  490. private void m_nero_OnWaitCDDone()
  491. {
  492. // When waiting on a disc is done, make sure to
  493. // enable us and hide the WaitCD form.
  494. //
  495. this.Enabled = true;
  496. m_frmWaitCD.Hide ();
  497. }
  498. private void m_nero_OnWaitCDMediaInfo(ref NERO_MEDIA_TYPE LastDetectedMedia, ref string LastDetectedMediaName, ref NERO_MEDIA_TYPE RequestedMedia, ref string RequestedMediaName)
  499. {
  500. // When this event is fired, we need to update the
  501. // information on the WaitCD form. Also, sometimes
  502. // this event can come before the actual OnWaitCD so
  503. // make sure that either of them is prepared to
  504. // show the WaitCD form.
  505. //
  506. m_frmWaitCD.c_LastDetectedMedia.Text = LastDetectedMediaName;
  507. m_frmWaitCD.c_RequestedMedia.Text = RequestedMediaName;
  508. m_frmWaitCD.Owner = this;
  509. m_frmWaitCD.Show ();
  510. this.Enabled = false;
  511. }
  512. private void m_frmWaitCD_OnCancel(object sender, EventArgs e)
  513. {
  514. // This handler is called when WaitCD form's Cancel button is
  515. // clicked. Make sure to abort.
  516. //
  517. m_bAborted = true;
  518. m_nero.Abort ();
  519. }
  520. private void m_nero_OnNonEmptyCDRW(ref NERO_RESPONSE Response)
  521. {
  522. // This event will be fired only if the proper conditions
  523. // are met AND if NERO_BURN_FLAGS.NERO_BURN_FLAG_DETECT_NON_EMPTY_CDRW
  524. // was specified to the burn fucntion. Ask if we should erase
  525. // the rewritable.
  526. //
  527. 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))
  528. {
  529. // If the answer was NO, ask for a new disc.
  530. //
  531. Response = NERO_RESPONSE.NERO_RETURN_RESTART;
  532. }
  533. else
  534. {
  535. // If YES, then do erase the disc and continue burning
  536. // afterwards.
  537. //
  538. EraseProgressForm frm = new EraseProgressForm (m_drive, true, false);
  539. frm.ShowDialog (this);
  540. Response = NERO_RESPONSE.NERO_RETURN_CONTINUE;
  541. }
  542. }
  543. private void m_drive_OnDisableAbort(ref bool EnableAbort)
  544. {
  545. // This event will be fired at appropriate moments
  546. // only if NERO_BURN_FLAGS.NERO_BURN_FLAG_DISABLE_ABORT
  547. // was specified to the burning function. Make sure to
  548. // update the state of the Cancel button accordingly.
  549. //
  550. c_Cancel.Enabled = EnableAbort;
  551. }
  552. // This function burns a copy of a disc in source drive.
  553. //
  554. 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)
  555. {
  556. try
  557. {
  558. // Subscribe to events and then pass all parameters to
  559. // the burning function.
  560. //
  561. SubscribeToEvents (true);
  562. m_drive.BurnDiscCopy (sourceDrive,
  563. bOnTheFly,
  564. sImageFilepath,
  565. bDeleteImage,
  566. iReadSpeed,
  567. iNumberOfRetries,
  568. bIgnoreDataReadErrors,
  569. bIgnoreAudioReadErrors,
  570. bReadISRCAndMediaCatalogNumber,
  571. bRAWReadMode,
  572. burnFlags,
  573. iWriteSpeed,
  574. mediaType);
  575. this.ShowDialog (owner);
  576. }
  577. catch (COMException ex)
  578. {
  579. SubscribeToEvents (false);
  580. MessageBox.Show (this, ex.Message);
  581. }
  582. }
  583. private void c_SaveLog_Click(object sender, System.EventArgs e)
  584. {
  585. // Ask for a filename to save to and then write the whole
  586. // log to the file.
  587. //
  588. SaveFileDialog dlg = new SaveFileDialog ();
  589. dlg.DefaultExt = ".log";
  590. dlg.Filter = "Log files (*.log)|*.log|All files (*.*)|*.*";
  591. if (DialogResult.OK == dlg.ShowDialog (this))
  592. {
  593. System.IO.StreamWriter fs = new System.IO.StreamWriter (dlg.FileName);
  594. fs.Write (m_nero.ErrorLog);
  595. }
  596. }
  597. public void BurnNeroBurnContext (NeroVisionAPI.INeroBurnContext pBurnContext, NERO_BURN_FLAGS burnFlags, int iWriteSpeed, System.Windows.Forms.IWin32Window owner)
  598. {
  599. try
  600. {
  601. // Subscribe to events and then pass all parameters to
  602. // the burning function.
  603. //
  604. SubscribeToEvents (true);
  605. m_drive.BurnNVAPI (pBurnContext,
  606. burnFlags,
  607. iWriteSpeed);
  608. this.ShowDialog (owner);
  609. }
  610. catch (COMException ex)
  611. {
  612. SubscribeToEvents (false);
  613. MessageBox.Show (this, ex.Message);
  614. }
  615. }
  616. }
  617. }