Misc Client.Common cleanups
This commit is contained in:
parent
e72aa11d5d
commit
cdb0802230
|
@ -72,12 +72,13 @@ namespace BizHawk.Client.Common
|
|||
[AttributeUsage(AttributeTargets.Property)]
|
||||
private class NameAttribute : Attribute
|
||||
{
|
||||
public string Name { get; private set; }
|
||||
public string Ext { get; private set; }
|
||||
public string Name { get; }
|
||||
public string Ext { get; }
|
||||
public NameAttribute(string name)
|
||||
{
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public NameAttribute(string name, string ext)
|
||||
{
|
||||
Name = name;
|
||||
|
@ -85,8 +86,8 @@ namespace BizHawk.Client.Common
|
|||
}
|
||||
}
|
||||
|
||||
public virtual string ReadName { get { return Name; } }
|
||||
public virtual string WriteName { get { return Ext != null ? Name + '.' + Ext : Name; } }
|
||||
public virtual string ReadName => Name;
|
||||
public virtual string WriteName => Ext != null ? Name + '.' + Ext : Name;
|
||||
|
||||
public string Name { get; protected set; }
|
||||
public string Ext { get; protected set; }
|
||||
|
@ -97,7 +98,9 @@ namespace BizHawk.Client.Common
|
|||
Ext = ext;
|
||||
}
|
||||
|
||||
protected BinaryStateLump() { }
|
||||
protected BinaryStateLump()
|
||||
{
|
||||
}
|
||||
|
||||
static BinaryStateLump()
|
||||
{
|
||||
|
@ -115,7 +118,7 @@ namespace BizHawk.Client.Common
|
|||
/// </summary>
|
||||
public class IndexedStateLump : BinaryStateLump
|
||||
{
|
||||
private BinaryStateLump _root;
|
||||
private readonly BinaryStateLump _root;
|
||||
private int _idx;
|
||||
public IndexedStateLump(BinaryStateLump root)
|
||||
{
|
||||
|
@ -200,7 +203,7 @@ namespace BizHawk.Client.Common
|
|||
}
|
||||
}
|
||||
|
||||
private static byte[] zipheader = new byte[] { 0x50, 0x4b, 0x03, 0x04 };
|
||||
private static byte[] zipheader = { 0x50, 0x4b, 0x03, 0x04 };
|
||||
public static BinaryStateLoader LoadAndDetect(string filename, bool isMovieLoad = false)
|
||||
{
|
||||
var ret = new BinaryStateLoader();
|
||||
|
@ -210,7 +213,9 @@ namespace BizHawk.Client.Common
|
|||
byte[] data = new byte[4];
|
||||
fs.Read(data, 0, 4);
|
||||
if (!data.SequenceEqual(zipheader))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
|
|
|
@ -1,58 +1,40 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
|
||||
using BizHawk.Emulation.Common;
|
||||
using BizHawk.Bizware.BizwareGL;
|
||||
|
||||
namespace BizHawk.Client.Common
|
||||
{
|
||||
public class BitmapBufferVideoProvider : IVideoProvider, IDisposable
|
||||
{
|
||||
BitmapBuffer bb;
|
||||
public BitmapBufferVideoProvider(BitmapBuffer bb)
|
||||
{
|
||||
this.bb = bb;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (bb != null) bb.Dispose();
|
||||
bb = null;
|
||||
}
|
||||
|
||||
public int[] GetVideoBuffer()
|
||||
{
|
||||
return bb.Pixels;
|
||||
}
|
||||
|
||||
public int VirtualWidth
|
||||
{
|
||||
get { return bb.Width; }
|
||||
}
|
||||
|
||||
public int VirtualHeight
|
||||
{
|
||||
get { return bb.Height; }
|
||||
}
|
||||
|
||||
public int BufferWidth
|
||||
{
|
||||
get { return bb.Width; }
|
||||
}
|
||||
|
||||
public int BufferHeight
|
||||
{
|
||||
get { return bb.Height; }
|
||||
}
|
||||
|
||||
public int BackgroundColor
|
||||
{
|
||||
get { return 0; }
|
||||
}
|
||||
|
||||
using System;
|
||||
|
||||
using BizHawk.Emulation.Common;
|
||||
using BizHawk.Bizware.BizwareGL;
|
||||
|
||||
namespace BizHawk.Client.Common
|
||||
{
|
||||
public class BitmapBufferVideoProvider : IVideoProvider, IDisposable
|
||||
{
|
||||
private BitmapBuffer _bb;
|
||||
|
||||
public BitmapBufferVideoProvider(BitmapBuffer bb)
|
||||
{
|
||||
_bb = bb;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_bb?.Dispose();
|
||||
_bb = null;
|
||||
}
|
||||
|
||||
public int[] GetVideoBuffer()
|
||||
{
|
||||
return _bb.Pixels;
|
||||
}
|
||||
|
||||
public int VirtualWidth => _bb.Width;
|
||||
|
||||
public int VirtualHeight => _bb.Height;
|
||||
|
||||
public int BufferWidth => _bb.Width;
|
||||
|
||||
public int BufferHeight => _bb.Height;
|
||||
|
||||
public int BackgroundColor => 0;
|
||||
|
||||
public int VsyncNumerator
|
||||
{
|
||||
get { throw new InvalidOperationException(); }
|
||||
|
@ -61,6 +43,6 @@ namespace BizHawk.Client.Common
|
|||
public int VsyncDenominator
|
||||
{
|
||||
get { throw new InvalidOperationException(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,10 +42,7 @@ namespace BizHawk.Client.Common
|
|||
/// <summary>don't do this</summary>
|
||||
public void ForceType(ControllerDefinition newtype) { _type = newtype; }
|
||||
|
||||
public bool this[string button]
|
||||
{
|
||||
get { return IsPressed(button); }
|
||||
}
|
||||
public bool this[string button] => IsPressed(button);
|
||||
|
||||
public bool AnyPressed
|
||||
{
|
||||
|
@ -63,7 +60,7 @@ namespace BizHawk.Client.Common
|
|||
// Looks for bindings which are activated by the supplied physical button.
|
||||
public List<string> SearchBindings(string button)
|
||||
{
|
||||
return (from kvp in _bindings from bound_button in kvp.Value where bound_button == button select kvp.Key).ToList();
|
||||
return (from kvp in _bindings from boundButton in kvp.Value where boundButton == button select kvp.Key).ToList();
|
||||
}
|
||||
|
||||
// Searches bindings for the controller and returns true if this binding is mapped somewhere in this controller
|
||||
|
@ -235,13 +232,7 @@ namespace BizHawk.Client.Common
|
|||
return (from key in _bindings from binding in key.Value select new KeyValuePair<string, string>(binding, key.Key)).ToList();
|
||||
}
|
||||
|
||||
public List<string> PressedButtons
|
||||
{
|
||||
get
|
||||
{
|
||||
return (from button in _buttons where button.Value select button.Key).ToList();
|
||||
}
|
||||
}
|
||||
public List<string> PressedButtons => (from button in _buttons where button.Value select button.Key).ToList();
|
||||
}
|
||||
|
||||
public class AutofireController : IController
|
||||
|
@ -267,7 +258,7 @@ namespace BizHawk.Client.Common
|
|||
public int On { get; set; }
|
||||
public int Off { get; set; }
|
||||
|
||||
public ControllerDefinition Definition { get { return _type; } }
|
||||
public ControllerDefinition Definition => _type;
|
||||
|
||||
public bool IsPressed(string button)
|
||||
{
|
||||
|
@ -364,12 +355,6 @@ namespace BizHawk.Client.Common
|
|||
}
|
||||
}
|
||||
|
||||
public List<string> PressedButtons
|
||||
{
|
||||
get
|
||||
{
|
||||
return (from button in _buttons where button.Value select button.Key).ToList();
|
||||
}
|
||||
}
|
||||
public List<string> PressedButtons => (from button in _buttons where button.Value select button.Key).ToList();
|
||||
}
|
||||
}
|
|
@ -19,7 +19,7 @@ namespace BizHawk.Client.Common
|
|||
|
||||
public string PathSubfile(string fname)
|
||||
{
|
||||
return Path.Combine(SubfileDirectory ?? String.Empty, fname);
|
||||
return Path.Combine(SubfileDirectory ?? string.Empty, fname);
|
||||
}
|
||||
|
||||
public string DllPath()
|
||||
|
@ -54,22 +54,20 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
if (required)
|
||||
{
|
||||
var fullmsg = String.Format(
|
||||
"Couldn't find required firmware \"{0}:{1}\". This is fatal{2}", sysID, firmwareID, msg != null ? ": " + msg : ".");
|
||||
var fullmsg = $"Couldn't find required firmware \"{sysID}:{firmwareID}\". This is fatal{(msg != null ? ": " + msg : ".")}";
|
||||
throw new MissingFirmwareException(fullmsg);
|
||||
}
|
||||
|
||||
if (msg != null)
|
||||
{
|
||||
var fullmsg = String.Format(
|
||||
"Couldn't find firmware \"{0}:{1}\". Will attempt to continue: {2}", sysID, firmwareID, msg);
|
||||
var fullmsg = $"Couldn't find firmware \"{sysID}:{firmwareID}\". Will attempt to continue: {msg}";
|
||||
_showWarning(fullmsg);
|
||||
}
|
||||
}
|
||||
|
||||
public string GetFirmwarePath(string sysID, string firmwareID, bool required, string msg = null)
|
||||
public string GetFirmwarePath(string sysId, string firmwareId, bool required, string msg = null)
|
||||
{
|
||||
var path = FirmwareManager.Request(sysID, firmwareID);
|
||||
var path = FirmwareManager.Request(sysId, firmwareId);
|
||||
if (path != null && !File.Exists(path))
|
||||
{
|
||||
path = null;
|
||||
|
@ -77,44 +75,46 @@ namespace BizHawk.Client.Common
|
|||
|
||||
if (path == null)
|
||||
{
|
||||
FirmwareWarn(sysID, firmwareID, required, msg);
|
||||
FirmwareWarn(sysId, firmwareId, required, msg);
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
private byte[] GetFirmwareWithPath(string sysID, string firmwareID, bool required, string msg, out string path)
|
||||
private byte[] GetFirmwareWithPath(string sysId, string firmwareId, bool required, string msg, out string path)
|
||||
{
|
||||
byte[] ret = null;
|
||||
var path_ = GetFirmwarePath(sysID, firmwareID, required, msg);
|
||||
var path_ = GetFirmwarePath(sysId, firmwareId, required, msg);
|
||||
if (path_ != null && File.Exists(path_))
|
||||
{
|
||||
try
|
||||
{
|
||||
ret = File.ReadAllBytes(path_);
|
||||
}
|
||||
catch (IOException) { }
|
||||
catch (IOException)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
if (ret == null && path_ != null)
|
||||
{
|
||||
FirmwareWarn(sysID, firmwareID, required, msg);
|
||||
FirmwareWarn(sysId, firmwareId, required, msg);
|
||||
}
|
||||
|
||||
path = path_;
|
||||
return ret;
|
||||
}
|
||||
|
||||
public byte[] GetFirmware(string sysID, string firmwareID, bool required, string msg = null)
|
||||
public byte[] GetFirmware(string sysId, string firmwareId, bool required, string msg = null)
|
||||
{
|
||||
string unused;
|
||||
return GetFirmwareWithPath(sysID, firmwareID, required, msg, out unused);
|
||||
return GetFirmwareWithPath(sysId, firmwareId, required, msg, out unused);
|
||||
}
|
||||
|
||||
public byte[] GetFirmwareWithGameInfo(string sysID, string firmwareID, bool required, out GameInfo gi, string msg = null)
|
||||
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);
|
||||
byte[] ret = GetFirmwareWithPath(sysId, firmwareId, required, msg, out path);
|
||||
if (ret != null && path != null)
|
||||
{
|
||||
gi = Database.GetGameInfo(ret, path);
|
||||
|
@ -123,6 +123,7 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
gi = null;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -133,9 +134,11 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
string superhack = null;
|
||||
if (target.CoreFileProvider != null && target.CoreFileProvider is CoreFileProvider)
|
||||
{
|
||||
superhack = ((CoreFileProvider)target.CoreFileProvider ).SubfileDirectory;
|
||||
var cfp = new CoreFileProvider(target.ShowMessage);
|
||||
cfp.SubfileDirectory = superhack;
|
||||
}
|
||||
|
||||
var cfp = new CoreFileProvider(target.ShowMessage) { SubfileDirectory = superhack };
|
||||
target.CoreFileProvider = cfp;
|
||||
cfp.FirmwareManager = Global.FirmwareManager;
|
||||
}
|
||||
|
|
|
@ -11,11 +11,19 @@ namespace BizHawk.Client.Common
|
|||
public static IGuiRenderer CreateRenderer(this IGL gl)
|
||||
{
|
||||
if (gl is IGL_TK)
|
||||
{
|
||||
return new GuiRenderer(gl);
|
||||
}
|
||||
|
||||
if (gl is IGL_SlimDX9)
|
||||
{
|
||||
return new GuiRenderer(gl);
|
||||
}
|
||||
|
||||
if (gl is IGL_GdiPlus)
|
||||
{
|
||||
return new GDIPlusGuiRenderer((IGL_GdiPlus)gl);
|
||||
}
|
||||
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
|
|
@ -45,7 +45,6 @@ namespace BizHawk.Client.Common
|
|||
RecentlyServed = new List<FirmwareEventArgs>();
|
||||
}
|
||||
|
||||
|
||||
public ResolutionInfo Resolve(string sysId, string firmwareId)
|
||||
{
|
||||
return Resolve(FirmwareDatabase.LookupFirmwareRecord(sysId, firmwareId));
|
||||
|
@ -68,6 +67,7 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
DoScanAndResolve();
|
||||
}
|
||||
|
||||
first = false;
|
||||
goto RETRY;
|
||||
}
|
||||
|
|
|
@ -7,42 +7,36 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
public class IonicZipWriter : IZipWriter
|
||||
{
|
||||
private ZipOutputStream z;
|
||||
private int level;
|
||||
private readonly int _level;
|
||||
private ZipOutputStream _zipOutputStream;
|
||||
|
||||
public IonicZipWriter(string path, int compressionlevel)
|
||||
{
|
||||
level = compressionlevel;
|
||||
z = new ZipOutputStream(path)
|
||||
_level = compressionlevel;
|
||||
_zipOutputStream = new ZipOutputStream(path)
|
||||
{
|
||||
EnableZip64 = Zip64Option.Never,
|
||||
CompressionLevel = (Ionic.Zlib.CompressionLevel)level
|
||||
CompressionLevel = (Ionic.Zlib.CompressionLevel)_level,
|
||||
CompressionMethod = CompressionMethod.Deflate
|
||||
};
|
||||
z.CompressionMethod = CompressionMethod.Deflate;
|
||||
}
|
||||
}
|
||||
|
||||
public void WriteItem(string name, Action<Stream> callback)
|
||||
{
|
||||
var e = z.PutNextEntry(name);
|
||||
if (level == 0)
|
||||
{
|
||||
e.CompressionMethod = CompressionMethod.None;
|
||||
}
|
||||
else
|
||||
{
|
||||
e.CompressionMethod = CompressionMethod.Deflate;
|
||||
}
|
||||
var e = _zipOutputStream.PutNextEntry(name);
|
||||
e.CompressionMethod = _level == 0
|
||||
? CompressionMethod.None
|
||||
: CompressionMethod.Deflate;
|
||||
|
||||
callback(z);
|
||||
// there is no CloseEntry() call
|
||||
callback(_zipOutputStream); // there is no CloseEntry() call
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (z != null)
|
||||
if (_zipOutputStream != null)
|
||||
{
|
||||
z.Dispose();
|
||||
z = null;
|
||||
_zipOutputStream.Dispose();
|
||||
_zipOutputStream = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -222,14 +222,14 @@ namespace BizHawk.Client.Common
|
|||
return false;
|
||||
}
|
||||
|
||||
public static string GetRomsPath(string sysID)
|
||||
public static string GetRomsPath(string sysId)
|
||||
{
|
||||
if (Global.Config.UseRecentForROMs)
|
||||
{
|
||||
return Environment.SpecialFolder.Recent.ToString();
|
||||
}
|
||||
|
||||
var path = Global.Config.PathEntries[sysID, "ROM"];
|
||||
var path = Global.Config.PathEntries[sysId, "ROM"];
|
||||
|
||||
if (path == null || !PathIsSet(path.Path))
|
||||
{
|
||||
|
@ -241,7 +241,7 @@ namespace BizHawk.Client.Common
|
|||
}
|
||||
}
|
||||
|
||||
return MakeAbsolutePath(path.Path, sysID);
|
||||
return MakeAbsolutePath(path.Path, sysId);
|
||||
}
|
||||
|
||||
public static string RemoveInvalidFileSystemChars(string name)
|
||||
|
@ -297,7 +297,10 @@ namespace BizHawk.Client.Common
|
|||
// hijinx here to get the core name out of the game name
|
||||
var name = FilesystemSafeName(game);
|
||||
name = Path.GetDirectoryName(name);
|
||||
if (name == string.Empty) name = FilesystemSafeName(game);
|
||||
if (name == string.Empty)
|
||||
{
|
||||
name = FilesystemSafeName(game);
|
||||
}
|
||||
|
||||
if (Global.MovieSession.Movie.IsActive)
|
||||
{
|
||||
|
@ -310,7 +313,6 @@ namespace BizHawk.Client.Common
|
|||
return Path.Combine(MakeAbsolutePath(pathEntry.Path, game.System), name);
|
||||
}
|
||||
|
||||
|
||||
public static string RetroSystemPath(GameInfo game)
|
||||
{
|
||||
// hijinx here to get the core name out of the game name
|
||||
|
@ -385,7 +387,7 @@ namespace BizHawk.Client.Common
|
|||
|
||||
public static string GetPathType(string system, string type)
|
||||
{
|
||||
var path = PathManager.GetPathEntryWithFallback(type, system).Path;
|
||||
var path = GetPathEntryWithFallback(type, system).Path;
|
||||
return MakeAbsolutePath(path, system);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,10 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
public class RomLoader
|
||||
{
|
||||
public enum LoadErrorType { Unknown, MissingFirmware, XML, DiscError }
|
||||
public enum LoadErrorType
|
||||
{
|
||||
Unknown, MissingFirmware, XML, DiscError
|
||||
}
|
||||
|
||||
// helper methods for the settings events
|
||||
private object GetCoreSettings<T>()
|
||||
|
|
Loading…
Reference in New Issue