2011-08-04 04:45:53 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2012-09-13 04:13:49 +00:00
|
|
|
|
using System.Globalization;
|
2011-08-04 04:45:53 +00:00
|
|
|
|
|
2013-11-04 00:40:46 +00:00
|
|
|
|
using BizHawk.Common;
|
|
|
|
|
|
2013-11-04 01:06:36 +00:00
|
|
|
|
namespace BizHawk.Emulation.Common
|
2011-08-04 04:45:53 +00:00
|
|
|
|
{
|
2011-08-10 23:50:01 +00:00
|
|
|
|
public class GameInfo
|
|
|
|
|
{
|
2017-04-24 12:41:55 +00:00
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
public string System { get; set; }
|
|
|
|
|
public string Hash { get; set; }
|
|
|
|
|
public string Region { get; set; }
|
|
|
|
|
public RomStatus Status { get; set; } = RomStatus.NotInDatabase;
|
|
|
|
|
public bool NotInDatabase { get; set; } = true;
|
|
|
|
|
public string FirmwareHash { get; set; }
|
|
|
|
|
public string ForcedCore { get; private set; }
|
2011-08-10 23:50:01 +00:00
|
|
|
|
|
2017-04-24 12:41:55 +00:00
|
|
|
|
private Dictionary<string, string> Options { get; set; } = new Dictionary<string, string>();
|
2011-08-10 23:50:01 +00:00
|
|
|
|
|
2017-04-24 12:41:55 +00:00
|
|
|
|
public GameInfo()
|
|
|
|
|
{
|
|
|
|
|
}
|
2013-11-04 00:45:23 +00:00
|
|
|
|
|
2014-05-23 15:47:48 +00:00
|
|
|
|
public GameInfo Clone()
|
|
|
|
|
{
|
|
|
|
|
var ret = (GameInfo)MemberwiseClone();
|
|
|
|
|
ret.Options = new Dictionary<string, string>(Options);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-24 12:41:55 +00:00
|
|
|
|
public static GameInfo NullInstance => new GameInfo
|
2013-11-04 00:45:23 +00:00
|
|
|
|
{
|
2017-04-24 12:41:55 +00:00
|
|
|
|
Name = "Null",
|
|
|
|
|
System = "NULL",
|
2017-05-10 11:45:23 +00:00
|
|
|
|
Hash = "",
|
|
|
|
|
Region = "",
|
2017-04-24 12:41:55 +00:00
|
|
|
|
Status = RomStatus.GoodDump,
|
2017-05-10 11:45:23 +00:00
|
|
|
|
ForcedCore = "",
|
2017-04-24 12:41:55 +00:00
|
|
|
|
NotInDatabase = false
|
|
|
|
|
};
|
2014-07-21 22:21:52 +00:00
|
|
|
|
|
2011-08-10 23:50:01 +00:00
|
|
|
|
internal GameInfo(CompactGameInfo cgi)
|
|
|
|
|
{
|
|
|
|
|
Name = cgi.Name;
|
|
|
|
|
System = cgi.System;
|
|
|
|
|
Hash = cgi.Hash;
|
2014-03-18 03:28:25 +00:00
|
|
|
|
Region = cgi.Region;
|
2011-08-10 23:50:01 +00:00
|
|
|
|
Status = cgi.Status;
|
2016-11-13 01:23:54 +00:00
|
|
|
|
ForcedCore = cgi.ForcedCore;
|
2011-08-10 23:50:01 +00:00
|
|
|
|
NotInDatabase = false;
|
|
|
|
|
ParseOptionsDictionary(cgi.MetaData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AddOption(string option)
|
|
|
|
|
{
|
2017-05-10 11:45:23 +00:00
|
|
|
|
Options[option] = "";
|
2011-08-10 23:50:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AddOption(string option, string param)
|
|
|
|
|
{
|
|
|
|
|
Options[option] = param;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RemoveOption(string option)
|
|
|
|
|
{
|
|
|
|
|
Options.Remove(option);
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-24 12:41:55 +00:00
|
|
|
|
public bool this[string option] => Options.ContainsKey(option);
|
2011-08-10 23:50:01 +00:00
|
|
|
|
|
|
|
|
|
public bool OptionPresent(string option)
|
|
|
|
|
{
|
|
|
|
|
return Options.ContainsKey(option);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string OptionValue(string option)
|
|
|
|
|
{
|
2020-02-26 21:51:29 +00:00
|
|
|
|
return Options.ContainsKey(option) ? Options[option] : null;
|
2011-08-10 23:50:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-04 00:45:23 +00:00
|
|
|
|
public int GetIntValue(string option)
|
|
|
|
|
{
|
|
|
|
|
return int.Parse(Options[option]);
|
|
|
|
|
}
|
2012-09-13 04:13:49 +00:00
|
|
|
|
|
2015-07-11 17:39:01 +00:00
|
|
|
|
public string GetStringValue(string option)
|
|
|
|
|
{
|
|
|
|
|
return Options[option];
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-04 00:45:23 +00:00
|
|
|
|
public int GetHexValue(string option)
|
|
|
|
|
{
|
|
|
|
|
return int.Parse(Options[option], NumberStyles.HexNumber);
|
|
|
|
|
}
|
2012-09-13 04:13:49 +00:00
|
|
|
|
|
2017-04-24 12:41:55 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// /// Gets a boolean value from the database
|
|
|
|
|
/// </summary>
|
2013-05-23 00:16:04 +00:00
|
|
|
|
/// <param name="parameter">The option to look up</param>
|
|
|
|
|
/// <param name="defaultVal">The value to return if the option is invalid or doesn't exist</param>
|
2017-04-24 12:41:55 +00:00
|
|
|
|
/// <returns> The boolean value from the database if present, otherwise the given default value</returns>
|
2013-05-23 00:16:04 +00:00
|
|
|
|
public bool GetBool(string parameter, bool defaultVal)
|
|
|
|
|
{
|
|
|
|
|
if (OptionPresent(parameter) && OptionValue(parameter) == "true")
|
2017-04-24 12:41:55 +00:00
|
|
|
|
{
|
2013-05-23 00:16:04 +00:00
|
|
|
|
return true;
|
2017-04-24 12:41:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (OptionPresent(parameter) && OptionValue(parameter) == "false")
|
|
|
|
|
{
|
2013-05-27 01:59:45 +00:00
|
|
|
|
return false;
|
2017-04-24 12:41:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return defaultVal;
|
2013-05-23 00:16:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-24 12:41:55 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// /// Gets an integer value from the database
|
|
|
|
|
/// </summary>
|
2013-05-23 00:16:04 +00:00
|
|
|
|
/// <param name="parameter">The option to look up</param>
|
|
|
|
|
/// <param name="defaultVal">The value to return if the option is invalid or doesn't exist</param>
|
2017-04-24 12:41:55 +00:00
|
|
|
|
/// <returns> The integer value from the database if present, otherwise the given default value</returns>
|
2013-05-23 00:16:04 +00:00
|
|
|
|
public int GetInt(string parameter, int defaultVal)
|
|
|
|
|
{
|
|
|
|
|
if (OptionPresent(parameter))
|
2017-04-24 12:41:55 +00:00
|
|
|
|
{
|
2013-05-23 00:16:04 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return int.Parse(OptionValue(parameter));
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
return defaultVal;
|
|
|
|
|
}
|
2017-04-24 12:41:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return defaultVal;
|
2013-05-23 00:16:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-10 23:50:01 +00:00
|
|
|
|
public ICollection<string> GetOptions()
|
|
|
|
|
{
|
|
|
|
|
return Options.Keys;
|
|
|
|
|
}
|
2017-04-24 12:41:55 +00:00
|
|
|
|
|
2011-08-10 23:50:01 +00:00
|
|
|
|
public IDictionary<string, string> GetOptionsDict()
|
|
|
|
|
{
|
|
|
|
|
return new ReadOnlyDictionary<string, string>(Options);
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-24 12:41:55 +00:00
|
|
|
|
private void ParseOptionsDictionary(string metaData)
|
2011-08-10 23:50:01 +00:00
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(metaData))
|
2017-04-24 12:41:55 +00:00
|
|
|
|
{
|
2011-08-10 23:50:01 +00:00
|
|
|
|
return;
|
2017-04-24 12:41:55 +00:00
|
|
|
|
}
|
2011-08-10 23:50:01 +00:00
|
|
|
|
|
|
|
|
|
var options = metaData.Split(';').Where(opt => string.IsNullOrEmpty(opt) == false).ToArray();
|
|
|
|
|
|
|
|
|
|
foreach (var opt in options)
|
|
|
|
|
{
|
|
|
|
|
var parts = opt.Split('=');
|
|
|
|
|
var key = parts[0];
|
2017-05-10 11:45:23 +00:00
|
|
|
|
var value = parts.Length > 1 ? parts[1] : "";
|
2011-08-10 23:50:01 +00:00
|
|
|
|
Options[key] = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-12-08 19:36:15 +00:00
|
|
|
|
|
|
|
|
|
public static class GameInfoExtensions
|
|
|
|
|
{
|
|
|
|
|
public static bool IsNullInstance(this GameInfo game)
|
|
|
|
|
{
|
|
|
|
|
return game == null || game.System == "NULL";
|
|
|
|
|
}
|
2020-03-15 23:37:49 +00:00
|
|
|
|
|
|
|
|
|
public static bool IsRomStatusBad(this GameInfo game)
|
|
|
|
|
{
|
|
|
|
|
return game.Status == RomStatus.BadDump || game.Status == RomStatus.Overdump;
|
|
|
|
|
}
|
2019-12-08 19:36:15 +00:00
|
|
|
|
}
|
2011-08-04 04:45:53 +00:00
|
|
|
|
}
|