123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952 |
- using System;
- using System.Drawing;
- using System.Collections;
- using System.ComponentModel;
- using System.Windows.Forms;
- using NEROLib;
- using System.IO;
- namespace LYFZ.NeroDiscBurn.NET
- {
- /// <summary>
- /// Summary description for BurnIsoAudioForm.
- /// </summary>
- public class BurnIsoAudioForm : System.Windows.Forms.Form
- {
- private NeroDrive m_drive;
- private Nero m_nero;
- private NeroAudioTrack[] m_audioTracks;
- private int m_iAudioFile;
- private FileStream m_fs;
- private bool m_bError;
- private bool m_bEof;
- private ChooseBurnFlagsForm m_frmChooseBurnFlags;
- private ChooseSessionForm m_frmChooseSession;
- private ChooseSpeedForm m_frmChooseWriteSpeed;
- private ChooseMediaForm m_frmChooseMedia;
- private _INeroDriveEvents_OnDoneImport2EventHandler m_evOnDoneImport2;
- private System.Windows.Forms.Button c_Burn;
- private System.Windows.Forms.Button c_Cancel;
- private System.Windows.Forms.TextBox c_Device;
- private System.Windows.Forms.Label label8;
- private System.Windows.Forms.ListView c_FilesAndFolders;
- private System.Windows.Forms.Label label1;
- private System.Windows.Forms.Button c_AddFiles;
- private System.Windows.Forms.Button c_AddFolders;
- private System.Windows.Forms.Button c_RemoveFilesAndFolders;
- private System.Windows.Forms.Label label2;
- private System.Windows.Forms.Button c_AddAudioFiles;
- private System.Windows.Forms.Button c_RemoveAudioFiles;
- private System.Windows.Forms.ListView c_AudioFiles;
- private System.Windows.Forms.TextBox c_Title;
- private System.Windows.Forms.Label label3;
- private System.Windows.Forms.Label label4;
- private System.Windows.Forms.TextBox c_Artist;
- private System.Windows.Forms.ColumnHeader columnHeader5;
- private System.Windows.Forms.ColumnHeader columnHeader6;
- private System.Windows.Forms.Label label7;
- private System.Windows.Forms.TextBox c_ISOVolumeName;
- private System.Windows.Forms.Button c_ChangeBurnFlags;
- private System.Windows.Forms.TextBox c_TextSettings;
- private System.Windows.Forms.Button c_ChooseSession;
- private System.Windows.Forms.Button c_WriteSpeed;
- private System.Windows.Forms.Button c_ChooseMedia;
- private System.Windows.Forms.Button c_EstimateTrackSize;
- private System.Windows.Forms.Label label5;
- private System.Windows.Forms.CheckBox c_UseEvent;
- /// <summary>
- /// Required designer variable.
- /// </summary>
- private System.ComponentModel.Container components = null;
- public BurnIsoAudioForm(NeroDrive drive, Nero nero)
- {
- //
- // Required for Windows Form Designer support
- //
- InitializeComponent();
- m_drive = drive;
- m_nero = nero;
- m_frmChooseBurnFlags = new ChooseBurnFlagsForm ();
- m_frmChooseSession = new ChooseSessionForm (m_drive);
- m_frmChooseWriteSpeed = new ChooseSpeedForm (m_drive, true);
- m_frmChooseMedia = new ChooseMediaForm (m_nero);
- }
- /// <summary>
- /// Clean up any resources being used.
- /// </summary>
- protected override void Dispose( bool disposing )
- {
- if( disposing )
- {
- if(components != null)
- {
- components.Dispose();
- }
- }
- base.Dispose( disposing );
- }
- #region Windows Form Designer generated code
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- private void InitializeComponent()
- {
- this.c_Burn = new System.Windows.Forms.Button();
- this.c_Cancel = new System.Windows.Forms.Button();
- this.c_Device = new System.Windows.Forms.TextBox();
- this.label8 = new System.Windows.Forms.Label();
- this.c_FilesAndFolders = new System.Windows.Forms.ListView();
- this.columnHeader5 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
- this.label1 = new System.Windows.Forms.Label();
- this.c_AddFiles = new System.Windows.Forms.Button();
- this.c_AddFolders = new System.Windows.Forms.Button();
- this.c_RemoveFilesAndFolders = new System.Windows.Forms.Button();
- this.label2 = new System.Windows.Forms.Label();
- this.c_AddAudioFiles = new System.Windows.Forms.Button();
- this.c_RemoveAudioFiles = new System.Windows.Forms.Button();
- this.c_AudioFiles = new System.Windows.Forms.ListView();
- this.columnHeader6 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
- this.c_Title = new System.Windows.Forms.TextBox();
- this.label3 = new System.Windows.Forms.Label();
- this.label4 = new System.Windows.Forms.Label();
- this.c_Artist = new System.Windows.Forms.TextBox();
- this.label7 = new System.Windows.Forms.Label();
- this.c_ISOVolumeName = new System.Windows.Forms.TextBox();
- this.c_ChangeBurnFlags = new System.Windows.Forms.Button();
- this.c_TextSettings = new System.Windows.Forms.TextBox();
- this.c_ChooseSession = new System.Windows.Forms.Button();
- this.c_WriteSpeed = new System.Windows.Forms.Button();
- this.c_ChooseMedia = new System.Windows.Forms.Button();
- this.c_EstimateTrackSize = new System.Windows.Forms.Button();
- this.label5 = new System.Windows.Forms.Label();
- this.c_UseEvent = new System.Windows.Forms.CheckBox();
- this.SuspendLayout();
- //
- // c_Burn
- //
- this.c_Burn.Location = new System.Drawing.Point(557, 9);
- this.c_Burn.Name = "c_Burn";
- this.c_Burn.Size = new System.Drawing.Size(90, 24);
- this.c_Burn.TabIndex = 25;
- this.c_Burn.Text = "刻录";
- this.c_Burn.Click += new System.EventHandler(this.c_Burn_Click);
- //
- // c_Cancel
- //
- this.c_Cancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
- this.c_Cancel.Location = new System.Drawing.Point(557, 43);
- this.c_Cancel.Name = "c_Cancel";
- this.c_Cancel.Size = new System.Drawing.Size(90, 25);
- this.c_Cancel.TabIndex = 26;
- this.c_Cancel.Text = "取消";
- //
- // c_Device
- //
- this.c_Device.Location = new System.Drawing.Point(77, 9);
- this.c_Device.Name = "c_Device";
- this.c_Device.ReadOnly = true;
- this.c_Device.Size = new System.Drawing.Size(297, 21);
- this.c_Device.TabIndex = 24;
- //
- // label8
- //
- this.label8.Location = new System.Drawing.Point(10, 9);
- this.label8.Name = "label8";
- this.label8.Size = new System.Drawing.Size(67, 17);
- this.label8.TabIndex = 23;
- this.label8.Text = "设备:";
- //
- // c_FilesAndFolders
- //
- this.c_FilesAndFolders.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
- this.columnHeader5});
- this.c_FilesAndFolders.FullRowSelect = true;
- this.c_FilesAndFolders.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
- this.c_FilesAndFolders.HideSelection = false;
- this.c_FilesAndFolders.Location = new System.Drawing.Point(10, 103);
- this.c_FilesAndFolders.Name = "c_FilesAndFolders";
- this.c_FilesAndFolders.Size = new System.Drawing.Size(259, 147);
- this.c_FilesAndFolders.TabIndex = 7;
- this.c_FilesAndFolders.UseCompatibleStateImageBehavior = false;
- this.c_FilesAndFolders.View = System.Windows.Forms.View.Details;
- //
- // columnHeader5
- //
- this.columnHeader5.Text = "File or folder";
- this.columnHeader5.Width = 194;
- //
- // label1
- //
- this.label1.Location = new System.Drawing.Point(10, 86);
- this.label1.Name = "label1";
- this.label1.Size = new System.Drawing.Size(230, 17);
- this.label1.TabIndex = 6;
- this.label1.Text = "文件和文件夹的ISO轨道烧:";
- //
- // c_AddFiles
- //
- this.c_AddFiles.Location = new System.Drawing.Point(10, 258);
- this.c_AddFiles.Name = "c_AddFiles";
- this.c_AddFiles.Size = new System.Drawing.Size(76, 25);
- this.c_AddFiles.TabIndex = 11;
- this.c_AddFiles.Text = "添加文件";
- this.c_AddFiles.Click += new System.EventHandler(this.c_AddFiles_Click);
- //
- // c_AddFolders
- //
- this.c_AddFolders.Location = new System.Drawing.Point(96, 258);
- this.c_AddFolders.Name = "c_AddFolders";
- this.c_AddFolders.Size = new System.Drawing.Size(77, 25);
- this.c_AddFolders.TabIndex = 12;
- this.c_AddFolders.Text = "添加目录";
- this.c_AddFolders.Click += new System.EventHandler(this.c_AddFolders_Click);
- //
- // c_RemoveFilesAndFolders
- //
- this.c_RemoveFilesAndFolders.Location = new System.Drawing.Point(182, 258);
- this.c_RemoveFilesAndFolders.Name = "c_RemoveFilesAndFolders";
- this.c_RemoveFilesAndFolders.Size = new System.Drawing.Size(87, 25);
- this.c_RemoveFilesAndFolders.TabIndex = 13;
- this.c_RemoveFilesAndFolders.Text = "删除";
- this.c_RemoveFilesAndFolders.Click += new System.EventHandler(this.c_RemoveFilesAndFolders_Click);
- //
- // label2
- //
- this.label2.Location = new System.Drawing.Point(278, 86);
- this.label2.Name = "label2";
- this.label2.Size = new System.Drawing.Size(231, 17);
- this.label2.TabIndex = 8;
- this.label2.Text = "音频文件刻录:";
- //
- // c_AddAudioFiles
- //
- this.c_AddAudioFiles.Location = new System.Drawing.Point(278, 258);
- this.c_AddAudioFiles.Name = "c_AddAudioFiles";
- this.c_AddAudioFiles.Size = new System.Drawing.Size(87, 25);
- this.c_AddAudioFiles.TabIndex = 14;
- this.c_AddAudioFiles.Text = "添加音频";
- this.c_AddAudioFiles.Click += new System.EventHandler(this.c_AddAudioFiles_Click);
- //
- // c_RemoveAudioFiles
- //
- this.c_RemoveAudioFiles.Location = new System.Drawing.Point(374, 258);
- this.c_RemoveAudioFiles.Name = "c_RemoveAudioFiles";
- this.c_RemoveAudioFiles.Size = new System.Drawing.Size(90, 25);
- this.c_RemoveAudioFiles.TabIndex = 15;
- this.c_RemoveAudioFiles.Text = "删除";
- this.c_RemoveAudioFiles.Click += new System.EventHandler(this.c_RemoveAudioFiles_Click);
- //
- // c_AudioFiles
- //
- this.c_AudioFiles.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
- this.columnHeader6});
- this.c_AudioFiles.FullRowSelect = true;
- this.c_AudioFiles.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
- this.c_AudioFiles.HideSelection = false;
- this.c_AudioFiles.Location = new System.Drawing.Point(278, 103);
- this.c_AudioFiles.Name = "c_AudioFiles";
- this.c_AudioFiles.Size = new System.Drawing.Size(240, 121);
- this.c_AudioFiles.TabIndex = 9;
- this.c_AudioFiles.UseCompatibleStateImageBehavior = false;
- this.c_AudioFiles.View = System.Windows.Forms.View.Details;
- //
- // columnHeader6
- //
- this.columnHeader6.Text = "Audio file";
- this.columnHeader6.Width = 177;
- //
- // c_Title
- //
- this.c_Title.Location = new System.Drawing.Point(403, 60);
- this.c_Title.Name = "c_Title";
- this.c_Title.Size = new System.Drawing.Size(115, 21);
- this.c_Title.TabIndex = 5;
- //
- // label3
- //
- this.label3.Location = new System.Drawing.Point(403, 43);
- this.label3.Name = "label3";
- this.label3.Size = new System.Drawing.Size(120, 17);
- this.label3.TabIndex = 4;
- this.label3.Text = "标题:";
- //
- // label4
- //
- this.label4.Location = new System.Drawing.Point(288, 43);
- this.label4.Name = "label4";
- this.label4.Size = new System.Drawing.Size(86, 17);
- this.label4.TabIndex = 2;
- this.label4.Text = "艺术家:";
- //
- // c_Artist
- //
- this.c_Artist.Location = new System.Drawing.Point(278, 60);
- this.c_Artist.Name = "c_Artist";
- this.c_Artist.Size = new System.Drawing.Size(116, 21);
- this.c_Artist.TabIndex = 3;
- //
- // label7
- //
- this.label7.Location = new System.Drawing.Point(10, 43);
- this.label7.Name = "label7";
- this.label7.Size = new System.Drawing.Size(134, 17);
- this.label7.TabIndex = 0;
- this.label7.Text = "ISO卷名:";
- //
- // c_ISOVolumeName
- //
- this.c_ISOVolumeName.Location = new System.Drawing.Point(10, 60);
- this.c_ISOVolumeName.Name = "c_ISOVolumeName";
- this.c_ISOVolumeName.Size = new System.Drawing.Size(134, 21);
- this.c_ISOVolumeName.TabIndex = 1;
- this.c_ISOVolumeName.Text = "Test";
- //
- // c_ChangeBurnFlags
- //
- this.c_ChangeBurnFlags.Location = new System.Drawing.Point(528, 103);
- this.c_ChangeBurnFlags.Name = "c_ChangeBurnFlags";
- this.c_ChangeBurnFlags.Size = new System.Drawing.Size(115, 25);
- this.c_ChangeBurnFlags.TabIndex = 18;
- this.c_ChangeBurnFlags.Text = "刻录标志";
- this.c_ChangeBurnFlags.Click += new System.EventHandler(this.c_ChangeBurnFlags_Click);
- //
- // c_TextSettings
- //
- this.c_TextSettings.Location = new System.Drawing.Point(10, 310);
- this.c_TextSettings.Multiline = true;
- this.c_TextSettings.Name = "c_TextSettings";
- this.c_TextSettings.ReadOnly = true;
- this.c_TextSettings.ScrollBars = System.Windows.Forms.ScrollBars.Both;
- this.c_TextSettings.Size = new System.Drawing.Size(508, 138);
- this.c_TextSettings.TabIndex = 17;
- //
- // c_ChooseSession
- //
- this.c_ChooseSession.Location = new System.Drawing.Point(528, 138);
- this.c_ChooseSession.Name = "c_ChooseSession";
- this.c_ChooseSession.Size = new System.Drawing.Size(115, 25);
- this.c_ChooseSession.TabIndex = 19;
- this.c_ChooseSession.Text = "选择会话";
- this.c_ChooseSession.Click += new System.EventHandler(this.c_ChooseSession_Click);
- //
- // c_WriteSpeed
- //
- this.c_WriteSpeed.Location = new System.Drawing.Point(528, 172);
- this.c_WriteSpeed.Name = "c_WriteSpeed";
- this.c_WriteSpeed.Size = new System.Drawing.Size(115, 25);
- this.c_WriteSpeed.TabIndex = 20;
- this.c_WriteSpeed.Text = "写入速度";
- this.c_WriteSpeed.Click += new System.EventHandler(this.c_WriteSpeed_Click);
- //
- // c_ChooseMedia
- //
- this.c_ChooseMedia.Location = new System.Drawing.Point(528, 207);
- this.c_ChooseMedia.Name = "c_ChooseMedia";
- this.c_ChooseMedia.Size = new System.Drawing.Size(115, 25);
- this.c_ChooseMedia.TabIndex = 21;
- this.c_ChooseMedia.Text = "选择媒体";
- this.c_ChooseMedia.Click += new System.EventHandler(this.c_ChooseMedia_Click);
- //
- // c_EstimateTrackSize
- //
- this.c_EstimateTrackSize.Location = new System.Drawing.Point(528, 258);
- this.c_EstimateTrackSize.Name = "c_EstimateTrackSize";
- this.c_EstimateTrackSize.Size = new System.Drawing.Size(115, 26);
- this.c_EstimateTrackSize.TabIndex = 22;
- this.c_EstimateTrackSize.Text = "预计大小";
- this.c_EstimateTrackSize.Click += new System.EventHandler(this.c_EstimateTrackSize_Click);
- //
- // label5
- //
- this.label5.Location = new System.Drawing.Point(10, 293);
- this.label5.Name = "label5";
- this.label5.Size = new System.Drawing.Size(120, 17);
- this.label5.TabIndex = 16;
- this.label5.Text = "设置:";
- //
- // c_UseEvent
- //
- this.c_UseEvent.Location = new System.Drawing.Point(278, 233);
- this.c_UseEvent.Name = "c_UseEvent";
- this.c_UseEvent.Size = new System.Drawing.Size(240, 17);
- this.c_UseEvent.TabIndex = 10;
- this.c_UseEvent.Text = "使用事件(只用RAW文件)";
- //
- // BurnIsoAudioForm
- //
- this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
- this.CancelButton = this.c_Cancel;
- this.ClientSize = new System.Drawing.Size(686, 468);
- this.Controls.Add(this.c_UseEvent);
- this.Controls.Add(this.label5);
- this.Controls.Add(this.c_TextSettings);
- this.Controls.Add(this.c_Title);
- this.Controls.Add(this.c_Device);
- this.Controls.Add(this.c_Artist);
- this.Controls.Add(this.c_ISOVolumeName);
- this.Controls.Add(this.c_ChangeBurnFlags);
- this.Controls.Add(this.label3);
- this.Controls.Add(this.c_AddFiles);
- this.Controls.Add(this.label1);
- this.Controls.Add(this.c_FilesAndFolders);
- this.Controls.Add(this.label8);
- this.Controls.Add(this.c_Cancel);
- this.Controls.Add(this.c_Burn);
- this.Controls.Add(this.c_AddFolders);
- this.Controls.Add(this.c_RemoveFilesAndFolders);
- this.Controls.Add(this.label2);
- this.Controls.Add(this.c_AddAudioFiles);
- this.Controls.Add(this.c_RemoveAudioFiles);
- this.Controls.Add(this.c_AudioFiles);
- this.Controls.Add(this.label4);
- this.Controls.Add(this.label7);
- this.Controls.Add(this.c_ChooseSession);
- this.Controls.Add(this.c_WriteSpeed);
- this.Controls.Add(this.c_ChooseMedia);
- this.Controls.Add(this.c_EstimateTrackSize);
- this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
- this.MaximizeBox = false;
- this.MinimizeBox = false;
- this.Name = "BurnIsoAudioForm";
- this.ShowInTaskbar = false;
- this.Text = "BurnIsoAudio";
- this.ResumeLayout(false);
- this.PerformLayout();
- }
- #endregion
- protected override void OnLoad(EventArgs e)
- {
- base.OnLoad (e);
- c_Device.Text = m_drive.DeviceName;
- UpdateSettings ();
- }
- private void c_AddFiles_Click(object sender, System.EventArgs e)
- {
- // When adding files, show the open file dialog.
- //
- OpenFileDialog dlg = new OpenFileDialog ();
- dlg.CheckFileExists = true;
- dlg.CheckPathExists = true;
- dlg.Multiselect = true;
- dlg.Filter = "All files (*.*)|*.*";
- if (DialogResult.OK == dlg.ShowDialog (this))
- {
- // We allowed multiple selection, so put all
- // filenames in the list view.
- //
- foreach (string sFilename in dlg.FileNames)
- {
- c_FilesAndFolders.Items.Add (sFilename);
- }
- }
- }
- // This is a helper function that removes all selected
- // items in a list view.
- //
- private void RemoveSelected (ListView lv)
- {
- foreach (ListViewItem lvi in lv.SelectedItems)
- {
- lv.Items.Remove (lvi);
- }
- }
- private void c_RemoveFilesAndFolders_Click(object sender, System.EventArgs e)
- {
- RemoveSelected (c_FilesAndFolders);
- }
- private void c_RemoveAudioFiles_Click(object sender, System.EventArgs e)
- {
- RemoveSelected (c_AudioFiles);
- }
- private void c_AddAudioFiles_Click(object sender, System.EventArgs e)
- {
- // When adding audio files, show the open file dialog.
- //
- OpenFileDialog dlg = new OpenFileDialog ();
- dlg.CheckFileExists = true;
- dlg.CheckPathExists = true;
- dlg.Multiselect = true;
- dlg.Filter = "All audio files|*.mp3;*.wav;*.aac;*.mp4;*.aif;*.vqf;*.wma|All files (*.*)|*.*";
- if (DialogResult.OK == dlg.ShowDialog (this))
- {
- foreach (string sFilename in dlg.FileNames)
- {
- c_AudioFiles.Items.Add (sFilename);
- }
- }
- }
- private void c_AddFolders_Click(object sender, System.EventArgs e)
- {
- Utility.BrowseForFolder.BrowseForFolderClass bff = new Utility.BrowseForFolder.BrowseForFolderClass ();
- string sFolder = bff.BrowseForFolder ("Please choose a folder:");
- if (sFolder != "")
- {
- c_FilesAndFolders.Items.Add (sFolder);
- }
- }
- // The following helper function assembles a NeroAudioTracks collection
- // from the audio files in a list view.
- //
- private NeroAudioTracks GetAudioTracks ()
- {
- NeroAudioTracks audioTracks = null;
- m_iAudioFile = 0;
- m_bError = false;
- m_bEof = false;
-
- // If there is at least one audio file...
- //
- if (c_AudioFiles.Items.Count > 0)
- {
- // Create the NeroAudioTracks collection object. Also,
- // create the array of NeroAudioTrack objects. This is
- // very important so that the events on the NeroAudioTrack
- // object work properly. In this loop we create as many
- // NeroAudioTrack object as there are items in the list view.
- // each of these objects is added to NeroAudioTracks collection.
- // As this is only a COM wrapper, not a native collection,
- // the NeroAudioTrack COM object is passed to the collection
- // and the connection with the .NET wrapper is lost. Therefore
- // in order for the events (that we subscribe to here) to work,
- // the .NET object needs to live as well. We keep those in a
- // separate array.
- //
- // This is all not needed at all if we don't use events.
- //
- audioTracks = new NeroAudioTracksClass ();
- m_audioTracks = new NeroAudioTrack[c_AudioFiles.Items.Count];
- int i = 0;
- foreach (ListViewItem lvi in c_AudioFiles.Items)
- {
- // For each list view item, we create a single NeroAudioTrack.
- //
- NeroAudioTrack audioTrack = new NeroAudioTrackClass ();
- audioTrack.Filename = lvi.Text;
-
- if (!c_UseEvent.Checked)
- {
- // If events are not requested, use the built-in mechanism.
- //
- string sLowerFilename = audioTrack.Filename.ToLower ();
- // WAV and WMA have their own types. All other supported types
- // belong together with MP3.
- //
- if (sLowerFilename.EndsWith (".wav"))
- {
- audioTrack.TrackType = NERO_AUDIO_TRACK_TYPE.NERO_AUDIO_TRACK_FILE_WAV;
- }
- else if (sLowerFilename.EndsWith (".wma"))
- {
- audioTrack.TrackType = NERO_AUDIO_TRACK_TYPE.NERO_AUDIO_TRACK_FILE_WMA;
- }
- else
- {
- audioTrack.TrackType = NERO_AUDIO_TRACK_TYPE.NERO_AUDIO_TRACK_FILE_MP3;
- }
- }
- else
- {
- // Ok, so the user requested that we perform IO using events.
- // Let's get the file size so we can calculate the length in
- // blocks.
- //
- FileStream fs = File.OpenRead (c_AudioFiles.Items[m_iAudioFile].Text);
- audioTrack.LengthInBlocks = (int) fs.Length/2352;
- fs = null;
- // If first track, specify 150 blocks (two seconds) pause.
- //
- audioTrack.PauseInBlksBeforeThisTrack = i == 0? 150: 0;
- audioTrack.TrackType = NERO_AUDIO_TRACK_TYPE.NERO_AUDIO_TRACK_THROUGH_EVENT;
- // Subscribe to events.
- //
- audioTrack.OnReadAudioBurn += new _INeroAudioTrackEvents_OnReadAudioBurnEventHandler(audioTrack_OnReadAudioBurn);
- audioTrack.OnEOF += new _INeroAudioTrackEvents_OnEOFEventHandler(audioTrack_OnEOF);
- audioTrack.OnError += new _INeroAudioTrackEvents_OnErrorEventHandler(audioTrack_OnError);
- }
- // Put the track into the array for safekeeping (so that the
- // events work properly) and add the track to the tracks
- // collection.
- //
- m_audioTracks[i++] = audioTrack;
- audioTracks.Add (audioTrack);
- }
- }
- // Return the tracks collection.
- //
- return audioTracks;
- }
- // This function is used to recursively add the path to the supplied
- // parent NeroFolder.
- //
- private void AddFolderRecursively (ref NeroFolder folderParent, string sPath)
- {
- NeroFolder folder = new NeroFolderClass ();
- folderParent.Folders.Add (folder);
- string [] sSplits = sPath.Split (new char [] {'\\'}, sPath.Length);
- if (sSplits.GetLength (0) >= 2)
- {
- string sFolderName = sSplits[sSplits.GetLength (0) - 2];
- folder.Name = sFolderName;
- string [] sDirectories = Directory.GetDirectories (sPath);
- foreach (string sSubDirPath in sDirectories)
- {
- AddFolderRecursively (ref folder, sSubDirPath + "\\");
- }
- }
- string [] sFiles = Directory.GetFiles (sPath);
- foreach (string sFile in sFiles)
- {
- NeroFile file = new NeroFileClass ();
- file.SourceFilePath = sFile;
- file.Name = Path.GetFileName (sFile);
- file.EntryTime = Directory.GetLastWriteTime (sFile);
- folder.Files.Add (file);
- }
- }
- // This function adds the files and folders from the list
- // view to the supplied NeroISOTrack.
- //
- private void AddFilesAndFoldersToISOTrack (ref NeroISOTrack isoTrack)
- {
- foreach (ListViewItem lvi in c_FilesAndFolders.Items)
- {
- string sPath = lvi.Text;
- // The string should really not be empty...
- //
- if (sPath != "")
- {
- // If path ends in a backslash, it is a folder.
- //
- if (sPath[sPath.Length - 1] == '\\')
- {
- NeroFolder folder = isoTrack.RootFolder;
- AddFolderRecursively (ref folder, sPath);
- }
- else
- {
- // This is a file. Create a new NeroFile
- // change its properties.
- //
- NeroFile file = new NeroFileClass ();
- file.SourceFilePath = sPath;
- file.Name = Path.GetFileName (sPath);
- file.EntryTime = Directory.GetLastWriteTime (sPath);
- // In this implementation, specified files are added
- // to the root of the disc only.
- //
- isoTrack.RootFolder.Files.Add (file);
- }
- }
- }
- }
- private void c_Burn_Click(object sender, System.EventArgs e)
- {
- // Ok, so the user wants to burn. Let's get the track number
- // to import, if any.
- //
- NERO_IMPORT_ISO_TRACK_FLAGS importFlags = NERO_IMPORT_ISO_TRACK_FLAGS.NERO_IMPORT_ISO_ONLY;
- int iTrackNumber = m_frmChooseSession.GetTrackNumber (ref importFlags);
- if (iTrackNumber != -1)
- {
- // If there is a track number to import, let's import it
- // here and now. Disable the form so nothing can happen
- // while we are importing. It can be a lengthy process.
- // Subscribe to the done import event and finally start
- // importing.
- //
- this.Enabled = false;
- m_evOnDoneImport2 = new _INeroDriveEvents_OnDoneImport2EventHandler(m_drive_OnDoneImport2);
- m_drive.OnDoneImport2 += m_evOnDoneImport2;
- m_drive.ImportIsoTrack (iTrackNumber - 1, importFlags);
- }
- else
- {
- // If nothing to import, go to burning straight ahead.
- //
- Burn (null, null);
- }
- }
- private void Burn (NeroFolder importedFolder, NeroCDStamp cdStamp)
- {
- // Call the helper function to prepare the audio tracks for
- // us. Then create the ISO track.
- //
- NeroAudioTracks audioTracks = GetAudioTracks ();
- NeroISOTrack isoTrack = new NeroISOTrackClass ();
- isoTrack.BurnOptions = (NERO_BURN_OPTIONS) ((uint) NERO_BURN_OPTIONS.NERO_BURN_OPTION_CREATE_ISO_FS + (uint) NERO_BURN_OPTIONS.NERO_BURN_OPTION_USE_JOLIET);
- isoTrack.Name = c_ISOVolumeName.Text;
- // If something was imported, make it the root folder
- // of the ISO track. We will add more items to it.
- //
- if (importedFolder != null)
- {
- isoTrack.RootFolder = importedFolder;
- }
- // Add all the specified files and folders to the ISO
- // track.
- //
- AddFilesAndFoldersToISOTrack (ref isoTrack);
- // Finally, create the burn progress form and call the
- // appropriate function.
- //
- BurnProgressForm frm = new BurnProgressForm (m_drive, m_nero);
- frm.BurnIsoAudio (c_Artist.Text,
- c_Title.Text,
- isoTrack,
- audioTracks,
- cdStamp,
- m_frmChooseBurnFlags.GetBurnFlags (),
- m_frmChooseWriteSpeed.GetSpeed (),
- m_frmChooseMedia.GetMediaType (),
- this);
- }
- private void m_drive_OnDoneImport2(bool bOk, NeroFolder pFolder, NeroCDStamp pCDStamp, NeroImportDataTrackInfo pImportInfo, NERO_IMPORT_DATA_TRACK_RESULT importResult)
- {
- // When importing is finished, unsubscribe from the event
- // and reenable the form.
- //
- m_drive.OnDoneImport2 -= m_evOnDoneImport2;
- this.Enabled = true;
- if (!bOk)
- {
- // On failure, show a more detailed description.
- //
- MessageBox.Show (this, "The previous session was not imported successfully!\n" + importResult.ToString ());
- }
- else
- {
- // If import was successful, proceed with burning.
- //
- Burn (pFolder, pCDStamp);
- }
- }
- private void c_ChangeBurnFlags_Click(object sender, System.EventArgs e)
- {
- if (DialogResult.OK == m_frmChooseBurnFlags.ShowDialog (this))
- {
- UpdateSettings ();
- }
- }
-
- private void UpdateSettings ()
- {
- c_TextSettings.Text = "Burn flags: " + m_frmChooseBurnFlags.ToString () + "\r\n\r\n"
- + "Session to import: " + m_frmChooseSession.ToString () + "\r\n\r\n"
- + "Write speed: " + m_frmChooseWriteSpeed.ToString () + "\r\n\r\n"
- + "Media types: " + m_frmChooseMedia.ToString ();
- }
- private void c_ChooseSession_Click(object sender, System.EventArgs e)
- {
- if (DialogResult.OK == m_frmChooseSession.ShowDialog (this))
- {
- UpdateSettings ();
- }
- }
- private void c_WriteSpeed_Click(object sender, System.EventArgs e)
- {
- if (DialogResult.OK == m_frmChooseWriteSpeed.ShowDialog (this))
- {
- UpdateSettings ();
- }
- }
- private void c_ChooseMedia_Click(object sender, System.EventArgs e)
- {
- if (DialogResult.OK == m_frmChooseMedia.ShowDialog (this))
- {
- UpdateSettings ();
- }
- }
- private void c_EstimateTrackSize_Click(object sender, System.EventArgs e)
- {
- // If track size estimation is reqested, we should create
- // the ISO track, assign it all the requried elements
- // and invoke a form that will show some options for
- // further track size estimation refinement.
- //
- NeroISOTrack isoTrack = new NeroISOTrackClass ();
- isoTrack.BurnOptions = (NERO_BURN_OPTIONS) ((uint) NERO_BURN_OPTIONS.NERO_BURN_OPTION_CREATE_ISO_FS + (uint) NERO_BURN_OPTIONS.NERO_BURN_OPTION_USE_JOLIET);
- isoTrack.Name = c_ISOVolumeName.Text;
-
- AddFilesAndFoldersToISOTrack (ref isoTrack);
- EstimateTrackSizeForm frm = new EstimateTrackSizeForm (m_drive, isoTrack, m_frmChooseMedia.GetMediaType (), m_frmChooseBurnFlags.GetBurnFlags ());
- frm.ShowDialog (this);
- }
- private void audioTrack_OnReadAudioBurn(ref int Length, ref object Data)
- {
- // This event is called during the burn process on a NeroAudioTrack
- // to supply the burning engine with audio data. The Data object
- // variable is a SAFEARRAY of VT_I2 which translates to a short[].
- // We need to fill it with audio data. We are required to return
- // 16-bit samples of interleaved stereo audio data. Data.Length
- // shows how many samples are we required to return. Just overwrite
- // the array each time. There is no need to reallocate a new array
- // of exact size. If less data needs to be returned, ref Length
- // should be set to the actual number of BYTES written. So, on input
- // Data.Length is the number of 16-bit samples and Length is twice
- // that (as it shows BYTES). On return, size or nature of Data array
- // is best not changed (except for contents). If less samples needs
- // to be returned, Length should reflect this (just make sure this
- // one is bytes, not shorts).
- //
- if (m_fs == null)
- {
- // If no file stream create until now, this is the first time
- // we are called.
- //
- try
- {
- // Try and create the file stream. Use m_iAudioFile as an
- // index of the current file we are working on.
- //
- m_fs = File.OpenRead (c_AudioFiles.Items[m_iAudioFile].Text);
- // Reset error and eof flags.
- //
- m_bError = false;
- m_bEof = false;
- }
- catch
- {
- // If file openning fails, set the error flag. This will
- // be reported first time OnError event is fired.
- //
- m_bError = true;
- }
- }
- // Ok, we are supposed to have the file stream at this point,
- // but still guard against the case that we don't.
- //
- if (m_fs != null)
- {
- // Check if the rest of file data is smaller than
- // the buffer supplied.
- //
- if (m_fs.Length - m_fs.Position < Length)
- {
- // If so, set the ref Length variable to
- // whatever is left of the file. Set the eof
- // flag and go to the next file, if any.
- //
- Length = (int) (m_fs.Length - m_fs.Position);
- m_bEof = true;
- m_iAudioFile ++;
- }
- // Allocate the byte array of the requested length.
- //
- byte[] bytedata = new byte[Length];
- try
- {
- // Try to read the amount of data requested.
- //
- m_fs.Read (bytedata, 0, Length);
- // Ok, now cast the Data input parameter to an
- // array of shorts. There are Length/2 of shorts.
- //
- short[] samples = (short[]) Data;
- // Convert the byte array into a short array. Assume
- // the byte array really contains shorts in LSB (Intel)
- // order.
- //
- for (int i = 0; i < Length/2; i ++)
- {
- samples[i] = (short) ((bytedata[2*i+1]*256U) + bytedata[2*i]);
- }
- // Finally, if position is past end of the file, get rid
- // of it, so that next time we are called we attempt to
- // open the next one.
- //
- if (m_fs.Length <= m_fs.Position)
- {
- m_fs = null;
- }
- }
- catch
- {
- m_bError = true;
- }
- }
- if (m_bError)
- {
- Length = 0;
- }
- }
- private void audioTrack_OnEOF(ref bool Eof)
- {
- // Just return whatever is the current state of
- // end-of-file flag.
- //
- Eof = m_bEof;
- }
- private void audioTrack_OnError(ref bool Error)
- {
- // Just return whatever is the current state of
- // error flag.
- //
- Error = m_bError;
- }
- }
- }
|