BurnIsoAudio.cs 34 KB

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