123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442 |
- using System;
- using System.Drawing;
- using System.Collections;
- using System.ComponentModel;
- using System.Windows.Forms;
- using NEROLib;
- namespace LYFZ.NeroDiscBurn.NET
- {
- /// <summary>
- /// Summary description for NVAPIForm.
- /// </summary>
- public class NVAPIForm : System.Windows.Forms.Form
- {
- private NeroDrive m_drive;
- private Nero m_nero;
- private ChooseBurnFlagsForm m_frmChooseBurnFlags;
- private ChooseSpeedForm m_frmChooseWriteSpeed;
- private NVAPIEstimateForm m_frmEstimateProgress;
- private NeroVisionAPI.Project m_project;
- private System.Windows.Forms.Label label1;
- private System.Windows.Forms.Button c_Browse;
- private System.Windows.Forms.TextBox c_Filename;
- private System.Windows.Forms.TextBox c_Device;
- private System.Windows.Forms.Label label2;
- private System.Windows.Forms.Button c_ChooseSpeed;
- private System.Windows.Forms.Button c_BurnFlags;
- private System.Windows.Forms.Label label4;
- private System.Windows.Forms.TextBox c_Settings;
- private System.Windows.Forms.Label label3;
- private System.Windows.Forms.Label label5;
- private System.Windows.Forms.Button c_Estimate;
- private System.Windows.Forms.Button c_Burn;
- private System.Windows.Forms.TextBox c_EstimatedTime;
- private System.Windows.Forms.TextBox c_EstimatedSize;
- private System.Windows.Forms.Button c_Cancel;
- /// <summary>
- /// Required designer variable.
- /// </summary>
- private System.ComponentModel.Container components = null;
- public NVAPIForm(NeroDrive drive, Nero nero)
- {
- //
- // Required for Windows Form Designer support
- //
- InitializeComponent();
- m_drive = drive;
- m_nero = nero;
- m_frmChooseBurnFlags = new ChooseBurnFlagsForm ();
- m_frmChooseWriteSpeed = new ChooseSpeedForm (m_drive, true);
- m_frmEstimateProgress = new NVAPIEstimateForm ();
- }
- /// <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.label1 = new System.Windows.Forms.Label();
- this.c_Browse = new System.Windows.Forms.Button();
- this.c_Filename = new System.Windows.Forms.TextBox();
- this.c_Device = new System.Windows.Forms.TextBox();
- this.label2 = new System.Windows.Forms.Label();
- this.c_ChooseSpeed = new System.Windows.Forms.Button();
- this.c_BurnFlags = new System.Windows.Forms.Button();
- this.label4 = new System.Windows.Forms.Label();
- this.c_Settings = new System.Windows.Forms.TextBox();
- this.label3 = new System.Windows.Forms.Label();
- this.label5 = new System.Windows.Forms.Label();
- this.c_Estimate = new System.Windows.Forms.Button();
- this.c_Burn = new System.Windows.Forms.Button();
- this.c_EstimatedTime = new System.Windows.Forms.TextBox();
- this.c_EstimatedSize = new System.Windows.Forms.TextBox();
- this.c_Cancel = new System.Windows.Forms.Button();
- this.SuspendLayout();
- //
- // label1
- //
- this.label1.Location = new System.Drawing.Point(8, 48);
- this.label1.Name = "label1";
- this.label1.Size = new System.Drawing.Size(120, 16);
- this.label1.TabIndex = 2;
- this.label1.Text = "XML Project Filename:";
- //
- // c_Browse
- //
- this.c_Browse.Location = new System.Drawing.Point(320, 64);
- this.c_Browse.Name = "c_Browse";
- this.c_Browse.Size = new System.Drawing.Size(88, 23);
- this.c_Browse.TabIndex = 4;
- this.c_Browse.Text = "Browse";
- this.c_Browse.Click += new System.EventHandler(this.c_Browse_Click);
- //
- // c_Filename
- //
- this.c_Filename.Location = new System.Drawing.Point(8, 64);
- this.c_Filename.Name = "c_Filename";
- this.c_Filename.Size = new System.Drawing.Size(304, 20);
- this.c_Filename.TabIndex = 3;
- this.c_Filename.Text = "";
- //
- // c_Device
- //
- this.c_Device.Location = new System.Drawing.Point(8, 24);
- this.c_Device.Name = "c_Device";
- this.c_Device.ReadOnly = true;
- this.c_Device.Size = new System.Drawing.Size(192, 20);
- this.c_Device.TabIndex = 1;
- this.c_Device.Text = "";
- //
- // label2
- //
- this.label2.Location = new System.Drawing.Point(8, 8);
- this.label2.Name = "label2";
- this.label2.Size = new System.Drawing.Size(120, 16);
- this.label2.TabIndex = 0;
- this.label2.Text = "Device:";
- //
- // c_ChooseSpeed
- //
- this.c_ChooseSpeed.Location = new System.Drawing.Point(320, 96);
- this.c_ChooseSpeed.Name = "c_ChooseSpeed";
- this.c_ChooseSpeed.Size = new System.Drawing.Size(88, 23);
- this.c_ChooseSpeed.TabIndex = 7;
- this.c_ChooseSpeed.Text = "Choose Speed";
- this.c_ChooseSpeed.Click += new System.EventHandler(this.c_ChooseSpeed_Click);
- //
- // c_BurnFlags
- //
- this.c_BurnFlags.Location = new System.Drawing.Point(320, 128);
- this.c_BurnFlags.Name = "c_BurnFlags";
- this.c_BurnFlags.Size = new System.Drawing.Size(88, 23);
- this.c_BurnFlags.TabIndex = 8;
- this.c_BurnFlags.Text = "Burn Flags";
- this.c_BurnFlags.Click += new System.EventHandler(this.c_BurnFlags_Click);
- //
- // label4
- //
- this.label4.Location = new System.Drawing.Point(8, 88);
- this.label4.Name = "label4";
- this.label4.Size = new System.Drawing.Size(120, 16);
- this.label4.TabIndex = 5;
- this.label4.Text = "Settings:";
- //
- // c_Settings
- //
- this.c_Settings.Location = new System.Drawing.Point(8, 104);
- this.c_Settings.Multiline = true;
- this.c_Settings.Name = "c_Settings";
- this.c_Settings.ReadOnly = true;
- this.c_Settings.ScrollBars = System.Windows.Forms.ScrollBars.Both;
- this.c_Settings.Size = new System.Drawing.Size(304, 88);
- this.c_Settings.TabIndex = 6;
- this.c_Settings.Text = "";
- //
- // label3
- //
- this.label3.Location = new System.Drawing.Point(8, 200);
- this.label3.Name = "label3";
- this.label3.Size = new System.Drawing.Size(192, 16);
- this.label3.TabIndex = 9;
- this.label3.Text = "Estimated time for video transcoding:";
- //
- // label5
- //
- this.label5.Location = new System.Drawing.Point(8, 248);
- this.label5.Name = "label5";
- this.label5.Size = new System.Drawing.Size(120, 16);
- this.label5.TabIndex = 11;
- this.label5.Text = "Estimated disc size:";
- //
- // c_Estimate
- //
- this.c_Estimate.Location = new System.Drawing.Point(320, 200);
- this.c_Estimate.Name = "c_Estimate";
- this.c_Estimate.Size = new System.Drawing.Size(88, 23);
- this.c_Estimate.TabIndex = 13;
- this.c_Estimate.Text = "Estimate";
- this.c_Estimate.Click += new System.EventHandler(this.c_Estimate_Click);
- //
- // c_Burn
- //
- this.c_Burn.Enabled = false;
- this.c_Burn.Location = new System.Drawing.Point(320, 232);
- this.c_Burn.Name = "c_Burn";
- this.c_Burn.Size = new System.Drawing.Size(88, 23);
- this.c_Burn.TabIndex = 14;
- this.c_Burn.Text = "Burn";
- this.c_Burn.Click += new System.EventHandler(this.c_Burn_Click);
- //
- // c_EstimatedTime
- //
- this.c_EstimatedTime.Location = new System.Drawing.Point(8, 216);
- this.c_EstimatedTime.Name = "c_EstimatedTime";
- this.c_EstimatedTime.ReadOnly = true;
- this.c_EstimatedTime.Size = new System.Drawing.Size(160, 20);
- this.c_EstimatedTime.TabIndex = 10;
- this.c_EstimatedTime.Text = "";
- //
- // c_EstimatedSize
- //
- this.c_EstimatedSize.Location = new System.Drawing.Point(8, 264);
- this.c_EstimatedSize.Name = "c_EstimatedSize";
- this.c_EstimatedSize.ReadOnly = true;
- this.c_EstimatedSize.Size = new System.Drawing.Size(160, 20);
- this.c_EstimatedSize.TabIndex = 12;
- this.c_EstimatedSize.Text = "";
- //
- // c_Cancel
- //
- this.c_Cancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
- this.c_Cancel.Location = new System.Drawing.Point(320, 264);
- this.c_Cancel.Name = "c_Cancel";
- this.c_Cancel.Size = new System.Drawing.Size(88, 23);
- this.c_Cancel.TabIndex = 15;
- this.c_Cancel.Text = "Cancel";
- //
- // NVAPIForm
- //
- this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
- this.CancelButton = this.c_Cancel;
- this.ClientSize = new System.Drawing.Size(418, 296);
- this.Controls.Add(this.c_EstimatedTime);
- this.Controls.Add(this.c_Settings);
- this.Controls.Add(this.c_Device);
- this.Controls.Add(this.c_Filename);
- this.Controls.Add(this.c_EstimatedSize);
- this.Controls.Add(this.c_Browse);
- this.Controls.Add(this.label1);
- this.Controls.Add(this.label2);
- this.Controls.Add(this.c_ChooseSpeed);
- this.Controls.Add(this.c_BurnFlags);
- this.Controls.Add(this.label4);
- this.Controls.Add(this.label3);
- this.Controls.Add(this.label5);
- this.Controls.Add(this.c_Estimate);
- this.Controls.Add(this.c_Burn);
- this.Controls.Add(this.c_Cancel);
- this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
- this.MaximizeBox = false;
- this.Name = "NVAPIForm";
- this.ShowInTaskbar = false;
- this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
- this.Text = "NVAPIForm";
- this.ResumeLayout(false);
- }
- #endregion
- protected override void OnLoad(EventArgs e)
- {
- base.OnLoad (e);
- c_Device.Text = m_drive.DeviceName;
- UpdateEstimateControls ();
- UpdateSettings ();
- }
- private void c_Browse_Click(object sender, System.EventArgs e)
- {
- OpenFileDialog dlg = new OpenFileDialog ();
- dlg.CheckFileExists = true;
- dlg.CheckPathExists = true;
- dlg.DefaultExt = ".xml";
- dlg.FileName = c_Filename.Text;
- dlg.Filter = "XML Project files|*.xml|All files (*.*)|*.*";
- if (DialogResult.OK == dlg.ShowDialog (this))
- {
- c_Filename.Text = dlg.FileName;
- UpdateEstimateControls ();
- }
- }
- private void UpdateEstimateControls ()
- {
- // Enable the Estimate button according to the content
- // of the filename editbox.
- //
- bool bEnabled = c_Filename.Text != "";
- c_Estimate.Enabled = bEnabled;
- if (!bEnabled)
- {
- c_EstimatedTime.Text = "--- nothing yet ---";
- c_EstimatedSize.Text = "--- nothing yet ---";
- }
- }
- private void UpdateSettings ()
- {
- // Update the settings readonly editbox with current
- // burn flags and write speed settings.
- //
- c_Settings.Text = "Burn flags: " + m_frmChooseBurnFlags.ToString () + "\r\n\r\n"
- + "Write speed: " + m_frmChooseWriteSpeed.ToString ();
- }
- private void c_BurnFlags_Click(object sender, System.EventArgs e)
- {
- if (DialogResult.OK == m_frmChooseBurnFlags.ShowDialog (this))
- {
- UpdateSettings ();
- }
- }
- private void c_ChooseSpeed_Click(object sender, System.EventArgs e)
- {
- if (DialogResult.OK == m_frmChooseWriteSpeed.ShowDialog (this))
- {
- UpdateSettings ();
- }
- }
- private void c_Estimate_Click(object sender, System.EventArgs e)
- {
- // The Estimate button is clicked.
- //
- bool bSuccess = false;
- // Create a new NeroVisionAPI project object.
- //
- m_project = new NeroVisionAPI.ProjectClass ();
- // Try load the XML project into the project object.
- //
- if (m_project.SetXMLFile (c_Filename.Text))
- {
- // If the project is loaded successfully, launch the
- // estimation form which will display progress of the
- // estimation.
- //
- double seconds;
- NVAPIEstimateForm frmEstimate = new NVAPIEstimateForm ();
- if (frmEstimate.Estimate (this, m_project, out seconds))
- {
- // If estimation went ok, display the estimated length.
- //
- c_EstimatedTime.Text = (seconds/60).ToString ("0") + " minutes and " + (seconds%60).ToString ("0") + " seconds";
- long size;
- // Now, try estimating the disc size.
- //
- if (m_project.EstimateDiskSize (out size))
- {
- c_EstimatedSize.Text = ((size + 512*1024)/(1024*1024)).ToString () + " MB";
- bSuccess = true;
- }
- }
- }
- // Enable the burn button according to the estimation success.
- //
- c_Burn.Enabled = bSuccess;
- if (!bSuccess)
- {
- // If the estimation failed, show the error!
- //
- c_EstimatedTime.Text = "--- error estimating time ---";
- c_EstimatedSize.Text = "--- error estimating size ---";
- ShowNVAPIError ();
- }
- }
- private void ShowNVAPIError ()
- {
- if (m_project != null)
- {
- // Get the error object from the project and
- // display its content.
- //
- NeroVisionAPI.IError err = m_project.LastError;
- MessageBox.Show (this, "Error: " + err.ErrText + ", code: " + err.ErrCode.ToString ());
- }
- }
- private void c_Burn_Click(object sender, System.EventArgs e)
- {
- // When the Burn button is clicked, create an estimation form
- // which is used for showing transcoding progress as well.
- //
- NVAPIEstimateForm frmEstimate = new NVAPIEstimateForm ();
- NeroVisionAPI.INeroBurnContext pBurnContext;
- // Display the progress form. We will get INeroBurnContext as a result.
- //
- if (frmEstimate.CreateNeroBurnContext (this, m_project, out pBurnContext))
- {
- // If transcoding went well, we should proceed with burning.
- // Create a burn progress form.
- //
- BurnProgressForm frmBurnProgress = new BurnProgressForm (m_drive, m_nero);
- // Start burning...
- //
- frmBurnProgress.BurnNeroBurnContext (pBurnContext,
- m_frmChooseBurnFlags.GetBurnFlags (),
- m_frmChooseWriteSpeed.GetSpeed (),
- this);
- }
- else
- {
- ShowNVAPIError ();
- }
- // Once burn was attempted, we should disable further attempts.
- // A successful estimation will re-enable it again.
- //
- c_Burn.Enabled = false;
- }
- }
- }
|