MultiDIskBundler - cleanup, pass dependencies to child controls

This commit is contained in:
adelikat 2019-12-22 11:59:41 -06:00
parent 3b60b08a11
commit 640e4260cd
2 changed files with 42 additions and 50 deletions

View File

@ -37,7 +37,7 @@ namespace BizHawk.Client.EmuHawk
{ {
var pieces = MainForm.CurrentlyOpenRom.Split('|'); var pieces = MainForm.CurrentlyOpenRom.Split('|');
var directory = Path.GetDirectoryName(pieces[0]); var directory = Path.GetDirectoryName(pieces[0]) ?? "";
var filename = Path.ChangeExtension(pieces[1], ".xml"); var filename = Path.ChangeExtension(pieces[1], ".xml");
NameBox.Text = Path.Combine(directory, filename); NameBox.Text = Path.Combine(directory, filename);
@ -52,7 +52,7 @@ namespace BizHawk.Client.EmuHawk
SystemDropDown.SelectedItem = Emulator.SystemId; SystemDropDown.SelectedItem = Emulator.SystemId;
} }
FileSelectors.First().SetName(MainForm.CurrentlyOpenRom); FileSelectors.First().Path = MainForm.CurrentlyOpenRom;
} }
} }
@ -120,7 +120,7 @@ namespace BizHawk.Client.EmuHawk
Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top
}; };
var mdf = new MultiDiskFileSelector var mdf = new MultiDiskFileSelector(this)
{ {
Location = UIHelper.Scale(new Point(7, 12)), Location = UIHelper.Scale(new Point(7, 12)),
Width = groupBox.ClientSize.Width - UIHelper.ScaleX(13), Width = groupBox.ClientSize.Width - UIHelper.ScaleX(13),
@ -169,7 +169,7 @@ namespace BizHawk.Client.EmuHawk
{ {
try try
{ {
var names = FileSelectors.Select(f => f.GetName()); var names = FileSelectors.Select(f => f.Path).ToList();
var name = NameBox.Text; var name = NameBox.Text;

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Windows.Forms; using System.Windows.Forms;
using BizHawk.Common;
using BizHawk.Client.Common; using BizHawk.Client.Common;
using BizHawk.Client.EmuHawk.WinFormExtensions; using BizHawk.Client.EmuHawk.WinFormExtensions;
using System.IO; using System.IO;
@ -9,38 +10,33 @@ namespace BizHawk.Client.EmuHawk
{ {
public partial class MultiDiskFileSelector : UserControl public partial class MultiDiskFileSelector : UserControl
{ {
public string SystemString = ""; private readonly ToolFormBase _parent;
public string GetName() public string SystemString { get; set; } = "";
{
return PathBox.Text;
}
public void SetName(string val) public string Path
{ {
PathBox.Text = val; get => PathBox.Text;
set => PathBox.Text = value;
} }
public event EventHandler NameChanged; public event EventHandler NameChanged;
private void HandleLabelTextChanged(object sender, EventArgs e) private void HandleLabelTextChanged(object sender, EventArgs e)
{ {
this.OnNameChanged(EventArgs.Empty); OnNameChanged(EventArgs.Empty);
} }
public MultiDiskFileSelector() public MultiDiskFileSelector(ToolFormBase parent)
{ {
_parent = parent;
InitializeComponent(); InitializeComponent();
PathBox.TextChanged += this.HandleLabelTextChanged; PathBox.TextChanged += HandleLabelTextChanged;
} }
protected virtual void OnNameChanged(EventArgs e) protected virtual void OnNameChanged(EventArgs e)
{ {
EventHandler handler = this.NameChanged; NameChanged?.Invoke(this, e);
if (handler != null)
{
handler(this, e);
}
} }
private void PathBox_DragEnter(object sender, DragEventArgs e) private void PathBox_DragEnter(object sender, DragEventArgs e)
@ -72,16 +68,16 @@ namespace BizHawk.Client.EmuHawk
{ {
using var ofd = new OpenFileDialog using var ofd = new OpenFileDialog
{ {
InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries["Global_NULL", "ROM"].Path, "Global_NULL"), InitialDirectory = PathManager.MakeAbsolutePath(_parent.Config.PathEntries["Global_NULL", "ROM"].Path, "Global_NULL"),
Filter = MainForm.RomFilter, Filter = MainForm.RomFilter,
RestoreDirectory = true RestoreDirectory = true
}; };
string _path = ""; string hawkPath = "";
var result = ofd.ShowHawkDialog(); var result = ofd.ShowHawkDialog();
if (result == DialogResult.OK) if (result == DialogResult.OK)
{ {
_path = ofd.FileName; hawkPath = ofd.FileName;
} }
else else
{ {
@ -93,44 +89,42 @@ namespace BizHawk.Client.EmuHawk
var file = new FileInfo(ofd.FileName); var file = new FileInfo(ofd.FileName);
var path = EmuHawkUtil.ResolveShortcut(file.FullName); var path = EmuHawkUtil.ResolveShortcut(file.FullName);
using (var hf = new BizHawk.Common.HawkFile(path)) using var hf = new HawkFile(path);
if (hf.IsArchive)
{ {
if (hf.IsArchive) // archive - run the archive chooser
if (SystemString == "PSX" || SystemString == "PCFX" || SystemString == "SAT")
{ {
// archive - run the archive chooser MessageBox.Show("Using archives with PSX, PCFX or SATURN is not currently recommended/supported.");
if (SystemString == "PSX" || SystemString == "PCFX" || SystemString == "SAT") return;
{
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
using var ac = new ArchiveChooser(new HawkFile(hawkPath));
int memIdx = -1;
if (ac.ShowDialog(this) == DialogResult.OK)
{ {
// file is not an archive memIdx = ac.SelectedMemberIndex;
PathBox.Text = _path;
} }
var intName = hf.ArchiveItems[memIdx];
PathBox.Text = $"{hawkPath}|{intName.Name}";
}
else
{
// file is not an archive
PathBox.Text = hawkPath;
} }
} }
catch catch
{ {
return; // Do nothing
} }
} }
private void UseCurrentRomButton_Click(object sender, EventArgs e) private void UseCurrentRomButton_Click(object sender, EventArgs e)
{ {
PathBox.Text = GlobalWin.MainForm.CurrentlyOpenRom; PathBox.Text = _parent.MainForm.CurrentlyOpenRom;
} }
private void DualGBFileSelector_Load(object sender, EventArgs e) private void DualGBFileSelector_Load(object sender, EventArgs e)
@ -138,13 +132,11 @@ namespace BizHawk.Client.EmuHawk
UpdateValues(); UpdateValues();
} }
public void NewUpdate(ToolFormUpdateType type) { }
public void UpdateValues() public void UpdateValues()
{ {
UseCurrentRomButton.Enabled = UseCurrentRomButton.Enabled =
!string.IsNullOrEmpty(GlobalWin.MainForm.CurrentlyOpenRom) !string.IsNullOrEmpty(_parent.MainForm.CurrentlyOpenRom)
&& !GlobalWin.MainForm.CurrentlyOpenRom.Contains(".xml"); // Can't already be an xml && !_parent.MainForm.CurrentlyOpenRom.Contains(".xml"); // Can't already be an xml
} }
private void PathBox_TextChanged(object sender, EventArgs e) private void PathBox_TextChanged(object sender, EventArgs e)