private void tsbOpen_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Title = "Open IV Archive"; ofd.Filter = "All Supported IV Archives|*.rpf;*.img|RPF Files (*.rpf)|*.rpf|IMG Files (*.img)|*.img"; ofd.FileName = _lastOpenPath; if (ofd.ShowDialog() == DialogResult.OK) { _lastOpenPath = ofd.FileName; FileSystem fs = null; if (ofd.FilterIndex == 2) { fs = new RPFFileSystem(); } else if (ofd.FilterIndex == 3) { fs = new IMGFileSystem(); } else { if (ofd.FileName.EndsWith(".rpf")) { fs = new RPFFileSystem(); } else if (ofd.FileName.EndsWith(".img")) { fs = new IMGFileSystem(); } else { MessageBox.Show("Please select a type for the file you are trying to open.", "Open IV Archive", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } OpenFile(ofd.FileName, fs); } }
public void OpenFile(string filename, FileSystem fs) { if (fs == null) { if (filename.EndsWith(".rpf")) { fs = new RPFFileSystem(); } else if (filename.EndsWith(".img")) { fs = new IMGFileSystem(); } else if (IODirectory.Exists(filename)) { fs = new RealFileSystem(); filename = (new DirectoryInfo(filename)).FullName; } } if (fs != null) { if (IOFile.Exists(filename)) { FileInfo fi = new FileInfo(filename); if ((fi.Attributes & FileAttributes.ReadOnly) != 0) { DialogResult result = MessageBox.Show("The file you are trying to open appears to be read-only. " + "Would you like to make it writable before opening this file?", "Open", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { fi.Attributes = fi.Attributes & ~FileAttributes.ReadOnly; } } } try { using (new WaitCursor(this)) { fs.Open(filename); if (_fs != null) { _fs.Close(); } _fs = fs; Text = Application.ProductName + " - " + new FileInfo(filename).Name; } PopulateUI(); } catch (Exception ex) { fs.Close(); MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }