using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using NEROLib;
using System.IO;
namespace NeroFiddlesCOM.NET
{
///
/// Summary description for BurnIsoAudioForm.
///
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;
///
/// Required designer variable.
///
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);
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
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 = 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 = 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(464, 8);
this.c_Burn.Name = "c_Burn";
this.c_Burn.TabIndex = 25;
this.c_Burn.Text = "Burn";
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(464, 40);
this.c_Cancel.Name = "c_Cancel";
this.c_Cancel.TabIndex = 26;
this.c_Cancel.Text = "Cancel";
//
// c_Device
//
this.c_Device.Location = new System.Drawing.Point(64, 8);
this.c_Device.Name = "c_Device";
this.c_Device.ReadOnly = true;
this.c_Device.Size = new System.Drawing.Size(248, 20);
this.c_Device.TabIndex = 24;
this.c_Device.Text = "";
//
// label8
//
this.label8.Location = new System.Drawing.Point(8, 8);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(56, 16);
this.label8.TabIndex = 23;
this.label8.Text = "Device:";
//
// 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(8, 96);
this.c_FilesAndFolders.Name = "c_FilesAndFolders";
this.c_FilesAndFolders.Size = new System.Drawing.Size(216, 136);
this.c_FilesAndFolders.TabIndex = 7;
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(8, 80);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(192, 16);
this.label1.TabIndex = 6;
this.label1.Text = "Files and folders to burn in ISO track:";
//
// c_AddFiles
//
this.c_AddFiles.Location = new System.Drawing.Point(8, 240);
this.c_AddFiles.Name = "c_AddFiles";
this.c_AddFiles.Size = new System.Drawing.Size(64, 23);
this.c_AddFiles.TabIndex = 11;
this.c_AddFiles.Text = "Add files";
this.c_AddFiles.Click += new System.EventHandler(this.c_AddFiles_Click);
//
// c_AddFolders
//
this.c_AddFolders.Location = new System.Drawing.Point(80, 240);
this.c_AddFolders.Name = "c_AddFolders";
this.c_AddFolders.Size = new System.Drawing.Size(64, 23);
this.c_AddFolders.TabIndex = 12;
this.c_AddFolders.Text = "Add folders";
this.c_AddFolders.Click += new System.EventHandler(this.c_AddFolders_Click);
//
// c_RemoveFilesAndFolders
//
this.c_RemoveFilesAndFolders.Location = new System.Drawing.Point(152, 240);
this.c_RemoveFilesAndFolders.Name = "c_RemoveFilesAndFolders";
this.c_RemoveFilesAndFolders.Size = new System.Drawing.Size(72, 23);
this.c_RemoveFilesAndFolders.TabIndex = 13;
this.c_RemoveFilesAndFolders.Text = "Remove";
this.c_RemoveFilesAndFolders.Click += new System.EventHandler(this.c_RemoveFilesAndFolders_Click);
//
// label2
//
this.label2.Location = new System.Drawing.Point(232, 80);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(192, 16);
this.label2.TabIndex = 8;
this.label2.Text = "Audio files to burn:";
//
// c_AddAudioFiles
//
this.c_AddAudioFiles.Location = new System.Drawing.Point(232, 240);
this.c_AddAudioFiles.Name = "c_AddAudioFiles";
this.c_AddAudioFiles.Size = new System.Drawing.Size(72, 23);
this.c_AddAudioFiles.TabIndex = 14;
this.c_AddAudioFiles.Text = "Add audio";
this.c_AddAudioFiles.Click += new System.EventHandler(this.c_AddAudioFiles_Click);
//
// c_RemoveAudioFiles
//
this.c_RemoveAudioFiles.Location = new System.Drawing.Point(312, 240);
this.c_RemoveAudioFiles.Name = "c_RemoveAudioFiles";
this.c_RemoveAudioFiles.TabIndex = 15;
this.c_RemoveAudioFiles.Text = "Remove";
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(232, 96);
this.c_AudioFiles.Name = "c_AudioFiles";
this.c_AudioFiles.Size = new System.Drawing.Size(200, 112);
this.c_AudioFiles.TabIndex = 9;
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(336, 56);
this.c_Title.Name = "c_Title";
this.c_Title.Size = new System.Drawing.Size(96, 20);
this.c_Title.TabIndex = 5;
this.c_Title.Text = "";
//
// label3
//
this.label3.Location = new System.Drawing.Point(336, 40);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(100, 16);
this.label3.TabIndex = 4;
this.label3.Text = "Title:";
//
// label4
//
this.label4.Location = new System.Drawing.Point(240, 40);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(72, 16);
this.label4.TabIndex = 2;
this.label4.Text = "Artist:";
//
// c_Artist
//
this.c_Artist.Location = new System.Drawing.Point(232, 56);
this.c_Artist.Name = "c_Artist";
this.c_Artist.Size = new System.Drawing.Size(96, 20);
this.c_Artist.TabIndex = 3;
this.c_Artist.Text = "";
//
// label7
//
this.label7.Location = new System.Drawing.Point(8, 40);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(112, 16);
this.label7.TabIndex = 0;
this.label7.Text = "ISO Volume Name:";
//
// c_ISOVolumeName
//
this.c_ISOVolumeName.Location = new System.Drawing.Point(8, 56);
this.c_ISOVolumeName.Name = "c_ISOVolumeName";
this.c_ISOVolumeName.Size = new System.Drawing.Size(112, 20);
this.c_ISOVolumeName.TabIndex = 1;
this.c_ISOVolumeName.Text = "Test";
//
// c_ChangeBurnFlags
//
this.c_ChangeBurnFlags.Location = new System.Drawing.Point(440, 96);
this.c_ChangeBurnFlags.Name = "c_ChangeBurnFlags";
this.c_ChangeBurnFlags.Size = new System.Drawing.Size(96, 23);
this.c_ChangeBurnFlags.TabIndex = 18;
this.c_ChangeBurnFlags.Text = "Burn Flags";
this.c_ChangeBurnFlags.Click += new System.EventHandler(this.c_ChangeBurnFlags_Click);
//
// c_TextSettings
//
this.c_TextSettings.Location = new System.Drawing.Point(8, 288);
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(424, 128);
this.c_TextSettings.TabIndex = 17;
this.c_TextSettings.Text = "";
//
// c_ChooseSession
//
this.c_ChooseSession.Location = new System.Drawing.Point(440, 128);
this.c_ChooseSession.Name = "c_ChooseSession";
this.c_ChooseSession.Size = new System.Drawing.Size(96, 23);
this.c_ChooseSession.TabIndex = 19;
this.c_ChooseSession.Text = "Choose Session";
this.c_ChooseSession.Click += new System.EventHandler(this.c_ChooseSession_Click);
//
// c_WriteSpeed
//
this.c_WriteSpeed.Location = new System.Drawing.Point(440, 160);
this.c_WriteSpeed.Name = "c_WriteSpeed";
this.c_WriteSpeed.Size = new System.Drawing.Size(96, 23);
this.c_WriteSpeed.TabIndex = 20;
this.c_WriteSpeed.Text = "Write speed";
this.c_WriteSpeed.Click += new System.EventHandler(this.c_WriteSpeed_Click);
//
// c_ChooseMedia
//
this.c_ChooseMedia.Location = new System.Drawing.Point(440, 192);
this.c_ChooseMedia.Name = "c_ChooseMedia";
this.c_ChooseMedia.Size = new System.Drawing.Size(96, 23);
this.c_ChooseMedia.TabIndex = 21;
this.c_ChooseMedia.Text = "Choose Media";
this.c_ChooseMedia.Click += new System.EventHandler(this.c_ChooseMedia_Click);
//
// c_EstimateTrackSize
//
this.c_EstimateTrackSize.Location = new System.Drawing.Point(440, 240);
this.c_EstimateTrackSize.Name = "c_EstimateTrackSize";
this.c_EstimateTrackSize.Size = new System.Drawing.Size(96, 24);
this.c_EstimateTrackSize.TabIndex = 22;
this.c_EstimateTrackSize.Text = "Estimate Size";
this.c_EstimateTrackSize.Click += new System.EventHandler(this.c_EstimateTrackSize_Click);
//
// label5
//
this.label5.Location = new System.Drawing.Point(8, 272);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(100, 16);
this.label5.TabIndex = 16;
this.label5.Text = "Settings:";
//
// c_UseEvent
//
this.c_UseEvent.Location = new System.Drawing.Point(232, 216);
this.c_UseEvent.Name = "c_UseEvent";
this.c_UseEvent.Size = new System.Drawing.Size(200, 16);
this.c_UseEvent.TabIndex = 10;
this.c_UseEvent.Text = "Use event (use RAW files only)";
//
// BurnIsoAudioForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.CancelButton = this.c_Cancel;
this.ClientSize = new System.Drawing.Size(546, 424);
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);
}
#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;
}
}
}