BurnIsoAudio.cs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950
  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6. using NEROLib;
  7. using System.IO;
  8. namespace NeroFiddlesCOM.NET
  9. {
  10. /// <summary>
  11. /// Summary description for BurnIsoAudioForm.
  12. /// </summary>
  13. public class BurnIsoAudioForm : System.Windows.Forms.Form
  14. {
  15. private NeroDrive m_drive;
  16. private Nero m_nero;
  17. private NeroAudioTrack[] m_audioTracks;
  18. private int m_iAudioFile;
  19. private FileStream m_fs;
  20. private bool m_bError;
  21. private bool m_bEof;
  22. private ChooseBurnFlagsForm m_frmChooseBurnFlags;
  23. private ChooseSessionForm m_frmChooseSession;
  24. private ChooseSpeedForm m_frmChooseWriteSpeed;
  25. private ChooseMediaForm m_frmChooseMedia;
  26. private _INeroDriveEvents_OnDoneImport2EventHandler m_evOnDoneImport2;
  27. private System.Windows.Forms.Button c_Burn;
  28. private System.Windows.Forms.Button c_Cancel;
  29. private System.Windows.Forms.TextBox c_Device;
  30. private System.Windows.Forms.Label label8;
  31. private System.Windows.Forms.ListView c_FilesAndFolders;
  32. private System.Windows.Forms.Label label1;
  33. private System.Windows.Forms.Button c_AddFiles;
  34. private System.Windows.Forms.Button c_AddFolders;
  35. private System.Windows.Forms.Button c_RemoveFilesAndFolders;
  36. private System.Windows.Forms.Label label2;
  37. private System.Windows.Forms.Button c_AddAudioFiles;
  38. private System.Windows.Forms.Button c_RemoveAudioFiles;
  39. private System.Windows.Forms.ListView c_AudioFiles;
  40. private System.Windows.Forms.TextBox c_Title;
  41. private System.Windows.Forms.Label label3;
  42. private System.Windows.Forms.Label label4;
  43. private System.Windows.Forms.TextBox c_Artist;
  44. private System.Windows.Forms.ColumnHeader columnHeader5;
  45. private System.Windows.Forms.ColumnHeader columnHeader6;
  46. private System.Windows.Forms.Label label7;
  47. private System.Windows.Forms.TextBox c_ISOVolumeName;
  48. private System.Windows.Forms.Button c_ChangeBurnFlags;
  49. private System.Windows.Forms.TextBox c_TextSettings;
  50. private System.Windows.Forms.Button c_ChooseSession;
  51. private System.Windows.Forms.Button c_WriteSpeed;
  52. private System.Windows.Forms.Button c_ChooseMedia;
  53. private System.Windows.Forms.Button c_EstimateTrackSize;
  54. private System.Windows.Forms.Label label5;
  55. private System.Windows.Forms.CheckBox c_UseEvent;
  56. /// <summary>
  57. /// Required designer variable.
  58. /// </summary>
  59. private System.ComponentModel.Container components = null;
  60. public BurnIsoAudioForm(NeroDrive drive, Nero nero)
  61. {
  62. //
  63. // Required for Windows Form Designer support
  64. //
  65. InitializeComponent();
  66. m_drive = drive;
  67. m_nero = nero;
  68. m_frmChooseBurnFlags = new ChooseBurnFlagsForm ();
  69. m_frmChooseSession = new ChooseSessionForm (m_drive);
  70. m_frmChooseWriteSpeed = new ChooseSpeedForm (m_drive, true);
  71. m_frmChooseMedia = new ChooseMediaForm (m_nero);
  72. }
  73. /// <summary>
  74. /// Clean up any resources being used.
  75. /// </summary>
  76. protected override void Dispose( bool disposing )
  77. {
  78. if( disposing )
  79. {
  80. if(components != null)
  81. {
  82. components.Dispose();
  83. }
  84. }
  85. base.Dispose( disposing );
  86. }
  87. #region Windows Form Designer generated code
  88. /// <summary>
  89. /// Required method for Designer support - do not modify
  90. /// the contents of this method with the code editor.
  91. /// </summary>
  92. private void InitializeComponent()
  93. {
  94. this.c_Burn = new System.Windows.Forms.Button();
  95. this.c_Cancel = new System.Windows.Forms.Button();
  96. this.c_Device = new System.Windows.Forms.TextBox();
  97. this.label8 = new System.Windows.Forms.Label();
  98. this.c_FilesAndFolders = new System.Windows.Forms.ListView();
  99. this.columnHeader5 = new System.Windows.Forms.ColumnHeader();
  100. this.label1 = new System.Windows.Forms.Label();
  101. this.c_AddFiles = new System.Windows.Forms.Button();
  102. this.c_AddFolders = new System.Windows.Forms.Button();
  103. this.c_RemoveFilesAndFolders = new System.Windows.Forms.Button();
  104. this.label2 = new System.Windows.Forms.Label();
  105. this.c_AddAudioFiles = new System.Windows.Forms.Button();
  106. this.c_RemoveAudioFiles = new System.Windows.Forms.Button();
  107. this.c_AudioFiles = new System.Windows.Forms.ListView();
  108. this.columnHeader6 = new System.Windows.Forms.ColumnHeader();
  109. this.c_Title = new System.Windows.Forms.TextBox();
  110. this.label3 = new System.Windows.Forms.Label();
  111. this.label4 = new System.Windows.Forms.Label();
  112. this.c_Artist = new System.Windows.Forms.TextBox();
  113. this.label7 = new System.Windows.Forms.Label();
  114. this.c_ISOVolumeName = new System.Windows.Forms.TextBox();
  115. this.c_ChangeBurnFlags = new System.Windows.Forms.Button();
  116. this.c_TextSettings = new System.Windows.Forms.TextBox();
  117. this.c_ChooseSession = new System.Windows.Forms.Button();
  118. this.c_WriteSpeed = new System.Windows.Forms.Button();
  119. this.c_ChooseMedia = new System.Windows.Forms.Button();
  120. this.c_EstimateTrackSize = new System.Windows.Forms.Button();
  121. this.label5 = new System.Windows.Forms.Label();
  122. this.c_UseEvent = new System.Windows.Forms.CheckBox();
  123. this.SuspendLayout();
  124. //
  125. // c_Burn
  126. //
  127. this.c_Burn.Location = new System.Drawing.Point(464, 8);
  128. this.c_Burn.Name = "c_Burn";
  129. this.c_Burn.TabIndex = 25;
  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(464, 40);
  137. this.c_Cancel.Name = "c_Cancel";
  138. this.c_Cancel.TabIndex = 26;
  139. this.c_Cancel.Text = "Cancel";
  140. //
  141. // c_Device
  142. //
  143. this.c_Device.Location = new System.Drawing.Point(64, 8);
  144. this.c_Device.Name = "c_Device";
  145. this.c_Device.ReadOnly = true;
  146. this.c_Device.Size = new System.Drawing.Size(248, 20);
  147. this.c_Device.TabIndex = 24;
  148. this.c_Device.Text = "";
  149. //
  150. // label8
  151. //
  152. this.label8.Location = new System.Drawing.Point(8, 8);
  153. this.label8.Name = "label8";
  154. this.label8.Size = new System.Drawing.Size(56, 16);
  155. this.label8.TabIndex = 23;
  156. this.label8.Text = "Device:";
  157. //
  158. // c_FilesAndFolders
  159. //
  160. this.c_FilesAndFolders.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
  161. this.columnHeader5});
  162. this.c_FilesAndFolders.FullRowSelect = true;
  163. this.c_FilesAndFolders.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
  164. this.c_FilesAndFolders.HideSelection = false;
  165. this.c_FilesAndFolders.Location = new System.Drawing.Point(8, 96);
  166. this.c_FilesAndFolders.Name = "c_FilesAndFolders";
  167. this.c_FilesAndFolders.Size = new System.Drawing.Size(216, 136);
  168. this.c_FilesAndFolders.TabIndex = 7;
  169. this.c_FilesAndFolders.View = System.Windows.Forms.View.Details;
  170. //
  171. // columnHeader5
  172. //
  173. this.columnHeader5.Text = "File or folder";
  174. this.columnHeader5.Width = 194;
  175. //
  176. // label1
  177. //
  178. this.label1.Location = new System.Drawing.Point(8, 80);
  179. this.label1.Name = "label1";
  180. this.label1.Size = new System.Drawing.Size(192, 16);
  181. this.label1.TabIndex = 6;
  182. this.label1.Text = "Files and folders to burn in ISO track:";
  183. //
  184. // c_AddFiles
  185. //
  186. this.c_AddFiles.Location = new System.Drawing.Point(8, 240);
  187. this.c_AddFiles.Name = "c_AddFiles";
  188. this.c_AddFiles.Size = new System.Drawing.Size(64, 23);
  189. this.c_AddFiles.TabIndex = 11;
  190. this.c_AddFiles.Text = "Add files";
  191. this.c_AddFiles.Click += new System.EventHandler(this.c_AddFiles_Click);
  192. //
  193. // c_AddFolders
  194. //
  195. this.c_AddFolders.Location = new System.Drawing.Point(80, 240);
  196. this.c_AddFolders.Name = "c_AddFolders";
  197. this.c_AddFolders.Size = new System.Drawing.Size(64, 23);
  198. this.c_AddFolders.TabIndex = 12;
  199. this.c_AddFolders.Text = "Add folders";
  200. this.c_AddFolders.Click += new System.EventHandler(this.c_AddFolders_Click);
  201. //
  202. // c_RemoveFilesAndFolders
  203. //
  204. this.c_RemoveFilesAndFolders.Location = new System.Drawing.Point(152, 240);
  205. this.c_RemoveFilesAndFolders.Name = "c_RemoveFilesAndFolders";
  206. this.c_RemoveFilesAndFolders.Size = new System.Drawing.Size(72, 23);
  207. this.c_RemoveFilesAndFolders.TabIndex = 13;
  208. this.c_RemoveFilesAndFolders.Text = "Remove";
  209. this.c_RemoveFilesAndFolders.Click += new System.EventHandler(this.c_RemoveFilesAndFolders_Click);
  210. //
  211. // label2
  212. //
  213. this.label2.Location = new System.Drawing.Point(232, 80);
  214. this.label2.Name = "label2";
  215. this.label2.Size = new System.Drawing.Size(192, 16);
  216. this.label2.TabIndex = 8;
  217. this.label2.Text = "Audio files to burn:";
  218. //
  219. // c_AddAudioFiles
  220. //
  221. this.c_AddAudioFiles.Location = new System.Drawing.Point(232, 240);
  222. this.c_AddAudioFiles.Name = "c_AddAudioFiles";
  223. this.c_AddAudioFiles.Size = new System.Drawing.Size(72, 23);
  224. this.c_AddAudioFiles.TabIndex = 14;
  225. this.c_AddAudioFiles.Text = "Add audio";
  226. this.c_AddAudioFiles.Click += new System.EventHandler(this.c_AddAudioFiles_Click);
  227. //
  228. // c_RemoveAudioFiles
  229. //
  230. this.c_RemoveAudioFiles.Location = new System.Drawing.Point(312, 240);
  231. this.c_RemoveAudioFiles.Name = "c_RemoveAudioFiles";
  232. this.c_RemoveAudioFiles.TabIndex = 15;
  233. this.c_RemoveAudioFiles.Text = "Remove";
  234. this.c_RemoveAudioFiles.Click += new System.EventHandler(this.c_RemoveAudioFiles_Click);
  235. //
  236. // c_AudioFiles
  237. //
  238. this.c_AudioFiles.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
  239. this.columnHeader6});
  240. this.c_AudioFiles.FullRowSelect = true;
  241. this.c_AudioFiles.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
  242. this.c_AudioFiles.HideSelection = false;
  243. this.c_AudioFiles.Location = new System.Drawing.Point(232, 96);
  244. this.c_AudioFiles.Name = "c_AudioFiles";
  245. this.c_AudioFiles.Size = new System.Drawing.Size(200, 112);
  246. this.c_AudioFiles.TabIndex = 9;
  247. this.c_AudioFiles.View = System.Windows.Forms.View.Details;
  248. //
  249. // columnHeader6
  250. //
  251. this.columnHeader6.Text = "Audio file";
  252. this.columnHeader6.Width = 177;
  253. //
  254. // c_Title
  255. //
  256. this.c_Title.Location = new System.Drawing.Point(336, 56);
  257. this.c_Title.Name = "c_Title";
  258. this.c_Title.Size = new System.Drawing.Size(96, 20);
  259. this.c_Title.TabIndex = 5;
  260. this.c_Title.Text = "";
  261. //
  262. // label3
  263. //
  264. this.label3.Location = new System.Drawing.Point(336, 40);
  265. this.label3.Name = "label3";
  266. this.label3.Size = new System.Drawing.Size(100, 16);
  267. this.label3.TabIndex = 4;
  268. this.label3.Text = "Title:";
  269. //
  270. // label4
  271. //
  272. this.label4.Location = new System.Drawing.Point(240, 40);
  273. this.label4.Name = "label4";
  274. this.label4.Size = new System.Drawing.Size(72, 16);
  275. this.label4.TabIndex = 2;
  276. this.label4.Text = "Artist:";
  277. //
  278. // c_Artist
  279. //
  280. this.c_Artist.Location = new System.Drawing.Point(232, 56);
  281. this.c_Artist.Name = "c_Artist";
  282. this.c_Artist.Size = new System.Drawing.Size(96, 20);
  283. this.c_Artist.TabIndex = 3;
  284. this.c_Artist.Text = "";
  285. //
  286. // label7
  287. //
  288. this.label7.Location = new System.Drawing.Point(8, 40);
  289. this.label7.Name = "label7";
  290. this.label7.Size = new System.Drawing.Size(112, 16);
  291. this.label7.TabIndex = 0;
  292. this.label7.Text = "ISO Volume Name:";
  293. //
  294. // c_ISOVolumeName
  295. //
  296. this.c_ISOVolumeName.Location = new System.Drawing.Point(8, 56);
  297. this.c_ISOVolumeName.Name = "c_ISOVolumeName";
  298. this.c_ISOVolumeName.Size = new System.Drawing.Size(112, 20);
  299. this.c_ISOVolumeName.TabIndex = 1;
  300. this.c_ISOVolumeName.Text = "Test";
  301. //
  302. // c_ChangeBurnFlags
  303. //
  304. this.c_ChangeBurnFlags.Location = new System.Drawing.Point(440, 96);
  305. this.c_ChangeBurnFlags.Name = "c_ChangeBurnFlags";
  306. this.c_ChangeBurnFlags.Size = new System.Drawing.Size(96, 23);
  307. this.c_ChangeBurnFlags.TabIndex = 18;
  308. this.c_ChangeBurnFlags.Text = "Burn Flags";
  309. this.c_ChangeBurnFlags.Click += new System.EventHandler(this.c_ChangeBurnFlags_Click);
  310. //
  311. // c_TextSettings
  312. //
  313. this.c_TextSettings.Location = new System.Drawing.Point(8, 288);
  314. this.c_TextSettings.Multiline = true;
  315. this.c_TextSettings.Name = "c_TextSettings";
  316. this.c_TextSettings.ReadOnly = true;
  317. this.c_TextSettings.ScrollBars = System.Windows.Forms.ScrollBars.Both;
  318. this.c_TextSettings.Size = new System.Drawing.Size(424, 128);
  319. this.c_TextSettings.TabIndex = 17;
  320. this.c_TextSettings.Text = "";
  321. //
  322. // c_ChooseSession
  323. //
  324. this.c_ChooseSession.Location = new System.Drawing.Point(440, 128);
  325. this.c_ChooseSession.Name = "c_ChooseSession";
  326. this.c_ChooseSession.Size = new System.Drawing.Size(96, 23);
  327. this.c_ChooseSession.TabIndex = 19;
  328. this.c_ChooseSession.Text = "Choose Session";
  329. this.c_ChooseSession.Click += new System.EventHandler(this.c_ChooseSession_Click);
  330. //
  331. // c_WriteSpeed
  332. //
  333. this.c_WriteSpeed.Location = new System.Drawing.Point(440, 160);
  334. this.c_WriteSpeed.Name = "c_WriteSpeed";
  335. this.c_WriteSpeed.Size = new System.Drawing.Size(96, 23);
  336. this.c_WriteSpeed.TabIndex = 20;
  337. this.c_WriteSpeed.Text = "Write speed";
  338. this.c_WriteSpeed.Click += new System.EventHandler(this.c_WriteSpeed_Click);
  339. //
  340. // c_ChooseMedia
  341. //
  342. this.c_ChooseMedia.Location = new System.Drawing.Point(440, 192);
  343. this.c_ChooseMedia.Name = "c_ChooseMedia";
  344. this.c_ChooseMedia.Size = new System.Drawing.Size(96, 23);
  345. this.c_ChooseMedia.TabIndex = 21;
  346. this.c_ChooseMedia.Text = "Choose Media";
  347. this.c_ChooseMedia.Click += new System.EventHandler(this.c_ChooseMedia_Click);
  348. //
  349. // c_EstimateTrackSize
  350. //
  351. this.c_EstimateTrackSize.Location = new System.Drawing.Point(440, 240);
  352. this.c_EstimateTrackSize.Name = "c_EstimateTrackSize";
  353. this.c_EstimateTrackSize.Size = new System.Drawing.Size(96, 24);
  354. this.c_EstimateTrackSize.TabIndex = 22;
  355. this.c_EstimateTrackSize.Text = "Estimate Size";
  356. this.c_EstimateTrackSize.Click += new System.EventHandler(this.c_EstimateTrackSize_Click);
  357. //
  358. // label5
  359. //
  360. this.label5.Location = new System.Drawing.Point(8, 272);
  361. this.label5.Name = "label5";
  362. this.label5.Size = new System.Drawing.Size(100, 16);
  363. this.label5.TabIndex = 16;
  364. this.label5.Text = "Settings:";
  365. //
  366. // c_UseEvent
  367. //
  368. this.c_UseEvent.Location = new System.Drawing.Point(232, 216);
  369. this.c_UseEvent.Name = "c_UseEvent";
  370. this.c_UseEvent.Size = new System.Drawing.Size(200, 16);
  371. this.c_UseEvent.TabIndex = 10;
  372. this.c_UseEvent.Text = "Use event (use RAW files only)";
  373. //
  374. // BurnIsoAudioForm
  375. //
  376. this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  377. this.CancelButton = this.c_Cancel;
  378. this.ClientSize = new System.Drawing.Size(546, 424);
  379. this.Controls.Add(this.c_UseEvent);
  380. this.Controls.Add(this.label5);
  381. this.Controls.Add(this.c_TextSettings);
  382. this.Controls.Add(this.c_Title);
  383. this.Controls.Add(this.c_Device);
  384. this.Controls.Add(this.c_Artist);
  385. this.Controls.Add(this.c_ISOVolumeName);
  386. this.Controls.Add(this.c_ChangeBurnFlags);
  387. this.Controls.Add(this.label3);
  388. this.Controls.Add(this.c_AddFiles);
  389. this.Controls.Add(this.label1);
  390. this.Controls.Add(this.c_FilesAndFolders);
  391. this.Controls.Add(this.label8);
  392. this.Controls.Add(this.c_Cancel);
  393. this.Controls.Add(this.c_Burn);
  394. this.Controls.Add(this.c_AddFolders);
  395. this.Controls.Add(this.c_RemoveFilesAndFolders);
  396. this.Controls.Add(this.label2);
  397. this.Controls.Add(this.c_AddAudioFiles);
  398. this.Controls.Add(this.c_RemoveAudioFiles);
  399. this.Controls.Add(this.c_AudioFiles);
  400. this.Controls.Add(this.label4);
  401. this.Controls.Add(this.label7);
  402. this.Controls.Add(this.c_ChooseSession);
  403. this.Controls.Add(this.c_WriteSpeed);
  404. this.Controls.Add(this.c_ChooseMedia);
  405. this.Controls.Add(this.c_EstimateTrackSize);
  406. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
  407. this.MaximizeBox = false;
  408. this.MinimizeBox = false;
  409. this.Name = "BurnIsoAudioForm";
  410. this.ShowInTaskbar = false;
  411. this.Text = "BurnIsoAudio";
  412. this.ResumeLayout(false);
  413. }
  414. #endregion
  415. protected override void OnLoad(EventArgs e)
  416. {
  417. base.OnLoad (e);
  418. c_Device.Text = m_drive.DeviceName;
  419. UpdateSettings ();
  420. }
  421. private void c_AddFiles_Click(object sender, System.EventArgs e)
  422. {
  423. // When adding files, show the open file dialog.
  424. //
  425. OpenFileDialog dlg = new OpenFileDialog ();
  426. dlg.CheckFileExists = true;
  427. dlg.CheckPathExists = true;
  428. dlg.Multiselect = true;
  429. dlg.Filter = "All files (*.*)|*.*";
  430. if (DialogResult.OK == dlg.ShowDialog (this))
  431. {
  432. // We allowed multiple selection, so put all
  433. // filenames in the list view.
  434. //
  435. foreach (string sFilename in dlg.FileNames)
  436. {
  437. c_FilesAndFolders.Items.Add (sFilename);
  438. }
  439. }
  440. }
  441. // This is a helper function that removes all selected
  442. // items in a list view.
  443. //
  444. private void RemoveSelected (ListView lv)
  445. {
  446. foreach (ListViewItem lvi in lv.SelectedItems)
  447. {
  448. lv.Items.Remove (lvi);
  449. }
  450. }
  451. private void c_RemoveFilesAndFolders_Click(object sender, System.EventArgs e)
  452. {
  453. RemoveSelected (c_FilesAndFolders);
  454. }
  455. private void c_RemoveAudioFiles_Click(object sender, System.EventArgs e)
  456. {
  457. RemoveSelected (c_AudioFiles);
  458. }
  459. private void c_AddAudioFiles_Click(object sender, System.EventArgs e)
  460. {
  461. // When adding audio files, show the open file dialog.
  462. //
  463. OpenFileDialog dlg = new OpenFileDialog ();
  464. dlg.CheckFileExists = true;
  465. dlg.CheckPathExists = true;
  466. dlg.Multiselect = true;
  467. dlg.Filter = "All audio files|*.mp3;*.wav;*.aac;*.mp4;*.aif;*.vqf;*.wma|All files (*.*)|*.*";
  468. if (DialogResult.OK == dlg.ShowDialog (this))
  469. {
  470. foreach (string sFilename in dlg.FileNames)
  471. {
  472. c_AudioFiles.Items.Add (sFilename);
  473. }
  474. }
  475. }
  476. private void c_AddFolders_Click(object sender, System.EventArgs e)
  477. {
  478. Utility.BrowseForFolder.BrowseForFolderClass bff = new Utility.BrowseForFolder.BrowseForFolderClass ();
  479. string sFolder = bff.BrowseForFolder ("Please choose a folder:");
  480. if (sFolder != "")
  481. {
  482. c_FilesAndFolders.Items.Add (sFolder);
  483. }
  484. }
  485. // The following helper function assembles a NeroAudioTracks collection
  486. // from the audio files in a list view.
  487. //
  488. private NeroAudioTracks GetAudioTracks ()
  489. {
  490. NeroAudioTracks audioTracks = null;
  491. m_iAudioFile = 0;
  492. m_bError = false;
  493. m_bEof = false;
  494. // If there is at least one audio file...
  495. //
  496. if (c_AudioFiles.Items.Count > 0)
  497. {
  498. // Create the NeroAudioTracks collection object. Also,
  499. // create the array of NeroAudioTrack objects. This is
  500. // very important so that the events on the NeroAudioTrack
  501. // object work properly. In this loop we create as many
  502. // NeroAudioTrack object as there are items in the list view.
  503. // each of these objects is added to NeroAudioTracks collection.
  504. // As this is only a COM wrapper, not a native collection,
  505. // the NeroAudioTrack COM object is passed to the collection
  506. // and the connection with the .NET wrapper is lost. Therefore
  507. // in order for the events (that we subscribe to here) to work,
  508. // the .NET object needs to live as well. We keep those in a
  509. // separate array.
  510. //
  511. // This is all not needed at all if we don't use events.
  512. //
  513. audioTracks = new NeroAudioTracksClass ();
  514. m_audioTracks = new NeroAudioTrack[c_AudioFiles.Items.Count];
  515. int i = 0;
  516. foreach (ListViewItem lvi in c_AudioFiles.Items)
  517. {
  518. // For each list view item, we create a single NeroAudioTrack.
  519. //
  520. NeroAudioTrack audioTrack = new NeroAudioTrackClass ();
  521. audioTrack.Filename = lvi.Text;
  522. if (!c_UseEvent.Checked)
  523. {
  524. // If events are not requested, use the built-in mechanism.
  525. //
  526. string sLowerFilename = audioTrack.Filename.ToLower ();
  527. // WAV and WMA have their own types. All other supported types
  528. // belong together with MP3.
  529. //
  530. if (sLowerFilename.EndsWith (".wav"))
  531. {
  532. audioTrack.TrackType = NERO_AUDIO_TRACK_TYPE.NERO_AUDIO_TRACK_FILE_WAV;
  533. }
  534. else if (sLowerFilename.EndsWith (".wma"))
  535. {
  536. audioTrack.TrackType = NERO_AUDIO_TRACK_TYPE.NERO_AUDIO_TRACK_FILE_WMA;
  537. }
  538. else
  539. {
  540. audioTrack.TrackType = NERO_AUDIO_TRACK_TYPE.NERO_AUDIO_TRACK_FILE_MP3;
  541. }
  542. }
  543. else
  544. {
  545. // Ok, so the user requested that we perform IO using events.
  546. // Let's get the file size so we can calculate the length in
  547. // blocks.
  548. //
  549. FileStream fs = File.OpenRead (c_AudioFiles.Items[m_iAudioFile].Text);
  550. audioTrack.LengthInBlocks = (int) fs.Length/2352;
  551. fs = null;
  552. // If first track, specify 150 blocks (two seconds) pause.
  553. //
  554. audioTrack.PauseInBlksBeforeThisTrack = i == 0? 150: 0;
  555. audioTrack.TrackType = NERO_AUDIO_TRACK_TYPE.NERO_AUDIO_TRACK_THROUGH_EVENT;
  556. // Subscribe to events.
  557. //
  558. audioTrack.OnReadAudioBurn += new _INeroAudioTrackEvents_OnReadAudioBurnEventHandler(audioTrack_OnReadAudioBurn);
  559. audioTrack.OnEOF += new _INeroAudioTrackEvents_OnEOFEventHandler(audioTrack_OnEOF);
  560. audioTrack.OnError += new _INeroAudioTrackEvents_OnErrorEventHandler(audioTrack_OnError);
  561. }
  562. // Put the track into the array for safekeeping (so that the
  563. // events work properly) and add the track to the tracks
  564. // collection.
  565. //
  566. m_audioTracks[i++] = audioTrack;
  567. audioTracks.Add (audioTrack);
  568. }
  569. }
  570. // Return the tracks collection.
  571. //
  572. return audioTracks;
  573. }
  574. // This function is used to recursively add the path to the supplied
  575. // parent NeroFolder.
  576. //
  577. private void AddFolderRecursively (ref NeroFolder folderParent, string sPath)
  578. {
  579. NeroFolder folder = new NeroFolderClass ();
  580. folderParent.Folders.Add (folder);
  581. string [] sSplits = sPath.Split (new char [] {'\\'}, sPath.Length);
  582. if (sSplits.GetLength (0) >= 2)
  583. {
  584. string sFolderName = sSplits[sSplits.GetLength (0) - 2];
  585. folder.Name = sFolderName;
  586. string [] sDirectories = Directory.GetDirectories (sPath);
  587. foreach (string sSubDirPath in sDirectories)
  588. {
  589. AddFolderRecursively (ref folder, sSubDirPath + "\\");
  590. }
  591. }
  592. string [] sFiles = Directory.GetFiles (sPath);
  593. foreach (string sFile in sFiles)
  594. {
  595. NeroFile file = new NeroFileClass ();
  596. file.SourceFilePath = sFile;
  597. file.Name = Path.GetFileName (sFile);
  598. file.EntryTime = Directory.GetLastWriteTime (sFile);
  599. folder.Files.Add (file);
  600. }
  601. }
  602. // This function adds the files and folders from the list
  603. // view to the supplied NeroISOTrack.
  604. //
  605. private void AddFilesAndFoldersToISOTrack (ref NeroISOTrack isoTrack)
  606. {
  607. foreach (ListViewItem lvi in c_FilesAndFolders.Items)
  608. {
  609. string sPath = lvi.Text;
  610. // The string should really not be empty...
  611. //
  612. if (sPath != "")
  613. {
  614. // If path ends in a backslash, it is a folder.
  615. //
  616. if (sPath[sPath.Length - 1] == '\\')
  617. {
  618. NeroFolder folder = isoTrack.RootFolder;
  619. AddFolderRecursively (ref folder, sPath);
  620. }
  621. else
  622. {
  623. // This is a file. Create a new NeroFile
  624. // change its properties.
  625. //
  626. NeroFile file = new NeroFileClass ();
  627. file.SourceFilePath = sPath;
  628. file.Name = Path.GetFileName (sPath);
  629. file.EntryTime = Directory.GetLastWriteTime (sPath);
  630. // In this implementation, specified files are added
  631. // to the root of the disc only.
  632. //
  633. isoTrack.RootFolder.Files.Add (file);
  634. }
  635. }
  636. }
  637. }
  638. private void c_Burn_Click(object sender, System.EventArgs e)
  639. {
  640. // Ok, so the user wants to burn. Let's get the track number
  641. // to import, if any.
  642. //
  643. NERO_IMPORT_ISO_TRACK_FLAGS importFlags = NERO_IMPORT_ISO_TRACK_FLAGS.NERO_IMPORT_ISO_ONLY;
  644. int iTrackNumber = m_frmChooseSession.GetTrackNumber (ref importFlags);
  645. if (iTrackNumber != -1)
  646. {
  647. // If there is a track number to import, let's import it
  648. // here and now. Disable the form so nothing can happen
  649. // while we are importing. It can be a lengthy process.
  650. // Subscribe to the done import event and finally start
  651. // importing.
  652. //
  653. this.Enabled = false;
  654. m_evOnDoneImport2 = new _INeroDriveEvents_OnDoneImport2EventHandler(m_drive_OnDoneImport2);
  655. m_drive.OnDoneImport2 += m_evOnDoneImport2;
  656. m_drive.ImportIsoTrack (iTrackNumber - 1, importFlags);
  657. }
  658. else
  659. {
  660. // If nothing to import, go to burning straight ahead.
  661. //
  662. Burn (null, null);
  663. }
  664. }
  665. private void Burn (NeroFolder importedFolder, NeroCDStamp cdStamp)
  666. {
  667. // Call the helper function to prepare the audio tracks for
  668. // us. Then create the ISO track.
  669. //
  670. NeroAudioTracks audioTracks = GetAudioTracks ();
  671. NeroISOTrack isoTrack = new NeroISOTrackClass ();
  672. isoTrack.BurnOptions = (NERO_BURN_OPTIONS) ((uint) NERO_BURN_OPTIONS.NERO_BURN_OPTION_CREATE_ISO_FS + (uint) NERO_BURN_OPTIONS.NERO_BURN_OPTION_USE_JOLIET);
  673. isoTrack.Name = c_ISOVolumeName.Text;
  674. // If something was imported, make it the root folder
  675. // of the ISO track. We will add more items to it.
  676. //
  677. if (importedFolder != null)
  678. {
  679. isoTrack.RootFolder = importedFolder;
  680. }
  681. // Add all the specified files and folders to the ISO
  682. // track.
  683. //
  684. AddFilesAndFoldersToISOTrack (ref isoTrack);
  685. // Finally, create the burn progress form and call the
  686. // appropriate function.
  687. //
  688. BurnProgressForm frm = new BurnProgressForm (m_drive, m_nero);
  689. frm.BurnIsoAudio (c_Artist.Text,
  690. c_Title.Text,
  691. isoTrack,
  692. audioTracks,
  693. cdStamp,
  694. m_frmChooseBurnFlags.GetBurnFlags (),
  695. m_frmChooseWriteSpeed.GetSpeed (),
  696. m_frmChooseMedia.GetMediaType (),
  697. this);
  698. }
  699. private void m_drive_OnDoneImport2(bool bOk, NeroFolder pFolder, NeroCDStamp pCDStamp, NeroImportDataTrackInfo pImportInfo, NERO_IMPORT_DATA_TRACK_RESULT importResult)
  700. {
  701. // When importing is finished, unsubscribe from the event
  702. // and reenable the form.
  703. //
  704. m_drive.OnDoneImport2 -= m_evOnDoneImport2;
  705. this.Enabled = true;
  706. if (!bOk)
  707. {
  708. // On failure, show a more detailed description.
  709. //
  710. MessageBox.Show (this, "The previous session was not imported successfully!\n" + importResult.ToString ());
  711. }
  712. else
  713. {
  714. // If import was successful, proceed with burning.
  715. //
  716. Burn (pFolder, pCDStamp);
  717. }
  718. }
  719. private void c_ChangeBurnFlags_Click(object sender, System.EventArgs e)
  720. {
  721. if (DialogResult.OK == m_frmChooseBurnFlags.ShowDialog (this))
  722. {
  723. UpdateSettings ();
  724. }
  725. }
  726. private void UpdateSettings ()
  727. {
  728. c_TextSettings.Text = "Burn flags: " + m_frmChooseBurnFlags.ToString () + "\r\n\r\n"
  729. + "Session to import: " + m_frmChooseSession.ToString () + "\r\n\r\n"
  730. + "Write speed: " + m_frmChooseWriteSpeed.ToString () + "\r\n\r\n"
  731. + "Media types: " + m_frmChooseMedia.ToString ();
  732. }
  733. private void c_ChooseSession_Click(object sender, System.EventArgs e)
  734. {
  735. if (DialogResult.OK == m_frmChooseSession.ShowDialog (this))
  736. {
  737. UpdateSettings ();
  738. }
  739. }
  740. private void c_WriteSpeed_Click(object sender, System.EventArgs e)
  741. {
  742. if (DialogResult.OK == m_frmChooseWriteSpeed.ShowDialog (this))
  743. {
  744. UpdateSettings ();
  745. }
  746. }
  747. private void c_ChooseMedia_Click(object sender, System.EventArgs e)
  748. {
  749. if (DialogResult.OK == m_frmChooseMedia.ShowDialog (this))
  750. {
  751. UpdateSettings ();
  752. }
  753. }
  754. private void c_EstimateTrackSize_Click(object sender, System.EventArgs e)
  755. {
  756. // If track size estimation is reqested, we should create
  757. // the ISO track, assign it all the requried elements
  758. // and invoke a form that will show some options for
  759. // further track size estimation refinement.
  760. //
  761. NeroISOTrack isoTrack = new NeroISOTrackClass ();
  762. isoTrack.BurnOptions = (NERO_BURN_OPTIONS) ((uint) NERO_BURN_OPTIONS.NERO_BURN_OPTION_CREATE_ISO_FS + (uint) NERO_BURN_OPTIONS.NERO_BURN_OPTION_USE_JOLIET);
  763. isoTrack.Name = c_ISOVolumeName.Text;
  764. AddFilesAndFoldersToISOTrack (ref isoTrack);
  765. EstimateTrackSizeForm frm = new EstimateTrackSizeForm (m_drive, isoTrack, m_frmChooseMedia.GetMediaType (), m_frmChooseBurnFlags.GetBurnFlags ());
  766. frm.ShowDialog (this);
  767. }
  768. private void audioTrack_OnReadAudioBurn(ref int Length, ref object Data)
  769. {
  770. // This event is called during the burn process on a NeroAudioTrack
  771. // to supply the burning engine with audio data. The Data object
  772. // variable is a SAFEARRAY of VT_I2 which translates to a short[].
  773. // We need to fill it with audio data. We are required to return
  774. // 16-bit samples of interleaved stereo audio data. Data.Length
  775. // shows how many samples are we required to return. Just overwrite
  776. // the array each time. There is no need to reallocate a new array
  777. // of exact size. If less data needs to be returned, ref Length
  778. // should be set to the actual number of BYTES written. So, on input
  779. // Data.Length is the number of 16-bit samples and Length is twice
  780. // that (as it shows BYTES). On return, size or nature of Data array
  781. // is best not changed (except for contents). If less samples needs
  782. // to be returned, Length should reflect this (just make sure this
  783. // one is bytes, not shorts).
  784. //
  785. if (m_fs == null)
  786. {
  787. // If no file stream create until now, this is the first time
  788. // we are called.
  789. //
  790. try
  791. {
  792. // Try and create the file stream. Use m_iAudioFile as an
  793. // index of the current file we are working on.
  794. //
  795. m_fs = File.OpenRead (c_AudioFiles.Items[m_iAudioFile].Text);
  796. // Reset error and eof flags.
  797. //
  798. m_bError = false;
  799. m_bEof = false;
  800. }
  801. catch
  802. {
  803. // If file openning fails, set the error flag. This will
  804. // be reported first time OnError event is fired.
  805. //
  806. m_bError = true;
  807. }
  808. }
  809. // Ok, we are supposed to have the file stream at this point,
  810. // but still guard against the case that we don't.
  811. //
  812. if (m_fs != null)
  813. {
  814. // Check if the rest of file data is smaller than
  815. // the buffer supplied.
  816. //
  817. if (m_fs.Length - m_fs.Position < Length)
  818. {
  819. // If so, set the ref Length variable to
  820. // whatever is left of the file. Set the eof
  821. // flag and go to the next file, if any.
  822. //
  823. Length = (int) (m_fs.Length - m_fs.Position);
  824. m_bEof = true;
  825. m_iAudioFile ++;
  826. }
  827. // Allocate the byte array of the requested length.
  828. //
  829. byte[] bytedata = new byte[Length];
  830. try
  831. {
  832. // Try to read the amount of data requested.
  833. //
  834. m_fs.Read (bytedata, 0, Length);
  835. // Ok, now cast the Data input parameter to an
  836. // array of shorts. There are Length/2 of shorts.
  837. //
  838. short[] samples = (short[]) Data;
  839. // Convert the byte array into a short array. Assume
  840. // the byte array really contains shorts in LSB (Intel)
  841. // order.
  842. //
  843. for (int i = 0; i < Length/2; i ++)
  844. {
  845. samples[i] = (short) ((bytedata[2*i+1]*256U) + bytedata[2*i]);
  846. }
  847. // Finally, if position is past end of the file, get rid
  848. // of it, so that next time we are called we attempt to
  849. // open the next one.
  850. //
  851. if (m_fs.Length <= m_fs.Position)
  852. {
  853. m_fs = null;
  854. }
  855. }
  856. catch
  857. {
  858. m_bError = true;
  859. }
  860. }
  861. if (m_bError)
  862. {
  863. Length = 0;
  864. }
  865. }
  866. private void audioTrack_OnEOF(ref bool Eof)
  867. {
  868. // Just return whatever is the current state of
  869. // end-of-file flag.
  870. //
  871. Eof = m_bEof;
  872. }
  873. private void audioTrack_OnError(ref bool Error)
  874. {
  875. // Just return whatever is the current state of
  876. // error flag.
  877. //
  878. Error = m_bError;
  879. }
  880. }
  881. }