Erase.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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 Erase.
  12. /// </summary>
  13. public class EraseForm : System.Windows.Forms.Form
  14. {
  15. private NeroDrive m_drive;
  16. private System.Windows.Forms.Label label1;
  17. private System.Windows.Forms.ComboBox c_EraseMode;
  18. private System.Windows.Forms.TextBox c_Device;
  19. private System.Windows.Forms.Label label8;
  20. private System.Windows.Forms.Button c_Erase;
  21. private System.Windows.Forms.Button c_Cancel;
  22. private System.Windows.Forms.Label label2;
  23. private System.Windows.Forms.TextBox c_ErasingTime;
  24. /// <summary>
  25. /// Required designer variable.
  26. /// </summary>
  27. private System.ComponentModel.Container components = null;
  28. private ControlEnabler m_controlEnabler;
  29. public EraseForm(NeroDrive drive)
  30. {
  31. //
  32. // Required for Windows Form Designer support
  33. //
  34. InitializeComponent();
  35. m_controlEnabler = new ControlEnabler (this);
  36. m_drive = drive;
  37. }
  38. /// <summary>
  39. /// Clean up any resources being used.
  40. /// </summary>
  41. protected override void Dispose( bool disposing )
  42. {
  43. if( disposing )
  44. {
  45. if(components != null)
  46. {
  47. components.Dispose();
  48. }
  49. }
  50. base.Dispose( disposing );
  51. }
  52. #region Windows Form Designer generated code
  53. /// <summary>
  54. /// Required method for Designer support - do not modify
  55. /// the contents of this method with the code editor.
  56. /// </summary>
  57. private void InitializeComponent()
  58. {
  59. this.label1 = new System.Windows.Forms.Label();
  60. this.c_EraseMode = new System.Windows.Forms.ComboBox();
  61. this.c_Device = new System.Windows.Forms.TextBox();
  62. this.label8 = new System.Windows.Forms.Label();
  63. this.c_Erase = new System.Windows.Forms.Button();
  64. this.c_Cancel = new System.Windows.Forms.Button();
  65. this.label2 = new System.Windows.Forms.Label();
  66. this.c_ErasingTime = new System.Windows.Forms.TextBox();
  67. this.SuspendLayout();
  68. //
  69. // label1
  70. //
  71. this.label1.Location = new System.Drawing.Point(10, 43);
  72. this.label1.Name = "label1";
  73. this.label1.Size = new System.Drawing.Size(86, 17);
  74. this.label1.TabIndex = 0;
  75. this.label1.Text = "Erase mode:";
  76. //
  77. // c_EraseMode
  78. //
  79. this.c_EraseMode.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  80. this.c_EraseMode.Items.AddRange(new object[] {
  81. "Entire",
  82. "Quick"});
  83. this.c_EraseMode.Location = new System.Drawing.Point(10, 60);
  84. this.c_EraseMode.Name = "c_EraseMode";
  85. this.c_EraseMode.Size = new System.Drawing.Size(145, 20);
  86. this.c_EraseMode.TabIndex = 1;
  87. this.c_EraseMode.SelectedIndexChanged += new System.EventHandler(this.c_EraseMode_SelectedIndexChanged);
  88. //
  89. // c_Device
  90. //
  91. this.c_Device.Location = new System.Drawing.Point(77, 9);
  92. this.c_Device.Name = "c_Device";
  93. this.c_Device.ReadOnly = true;
  94. this.c_Device.Size = new System.Drawing.Size(249, 21);
  95. this.c_Device.TabIndex = 7;
  96. //
  97. // label8
  98. //
  99. this.label8.Location = new System.Drawing.Point(10, 9);
  100. this.label8.Name = "label8";
  101. this.label8.Size = new System.Drawing.Size(67, 17);
  102. this.label8.TabIndex = 6;
  103. this.label8.Text = "Device:";
  104. //
  105. // c_Erase
  106. //
  107. this.c_Erase.DialogResult = System.Windows.Forms.DialogResult.OK;
  108. this.c_Erase.Location = new System.Drawing.Point(144, 103);
  109. this.c_Erase.Name = "c_Erase";
  110. this.c_Erase.Size = new System.Drawing.Size(90, 25);
  111. this.c_Erase.TabIndex = 4;
  112. this.c_Erase.Text = "Erase";
  113. this.c_Erase.Click += new System.EventHandler(this.c_Erase_Click);
  114. //
  115. // c_Cancel
  116. //
  117. this.c_Cancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
  118. this.c_Cancel.Location = new System.Drawing.Point(240, 103);
  119. this.c_Cancel.Name = "c_Cancel";
  120. this.c_Cancel.Size = new System.Drawing.Size(90, 25);
  121. this.c_Cancel.TabIndex = 5;
  122. this.c_Cancel.Text = "Cancel";
  123. //
  124. // label2
  125. //
  126. this.label2.Location = new System.Drawing.Point(173, 43);
  127. this.label2.Name = "label2";
  128. this.label2.Size = new System.Drawing.Size(86, 17);
  129. this.label2.TabIndex = 2;
  130. this.label2.Text = "Erasing time:";
  131. //
  132. // c_ErasingTime
  133. //
  134. this.c_ErasingTime.Location = new System.Drawing.Point(173, 60);
  135. this.c_ErasingTime.Name = "c_ErasingTime";
  136. this.c_ErasingTime.ReadOnly = true;
  137. this.c_ErasingTime.Size = new System.Drawing.Size(77, 21);
  138. this.c_ErasingTime.TabIndex = 3;
  139. this.c_ErasingTime.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
  140. //
  141. // EraseForm
  142. //
  143. this.AcceptButton = this.c_Erase;
  144. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  145. this.CancelButton = this.c_Cancel;
  146. this.ClientSize = new System.Drawing.Size(419, 150);
  147. this.Controls.Add(this.c_ErasingTime);
  148. this.Controls.Add(this.c_Device);
  149. this.Controls.Add(this.c_Erase);
  150. this.Controls.Add(this.label8);
  151. this.Controls.Add(this.c_EraseMode);
  152. this.Controls.Add(this.label1);
  153. this.Controls.Add(this.c_Cancel);
  154. this.Controls.Add(this.label2);
  155. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
  156. this.MaximizeBox = false;
  157. this.MinimizeBox = false;
  158. this.Name = "EraseForm";
  159. this.ShowInTaskbar = false;
  160. this.Text = "Erase";
  161. this.ResumeLayout(false);
  162. this.PerformLayout();
  163. }
  164. #endregion
  165. protected override void OnLoad(EventArgs e)
  166. {
  167. base.OnLoad (e);
  168. c_Device.Text = m_drive.DeviceName;
  169. // Make quick selected by default.
  170. //
  171. c_EraseMode.SelectedIndex = 1;
  172. }
  173. protected void UpdateErasingTime ()
  174. {
  175. // Let's update the erasing time according to the
  176. // method chosen.
  177. //
  178. if (-1 != c_EraseMode.SelectedIndex)
  179. {
  180. // Quick erase is at index 1, while entire is at 0.
  181. //
  182. bool bQuick = c_EraseMode.SelectedIndex != 0;
  183. try
  184. {
  185. // Get the erasing time. The value returned is in seconds.
  186. // Let's convert it to mm:ss.
  187. //
  188. int iSeconds = m_drive.get_CDRWErasingTime (bQuick);
  189. int iMinutes = iSeconds/60;
  190. iSeconds %= 60;
  191. // Format the time with leading zeroes as mm:ss
  192. //
  193. c_ErasingTime.Text = iMinutes.ToString ("00") + ":" + iSeconds.ToString ("00");
  194. c_Erase.Enabled = true;
  195. c_EraseMode.Enabled = true;
  196. }
  197. catch (COMException ex)
  198. {
  199. // If a COM exception occurs, we could not obtain the
  200. // time needed to erase the disc.
  201. //
  202. c_ErasingTime.Text = "";
  203. c_Erase.Enabled = false;
  204. c_EraseMode.Enabled = false;
  205. MessageBox.Show (this, ex.Message );
  206. }
  207. }
  208. else
  209. {
  210. c_ErasingTime.Text = "";
  211. }
  212. }
  213. private void c_EraseMode_SelectedIndexChanged(object sender, System.EventArgs e)
  214. {
  215. // When the erase method is changed, display the new time.
  216. //
  217. UpdateErasingTime ();
  218. }
  219. private void c_Erase_Click(object sender, System.EventArgs e)
  220. {
  221. // When erase is reqested, hide the current form and display
  222. // the erase progress form. ShowDialog will start the actual
  223. // erase process.
  224. //
  225. bool bQuick = c_EraseMode.SelectedIndex != 0;
  226. EraseProgressForm frm = new EraseProgressForm (m_drive, bQuick);
  227. this.Hide ();
  228. frm.ShowDialog (this);
  229. }
  230. }
  231. }