Erase.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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 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(8, 40);
  72. this.label1.Name = "label1";
  73. this.label1.Size = new System.Drawing.Size(72, 16);
  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(8, 56);
  84. this.c_EraseMode.Name = "c_EraseMode";
  85. this.c_EraseMode.Size = new System.Drawing.Size(121, 21);
  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(64, 8);
  92. this.c_Device.Name = "c_Device";
  93. this.c_Device.ReadOnly = true;
  94. this.c_Device.Size = new System.Drawing.Size(208, 20);
  95. this.c_Device.TabIndex = 7;
  96. this.c_Device.Text = "";
  97. //
  98. // label8
  99. //
  100. this.label8.Location = new System.Drawing.Point(8, 8);
  101. this.label8.Name = "label8";
  102. this.label8.Size = new System.Drawing.Size(56, 16);
  103. this.label8.TabIndex = 6;
  104. this.label8.Text = "Device:";
  105. //
  106. // c_Erase
  107. //
  108. this.c_Erase.DialogResult = System.Windows.Forms.DialogResult.OK;
  109. this.c_Erase.Location = new System.Drawing.Point(120, 96);
  110. this.c_Erase.Name = "c_Erase";
  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(200, 96);
  119. this.c_Cancel.Name = "c_Cancel";
  120. this.c_Cancel.TabIndex = 5;
  121. this.c_Cancel.Text = "Cancel";
  122. //
  123. // label2
  124. //
  125. this.label2.Location = new System.Drawing.Point(144, 40);
  126. this.label2.Name = "label2";
  127. this.label2.Size = new System.Drawing.Size(72, 16);
  128. this.label2.TabIndex = 2;
  129. this.label2.Text = "Erasing time:";
  130. //
  131. // c_ErasingTime
  132. //
  133. this.c_ErasingTime.Location = new System.Drawing.Point(144, 56);
  134. this.c_ErasingTime.Name = "c_ErasingTime";
  135. this.c_ErasingTime.ReadOnly = true;
  136. this.c_ErasingTime.Size = new System.Drawing.Size(64, 20);
  137. this.c_ErasingTime.TabIndex = 3;
  138. this.c_ErasingTime.Text = "";
  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(5, 13);
  145. this.CancelButton = this.c_Cancel;
  146. this.ClientSize = new System.Drawing.Size(282, 128);
  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. }
  163. #endregion
  164. protected override void OnLoad(EventArgs e)
  165. {
  166. base.OnLoad (e);
  167. c_Device.Text = m_drive.DeviceName;
  168. // Make quick selected by default.
  169. //
  170. c_EraseMode.SelectedIndex = 1;
  171. }
  172. protected void UpdateErasingTime ()
  173. {
  174. // Let's update the erasing time according to the
  175. // method chosen.
  176. //
  177. if (-1 != c_EraseMode.SelectedIndex)
  178. {
  179. // Quick erase is at index 1, while entire is at 0.
  180. //
  181. bool bQuick = c_EraseMode.SelectedIndex != 0;
  182. try
  183. {
  184. // Get the erasing time. The value returned is in seconds.
  185. // Let's convert it to mm:ss.
  186. //
  187. int iSeconds = m_drive.get_CDRWErasingTime (bQuick);
  188. int iMinutes = iSeconds/60;
  189. iSeconds %= 60;
  190. // Format the time with leading zeroes as mm:ss
  191. //
  192. c_ErasingTime.Text = iMinutes.ToString ("00") + ":" + iSeconds.ToString ("00");
  193. c_Erase.Enabled = true;
  194. c_EraseMode.Enabled = true;
  195. }
  196. catch (COMException ex)
  197. {
  198. // If a COM exception occurs, we could not obtain the
  199. // time needed to erase the disc.
  200. //
  201. c_ErasingTime.Text = "";
  202. c_Erase.Enabled = false;
  203. c_EraseMode.Enabled = false;
  204. MessageBox.Show (this, ex.Message );
  205. }
  206. }
  207. else
  208. {
  209. c_ErasingTime.Text = "";
  210. }
  211. }
  212. private void c_EraseMode_SelectedIndexChanged(object sender, System.EventArgs e)
  213. {
  214. // When the erase method is changed, display the new time.
  215. //
  216. UpdateErasingTime ();
  217. }
  218. private void c_Erase_Click(object sender, System.EventArgs e)
  219. {
  220. // When erase is reqested, hide the current form and display
  221. // the erase progress form. ShowDialog will start the actual
  222. // erase process.
  223. //
  224. bool bQuick = c_EraseMode.SelectedIndex != 0;
  225. EraseProgressForm frm = new EraseProgressForm (m_drive, bQuick);
  226. this.Hide ();
  227. frm.ShowDialog (this);
  228. }
  229. }
  230. }