BurnImage.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6. using NEROLib;
  7. namespace LYFZ.NeroDiscBurn.NET
  8. {
  9. /// <summary>
  10. /// Summary description for BurnImage.
  11. /// </summary>
  12. public class BurnImageForm : System.Windows.Forms.Form
  13. {
  14. private NeroDrive m_drive;
  15. private Nero m_nero;
  16. private ChooseBurnFlagsForm m_frmChooseBurnFlags;
  17. private ChooseMediaForm m_frmChooseMedia;
  18. private ChooseSpeedForm m_frmChooseWriteSpeed;
  19. private System.Windows.Forms.TextBox c_ImageFilename;
  20. private System.Windows.Forms.Label label1;
  21. private System.Windows.Forms.Button c_Browse;
  22. private System.Windows.Forms.TextBox c_Device;
  23. private System.Windows.Forms.Label label8;
  24. private System.Windows.Forms.Button c_Burn;
  25. private System.Windows.Forms.Button c_Cancel;
  26. private System.Windows.Forms.Button c_ChooseBurnFlags;
  27. private System.Windows.Forms.Button c_ChooseWriteSpeed;
  28. private System.Windows.Forms.Button c_MediaType;
  29. private System.Windows.Forms.TextBox c_Settings;
  30. private System.Windows.Forms.Label label2;
  31. /// <summary>
  32. /// Required designer variable.
  33. /// </summary>
  34. private System.ComponentModel.Container components = null;
  35. public BurnImageForm(NeroDrive drive, Nero nero)
  36. {
  37. //
  38. // Required for Windows Form Designer support
  39. //
  40. InitializeComponent();
  41. m_drive = drive;
  42. m_nero = nero;
  43. m_frmChooseBurnFlags = new ChooseBurnFlagsForm ();
  44. m_frmChooseMedia = new ChooseMediaForm (m_nero);
  45. m_frmChooseWriteSpeed = new ChooseSpeedForm (m_drive, true);
  46. }
  47. /// <summary>
  48. /// Clean up any resources being used.
  49. /// </summary>
  50. protected override void Dispose( bool disposing )
  51. {
  52. if( disposing )
  53. {
  54. if(components != null)
  55. {
  56. components.Dispose();
  57. }
  58. }
  59. base.Dispose( disposing );
  60. }
  61. #region Windows Form Designer generated code
  62. /// <summary>
  63. /// Required method for Designer support - do not modify
  64. /// the contents of this method with the code editor.
  65. /// </summary>
  66. private void InitializeComponent()
  67. {
  68. this.c_ImageFilename = new System.Windows.Forms.TextBox();
  69. this.label1 = new System.Windows.Forms.Label();
  70. this.c_Browse = new System.Windows.Forms.Button();
  71. this.c_Device = new System.Windows.Forms.TextBox();
  72. this.label8 = new System.Windows.Forms.Label();
  73. this.c_Burn = new System.Windows.Forms.Button();
  74. this.c_Cancel = new System.Windows.Forms.Button();
  75. this.c_ChooseBurnFlags = new System.Windows.Forms.Button();
  76. this.c_ChooseWriteSpeed = new System.Windows.Forms.Button();
  77. this.c_MediaType = new System.Windows.Forms.Button();
  78. this.c_Settings = new System.Windows.Forms.TextBox();
  79. this.label2 = new System.Windows.Forms.Label();
  80. this.SuspendLayout();
  81. //
  82. // c_ImageFilename
  83. //
  84. this.c_ImageFilename.Location = new System.Drawing.Point(8, 88);
  85. this.c_ImageFilename.Name = "c_ImageFilename";
  86. this.c_ImageFilename.Size = new System.Drawing.Size(288, 20);
  87. this.c_ImageFilename.TabIndex = 1;
  88. this.c_ImageFilename.Text = "";
  89. this.c_ImageFilename.TextChanged += new System.EventHandler(this.c_ImageFilename_TextChanged);
  90. //
  91. // label1
  92. //
  93. this.label1.Location = new System.Drawing.Point(8, 72);
  94. this.label1.Name = "label1";
  95. this.label1.Size = new System.Drawing.Size(88, 16);
  96. this.label1.TabIndex = 0;
  97. this.label1.Text = "Image filename:";
  98. //
  99. // c_Browse
  100. //
  101. this.c_Browse.Location = new System.Drawing.Point(304, 88);
  102. this.c_Browse.Name = "c_Browse";
  103. this.c_Browse.TabIndex = 2;
  104. this.c_Browse.Text = "Browse";
  105. this.c_Browse.Click += new System.EventHandler(this.c_Browse_Click);
  106. //
  107. // c_Device
  108. //
  109. this.c_Device.Location = new System.Drawing.Point(8, 24);
  110. this.c_Device.Name = "c_Device";
  111. this.c_Device.ReadOnly = true;
  112. this.c_Device.Size = new System.Drawing.Size(208, 20);
  113. this.c_Device.TabIndex = 9;
  114. this.c_Device.Text = "";
  115. //
  116. // label8
  117. //
  118. this.label8.Location = new System.Drawing.Point(8, 8);
  119. this.label8.Name = "label8";
  120. this.label8.Size = new System.Drawing.Size(56, 16);
  121. this.label8.TabIndex = 8;
  122. this.label8.Text = "Device:";
  123. //
  124. // c_Burn
  125. //
  126. this.c_Burn.DialogResult = System.Windows.Forms.DialogResult.OK;
  127. this.c_Burn.Location = new System.Drawing.Point(304, 8);
  128. this.c_Burn.Name = "c_Burn";
  129. this.c_Burn.TabIndex = 10;
  130. this.c_Burn.Text = "Burn";
  131. this.c_Burn.Click += new System.EventHandler(this.c_Burn_Click);
  132. //
  133. // c_Cancel
  134. //
  135. this.c_Cancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
  136. this.c_Cancel.Location = new System.Drawing.Point(304, 40);
  137. this.c_Cancel.Name = "c_Cancel";
  138. this.c_Cancel.TabIndex = 11;
  139. this.c_Cancel.Text = "Cancel";
  140. //
  141. // c_ChooseBurnFlags
  142. //
  143. this.c_ChooseBurnFlags.Location = new System.Drawing.Point(304, 136);
  144. this.c_ChooseBurnFlags.Name = "c_ChooseBurnFlags";
  145. this.c_ChooseBurnFlags.TabIndex = 5;
  146. this.c_ChooseBurnFlags.Text = "Burn Flags";
  147. this.c_ChooseBurnFlags.Click += new System.EventHandler(this.c_ChooseBurnFlags_Click);
  148. //
  149. // c_ChooseWriteSpeed
  150. //
  151. this.c_ChooseWriteSpeed.Location = new System.Drawing.Point(304, 168);
  152. this.c_ChooseWriteSpeed.Name = "c_ChooseWriteSpeed";
  153. this.c_ChooseWriteSpeed.TabIndex = 6;
  154. this.c_ChooseWriteSpeed.Text = "Write Speed";
  155. this.c_ChooseWriteSpeed.Click += new System.EventHandler(this.c_ChooseWriteSpeed_Click);
  156. //
  157. // c_MediaType
  158. //
  159. this.c_MediaType.Location = new System.Drawing.Point(304, 200);
  160. this.c_MediaType.Name = "c_MediaType";
  161. this.c_MediaType.TabIndex = 7;
  162. this.c_MediaType.Text = "Media Type";
  163. this.c_MediaType.Click += new System.EventHandler(this.c_MediaType_Click);
  164. //
  165. // c_Settings
  166. //
  167. this.c_Settings.Location = new System.Drawing.Point(8, 128);
  168. this.c_Settings.Multiline = true;
  169. this.c_Settings.Name = "c_Settings";
  170. this.c_Settings.ReadOnly = true;
  171. this.c_Settings.Size = new System.Drawing.Size(288, 96);
  172. this.c_Settings.TabIndex = 4;
  173. this.c_Settings.Text = "";
  174. //
  175. // label2
  176. //
  177. this.label2.Location = new System.Drawing.Point(8, 112);
  178. this.label2.Name = "label2";
  179. this.label2.Size = new System.Drawing.Size(88, 16);
  180. this.label2.TabIndex = 3;
  181. this.label2.Text = "Settings:";
  182. //
  183. // BurnImageForm
  184. //
  185. this.AcceptButton = this.c_Burn;
  186. this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  187. this.CancelButton = this.c_Cancel;
  188. this.ClientSize = new System.Drawing.Size(386, 232);
  189. this.Controls.Add(this.c_Settings);
  190. this.Controls.Add(this.c_Cancel);
  191. this.Controls.Add(this.c_Burn);
  192. this.Controls.Add(this.c_Device);
  193. this.Controls.Add(this.c_ImageFilename);
  194. this.Controls.Add(this.label8);
  195. this.Controls.Add(this.c_Browse);
  196. this.Controls.Add(this.label1);
  197. this.Controls.Add(this.c_ChooseBurnFlags);
  198. this.Controls.Add(this.c_ChooseWriteSpeed);
  199. this.Controls.Add(this.c_MediaType);
  200. this.Controls.Add(this.label2);
  201. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
  202. this.MaximizeBox = false;
  203. this.MinimizeBox = false;
  204. this.Name = "BurnImageForm";
  205. this.ShowInTaskbar = false;
  206. this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
  207. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
  208. this.Text = "BurnImage";
  209. this.ResumeLayout(false);
  210. }
  211. #endregion
  212. protected override void OnLoad(EventArgs e)
  213. {
  214. base.OnLoad (e);
  215. // Update GUI on load.
  216. //
  217. c_Device.Text = m_drive.DeviceName;
  218. UpdateBurnButton ();
  219. UpdateSettings ();
  220. }
  221. private void c_Browse_Click(object sender, System.EventArgs e)
  222. {
  223. // Open the file dialog asking for an image filename.
  224. //
  225. OpenFileDialog dlg = new OpenFileDialog ();
  226. dlg.CheckFileExists = true;
  227. dlg.CheckPathExists = true;
  228. dlg.DefaultExt = ".nrg";
  229. dlg.FileName = c_ImageFilename.Text;
  230. dlg.Filter = "All image files|*.nrg;*.iso|NRG files (*.nrg)|*.nrg|ISO files (*.iso)|*.iso|All files (*.*)|*.*";
  231. if (DialogResult.OK == dlg.ShowDialog (this))
  232. {
  233. c_ImageFilename.Text = dlg.FileName;
  234. UpdateBurnButton ();
  235. }
  236. }
  237. private void UpdateBurnButton ()
  238. {
  239. // Enable the burn button if image filename is not
  240. // empty.
  241. //
  242. bool bEnable = c_ImageFilename.Text != "";
  243. c_Burn.Enabled = bEnable;
  244. }
  245. private void c_ImageFilename_TextChanged(object sender, System.EventArgs e)
  246. {
  247. // When image filename is chaned by typing, update
  248. // the burn button as well.
  249. //
  250. UpdateBurnButton ();
  251. }
  252. private void c_Burn_Click(object sender, System.EventArgs e)
  253. {
  254. // When burning is requested, just do it. Pass all
  255. // the params.
  256. //
  257. BurnProgressForm frm = new BurnProgressForm (m_drive, m_nero);
  258. frm.BurnImage (c_ImageFilename.Text,
  259. m_frmChooseBurnFlags.GetBurnFlags (),
  260. m_frmChooseWriteSpeed.GetSpeed (),
  261. m_frmChooseMedia.GetMediaType (),
  262. this);
  263. }
  264. private void UpdateSettings ()
  265. {
  266. c_Settings.Text = "Burn flags: " + m_frmChooseBurnFlags.ToString () + "\r\n\r\n"
  267. + "Write speed: " + m_frmChooseWriteSpeed.ToString () + "\r\n\r\n"
  268. + "Media types: " + m_frmChooseMedia.ToString ();
  269. }
  270. private void c_ChooseBurnFlags_Click(object sender, System.EventArgs e)
  271. {
  272. if (DialogResult.OK == m_frmChooseBurnFlags.ShowDialog (this))
  273. {
  274. UpdateSettings ();
  275. }
  276. }
  277. private void c_ChooseWriteSpeed_Click(object sender, System.EventArgs e)
  278. {
  279. if (DialogResult.OK == m_frmChooseWriteSpeed.ShowDialog (this))
  280. {
  281. UpdateSettings ();
  282. }
  283. }
  284. private void c_MediaType_Click(object sender, System.EventArgs e)
  285. {
  286. if (DialogResult.OK == m_frmChooseMedia.ShowDialog (this))
  287. {
  288. UpdateSettings ();
  289. }
  290. }
  291. }
  292. }