using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using NEROLib;
namespace NeroFiddlesCOM.NET
{
///
/// Summary description for MainForm.
///
public class MainForm : System.Windows.Forms.Form
{
private Nero m_nero;
private NeroDrives m_devices;
private NeroDrive m_lastDrive;
private _INeroDriveEvents_OnDriveStatusChangedEventHandler m_evDriveStatusChanged;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.ComboBox c_Devices;
private System.Windows.Forms.Button c_BurnIsoAudio;
private System.Windows.Forms.Button c_Erase;
private System.Windows.Forms.Button c_BurnImage;
private System.Windows.Forms.Button c_Exit;
private System.Windows.Forms.Button c_DriveInfo;
private System.Windows.Forms.Button c_Eject;
private System.Windows.Forms.Button c_Load;
private System.Windows.Forms.Button c_DAE;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label c_LastDriveStatus;
private System.Windows.Forms.Button c_BurnCopy;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label c_APIVersion;
private System.Windows.Forms.Button c_ImageInfo;
private System.Windows.Forms.Button c_DiscInfo;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.GroupBox groupBox4;
private System.Windows.Forms.Button c_NVAPI;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public MainForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad (e);
// When the main form loads, let's create the Nero object first.
// Then get the available devices and fill the combobox.
//
m_nero = new NeroClass();
m_devices = m_nero.GetDrives(NERO_MEDIA_TYPE.NERO_MEDIA_CD);
for (int i = 0; i < m_devices.Count; i ++)
{
NeroDrive drive = (NeroDrive) m_devices.Item (i);
string sDriveLetter = (drive.DriveLetter == "")? "?": drive.DriveLetter.ToUpper ();
c_Devices.Items.Add (sDriveLetter + ": " + drive.DeviceName);
}
c_Devices.SelectedIndex = 0;
// Show the version.
//
short v1 = 0, v2 = 0, v3 = 0, v4 = 0;
m_nero.APIVersion (ref v1, ref v2, ref v3, ref v4);
c_APIVersion.Text = v1.ToString () + "." + v2.ToString () + "." + v3.ToString () + "." + v4.ToString ();
}
///
/// 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.label1 = new System.Windows.Forms.Label();
this.c_DiscInfo = new System.Windows.Forms.Button();
this.c_Devices = new System.Windows.Forms.ComboBox();
this.c_BurnIsoAudio = new System.Windows.Forms.Button();
this.c_Erase = new System.Windows.Forms.Button();
this.c_BurnImage = new System.Windows.Forms.Button();
this.c_Exit = new System.Windows.Forms.Button();
this.c_DriveInfo = new System.Windows.Forms.Button();
this.c_Eject = new System.Windows.Forms.Button();
this.c_Load = new System.Windows.Forms.Button();
this.c_DAE = new System.Windows.Forms.Button();
this.label2 = new System.Windows.Forms.Label();
this.c_LastDriveStatus = new System.Windows.Forms.Label();
this.c_BurnCopy = new System.Windows.Forms.Button();
this.label3 = new System.Windows.Forms.Label();
this.c_APIVersion = new System.Windows.Forms.Label();
this.c_ImageInfo = new System.Windows.Forms.Button();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.groupBox4 = new System.Windows.Forms.GroupBox();
this.c_NVAPI = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(10, 9);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(144, 17);
this.label1.TabIndex = 0;
this.label1.Text = "Devices:";
//
// c_DiscInfo
//
this.c_DiscInfo.Location = new System.Drawing.Point(19, 155);
this.c_DiscInfo.Name = "c_DiscInfo";
this.c_DiscInfo.Size = new System.Drawing.Size(96, 25);
this.c_DiscInfo.TabIndex = 8;
this.c_DiscInfo.Text = "Disc Info";
this.c_DiscInfo.Click += new System.EventHandler(this.DiscInfo_Click);
//
// c_Devices
//
this.c_Devices.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.c_Devices.Location = new System.Drawing.Point(10, 26);
this.c_Devices.Name = "c_Devices";
this.c_Devices.Size = new System.Drawing.Size(230, 20);
this.c_Devices.TabIndex = 1;
this.c_Devices.SelectedIndexChanged += new System.EventHandler(this.c_Devices_SelectedIndexChanged);
//
// c_BurnIsoAudio
//
this.c_BurnIsoAudio.Location = new System.Drawing.Point(144, 121);
this.c_BurnIsoAudio.Name = "c_BurnIsoAudio";
this.c_BurnIsoAudio.Size = new System.Drawing.Size(96, 24);
this.c_BurnIsoAudio.TabIndex = 11;
this.c_BurnIsoAudio.Text = "BurnIsoAudio";
this.c_BurnIsoAudio.Click += new System.EventHandler(this.c_BurnIsoAudio_Click);
//
// c_Erase
//
this.c_Erase.Location = new System.Drawing.Point(394, 155);
this.c_Erase.Name = "c_Erase";
this.c_Erase.Size = new System.Drawing.Size(96, 25);
this.c_Erase.TabIndex = 20;
this.c_Erase.Text = "Erase";
this.c_Erase.Click += new System.EventHandler(this.c_Erase_Click);
//
// c_BurnImage
//
this.c_BurnImage.Location = new System.Drawing.Point(144, 155);
this.c_BurnImage.Name = "c_BurnImage";
this.c_BurnImage.Size = new System.Drawing.Size(96, 25);
this.c_BurnImage.TabIndex = 12;
this.c_BurnImage.Text = "Burn Image";
this.c_BurnImage.Click += new System.EventHandler(this.c_BurnImage_Click);
//
// c_Exit
//
this.c_Exit.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.c_Exit.Location = new System.Drawing.Point(403, 17);
this.c_Exit.Name = "c_Exit";
this.c_Exit.Size = new System.Drawing.Size(96, 25);
this.c_Exit.TabIndex = 21;
this.c_Exit.Text = "Exit";
this.c_Exit.Click += new System.EventHandler(this.c_Exit_Click);
//
// c_DriveInfo
//
this.c_DriveInfo.Location = new System.Drawing.Point(19, 121);
this.c_DriveInfo.Name = "c_DriveInfo";
this.c_DriveInfo.Size = new System.Drawing.Size(96, 24);
this.c_DriveInfo.TabIndex = 7;
this.c_DriveInfo.Text = "Drive Info";
this.c_DriveInfo.Click += new System.EventHandler(this.c_DriveInfo_Click);
//
// c_Eject
//
this.c_Eject.Location = new System.Drawing.Point(269, 121);
this.c_Eject.Name = "c_Eject";
this.c_Eject.Size = new System.Drawing.Size(96, 24);
this.c_Eject.TabIndex = 16;
this.c_Eject.Text = "Eject";
this.c_Eject.Click += new System.EventHandler(this.c_Eject_Click);
//
// c_Load
//
this.c_Load.Location = new System.Drawing.Point(269, 155);
this.c_Load.Name = "c_Load";
this.c_Load.Size = new System.Drawing.Size(96, 25);
this.c_Load.TabIndex = 17;
this.c_Load.Text = "Load";
this.c_Load.Click += new System.EventHandler(this.c_Load_Click);
//
// c_DAE
//
this.c_DAE.Location = new System.Drawing.Point(394, 121);
this.c_DAE.Name = "c_DAE";
this.c_DAE.Size = new System.Drawing.Size(96, 24);
this.c_DAE.TabIndex = 19;
this.c_DAE.Text = "DAE";
this.c_DAE.Click += new System.EventHandler(this.c_DAE_Click);
//
// label2
//
this.label2.Location = new System.Drawing.Point(10, 60);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(115, 18);
this.label2.TabIndex = 4;
this.label2.Text = "Last drive status:";
//
// c_LastDriveStatus
//
this.c_LastDriveStatus.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.c_LastDriveStatus.Location = new System.Drawing.Point(134, 60);
this.c_LastDriveStatus.Name = "c_LastDriveStatus";
this.c_LastDriveStatus.Size = new System.Drawing.Size(202, 18);
this.c_LastDriveStatus.TabIndex = 5;
//
// c_BurnCopy
//
this.c_BurnCopy.Location = new System.Drawing.Point(144, 190);
this.c_BurnCopy.Name = "c_BurnCopy";
this.c_BurnCopy.Size = new System.Drawing.Size(96, 24);
this.c_BurnCopy.TabIndex = 13;
this.c_BurnCopy.Text = "Disc Copy";
this.c_BurnCopy.Click += new System.EventHandler(this.c_BurnCopy_Click);
//
// label3
//
this.label3.Location = new System.Drawing.Point(250, 9);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(105, 17);
this.label3.TabIndex = 2;
this.label3.Text = "API Version:";
//
// c_APIVersion
//
this.c_APIVersion.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.c_APIVersion.Location = new System.Drawing.Point(250, 26);
this.c_APIVersion.Name = "c_APIVersion";
this.c_APIVersion.Size = new System.Drawing.Size(115, 17);
this.c_APIVersion.TabIndex = 3;
//
// c_ImageInfo
//
this.c_ImageInfo.Location = new System.Drawing.Point(19, 190);
this.c_ImageInfo.Name = "c_ImageInfo";
this.c_ImageInfo.Size = new System.Drawing.Size(96, 24);
this.c_ImageInfo.TabIndex = 9;
this.c_ImageInfo.Text = "Image Info";
this.c_ImageInfo.Click += new System.EventHandler(this.c_ImageInfo_Click);
//
// groupBox1
//
this.groupBox1.Location = new System.Drawing.Point(10, 95);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(115, 163);
this.groupBox1.TabIndex = 6;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Info";
//
// groupBox2
//
this.groupBox2.Location = new System.Drawing.Point(134, 95);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(116, 163);
this.groupBox2.TabIndex = 10;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Burn";
//
// groupBox3
//
this.groupBox3.Location = new System.Drawing.Point(259, 95);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(115, 163);
this.groupBox3.TabIndex = 15;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "Eject/Load";
//
// groupBox4
//
this.groupBox4.Location = new System.Drawing.Point(384, 95);
this.groupBox4.Name = "groupBox4";
this.groupBox4.Size = new System.Drawing.Size(115, 163);
this.groupBox4.TabIndex = 18;
this.groupBox4.TabStop = false;
this.groupBox4.Text = "Misc";
//
// c_NVAPI
//
this.c_NVAPI.Location = new System.Drawing.Point(144, 224);
this.c_NVAPI.Name = "c_NVAPI";
this.c_NVAPI.Size = new System.Drawing.Size(96, 25);
this.c_NVAPI.TabIndex = 14;
this.c_NVAPI.Text = "Burn NVAPI";
this.c_NVAPI.Click += new System.EventHandler(this.c_NVAPI_Click);
//
// MainForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.CancelButton = this.c_Exit;
this.ClientSize = new System.Drawing.Size(531, 288);
this.Controls.Add(this.c_NVAPI);
this.Controls.Add(this.label2);
this.Controls.Add(this.c_DriveInfo);
this.Controls.Add(this.c_Exit);
this.Controls.Add(this.c_Erase);
this.Controls.Add(this.c_BurnIsoAudio);
this.Controls.Add(this.c_Devices);
this.Controls.Add(this.c_DiscInfo);
this.Controls.Add(this.label1);
this.Controls.Add(this.c_BurnImage);
this.Controls.Add(this.c_Eject);
this.Controls.Add(this.c_Load);
this.Controls.Add(this.c_DAE);
this.Controls.Add(this.c_LastDriveStatus);
this.Controls.Add(this.c_BurnCopy);
this.Controls.Add(this.label3);
this.Controls.Add(this.c_APIVersion);
this.Controls.Add(this.c_ImageInfo);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox3);
this.Controls.Add(this.groupBox4);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.Name = "MainForm";
this.Text = "NeroFiddlesCOM.NET";
this.ResumeLayout(false);
}
#endregion
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.Run(new MainForm());
}
// This is a helper function to get the currently selected drive
// from the combobox as NeroDrive.
//
private NeroDrive GetCurrentlySelectedDrive ()
{
return c_Devices.SelectedIndex == -1? null: (NeroDrive) m_devices.Item (c_Devices.SelectedIndex);
}
private void DiscInfo_Click(object sender, System.EventArgs e)
{
// Show the disc info form.
//
DiscInfoForm frm = new DiscInfoForm (GetCurrentlySelectedDrive (), m_nero);
frm.ShowDialog (this);
}
private void c_BurnIsoAudio_Click(object sender, System.EventArgs e)
{
// Show the burn iso audio form.
//
BurnIsoAudioForm frm = new BurnIsoAudioForm (GetCurrentlySelectedDrive (), m_nero);
frm.ShowDialog (this);
}
private void c_Erase_Click(object sender, System.EventArgs e)
{
// Show the erase form.
//
EraseForm frm = new EraseForm (GetCurrentlySelectedDrive ());
frm.ShowDialog (this);
}
private void c_BurnImage_Click(object sender, System.EventArgs e)
{
// Show the burn image form.
//
BurnImageForm frm = new BurnImageForm (GetCurrentlySelectedDrive (), m_nero);
frm.ShowDialog (this);
}
private void c_Exit_Click(object sender, System.EventArgs e)
{
this.Close ();
}
private void c_DriveInfo_Click(object sender, System.EventArgs e)
{
// Show drive info form.
//
DriveInfoForm frm = new DriveInfoForm (m_nero, GetCurrentlySelectedDrive ());
frm.ShowDialog (this);
}
private void c_Eject_Click(object sender, System.EventArgs e)
{
// Eject the current drive.
//
NeroDrive drive = GetCurrentlySelectedDrive ();
if (drive != null)
{
drive.EjectCD ();
}
}
private void c_Load_Click(object sender, System.EventArgs e)
{
// Load the current drive.
//
NeroDrive drive = GetCurrentlySelectedDrive ();
if (drive != null)
{
drive.LoadCD ();
}
}
private void c_DAE_Click(object sender, System.EventArgs e)
{
// Show the DAE form.
//
DAEForm frm = new DAEForm (GetCurrentlySelectedDrive ());
frm.ShowDialog (this);
}
private void c_Devices_SelectedIndexChanged(object sender, System.EventArgs e)
{
// When selected index of the drive combobox is changed, let's
// disable the status callback on that drive and enable it on
// the new one.
//
if (m_lastDrive != null)
{
m_lastDrive.EnableStatusCallback (NERO_DRIVESTATUS_TYPE.NDT_DISC_CHANGE, false);
m_lastDrive.EnableStatusCallback (NERO_DRIVESTATUS_TYPE.NDT_IN_USE_CHANGE, false);
m_lastDrive.OnDriveStatusChanged -= m_evDriveStatusChanged;
}
m_lastDrive = GetCurrentlySelectedDrive ();
if (m_lastDrive != null)
{
c_LastDriveStatus.Text = "";
m_evDriveStatusChanged = new _INeroDriveEvents_OnDriveStatusChangedEventHandler(m_lastDrive_OnDriveStatusChanged);
m_lastDrive.OnDriveStatusChanged += m_evDriveStatusChanged;
m_lastDrive.EnableStatusCallback (NERO_DRIVESTATUS_TYPE.NDT_DISC_CHANGE, true);
m_lastDrive.EnableStatusCallback (NERO_DRIVESTATUS_TYPE.NDT_IN_USE_CHANGE, true);
}
}
private void m_lastDrive_OnDriveStatusChanged(NERO_DRIVESTATUS_RESULT driveStatus)
{
// When the status is changed on the currently selected drive,
// let's display it.
//
string sStatus;
switch (driveStatus)
{
case NERO_DRIVESTATUS_RESULT.NDR_DISC_INSERTED:
sStatus = "Disc inserted";
break;
case NERO_DRIVESTATUS_RESULT.NDR_DISC_REMOVED:
sStatus = "Disc removed";
break;
case NERO_DRIVESTATUS_RESULT.NDR_DRIVE_IN_USE:
sStatus = "Drive in use";
break;
case NERO_DRIVESTATUS_RESULT.NDR_DRIVE_NOT_IN_USE:
sStatus = "Drive not in use";
break;
default:
sStatus = "Unknown status";
break;
}
c_LastDriveStatus.Text = sStatus;
}
private void c_BurnCopy_Click(object sender, System.EventArgs e)
{
// Show the disc copy form.
//
BurnDiscCopyForm frm = new BurnDiscCopyForm (m_nero, GetCurrentlySelectedDrive ());
frm.ShowDialog (this);
}
private void c_ImageInfo_Click(object sender, System.EventArgs e)
{
// Show the disc info form but initialize it with a different
// constructor. But first, get the user to select an image file.
//
OpenFileDialog dlg = new OpenFileDialog ();
dlg.CheckFileExists = true;
dlg.CheckPathExists = true;
dlg.DefaultExt = ".nrg";
dlg.Filter = "All image files|*.nrg;*.iso|NRG files (*.nrg)|*.nrg|ISO files (*.iso)|*.iso|All files (*.*)|*.*";
if (DialogResult.OK == dlg.ShowDialog (this))
{
DiscInfoForm frm = new DiscInfoForm (dlg.FileName, m_nero);
frm.ShowDialog (this);
}
}
private void c_NVAPI_Click(object sender, System.EventArgs e)
{
// Show the form that allows to burn a NeroVisionAPI XML
// project.
//
NVAPIForm frm = new NVAPIForm (GetCurrentlySelectedDrive (), m_nero);
frm.ShowDialog (this);
}
}
}