private void BrowseButton_Click(object sender, EventArgs e) { using var ofd = new OpenFileDialog { InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries["Global_NULL", "ROM"].Path, "Global_NULL"), Filter = MainForm.RomFilter, RestoreDirectory = true }; string _path = ""; var result = ofd.ShowHawkDialog(); if (result == DialogResult.OK) { _path = ofd.FileName; } else { return; } try { var file = new FileInfo(ofd.FileName); var path = BizHawk.Common.HawkFile.Util_ResolveLink(file.FullName); using (var hf = new BizHawk.Common.HawkFile(path)) { if (hf.IsArchive) { // archive - run the archive chooser if (SystemString == "PSX" || SystemString == "PCFX" || SystemString == "SAT") { MessageBox.Show("Using archives with PSX, PCFX or SATURN is not currently recommended/supported."); return; } using var ac = new ArchiveChooser(new BizHawk.Common.HawkFile(_path)); int memIdx = -1; if (ac.ShowDialog(this) == DialogResult.OK) { memIdx = ac.SelectedMemberIndex; } var intName = hf.ArchiveItems[memIdx]; PathBox.Text = $"{_path}|{intName.Name}"; } else { // file is not an archive PathBox.Text = _path; } } } catch { return; } }
private int? LoadArhiveChooser(HawkFile file) { var ac = new BizHawk.Client.EmuHawk.ArchiveChooser(file); if (ac.ShowDialog(this) == DialogResult.OK) { return ac.SelectedMemberIndex; } else { return null; } }
private void tsmiSetCustomization_Click(object sender, EventArgs e) { using (var ofd = new OpenFileDialog()) { ofd.InitialDirectory = currSelectorDir; ofd.RestoreDirectory = true; string frmwarePath = PathManager.MakeAbsolutePath(Global.Config.PathEntries.FirmwaresPathFragment, null); if (ofd.ShowDialog() == DialogResult.OK) { // remember the location we selected this firmware from, maybe there are others currSelectorDir = Path.GetDirectoryName(ofd.FileName); try { using (var hf = new HawkFile(ofd.FileName)) { // for each selected item, set the user choice (even though multiple selection for this operation is no longer allowed) foreach (ListViewItem lvi in lvFirmwares.SelectedItems) { var fr = lvi.Tag as FirmwareDatabase.FirmwareRecord; string filePath = ofd.FileName; // if the selected file is an archive, allow the user to pick the inside file // to always be copied to the global firmwares directory if (hf.IsArchive) { var ac = new ArchiveChooser(new HawkFile(filePath)); int memIdx = -1; if (ac.ShowDialog(this) == DialogResult.OK) { memIdx = ac.SelectedMemberIndex; } else { return; } var insideFile = hf.BindArchiveMember(memIdx); var fileData = insideFile.ReadAllBytes(); // write to file in the firmwares folder File.WriteAllBytes(Path.Combine(frmwarePath, insideFile.Name), fileData); filePath = Path.Combine(frmwarePath, insideFile.Name); } else { // selected file is not an archive // check whether this file is currently outside of the global firmware directory if (currSelectorDir != frmwarePath) { var askMoveResult = MessageBox.Show(this, "The selected custom firmware does not reside in the root of the global firmware directory.\nDo you want to copy it there?", "Import Custom Firmware", MessageBoxButtons.YesNo); if (askMoveResult == DialogResult.Yes) { try { FileInfo fi = new FileInfo(filePath); filePath = Path.Combine(frmwarePath, fi.Name); File.Copy(ofd.FileName, filePath); } catch (Exception ex) { MessageBox.Show(this, $"There was an issue copying the file. The customization has NOT been set.\n\n{ex.StackTrace}"); continue; } } } } Global.Config.FirmwareUserSpecifications[fr.ConfigKey] = filePath; } } } catch (Exception ex) { MessageBox.Show(this, $"There was an issue during the process. The customization has NOT been set.\n\n{ex.StackTrace}"); return; } DoScan(); } } }