From 9430b9f206931913aa1a9a091f3be62dea6bb193 Mon Sep 17 00:00:00 2001 From: zeromus Date: Sun, 12 Oct 2014 04:19:01 +0000 Subject: [PATCH] --- BizHawk.Common/SwitcherStream.cs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/BizHawk.Common/SwitcherStream.cs b/BizHawk.Common/SwitcherStream.cs index 07d9809867..a899d2216d 100644 --- a/BizHawk.Common/SwitcherStream.cs +++ b/BizHawk.Common/SwitcherStream.cs @@ -1,3 +1,4 @@ +using System; using System.IO; namespace BizHawk.Common @@ -18,6 +19,11 @@ namespace BizHawk.Common { } + /// + /// if this is enabled, seeks to Begin,0 will get ignored; anything else will be an exception + /// + public bool DenySeekHack = false; + public override bool CanRead { get { return _currStream.CanRead; } } public override bool CanSeek { get { return _currStream.CanSeek; } } public override bool CanWrite { get { return _currStream.CanWrite; } } @@ -33,7 +39,12 @@ namespace BizHawk.Common set { - _currStream.Position = Position; + if (DenySeekHack) + { + if (value == 0) return; + else throw new InvalidOperationException("Cannot set position to non-zero in a SwitcherStream with DenySeekHack=true"); + } + _currStream.Position = value; } } @@ -54,6 +65,11 @@ namespace BizHawk.Common public override long Seek(long offset, SeekOrigin origin) { + if (DenySeekHack) + { + if (offset == 0 && origin == SeekOrigin.Begin) return 0; + else throw new InvalidOperationException("Cannot call Seek with non-zero offset or non-Begin origin in a SwitcherStream with DenySeekHack=true"); + } return _currStream.Seek(offset, origin); }