ChooseSession.cs 10 KB

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