DAE.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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 DAE.
  11. /// </summary>
  12. public class DAEForm : System.Windows.Forms.Form
  13. {
  14. private NeroDrive m_drive;
  15. private _INeroDriveEvents_OnDoneCDInfoEventHandler m_evOnDoneCDInfo;
  16. private ControlEnabler m_controlEnabler;
  17. private System.Windows.Forms.Button c_DAE;
  18. private System.Windows.Forms.Button c_Close;
  19. private System.Windows.Forms.Label label1;
  20. private System.Windows.Forms.ColumnHeader columnHeader1;
  21. private System.Windows.Forms.ColumnHeader columnHeader2;
  22. private System.Windows.Forms.ColumnHeader columnHeader3;
  23. private System.Windows.Forms.ColumnHeader columnHeader4;
  24. private System.Windows.Forms.Button c_Browse;
  25. private System.Windows.Forms.Label label2;
  26. private System.Windows.Forms.Button c_Refresh;
  27. private System.Windows.Forms.ListView c_Tracks;
  28. private System.Windows.Forms.TextBox c_Filename;
  29. /// <summary>
  30. /// Required designer variable.
  31. /// </summary>
  32. private System.ComponentModel.Container components = null;
  33. public DAEForm(NeroDrive drive)
  34. {
  35. //
  36. // Required for Windows Form Designer support
  37. //
  38. InitializeComponent();
  39. m_drive = drive;
  40. m_controlEnabler = new ControlEnabler (this);
  41. }
  42. /// <summary>
  43. /// Clean up any resources being used.
  44. /// </summary>
  45. protected override void Dispose( bool disposing )
  46. {
  47. if( disposing )
  48. {
  49. if(components != null)
  50. {
  51. components.Dispose();
  52. }
  53. }
  54. base.Dispose( disposing );
  55. }
  56. #region Windows Form Designer generated code
  57. /// <summary>
  58. /// Required method for Designer support - do not modify
  59. /// the contents of this method with the code editor.
  60. /// </summary>
  61. private void InitializeComponent()
  62. {
  63. this.c_DAE = new System.Windows.Forms.Button();
  64. this.c_Close = new System.Windows.Forms.Button();
  65. this.label1 = new System.Windows.Forms.Label();
  66. this.c_Tracks = new System.Windows.Forms.ListView();
  67. this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
  68. this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
  69. this.columnHeader3 = new System.Windows.Forms.ColumnHeader();
  70. this.columnHeader4 = new System.Windows.Forms.ColumnHeader();
  71. this.c_Filename = new System.Windows.Forms.TextBox();
  72. this.c_Browse = new System.Windows.Forms.Button();
  73. this.label2 = new System.Windows.Forms.Label();
  74. this.c_Refresh = new System.Windows.Forms.Button();
  75. this.SuspendLayout();
  76. //
  77. // c_DAE
  78. //
  79. this.c_DAE.Location = new System.Drawing.Point(408, 64);
  80. this.c_DAE.Name = "c_DAE";
  81. this.c_DAE.TabIndex = 6;
  82. this.c_DAE.Text = "Do DAE";
  83. this.c_DAE.Click += new System.EventHandler(this.c_DAE_Click);
  84. //
  85. // c_Close
  86. //
  87. this.c_Close.DialogResult = System.Windows.Forms.DialogResult.Cancel;
  88. this.c_Close.Location = new System.Drawing.Point(408, 8);
  89. this.c_Close.Name = "c_Close";
  90. this.c_Close.TabIndex = 7;
  91. this.c_Close.Text = "Close";
  92. //
  93. // label1
  94. //
  95. this.label1.Location = new System.Drawing.Point(8, 8);
  96. this.label1.Name = "label1";
  97. this.label1.Size = new System.Drawing.Size(100, 16);
  98. this.label1.TabIndex = 0;
  99. this.label1.Text = "Audio Tracks:";
  100. //
  101. // c_Tracks
  102. //
  103. this.c_Tracks.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
  104. this.columnHeader1,
  105. this.columnHeader2,
  106. this.columnHeader3,
  107. this.columnHeader4});
  108. this.c_Tracks.FullRowSelect = true;
  109. this.c_Tracks.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
  110. this.c_Tracks.HideSelection = false;
  111. this.c_Tracks.Location = new System.Drawing.Point(8, 24);
  112. this.c_Tracks.MultiSelect = false;
  113. this.c_Tracks.Name = "c_Tracks";
  114. this.c_Tracks.Size = new System.Drawing.Size(392, 128);
  115. this.c_Tracks.TabIndex = 1;
  116. this.c_Tracks.View = System.Windows.Forms.View.Details;
  117. this.c_Tracks.SelectedIndexChanged += new System.EventHandler(this.c_Tracks_SelectedIndexChanged);
  118. //
  119. // columnHeader1
  120. //
  121. this.columnHeader1.Text = "T#";
  122. this.columnHeader1.Width = 35;
  123. //
  124. // columnHeader2
  125. //
  126. this.columnHeader2.Text = "Name";
  127. this.columnHeader2.Width = 184;
  128. //
  129. // columnHeader3
  130. //
  131. this.columnHeader3.Text = "Start block";
  132. this.columnHeader3.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
  133. this.columnHeader3.Width = 76;
  134. //
  135. // columnHeader4
  136. //
  137. this.columnHeader4.Text = "Length";
  138. this.columnHeader4.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
  139. this.columnHeader4.Width = 73;
  140. //
  141. // c_Filename
  142. //
  143. this.c_Filename.Location = new System.Drawing.Point(8, 176);
  144. this.c_Filename.Name = "c_Filename";
  145. this.c_Filename.Size = new System.Drawing.Size(392, 20);
  146. this.c_Filename.TabIndex = 3;
  147. this.c_Filename.Text = "";
  148. this.c_Filename.TextChanged += new System.EventHandler(this.c_Filename_TextChanged);
  149. //
  150. // c_Browse
  151. //
  152. this.c_Browse.Location = new System.Drawing.Point(408, 176);
  153. this.c_Browse.Name = "c_Browse";
  154. this.c_Browse.TabIndex = 4;
  155. this.c_Browse.Text = "Browse";
  156. this.c_Browse.Click += new System.EventHandler(this.c_Browse_Click);
  157. //
  158. // label2
  159. //
  160. this.label2.Location = new System.Drawing.Point(8, 160);
  161. this.label2.Name = "label2";
  162. this.label2.Size = new System.Drawing.Size(100, 16);
  163. this.label2.TabIndex = 2;
  164. this.label2.Text = "Save filename:";
  165. //
  166. // c_Refresh
  167. //
  168. this.c_Refresh.Location = new System.Drawing.Point(408, 96);
  169. this.c_Refresh.Name = "c_Refresh";
  170. this.c_Refresh.TabIndex = 5;
  171. this.c_Refresh.Text = "Refresh";
  172. this.c_Refresh.Click += new System.EventHandler(this.c_Refresh_Click);
  173. //
  174. // DAEForm
  175. //
  176. this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  177. this.CancelButton = this.c_Close;
  178. this.ClientSize = new System.Drawing.Size(488, 206);
  179. this.Controls.Add(this.c_Filename);
  180. this.Controls.Add(this.c_Tracks);
  181. this.Controls.Add(this.label1);
  182. this.Controls.Add(this.c_DAE);
  183. this.Controls.Add(this.c_Close);
  184. this.Controls.Add(this.c_Browse);
  185. this.Controls.Add(this.label2);
  186. this.Controls.Add(this.c_Refresh);
  187. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
  188. this.MaximizeBox = false;
  189. this.MinimizeBox = false;
  190. this.Name = "DAEForm";
  191. this.ShowInTaskbar = false;
  192. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
  193. this.Text = "DAE";
  194. this.ResumeLayout(false);
  195. }
  196. #endregion
  197. protected override void OnLoad(EventArgs e)
  198. {
  199. base.OnLoad (e);
  200. RefreshTracks ();
  201. }
  202. private void c_Refresh_Click(object sender, System.EventArgs e)
  203. {
  204. RefreshTracks ();
  205. }
  206. private void RefreshTracks ()
  207. {
  208. // Subscribe to OnDoneCDInfo event, disable controls and
  209. // show wait cursor. Then do the disc info.
  210. //
  211. m_evOnDoneCDInfo = new _INeroDriveEvents_OnDoneCDInfoEventHandler(m_drive_OnDoneCDInfo);
  212. m_drive.OnDoneCDInfo += m_evOnDoneCDInfo;
  213. m_controlEnabler.EnableAllControls (false);
  214. this.Cursor = Cursors.WaitCursor;
  215. m_drive.CDInfo (0);
  216. }
  217. private void m_drive_OnDoneCDInfo(INeroCDInfo pCDInfo)
  218. {
  219. // Unsubscribe from event and display disc info information.
  220. //
  221. m_drive.OnDoneCDInfo -= m_evOnDoneCDInfo;
  222. c_Tracks.Items.Clear ();
  223. if (pCDInfo != null)
  224. {
  225. foreach (NeroTrack trk in pCDInfo.Tracks)
  226. {
  227. // Display all audio tracks in a list view.
  228. //
  229. if (trk.TrackType == NERO_TRACK_TYPE.NERO_TT_AUDIO)
  230. {
  231. ListViewItem lvi = c_Tracks.Items.Add (trk.TrackNumber.ToString ());
  232. string sArtist = trk.Artist == ""? "Unknown": trk.Artist;
  233. string sTitle = trk.Title == ""? "Unknown": trk.Title;
  234. lvi.SubItems.Add (sArtist + " - " + sTitle);
  235. lvi.SubItems.Add (trk.TrackStartBlk.ToString ());
  236. lvi.SubItems.Add (trk.TrackLengthInBlks.ToString ());
  237. }
  238. }
  239. }
  240. // Restore controls' values and restore the cursor.
  241. //
  242. m_controlEnabler.EnableAllControls (true);
  243. this.Cursor = Cursors.Default;
  244. // Update the state of DAE button.
  245. //
  246. UpdateDAEButton ();
  247. }
  248. private void UpdateDAEButton ()
  249. {
  250. // Enable DAE button if some audio track is selected and a filename
  251. // exists.
  252. //
  253. c_DAE.Enabled = c_Tracks.SelectedIndices.Count > 0 && c_Filename.Text != "";
  254. }
  255. private void c_Tracks_SelectedIndexChanged(object sender, System.EventArgs e)
  256. {
  257. UpdateDAEButton ();
  258. }
  259. private void c_Browse_Click(object sender, System.EventArgs e)
  260. {
  261. SaveFileDialog dlg = new SaveFileDialog ();
  262. dlg.DefaultExt = ".wav";
  263. dlg.Filter = "All files (*.*)|*.*";
  264. if (DialogResult.OK == dlg.ShowDialog (this))
  265. {
  266. c_Filename.Text = dlg.FileName;
  267. UpdateDAEButton ();
  268. }
  269. }
  270. private void c_DAE_Click(object sender, System.EventArgs e)
  271. {
  272. if (c_Tracks.SelectedIndices.Count > 0 &&
  273. c_Filename.Text != "")
  274. {
  275. // Get the start block and block length of the selected audio
  276. // track.
  277. //
  278. ListViewItem lvi = c_Tracks.SelectedItems[0];
  279. int iStartBlock = Convert.ToInt32 (lvi.SubItems[2].Text);
  280. int iLengthInBlocks = Convert.ToInt32 (lvi.SubItems[3].Text);
  281. // Pass the params to DAE progress form and start the process
  282. // by calling ShowDialog.
  283. //
  284. DAEProgressForm frm = new DAEProgressForm (m_drive, iStartBlock, iLengthInBlocks, c_Filename.Text, 0);
  285. frm.ShowDialog ();
  286. }
  287. }
  288. private void c_Filename_TextChanged(object sender, System.EventArgs e)
  289. {
  290. UpdateDAEButton ();
  291. }
  292. }
  293. }