misc cleanups
This commit is contained in:
parent
e974006ea6
commit
5a1341dd47
|
@ -27,11 +27,6 @@ namespace BizHawk.Client.Common
|
|||
return Path.Combine(PathManager.GetExeDirectoryAbsolute(), "dll");
|
||||
}
|
||||
|
||||
public string GetSaveRAMPath()
|
||||
{
|
||||
return PathManager.SaveRamPath(Global.Game);
|
||||
}
|
||||
|
||||
public string GetRetroSaveRAMDirectory()
|
||||
{
|
||||
return PathManager.RetroSaveRAMDirectory(Global.Game);
|
||||
|
@ -53,14 +48,14 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
if (required)
|
||||
{
|
||||
var fullmsg = $"Couldn't find required firmware \"{sysID}:{firmwareID}\". This is fatal{(msg != null ? $": {msg}" : ".")}";
|
||||
throw new MissingFirmwareException(fullmsg);
|
||||
var fullMsg = $"Couldn't find required firmware \"{sysID}:{firmwareID}\". This is fatal{(msg != null ? $": {msg}" : ".")}";
|
||||
throw new MissingFirmwareException(fullMsg);
|
||||
}
|
||||
|
||||
if (msg != null)
|
||||
{
|
||||
var fullmsg = $"Couldn't find firmware \"{sysID}:{firmwareID}\". Will attempt to continue: {msg}";
|
||||
_showWarning(fullmsg);
|
||||
var fullMsg = $"Couldn't find firmware \"{sysID}:{firmwareID}\". Will attempt to continue: {msg}";
|
||||
_showWarning(fullMsg);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -112,8 +107,7 @@ namespace BizHawk.Client.Common
|
|||
|
||||
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 var path);
|
||||
if (ret != null && path != null)
|
||||
{
|
||||
gi = Database.GetGameInfo(ret, path);
|
||||
|
|
|
@ -64,7 +64,7 @@ namespace BizHawk.Client.Common
|
|||
return;
|
||||
}
|
||||
|
||||
byte[] savestateCopy = null;
|
||||
byte[] savestateCopy;
|
||||
while (_stateBufferPool.TryPop(out savestateCopy) && savestateCopy.Length != coreSavestate.Length)
|
||||
{
|
||||
savestateCopy = null;
|
||||
|
|
|
@ -348,47 +348,43 @@ namespace BizHawk.Client.Common
|
|||
|
||||
private void LoadPreviousState()
|
||||
{
|
||||
using (var reader = new BinaryReader(GetPreviousStateMemoryStream()))
|
||||
using var reader = new BinaryReader(GetPreviousStateMemoryStream());
|
||||
byte[] buf = ((MemoryStream)reader.BaseStream).GetBuffer();
|
||||
bool fullState = reader.ReadByte() == 1;
|
||||
if (_rewindDeltaEnable)
|
||||
{
|
||||
byte[] buf = ((MemoryStream)reader.BaseStream).GetBuffer();
|
||||
bool fullState = reader.ReadByte() == 1;
|
||||
if (_rewindDeltaEnable)
|
||||
if (fullState)
|
||||
{
|
||||
if (fullState)
|
||||
{
|
||||
UpdateLastState(buf, 1, buf.Length - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
int index = 1;
|
||||
int offset = 0;
|
||||
|
||||
while (index < buf.Length)
|
||||
{
|
||||
int offsetDelta = (int)VLInteger.ReadUnsigned(buf, ref index);
|
||||
int length = (int)VLInteger.ReadUnsigned(buf, ref index);
|
||||
|
||||
offset += offsetDelta;
|
||||
|
||||
Buffer.BlockCopy(buf, index, _lastState, offset, length);
|
||||
index += length;
|
||||
}
|
||||
}
|
||||
|
||||
using (var lastStateReader = new BinaryReader(new MemoryStream(_lastState)))
|
||||
{
|
||||
Global.Emulator.AsStatable().LoadStateBinary(lastStateReader);
|
||||
}
|
||||
UpdateLastState(buf, 1, buf.Length - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!fullState)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
int index = 1;
|
||||
int offset = 0;
|
||||
|
||||
Global.Emulator.AsStatable().LoadStateBinary(reader);
|
||||
while (index < buf.Length)
|
||||
{
|
||||
int offsetDelta = (int)VLInteger.ReadUnsigned(buf, ref index);
|
||||
int length = (int)VLInteger.ReadUnsigned(buf, ref index);
|
||||
|
||||
offset += offsetDelta;
|
||||
|
||||
Buffer.BlockCopy(buf, index, _lastState, offset, length);
|
||||
index += length;
|
||||
}
|
||||
}
|
||||
|
||||
using var lastStateReader = new BinaryReader(new MemoryStream(_lastState));
|
||||
Global.Emulator.AsStatable().LoadStateBinary(lastStateReader);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!fullState)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
Global.Emulator.AsStatable().LoadStateBinary(reader);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,9 +17,7 @@ namespace BizHawk.Client.Common
|
|||
private readonly long _mCapacity;
|
||||
|
||||
private byte[] _mAllocatedBuffer;
|
||||
private Stream _mStream;
|
||||
private LinkedListNode<ListItem> _mHead, _mTail;
|
||||
private long _mSize;
|
||||
|
||||
public StreamBlobDatabase(bool onDisk, long capacity, StreamBlobDatabaseBufferManager mBufferManage)
|
||||
{
|
||||
|
@ -32,19 +30,19 @@ namespace BizHawk.Client.Common
|
|||
// I checked the DeleteOnClose operation to make sure it cleans up when the process is aborted, and it seems to.
|
||||
// Otherwise we would have a more complex tempfile management problem here.
|
||||
// 4KB buffer chosen due to similarity to .net defaults, and fear of anything larger making hiccups for small systems (we could try asyncing this stuff though...)
|
||||
_mStream = new FileStream(path, FileMode.Create, System.Security.AccessControl.FileSystemRights.FullControl, FileShare.None, 4 * 1024, FileOptions.DeleteOnClose);
|
||||
Stream = new FileStream(path, FileMode.Create, System.Security.AccessControl.FileSystemRights.FullControl, FileShare.None, 4 * 1024, FileOptions.DeleteOnClose);
|
||||
}
|
||||
else
|
||||
{
|
||||
_mAllocatedBuffer = _mBufferManage(null, ref _mCapacity, true);
|
||||
_mStream = new MemoryStream(_mAllocatedBuffer);
|
||||
Stream = new MemoryStream(_mAllocatedBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the amount of the buffer that's used
|
||||
/// </summary>
|
||||
public long Size => _mSize;
|
||||
public long Size { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current fullness ratio (Size/Capacity). Note that this wont reach 100% due to the buffer size not being a multiple of a fixed savestate size.
|
||||
|
@ -59,12 +57,12 @@ namespace BizHawk.Client.Common
|
|||
/// <summary>
|
||||
/// Gets the underlying stream to
|
||||
/// </summary>
|
||||
public Stream Stream => _mStream;
|
||||
public Stream Stream { get; private set; }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_mStream.Dispose();
|
||||
_mStream = null;
|
||||
Stream.Dispose();
|
||||
Stream = null;
|
||||
if (_mAllocatedBuffer != null)
|
||||
{
|
||||
long capacity = 0;
|
||||
|
@ -76,7 +74,7 @@ namespace BizHawk.Client.Common
|
|||
public void Clear()
|
||||
{
|
||||
_mHead = _mTail = null;
|
||||
_mSize = 0;
|
||||
Size = 0;
|
||||
_mBookmarks.Clear();
|
||||
}
|
||||
|
||||
|
@ -88,8 +86,8 @@ namespace BizHawk.Client.Common
|
|||
var buf = seg.Array;
|
||||
int len = seg.Count;
|
||||
long offset = Enqueue(0, len);
|
||||
_mStream.Position = offset;
|
||||
_mStream.Write(buf, seg.Offset, len);
|
||||
Stream.Position = offset;
|
||||
Stream.Write(buf, seg.Offset, len);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -108,14 +106,14 @@ namespace BizHawk.Client.Common
|
|||
private MemoryStream CreateMemoryStream(ListItem item)
|
||||
{
|
||||
var buf = new byte[item.Length];
|
||||
_mStream.Position = item.Index;
|
||||
_mStream.Read(buf, 0, item.Length);
|
||||
Stream.Position = item.Index;
|
||||
Stream.Read(buf, 0, item.Length);
|
||||
return new MemoryStream(buf, 0, item.Length, false, true);
|
||||
}
|
||||
|
||||
public long Enqueue(int timestamp, int amount)
|
||||
{
|
||||
_mSize += amount;
|
||||
Size += amount;
|
||||
|
||||
if (_mHead == null)
|
||||
{
|
||||
|
@ -126,7 +124,7 @@ namespace BizHawk.Client.Common
|
|||
long target = _mHead.Value.EndExclusive + amount;
|
||||
if (_mTail != null && target <= _mTail.Value.Index)
|
||||
{
|
||||
// theres room to add a new head before the tail
|
||||
// there's room to add a new head before the tail
|
||||
_mHead = _mBookmarks.AddAfter(_mHead, new ListItem(timestamp, _mHead.Value.EndExclusive, amount));
|
||||
goto CLEANUP;
|
||||
}
|
||||
|
@ -136,7 +134,7 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
if (target <= _mCapacity)
|
||||
{
|
||||
// theres room to add a new head before the end of capacity
|
||||
// there's room to add a new head before the end of capacity
|
||||
_mHead = _mBookmarks.AddAfter(_mHead, new ListItem(timestamp, _mHead.Value.EndExclusive, amount));
|
||||
goto CLEANUP;
|
||||
}
|
||||
|
@ -164,7 +162,7 @@ namespace BizHawk.Client.Common
|
|||
if (_mHead.Value.EndExclusive > _mTail.Value.Index && _mHead.Value.Index <= _mTail.Value.Index && _mHead != _mTail)
|
||||
{
|
||||
var nextTail = _mTail.Next;
|
||||
_mSize -= _mTail.Value.Length;
|
||||
Size -= _mTail.Value.Length;
|
||||
_mBookmarks.Remove(_mTail);
|
||||
_mTail = nextTail;
|
||||
}
|
||||
|
@ -196,7 +194,7 @@ namespace BizHawk.Client.Common
|
|||
}
|
||||
|
||||
var ret = _mHead.Value;
|
||||
_mSize -= ret.Length;
|
||||
Size -= ret.Length;
|
||||
LinkedListNode<ListItem> nextHead = _mHead.Previous;
|
||||
_mBookmarks.Remove(_mHead);
|
||||
if (_mHead == _mTail)
|
||||
|
@ -227,7 +225,7 @@ namespace BizHawk.Client.Common
|
|||
}
|
||||
|
||||
var ret = _mTail.Value;
|
||||
_mSize -= ret.Length;
|
||||
Size -= ret.Length;
|
||||
var nextTail = _mTail.Next;
|
||||
_mBookmarks.Remove(_mTail);
|
||||
if (_mTail == _mHead)
|
||||
|
|
|
@ -265,6 +265,7 @@
|
|||
<s:Boolean x:Key="/Default/UserDictionary/Words/=performant/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Phaser/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Pollable/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=preload/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Prereqs/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=quicksave/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Regionable/@EntryIndexedValue">True</s:Boolean>
|
||||
|
|
Loading…
Reference in New Issue