NVAPI.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6. using NEROLib;
  7. namespace LYFZ.NeroDiscBurn.NET
  8. {
  9. /// <summary>
  10. /// Summary description for NVAPIForm.
  11. /// </summary>
  12. public class NVAPIForm : System.Windows.Forms.Form
  13. {
  14. private NeroDrive m_drive;
  15. private Nero m_nero;
  16. private ChooseBurnFlagsForm m_frmChooseBurnFlags;
  17. private ChooseSpeedForm m_frmChooseWriteSpeed;
  18. private NVAPIEstimateForm m_frmEstimateProgress;
  19. private NeroVisionAPI.Project m_project;
  20. private System.Windows.Forms.Label label1;
  21. private System.Windows.Forms.Button c_Browse;
  22. private System.Windows.Forms.TextBox c_Filename;
  23. private System.Windows.Forms.TextBox c_Device;
  24. private System.Windows.Forms.Label label2;
  25. private System.Windows.Forms.Button c_ChooseSpeed;
  26. private System.Windows.Forms.Button c_BurnFlags;
  27. private System.Windows.Forms.Label label4;
  28. private System.Windows.Forms.TextBox c_Settings;
  29. private System.Windows.Forms.Label label3;
  30. private System.Windows.Forms.Label label5;
  31. private System.Windows.Forms.Button c_Estimate;
  32. private System.Windows.Forms.Button c_Burn;
  33. private System.Windows.Forms.TextBox c_EstimatedTime;
  34. private System.Windows.Forms.TextBox c_EstimatedSize;
  35. private System.Windows.Forms.Button c_Cancel;
  36. /// <summary>
  37. /// Required designer variable.
  38. /// </summary>
  39. private System.ComponentModel.Container components = null;
  40. public NVAPIForm(NeroDrive drive, Nero nero)
  41. {
  42. //
  43. // Required for Windows Form Designer support
  44. //
  45. InitializeComponent();
  46. m_drive = drive;
  47. m_nero = nero;
  48. m_frmChooseBurnFlags = new ChooseBurnFlagsForm ();
  49. m_frmChooseWriteSpeed = new ChooseSpeedForm (m_drive, true);
  50. m_frmEstimateProgress = new NVAPIEstimateForm ();
  51. }
  52. /// <summary>
  53. /// Clean up any resources being used.
  54. /// </summary>
  55. protected override void Dispose( bool disposing )
  56. {
  57. if( disposing )
  58. {
  59. if(components != null)
  60. {
  61. components.Dispose();
  62. }
  63. }
  64. base.Dispose( disposing );
  65. }
  66. #region Windows Form Designer generated code
  67. /// <summary>
  68. /// Required method for Designer support - do not modify
  69. /// the contents of this method with the code editor.
  70. /// </summary>
  71. private void InitializeComponent()
  72. {
  73. this.label1 = new System.Windows.Forms.Label();
  74. this.c_Browse = new System.Windows.Forms.Button();
  75. this.c_Filename = new System.Windows.Forms.TextBox();
  76. this.c_Device = new System.Windows.Forms.TextBox();
  77. this.label2 = new System.Windows.Forms.Label();
  78. this.c_ChooseSpeed = new System.Windows.Forms.Button();
  79. this.c_BurnFlags = new System.Windows.Forms.Button();
  80. this.label4 = new System.Windows.Forms.Label();
  81. this.c_Settings = new System.Windows.Forms.TextBox();
  82. this.label3 = new System.Windows.Forms.Label();
  83. this.label5 = new System.Windows.Forms.Label();
  84. this.c_Estimate = new System.Windows.Forms.Button();
  85. this.c_Burn = new System.Windows.Forms.Button();
  86. this.c_EstimatedTime = new System.Windows.Forms.TextBox();
  87. this.c_EstimatedSize = new System.Windows.Forms.TextBox();
  88. this.c_Cancel = new System.Windows.Forms.Button();
  89. this.SuspendLayout();
  90. //
  91. // label1
  92. //
  93. this.label1.Location = new System.Drawing.Point(8, 48);
  94. this.label1.Name = "label1";
  95. this.label1.Size = new System.Drawing.Size(120, 16);
  96. this.label1.TabIndex = 2;
  97. this.label1.Text = "XML Project Filename:";
  98. //
  99. // c_Browse
  100. //
  101. this.c_Browse.Location = new System.Drawing.Point(320, 64);
  102. this.c_Browse.Name = "c_Browse";
  103. this.c_Browse.Size = new System.Drawing.Size(88, 23);
  104. this.c_Browse.TabIndex = 4;
  105. this.c_Browse.Text = "Browse";
  106. this.c_Browse.Click += new System.EventHandler(this.c_Browse_Click);
  107. //
  108. // c_Filename
  109. //
  110. this.c_Filename.Location = new System.Drawing.Point(8, 64);
  111. this.c_Filename.Name = "c_Filename";
  112. this.c_Filename.Size = new System.Drawing.Size(304, 20);
  113. this.c_Filename.TabIndex = 3;
  114. this.c_Filename.Text = "";
  115. //
  116. // c_Device
  117. //
  118. this.c_Device.Location = new System.Drawing.Point(8, 24);
  119. this.c_Device.Name = "c_Device";
  120. this.c_Device.ReadOnly = true;
  121. this.c_Device.Size = new System.Drawing.Size(192, 20);
  122. this.c_Device.TabIndex = 1;
  123. this.c_Device.Text = "";
  124. //
  125. // label2
  126. //
  127. this.label2.Location = new System.Drawing.Point(8, 8);
  128. this.label2.Name = "label2";
  129. this.label2.Size = new System.Drawing.Size(120, 16);
  130. this.label2.TabIndex = 0;
  131. this.label2.Text = "Device:";
  132. //
  133. // c_ChooseSpeed
  134. //
  135. this.c_ChooseSpeed.Location = new System.Drawing.Point(320, 96);
  136. this.c_ChooseSpeed.Name = "c_ChooseSpeed";
  137. this.c_ChooseSpeed.Size = new System.Drawing.Size(88, 23);
  138. this.c_ChooseSpeed.TabIndex = 7;
  139. this.c_ChooseSpeed.Text = "Choose Speed";
  140. this.c_ChooseSpeed.Click += new System.EventHandler(this.c_ChooseSpeed_Click);
  141. //
  142. // c_BurnFlags
  143. //
  144. this.c_BurnFlags.Location = new System.Drawing.Point(320, 128);
  145. this.c_BurnFlags.Name = "c_BurnFlags";
  146. this.c_BurnFlags.Size = new System.Drawing.Size(88, 23);
  147. this.c_BurnFlags.TabIndex = 8;
  148. this.c_BurnFlags.Text = "Burn Flags";
  149. this.c_BurnFlags.Click += new System.EventHandler(this.c_BurnFlags_Click);
  150. //
  151. // label4
  152. //
  153. this.label4.Location = new System.Drawing.Point(8, 88);
  154. this.label4.Name = "label4";
  155. this.label4.Size = new System.Drawing.Size(120, 16);
  156. this.label4.TabIndex = 5;
  157. this.label4.Text = "Settings:";
  158. //
  159. // c_Settings
  160. //
  161. this.c_Settings.Location = new System.Drawing.Point(8, 104);
  162. this.c_Settings.Multiline = true;
  163. this.c_Settings.Name = "c_Settings";
  164. this.c_Settings.ReadOnly = true;
  165. this.c_Settings.ScrollBars = System.Windows.Forms.ScrollBars.Both;
  166. this.c_Settings.Size = new System.Drawing.Size(304, 88);
  167. this.c_Settings.TabIndex = 6;
  168. this.c_Settings.Text = "";
  169. //
  170. // label3
  171. //
  172. this.label3.Location = new System.Drawing.Point(8, 200);
  173. this.label3.Name = "label3";
  174. this.label3.Size = new System.Drawing.Size(192, 16);
  175. this.label3.TabIndex = 9;
  176. this.label3.Text = "Estimated time for video transcoding:";
  177. //
  178. // label5
  179. //
  180. this.label5.Location = new System.Drawing.Point(8, 248);
  181. this.label5.Name = "label5";
  182. this.label5.Size = new System.Drawing.Size(120, 16);
  183. this.label5.TabIndex = 11;
  184. this.label5.Text = "Estimated disc size:";
  185. //
  186. // c_Estimate
  187. //
  188. this.c_Estimate.Location = new System.Drawing.Point(320, 200);
  189. this.c_Estimate.Name = "c_Estimate";
  190. this.c_Estimate.Size = new System.Drawing.Size(88, 23);
  191. this.c_Estimate.TabIndex = 13;
  192. this.c_Estimate.Text = "Estimate";
  193. this.c_Estimate.Click += new System.EventHandler(this.c_Estimate_Click);
  194. //
  195. // c_Burn
  196. //
  197. this.c_Burn.Enabled = false;
  198. this.c_Burn.Location = new System.Drawing.Point(320, 232);
  199. this.c_Burn.Name = "c_Burn";
  200. this.c_Burn.Size = new System.Drawing.Size(88, 23);
  201. this.c_Burn.TabIndex = 14;
  202. this.c_Burn.Text = "Burn";
  203. this.c_Burn.Click += new System.EventHandler(this.c_Burn_Click);
  204. //
  205. // c_EstimatedTime
  206. //
  207. this.c_EstimatedTime.Location = new System.Drawing.Point(8, 216);
  208. this.c_EstimatedTime.Name = "c_EstimatedTime";
  209. this.c_EstimatedTime.ReadOnly = true;
  210. this.c_EstimatedTime.Size = new System.Drawing.Size(160, 20);
  211. this.c_EstimatedTime.TabIndex = 10;
  212. this.c_EstimatedTime.Text = "";
  213. //
  214. // c_EstimatedSize
  215. //
  216. this.c_EstimatedSize.Location = new System.Drawing.Point(8, 264);
  217. this.c_EstimatedSize.Name = "c_EstimatedSize";
  218. this.c_EstimatedSize.ReadOnly = true;
  219. this.c_EstimatedSize.Size = new System.Drawing.Size(160, 20);
  220. this.c_EstimatedSize.TabIndex = 12;
  221. this.c_EstimatedSize.Text = "";
  222. //
  223. // c_Cancel
  224. //
  225. this.c_Cancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
  226. this.c_Cancel.Location = new System.Drawing.Point(320, 264);
  227. this.c_Cancel.Name = "c_Cancel";
  228. this.c_Cancel.Size = new System.Drawing.Size(88, 23);
  229. this.c_Cancel.TabIndex = 15;
  230. this.c_Cancel.Text = "Cancel";
  231. //
  232. // NVAPIForm
  233. //
  234. this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  235. this.CancelButton = this.c_Cancel;
  236. this.ClientSize = new System.Drawing.Size(418, 296);
  237. this.Controls.Add(this.c_EstimatedTime);
  238. this.Controls.Add(this.c_Settings);
  239. this.Controls.Add(this.c_Device);
  240. this.Controls.Add(this.c_Filename);
  241. this.Controls.Add(this.c_EstimatedSize);
  242. this.Controls.Add(this.c_Browse);
  243. this.Controls.Add(this.label1);
  244. this.Controls.Add(this.label2);
  245. this.Controls.Add(this.c_ChooseSpeed);
  246. this.Controls.Add(this.c_BurnFlags);
  247. this.Controls.Add(this.label4);
  248. this.Controls.Add(this.label3);
  249. this.Controls.Add(this.label5);
  250. this.Controls.Add(this.c_Estimate);
  251. this.Controls.Add(this.c_Burn);
  252. this.Controls.Add(this.c_Cancel);
  253. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
  254. this.MaximizeBox = false;
  255. this.Name = "NVAPIForm";
  256. this.ShowInTaskbar = false;
  257. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
  258. this.Text = "NVAPIForm";
  259. this.ResumeLayout(false);
  260. }
  261. #endregion
  262. protected override void OnLoad(EventArgs e)
  263. {
  264. base.OnLoad (e);
  265. c_Device.Text = m_drive.DeviceName;
  266. UpdateEstimateControls ();
  267. UpdateSettings ();
  268. }
  269. private void c_Browse_Click(object sender, System.EventArgs e)
  270. {
  271. OpenFileDialog dlg = new OpenFileDialog ();
  272. dlg.CheckFileExists = true;
  273. dlg.CheckPathExists = true;
  274. dlg.DefaultExt = ".xml";
  275. dlg.FileName = c_Filename.Text;
  276. dlg.Filter = "XML Project files|*.xml|All files (*.*)|*.*";
  277. if (DialogResult.OK == dlg.ShowDialog (this))
  278. {
  279. c_Filename.Text = dlg.FileName;
  280. UpdateEstimateControls ();
  281. }
  282. }
  283. private void UpdateEstimateControls ()
  284. {
  285. // Enable the Estimate button according to the content
  286. // of the filename editbox.
  287. //
  288. bool bEnabled = c_Filename.Text != "";
  289. c_Estimate.Enabled = bEnabled;
  290. if (!bEnabled)
  291. {
  292. c_EstimatedTime.Text = "--- nothing yet ---";
  293. c_EstimatedSize.Text = "--- nothing yet ---";
  294. }
  295. }
  296. private void UpdateSettings ()
  297. {
  298. // Update the settings readonly editbox with current
  299. // burn flags and write speed settings.
  300. //
  301. c_Settings.Text = "Burn flags: " + m_frmChooseBurnFlags.ToString () + "\r\n\r\n"
  302. + "Write speed: " + m_frmChooseWriteSpeed.ToString ();
  303. }
  304. private void c_BurnFlags_Click(object sender, System.EventArgs e)
  305. {
  306. if (DialogResult.OK == m_frmChooseBurnFlags.ShowDialog (this))
  307. {
  308. UpdateSettings ();
  309. }
  310. }
  311. private void c_ChooseSpeed_Click(object sender, System.EventArgs e)
  312. {
  313. if (DialogResult.OK == m_frmChooseWriteSpeed.ShowDialog (this))
  314. {
  315. UpdateSettings ();
  316. }
  317. }
  318. private void c_Estimate_Click(object sender, System.EventArgs e)
  319. {
  320. // The Estimate button is clicked.
  321. //
  322. bool bSuccess = false;
  323. // Create a new NeroVisionAPI project object.
  324. //
  325. m_project = new NeroVisionAPI.ProjectClass ();
  326. // Try load the XML project into the project object.
  327. //
  328. if (m_project.SetXMLFile (c_Filename.Text))
  329. {
  330. // If the project is loaded successfully, launch the
  331. // estimation form which will display progress of the
  332. // estimation.
  333. //
  334. double seconds;
  335. NVAPIEstimateForm frmEstimate = new NVAPIEstimateForm ();
  336. if (frmEstimate.Estimate (this, m_project, out seconds))
  337. {
  338. // If estimation went ok, display the estimated length.
  339. //
  340. c_EstimatedTime.Text = (seconds/60).ToString ("0") + " minutes and " + (seconds%60).ToString ("0") + " seconds";
  341. long size;
  342. // Now, try estimating the disc size.
  343. //
  344. if (m_project.EstimateDiskSize (out size))
  345. {
  346. c_EstimatedSize.Text = ((size + 512*1024)/(1024*1024)).ToString () + " MB";
  347. bSuccess = true;
  348. }
  349. }
  350. }
  351. // Enable the burn button according to the estimation success.
  352. //
  353. c_Burn.Enabled = bSuccess;
  354. if (!bSuccess)
  355. {
  356. // If the estimation failed, show the error!
  357. //
  358. c_EstimatedTime.Text = "--- error estimating time ---";
  359. c_EstimatedSize.Text = "--- error estimating size ---";
  360. ShowNVAPIError ();
  361. }
  362. }
  363. private void ShowNVAPIError ()
  364. {
  365. if (m_project != null)
  366. {
  367. // Get the error object from the project and
  368. // display its content.
  369. //
  370. NeroVisionAPI.IError err = m_project.LastError;
  371. MessageBox.Show (this, "Error: " + err.ErrText + ", code: " + err.ErrCode.ToString ());
  372. }
  373. }
  374. private void c_Burn_Click(object sender, System.EventArgs e)
  375. {
  376. // When the Burn button is clicked, create an estimation form
  377. // which is used for showing transcoding progress as well.
  378. //
  379. NVAPIEstimateForm frmEstimate = new NVAPIEstimateForm ();
  380. NeroVisionAPI.INeroBurnContext pBurnContext;
  381. // Display the progress form. We will get INeroBurnContext as a result.
  382. //
  383. if (frmEstimate.CreateNeroBurnContext (this, m_project, out pBurnContext))
  384. {
  385. // If transcoding went well, we should proceed with burning.
  386. // Create a burn progress form.
  387. //
  388. BurnProgressForm frmBurnProgress = new BurnProgressForm (m_drive, m_nero);
  389. // Start burning...
  390. //
  391. frmBurnProgress.BurnNeroBurnContext (pBurnContext,
  392. m_frmChooseBurnFlags.GetBurnFlags (),
  393. m_frmChooseWriteSpeed.GetSpeed (),
  394. this);
  395. }
  396. else
  397. {
  398. ShowNVAPIError ();
  399. }
  400. // Once burn was attempted, we should disable further attempts.
  401. // A successful estimation will re-enable it again.
  402. //
  403. c_Burn.Enabled = false;
  404. }
  405. }
  406. }