SelectDiskImageForm.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.IO;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using DiskAccessLibrary;
  9. namespace ISCSIConsole
  10. {
  11. public partial class SelectDiskImageForm : Form
  12. {
  13. private DiskImage m_diskImage;
  14. public SelectDiskImageForm()
  15. {
  16. InitializeComponent();
  17. }
  18. private void btnCancel_Click(object sender, EventArgs e)
  19. {
  20. this.DialogResult = DialogResult.Cancel;
  21. this.Close();
  22. }
  23. private void btnOK_Click(object sender, EventArgs e)
  24. {
  25. string path = txtFilePath.Text;
  26. if (path == String.Empty)
  27. {
  28. MessageBox.Show("Please choose file location.", "Error");
  29. return;
  30. }
  31. DiskImage diskImage;
  32. try
  33. {
  34. diskImage = DiskImage.GetDiskImage(path);
  35. }
  36. catch (IOException)
  37. {
  38. MessageBox.Show("Can't open disk image.", "Error");
  39. return;
  40. }
  41. bool isLocked = diskImage.ExclusiveLock();
  42. if (!isLocked)
  43. {
  44. MessageBox.Show("Cannot lock the disk image for exclusive access.", "Error");
  45. return;
  46. }
  47. m_diskImage = diskImage;
  48. this.DialogResult = DialogResult.OK;
  49. this.Close();
  50. }
  51. private void btnBrowse_Click(object sender, EventArgs e)
  52. {
  53. DialogResult result = openDiskImageDialog.ShowDialog();
  54. if (result == DialogResult.OK)
  55. {
  56. txtFilePath.Text = openDiskImageDialog.FileName;
  57. }
  58. }
  59. public DiskImage DiskImage
  60. {
  61. get
  62. {
  63. return m_diskImage;
  64. }
  65. }
  66. }
  67. }