MultiDIskBundler - cleanup, pass dependencies to child controls
This commit is contained in:
parent
3b60b08a11
commit
640e4260cd
|
@ -37,7 +37,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
var pieces = MainForm.CurrentlyOpenRom.Split('|');
|
||||
|
||||
var directory = Path.GetDirectoryName(pieces[0]);
|
||||
var directory = Path.GetDirectoryName(pieces[0]) ?? "";
|
||||
var filename = Path.ChangeExtension(pieces[1], ".xml");
|
||||
|
||||
NameBox.Text = Path.Combine(directory, filename);
|
||||
|
@ -52,7 +52,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
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
|
||||
};
|
||||
|
||||
var mdf = new MultiDiskFileSelector
|
||||
var mdf = new MultiDiskFileSelector(this)
|
||||
{
|
||||
Location = UIHelper.Scale(new Point(7, 12)),
|
||||
Width = groupBox.ClientSize.Width - UIHelper.ScaleX(13),
|
||||
|
@ -169,7 +169,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
try
|
||||
{
|
||||
var names = FileSelectors.Select(f => f.GetName());
|
||||
var names = FileSelectors.Select(f => f.Path).ToList();
|
||||
|
||||
var name = NameBox.Text;
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using BizHawk.Common;
|
||||
using BizHawk.Client.Common;
|
||||
using BizHawk.Client.EmuHawk.WinFormExtensions;
|
||||
using System.IO;
|
||||
|
@ -9,38 +10,33 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
public partial class MultiDiskFileSelector : UserControl
|
||||
{
|
||||
public string SystemString = "";
|
||||
private readonly ToolFormBase _parent;
|
||||
|
||||
public string GetName()
|
||||
{
|
||||
return PathBox.Text;
|
||||
}
|
||||
public string SystemString { get; set; } = "";
|
||||
|
||||
public void SetName(string val)
|
||||
public string Path
|
||||
{
|
||||
PathBox.Text = val;
|
||||
get => PathBox.Text;
|
||||
set => PathBox.Text = value;
|
||||
}
|
||||
|
||||
public event EventHandler NameChanged;
|
||||
|
||||
private void HandleLabelTextChanged(object sender, EventArgs e)
|
||||
{
|
||||
this.OnNameChanged(EventArgs.Empty);
|
||||
OnNameChanged(EventArgs.Empty);
|
||||
}
|
||||
|
||||
public MultiDiskFileSelector()
|
||||
public MultiDiskFileSelector(ToolFormBase parent)
|
||||
{
|
||||
_parent = parent;
|
||||
InitializeComponent();
|
||||
PathBox.TextChanged += this.HandleLabelTextChanged;
|
||||
PathBox.TextChanged += HandleLabelTextChanged;
|
||||
}
|
||||
|
||||
protected virtual void OnNameChanged(EventArgs e)
|
||||
{
|
||||
EventHandler handler = this.NameChanged;
|
||||
if (handler != null)
|
||||
{
|
||||
handler(this, e);
|
||||
}
|
||||
NameChanged?.Invoke(this, e);
|
||||
}
|
||||
|
||||
private void PathBox_DragEnter(object sender, DragEventArgs e)
|
||||
|
@ -72,16 +68,16 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
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,
|
||||
RestoreDirectory = true
|
||||
};
|
||||
string _path = "";
|
||||
string hawkPath = "";
|
||||
|
||||
var result = ofd.ShowHawkDialog();
|
||||
if (result == DialogResult.OK)
|
||||
{
|
||||
_path = ofd.FileName;
|
||||
hawkPath = ofd.FileName;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -93,44 +89,42 @@ namespace BizHawk.Client.EmuHawk
|
|||
var file = new FileInfo(ofd.FileName);
|
||||
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
|
||||
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}";
|
||||
MessageBox.Show("Using archives with PSX, PCFX or SATURN is not currently recommended/supported.");
|
||||
return;
|
||||
}
|
||||
else
|
||||
|
||||
using var ac = new ArchiveChooser(new HawkFile(hawkPath));
|
||||
int memIdx = -1;
|
||||
|
||||
if (ac.ShowDialog(this) == DialogResult.OK)
|
||||
{
|
||||
// file is not an archive
|
||||
PathBox.Text = _path;
|
||||
memIdx = ac.SelectedMemberIndex;
|
||||
}
|
||||
|
||||
var intName = hf.ArchiveItems[memIdx];
|
||||
PathBox.Text = $"{hawkPath}|{intName.Name}";
|
||||
}
|
||||
else
|
||||
{
|
||||
// file is not an archive
|
||||
PathBox.Text = hawkPath;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return;
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
|
@ -138,13 +132,11 @@ namespace BizHawk.Client.EmuHawk
|
|||
UpdateValues();
|
||||
}
|
||||
|
||||
public void NewUpdate(ToolFormUpdateType type) { }
|
||||
|
||||
public void UpdateValues()
|
||||
{
|
||||
UseCurrentRomButton.Enabled =
|
||||
!string.IsNullOrEmpty(GlobalWin.MainForm.CurrentlyOpenRom)
|
||||
&& !GlobalWin.MainForm.CurrentlyOpenRom.Contains(".xml"); // Can't already be an xml
|
||||
!string.IsNullOrEmpty(_parent.MainForm.CurrentlyOpenRom)
|
||||
&& !_parent.MainForm.CurrentlyOpenRom.Contains(".xml"); // Can't already be an xml
|
||||
}
|
||||
|
||||
private void PathBox_TextChanged(object sender, EventArgs e)
|
||||
|
|
Loading…
Reference in New Issue