ChooseSession.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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 ChooseSession.
  11. /// ¸ÅҪ˵Ã÷ÁËÑ¡Ôñ»á»°¡£
  12. /// </summary>
  13. public class ChooseSessionForm : System.Windows.Forms.Form
  14. {
  15. private NeroDrive m_drive;
  16. private _INeroDriveEvents_OnDoneCDInfoEventHandler m_evOnDoneCDInfo;
  17. private ControlEnabler m_controlEnabler;
  18. private System.Windows.Forms.Button c_OK;
  19. private System.Windows.Forms.Button c_Cancel;
  20. private System.Windows.Forms.Label label5;
  21. private System.Windows.Forms.ListView c_PreviousVMS;
  22. private System.Windows.Forms.ColumnHeader columnHeader4;
  23. private System.Windows.Forms.ColumnHeader columnHeader2;
  24. private System.Windows.Forms.ListView c_PreviousSessions;
  25. private System.Windows.Forms.ColumnHeader columnHeader3;
  26. private System.Windows.Forms.ColumnHeader columnHeader1;
  27. private System.Windows.Forms.Button c_Refresh;
  28. private System.Windows.Forms.Label label6;
  29. /// <summary>
  30. /// Required designer variable.
  31. /// </summary>
  32. private System.ComponentModel.Container components = null;
  33. public ChooseSessionForm(NeroDrive drive)
  34. {
  35. //
  36. // Required for Windows Form Designer support
  37. //
  38. InitializeComponent();
  39. m_drive = drive;
  40. m_controlEnabler = new ControlEnabler (this);
  41. }
  42. /// <summary>
  43. /// Clean up any resources being used.
  44. /// </summary>
  45. protected override void Dispose( bool disposing )
  46. {
  47. if( disposing )
  48. {
  49. if(components != null)
  50. {
  51. components.Dispose();
  52. }
  53. }
  54. base.Dispose( disposing );
  55. }
  56. #region Windows Form Designer generated code
  57. /// <summary>
  58. /// Required method for Designer support - do not modify
  59. /// the contents of this method with the code editor.
  60. /// </summary>
  61. private void InitializeComponent()
  62. {
  63. this.c_OK = new System.Windows.Forms.Button();
  64. this.c_Cancel = new System.Windows.Forms.Button();
  65. this.label5 = new System.Windows.Forms.Label();
  66. this.c_PreviousVMS = new System.Windows.Forms.ListView();
  67. this.columnHeader4 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
  68. this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
  69. this.c_PreviousSessions = new System.Windows.Forms.ListView();
  70. this.columnHeader3 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
  71. this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
  72. this.c_Refresh = new System.Windows.Forms.Button();
  73. this.label6 = new System.Windows.Forms.Label();
  74. this.SuspendLayout();
  75. //
  76. // c_OK
  77. //
  78. this.c_OK.DialogResult = System.Windows.Forms.DialogResult.OK;
  79. this.c_OK.Location = new System.Drawing.Point(269, 26);
  80. this.c_OK.Name = "c_OK";
  81. this.c_OK.Size = new System.Drawing.Size(90, 25);
  82. this.c_OK.TabIndex = 5;
  83. this.c_OK.Text = "OK";
  84. //
  85. // c_Cancel
  86. //
  87. this.c_Cancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
  88. this.c_Cancel.Location = new System.Drawing.Point(269, 60);
  89. this.c_Cancel.Name = "c_Cancel";
  90. this.c_Cancel.Size = new System.Drawing.Size(90, 25);
  91. this.c_Cancel.TabIndex = 6;
  92. this.c_Cancel.Text = "Cancel";
  93. //
  94. // label5
  95. //
  96. this.label5.Location = new System.Drawing.Point(10, 9);
  97. this.label5.Name = "label5";
  98. this.label5.Size = new System.Drawing.Size(120, 17);
  99. this.label5.TabIndex = 0;
  100. this.label5.Text = "Previous sessions:";
  101. //
  102. // c_PreviousVMS
  103. //
  104. this.c_PreviousVMS.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
  105. this.columnHeader4,
  106. this.columnHeader2});
  107. this.c_PreviousVMS.Enabled = false;
  108. this.c_PreviousVMS.FullRowSelect = true;
  109. this.c_PreviousVMS.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
  110. this.c_PreviousVMS.HideSelection = false;
  111. this.c_PreviousVMS.Location = new System.Drawing.Point(10, 172);
  112. this.c_PreviousVMS.MultiSelect = false;
  113. this.c_PreviousVMS.Name = "c_PreviousVMS";
  114. this.c_PreviousVMS.Size = new System.Drawing.Size(249, 121);
  115. this.c_PreviousVMS.TabIndex = 3;
  116. this.c_PreviousVMS.UseCompatibleStateImageBehavior = false;
  117. this.c_PreviousVMS.View = System.Windows.Forms.View.Details;
  118. //
  119. // columnHeader4
  120. //
  121. this.columnHeader4.Text = "T#";
  122. this.columnHeader4.Width = 33;
  123. //
  124. // columnHeader2
  125. //
  126. this.columnHeader2.Text = "Session Name";
  127. this.columnHeader2.Width = 152;
  128. //
  129. // c_PreviousSessions
  130. //
  131. this.c_PreviousSessions.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
  132. this.columnHeader3,
  133. this.columnHeader1});
  134. this.c_PreviousSessions.Enabled = false;
  135. this.c_PreviousSessions.FullRowSelect = true;
  136. this.c_PreviousSessions.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
  137. this.c_PreviousSessions.HideSelection = false;
  138. this.c_PreviousSessions.Location = new System.Drawing.Point(10, 26);
  139. this.c_PreviousSessions.MultiSelect = false;
  140. this.c_PreviousSessions.Name = "c_PreviousSessions";
  141. this.c_PreviousSessions.Size = new System.Drawing.Size(249, 120);
  142. this.c_PreviousSessions.TabIndex = 1;
  143. this.c_PreviousSessions.UseCompatibleStateImageBehavior = false;
  144. this.c_PreviousSessions.View = System.Windows.Forms.View.Details;
  145. //
  146. // columnHeader3
  147. //
  148. this.columnHeader3.Text = "Session number";
  149. this.columnHeader3.Width = 97;
  150. //
  151. // columnHeader1
  152. //
  153. this.columnHeader1.Text = "Track number";
  154. this.columnHeader1.Width = 85;
  155. //
  156. // c_Refresh
  157. //
  158. this.c_Refresh.Location = new System.Drawing.Point(269, 121);
  159. this.c_Refresh.Name = "c_Refresh";
  160. this.c_Refresh.Size = new System.Drawing.Size(90, 24);
  161. this.c_Refresh.TabIndex = 4;
  162. this.c_Refresh.Text = "Refresh";
  163. this.c_Refresh.Click += new System.EventHandler(this.c_Refresh_Click);
  164. //
  165. // label6
  166. //
  167. this.label6.Location = new System.Drawing.Point(10, 155);
  168. this.label6.Name = "label6";
  169. this.label6.Size = new System.Drawing.Size(120, 17);
  170. this.label6.TabIndex = 2;
  171. this.label6.Text = "Previous VMS:";
  172. //
  173. // ChooseSessionForm
  174. //
  175. this.AcceptButton = this.c_OK;
  176. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  177. this.CancelButton = this.c_Cancel;
  178. this.ClientSize = new System.Drawing.Size(457, 280);
  179. this.Controls.Add(this.label5);
  180. this.Controls.Add(this.c_PreviousVMS);
  181. this.Controls.Add(this.c_PreviousSessions);
  182. this.Controls.Add(this.c_Refresh);
  183. this.Controls.Add(this.label6);
  184. this.Controls.Add(this.c_OK);
  185. this.Controls.Add(this.c_Cancel);
  186. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
  187. this.MaximizeBox = false;
  188. this.MinimizeBox = false;
  189. this.Name = "ChooseSessionForm";
  190. this.ShowInTaskbar = false;
  191. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
  192. this.Text = "ChooseSession";
  193. this.ResumeLayout(false);
  194. }
  195. #endregion
  196. protected override void OnLoad(EventArgs e)
  197. {
  198. base.OnLoad (e);
  199. // On load, display the sessions.
  200. //
  201. RefreshSessions ();
  202. }
  203. private void RefreshSessions()
  204. {
  205. // Subscribe to the OnDoneCDInfo event.
  206. //
  207. m_evOnDoneCDInfo = new _INeroDriveEvents_OnDoneCDInfoEventHandler(m_drive_OnDoneCDInfo);
  208. m_drive.OnDoneCDInfo += m_evOnDoneCDInfo;
  209. // We could do a this.Enabled=false here but then the wait
  210. // cursor will always be the arrow.
  211. //
  212. m_controlEnabler.EnableAllControls (false);
  213. this.Cursor = Cursors.WaitCursor;
  214. // When everything is setup, do the disc info.
  215. //
  216. m_drive.CDInfo (0);
  217. }
  218. private void c_Refresh_Click(object sender, System.EventArgs e)
  219. {
  220. // Refresh everything on request...
  221. //
  222. RefreshSessions ();
  223. }
  224. private void m_drive_OnDoneCDInfo(INeroCDInfo pCDInfo)
  225. {
  226. // When the disc info event fires, we should return
  227. // to the previous state of all controls, restore the
  228. // cursor and unsubscribe from the event.
  229. //
  230. m_controlEnabler.EnableAllControls (true);
  231. m_drive.OnDoneCDInfo -= m_evOnDoneCDInfo;
  232. c_PreviousSessions.Items.Clear ();
  233. c_PreviousVMS.Items.Clear ();
  234. NeroCDInfo cdinfo = (NeroCDInfo) pCDInfo;
  235. if (cdinfo != null)
  236. {
  237. // If we got a disc information, let's add all the data
  238. // tracks to the list view.
  239. //
  240. int iTrackCount = 0;
  241. foreach (NeroTrack trk in cdinfo.Tracks)
  242. {
  243. if (trk.TrackType == NERO_TRACK_TYPE.NERO_TT_DATA)
  244. {
  245. iTrackCount ++;
  246. ListViewItem lvi = c_PreviousSessions.Items.Add (trk.SessionNumber.ToString ());
  247. lvi.SubItems.Add (trk.TrackNumber.ToString ());
  248. }
  249. }
  250. int iVMSCount = 0;
  251. bool bVMS = 0 != (cdinfo.MediumFlags & NERO_MEDIUM_FLAGS.NCDIMF_VIRTUALMULTISESSION);
  252. // If there is VMS info, display that as well.
  253. //
  254. if (bVMS)
  255. {
  256. NeroVMSInfo vmsInfo = m_drive.GetVMSInfo ();
  257. if (vmsInfo != null)
  258. {
  259. iVMSCount = vmsInfo.Count;
  260. int i = 1;
  261. foreach (NeroVMSSession vmsSession in vmsInfo)
  262. {
  263. ListViewItem lvi = c_PreviousVMS.Items.Add (i.ToString ());
  264. lvi.SubItems.Add (vmsSession.SessionName);
  265. i++;
  266. }
  267. }
  268. }
  269. c_PreviousSessions.Enabled = !bVMS && iTrackCount > 0;
  270. c_PreviousVMS.Enabled = bVMS && iVMSCount > 0;
  271. }
  272. else
  273. {
  274. c_PreviousSessions.Enabled = false;
  275. c_PreviousVMS.Enabled = false;
  276. }
  277. this.Cursor = Cursors.Default;
  278. }
  279. // This is a public function for the outside world to
  280. // find out which is the selected previous session,
  281. // if any. It is required that NERO_IMPORT_ISO_TRACK_FLAGS
  282. // variable is passed by reference so that it is modified
  283. // if needed.
  284. //
  285. public int GetTrackNumber (ref NERO_IMPORT_ISO_TRACK_FLAGS importFlags)
  286. {
  287. int iTrackNumber = -1;
  288. if (c_PreviousSessions.Enabled && c_PreviousSessions.SelectedIndices.Count > 0)
  289. {
  290. iTrackNumber = Convert.ToInt32 (c_PreviousSessions.SelectedItems[0].SubItems[0].Text);
  291. }
  292. else if (c_PreviousVMS.Enabled && c_PreviousVMS.SelectedIndices.Count > 0)
  293. {
  294. iTrackNumber = Convert.ToInt32 (c_PreviousVMS.SelectedItems[0].Text);
  295. importFlags = (NERO_IMPORT_ISO_TRACK_FLAGS) ((uint)importFlags + (uint)NERO_IMPORT_ISO_TRACK_FLAGS.NERO_IMPORT_VMS_SESSION);
  296. }
  297. return iTrackNumber;
  298. }
  299. // This is a ToString override that returns the description of
  300. // the currently selected session.
  301. //
  302. public new string ToString ()
  303. {
  304. NERO_IMPORT_ISO_TRACK_FLAGS importFlags = 0;
  305. int iTrackNumber = GetTrackNumber (ref importFlags);
  306. if (iTrackNumber != -1)
  307. {
  308. return iTrackNumber.ToString () + (0 != (importFlags & NERO_IMPORT_ISO_TRACK_FLAGS.NERO_IMPORT_VMS_SESSION)? " (VMS)" : "");
  309. }
  310. else
  311. {
  312. return "<none>";
  313. }
  314. }
  315. }
  316. }