SelectDiskImageForm.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using DiskAccessLibrary;
  2. using ISCSIConsole.Mods;
  3. using System;
  4. using System.IO;
  5. using System.Windows.Forms;
  6. namespace ISCSIConsole
  7. {
  8. public partial class SelectDiskImageForm : BaseForm
  9. {
  10. private DiskImage m_diskImage;
  11. public SelectDiskImageForm()
  12. {
  13. InitializeComponent();
  14. }
  15. private void btnCancel_Click(object sender, EventArgs e)
  16. {
  17. this.DialogResult = DialogResult.Cancel;
  18. this.Close();
  19. }
  20. private void btnOK_Click(object sender, EventArgs e)
  21. {
  22. string path = txtFilePath.Text;
  23. if (path == String.Empty)
  24. {
  25. MessageBox.Show("Please choose file location.", "Error");
  26. return;
  27. }
  28. DiskImage diskImage;
  29. try
  30. {
  31. diskImage = DiskImage.GetDiskImage(path, chkReadOnly.Checked);
  32. }
  33. catch (IOException ex)
  34. {
  35. MessageBox.Show("Can't open disk image: " + ex.Message, "Error");
  36. return;
  37. }
  38. catch (InvalidDataException ex)
  39. {
  40. MessageBox.Show("Invalid disk image: " + ex.Message, "Error");
  41. return;
  42. }
  43. catch (NotImplementedException)
  44. {
  45. MessageBox.Show("Unsupported Disk Image Format", "Error");
  46. return;
  47. }
  48. bool isLocked = false;
  49. try
  50. {
  51. isLocked = diskImage.ExclusiveLock();
  52. }
  53. catch (IOException)
  54. {
  55. }
  56. if (!isLocked)
  57. {
  58. MessageBox.Show("Cannot lock the disk image for exclusive access.", "Error");
  59. return;
  60. }
  61. m_diskImage = diskImage;
  62. this.DialogResult = DialogResult.OK;
  63. this.Close();
  64. }
  65. private void btnBrowse_Click(object sender, EventArgs e)
  66. {
  67. DialogResult result = openDiskImageDialog.ShowDialog();
  68. if (result == DialogResult.OK)
  69. {
  70. txtFilePath.Text = openDiskImageDialog.FileName;
  71. DiskInfiValueLabel.Text = DiskImage.GetDiskImageInfo(txtFilePath.Text);
  72. }
  73. }
  74. public DiskImage DiskImage
  75. {
  76. get
  77. {
  78. return m_diskImage;
  79. }
  80. }
  81. }
  82. }