2013-10-25 00:59:34 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
2013-11-04 01:39:19 +00:00
|
|
|
|
using BizHawk.Emulation.Common;
|
|
|
|
|
|
2013-10-25 00:59:34 +00:00
|
|
|
|
namespace BizHawk.Client.Common
|
|
|
|
|
{
|
|
|
|
|
public class CoreFileProvider : ICoreFileProvider
|
|
|
|
|
{
|
2014-01-08 03:53:53 +00:00
|
|
|
|
public string SubfileDirectory { get; set; }
|
|
|
|
|
public FirmwareManager FirmwareManager { get; set; }
|
2013-10-25 00:59:34 +00:00
|
|
|
|
|
2014-01-08 03:53:53 +00:00
|
|
|
|
private readonly Action<string> _showWarning;
|
2013-12-10 17:58:12 +00:00
|
|
|
|
|
2013-12-30 01:58:44 +00:00
|
|
|
|
public CoreFileProvider(Action<string> showWarning)
|
2013-12-10 17:58:12 +00:00
|
|
|
|
{
|
2014-01-08 03:53:53 +00:00
|
|
|
|
_showWarning = showWarning;
|
2013-12-10 17:58:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-10-25 00:59:34 +00:00
|
|
|
|
public string PathSubfile(string fname)
|
|
|
|
|
{
|
2013-10-27 17:47:54 +00:00
|
|
|
|
return Path.Combine(Path.GetDirectoryName(SubfileDirectory) ?? String.Empty, fname);
|
2013-10-25 00:59:34 +00:00
|
|
|
|
}
|
2013-11-01 23:17:30 +00:00
|
|
|
|
|
2013-12-27 17:59:19 +00:00
|
|
|
|
public string DllPath()
|
|
|
|
|
{
|
|
|
|
|
return Path.Combine(PathManager.GetExeDirectoryAbsolute(), "dll");
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-10 17:58:12 +00:00
|
|
|
|
#region EmuLoadHelper api
|
2013-12-30 01:58:44 +00:00
|
|
|
|
|
2014-01-08 03:53:53 +00:00
|
|
|
|
private void FirmwareWarn(string sysID, string firmwareID, bool required, string msg = null)
|
2013-12-10 17:58:12 +00:00
|
|
|
|
{
|
|
|
|
|
if (required)
|
|
|
|
|
{
|
2014-01-08 03:53:53 +00:00
|
|
|
|
var fullmsg = String.Format(
|
2013-12-10 17:58:12 +00:00
|
|
|
|
"Couldn't find required firmware \"{0}:{1}\". This is fatal{2}", sysID, firmwareID, msg != null ? ": " + msg : ".");
|
2014-07-31 21:40:25 +00:00
|
|
|
|
throw new MissingFirmwareException(fullmsg);
|
2013-12-10 17:58:12 +00:00
|
|
|
|
}
|
2014-07-03 18:17:09 +00:00
|
|
|
|
|
|
|
|
|
if (msg != null)
|
2013-12-10 17:58:12 +00:00
|
|
|
|
{
|
2014-07-03 18:17:09 +00:00
|
|
|
|
var fullmsg = String.Format(
|
|
|
|
|
"Couldn't find firmware \"{0}:{1}\". Will attempt to continue: {2}", sysID, firmwareID, msg);
|
|
|
|
|
_showWarning(fullmsg);
|
2013-12-10 17:58:12 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string GetFirmwarePath(string sysID, string firmwareID, bool required, string msg = null)
|
|
|
|
|
{
|
2014-01-08 03:53:53 +00:00
|
|
|
|
var path = FirmwareManager.Request(sysID, firmwareID);
|
2013-12-10 17:58:12 +00:00
|
|
|
|
if (path != null && !File.Exists(path))
|
2014-01-08 03:53:53 +00:00
|
|
|
|
{
|
2013-12-10 17:58:12 +00:00
|
|
|
|
path = null;
|
2014-01-08 03:53:53 +00:00
|
|
|
|
}
|
2013-12-10 17:58:12 +00:00
|
|
|
|
|
|
|
|
|
if (path == null)
|
2014-01-08 03:53:53 +00:00
|
|
|
|
{
|
2013-12-10 17:58:12 +00:00
|
|
|
|
FirmwareWarn(sysID, firmwareID, required, msg);
|
2014-01-08 03:53:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-10 17:58:12 +00:00
|
|
|
|
return path;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-10 15:26:18 +00:00
|
|
|
|
private byte[] GetFirmwareWithPath(string sysID, string firmwareID, bool required, string msg, out string path)
|
2013-12-10 17:58:12 +00:00
|
|
|
|
{
|
|
|
|
|
byte[] ret = null;
|
2014-02-10 15:26:18 +00:00
|
|
|
|
var path_ = GetFirmwarePath(sysID, firmwareID, required, msg);
|
|
|
|
|
if (path_ != null && File.Exists(path_))
|
2013-12-10 17:58:12 +00:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2014-02-10 15:26:18 +00:00
|
|
|
|
ret = File.ReadAllBytes(path_);
|
2013-12-10 17:58:12 +00:00
|
|
|
|
}
|
|
|
|
|
catch (IOException) { }
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-10 15:26:18 +00:00
|
|
|
|
if (ret == null && path_ != null)
|
2014-01-08 03:53:53 +00:00
|
|
|
|
{
|
2013-12-10 17:58:12 +00:00
|
|
|
|
FirmwareWarn(sysID, firmwareID, required, msg);
|
2014-01-08 03:53:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-10 15:26:18 +00:00
|
|
|
|
path = path_;
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public byte[] GetFirmware(string sysID, string firmwareID, bool required, string msg = null)
|
|
|
|
|
{
|
|
|
|
|
string unused;
|
|
|
|
|
return GetFirmwareWithPath(sysID, firmwareID, required, msg, out unused);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public byte[] GetFirmwareWithGameInfo(string sysID, string firmwareID, bool required, out GameInfo gi, string msg = null)
|
|
|
|
|
{
|
|
|
|
|
string path;
|
|
|
|
|
byte[] ret = GetFirmwareWithPath(sysID, firmwareID, required, msg, out path);
|
|
|
|
|
if (ret != null && path != null)
|
|
|
|
|
{
|
|
|
|
|
gi = Database.GetGameInfo(ret, path);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
gi = null;
|
|
|
|
|
}
|
2013-12-10 17:58:12 +00:00
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2014-01-09 23:50:10 +00:00
|
|
|
|
// this should go away now
|
2013-11-03 02:51:21 +00:00
|
|
|
|
public static void SyncCoreCommInputSignals(CoreComm target = null)
|
2013-11-01 23:17:30 +00:00
|
|
|
|
{
|
2013-11-03 02:51:21 +00:00
|
|
|
|
if (target == null)
|
|
|
|
|
{
|
|
|
|
|
target = Global.CoreComm;
|
|
|
|
|
}
|
2013-11-01 23:17:30 +00:00
|
|
|
|
|
2013-12-10 17:58:12 +00:00
|
|
|
|
var cfp = new CoreFileProvider(target.ShowMessage);
|
2013-11-01 23:17:30 +00:00
|
|
|
|
target.CoreFileProvider = cfp;
|
|
|
|
|
cfp.FirmwareManager = Global.FirmwareManager;
|
|
|
|
|
}
|
2013-10-25 00:59:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|