This commit is contained in:
hegyak 2015-11-15 06:27:53 -08:00
commit 26758d00fd
18 changed files with 271 additions and 31 deletions

View File

@ -154,6 +154,7 @@
<Compile Include="movie\bk2\Bk2Movie.HeaderApi.cs">
<DependentUpon>Bk2Movie.cs</DependentUpon>
</Compile>
<Compile Include="movie\bk2\StringLogs.cs" />
<Compile Include="movie\import\PXMImport.cs" />
<Compile Include="movie\tasproj\StateManagerState.cs" />
<Compile Include="movie\tasproj\TasBranch.cs" />
@ -229,7 +230,6 @@
<Compile Include="SevenZipWriter.cs" />
<Compile Include="SharpZipWriter.cs" />
<Compile Include="SystemInfo.cs" />
<Compile Include="TempFileCleaner.cs" />
<Compile Include="tools\Cheat.cs" />
<Compile Include="tools\CheatList.cs" />
<Compile Include="tools\RamSearchEngine.cs" />

View File

@ -77,6 +77,7 @@ namespace BizHawk.Client.Common
public bool ForbidUD_LR = false;
public bool ShowContextMenu = true;
public bool EnableBackupMovies = true;
public bool MoviesOnDisk = false;
public bool HotkeyConfigAutoTab = true;
public bool InputConfigAutoTab = true;
public bool ShowLogWindow = false;

View File

@ -121,8 +121,11 @@ namespace BizHawk.Client.Common
//" C " is for N64 "P1 C Up" and the like, which should not be subject to mutexing
//regarding the unpressing and UDLR logic...... don't think about it. don't question it. don't look at it.
if (button.Contains("Down") && !button.Contains(" C "))
{
if (!Source.IsPressed(button)) Unpresses.Remove(button);
prefix = button.GetPrecedingString("Down");
string other = prefix + "Up";
if (Source.IsPressed(other))
@ -136,6 +139,7 @@ namespace BizHawk.Client.Common
if (button.Contains("Up") && !button.Contains(" C "))
{
if (!Source.IsPressed(button)) Unpresses.Remove(button);
prefix = button.GetPrecedingString("Up");
string other = prefix + "Down";
if (Source.IsPressed(other))
@ -150,6 +154,7 @@ namespace BizHawk.Client.Common
if (button.Contains("Right") && !button.Contains(" C "))
{
if (!Source.IsPressed(button)) Unpresses.Remove(button);
prefix = button.GetPrecedingString("Right");
string other = prefix + "Left";
if (Source.IsPressed(other))
@ -163,6 +168,7 @@ namespace BizHawk.Client.Common
if (button.Contains("Left") && !button.Contains(" C "))
{
if (!Source.IsPressed(button)) Unpresses.Remove(button);
prefix = button.GetPrecedingString("Left");
string other = prefix + "Right";
if (Source.IsPressed(other))

View File

@ -8,7 +8,7 @@ namespace BizHawk.Client.Common
{
public partial class Bk2Movie
{
protected List<string> _log = new List<string>();
protected IStringLog _log;
protected string LogKey = string.Empty;
public string GetInputLog()
@ -58,7 +58,7 @@ namespace BizHawk.Client.Common
// We are in record mode so replace the movie log with the one from the savestate
if (!Global.MovieSession.MultiTrack.IsActive)
{
if (Global.Config.EnableBackupMovies && MakeBackup && _log.Any())
if (Global.Config.EnableBackupMovies && MakeBackup && _log.Count != 0)
{
SaveBackup();
MakeBackup = false;

View File

@ -27,6 +27,8 @@ namespace BizHawk.Client.Common
MakeBackup = true;
Header[HeaderKeys.MOVIEVERSION] = "BizHawk v2.0.0";
_log = StringLogUtil.MakeStringLog();
}
private string _filename;

View File

@ -0,0 +1,196 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using BizHawk.Common;
namespace BizHawk.Client.Common
{
public static class StringLogUtil
{
public static bool DefaultToDisk;
public static IStringLog MakeStringLog()
{
if (DefaultToDisk)
return new DiskStringLog();
else return new ListStringLog();
}
}
public interface IStringLog : IDisposable, IEnumerable<string>
{
void RemoveAt(int index);
int Count { get; }
void Clear();
void Add(string str);
string this[int index] { get; set; }
void Insert(int index, string val);
void InsertRange(int index, IEnumerable<string> collection);
void AddRange(IEnumerable<string> collection);
void RemoveRange(int index, int count);
IStringLog Clone();
void CopyTo(string[] array);
void CopyTo(int index, string[] array, int arrayIndex, int count);
}
class ListStringLog : List<string>, IStringLog
{
public IStringLog Clone()
{
ListStringLog ret = new ListStringLog();
ret.AddRange(this);
return ret;
}
public void Dispose() { }
}
/// <summary>
/// A dumb-ish IStringLog with storage on disk with no provision for recovering lost space, except upon Clear()
/// The purpose here is to avoid having too complicated buggy logic or a dependency on sqlite or such.
/// It should be faster than those alternatives, but wasteful of disk space.
/// It should also be easier to add new IList<string>-like methods than dealing with a database
/// </summary>
class DiskStringLog : IStringLog
{
List<long> Offsets = new List<long>();
long cursor = 0;
BinaryWriter bw;
BinaryReader br;
FileStream stream;
public DiskStringLog()
{
var path = TempFileCleaner.GetTempFilename("movieOnDisk");
stream = new FileStream(path, FileMode.Create, System.Security.AccessControl.FileSystemRights.FullControl, FileShare.None, 4 * 1024, FileOptions.DeleteOnClose);
bw = new BinaryWriter(stream);
br = new BinaryReader(stream);
}
public IStringLog Clone()
{
DiskStringLog ret = new DiskStringLog();
for (int i = 0; i < Count; i++)
ret.Add(this[i]);
return ret;
}
public void Dispose()
{
stream.Dispose();
}
public int Count { get { return Offsets.Count; } }
public void Clear()
{
stream.SetLength(0);
Offsets.Clear();
cursor = 0;
}
public void Add(string str)
{
Offsets.Add(stream.Position);
bw.Write(str);
bw.Flush();
}
public void RemoveAt(int index)
{
Offsets.RemoveAt(index);
//no garbage collection in the disk file... oh well.
}
public string this[int index]
{
get
{
stream.Position = Offsets[index];
return br.ReadString();
}
set
{
stream.Position = stream.Length;
Offsets[index] = stream.Position;
bw.Write(value);
bw.Flush();
}
}
public void Insert(int index, string val)
{
Offsets.Insert(index, stream.Position);
bw.Write(val);
bw.Flush();
}
public void InsertRange(int index, IEnumerable<string> collection)
{
foreach(var item in collection)
Insert(index++,item);
}
public void AddRange(IEnumerable<string> collection)
{
foreach (var item in collection)
Add(item);
}
class Enumerator : IEnumerator<string>
{
public DiskStringLog log;
int index;
public string Current { get { return log[index]; } }
object System.Collections.IEnumerator.Current { get { return log[index]; } }
bool System.Collections.IEnumerator.MoveNext()
{
index++;
if (index >= log.Count)
{
index = log.Count;
return false;
}
return true;
}
void System.Collections.IEnumerator.Reset() { index = 0; }
public void Dispose() { }
}
IEnumerator<string> IEnumerable<string>.GetEnumerator()
{
return new Enumerator() { log = this };
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return new Enumerator() { log = this };
}
public void RemoveRange(int index, int count)
{
int end = index + count - 1;
for (int i = 0; i < count; i++)
{
RemoveAt(end);
end--;
}
}
public void CopyTo(string[] array)
{
for (int i = 0; i < Count; i++)
array[i] = this[i];
}
public void CopyTo(int index, string[] array, int arrayIndex, int count)
{
for (int i = 0; i < count; i++)
array[i + arrayIndex] = this[index + i];
}
}
}

View File

@ -145,7 +145,7 @@ namespace BizHawk.Client.Common.MovieConversionExtensions
tas.BinarySavestate = savestate;
tas.ClearLagLog();
List<string> entries = old.GetLogEntries();
var entries = old.GetLogEntries();
tas.CopyLog(entries.Skip(frame));
tas.CopyVerificationLog(old.VerificationLog);
@ -220,7 +220,7 @@ namespace BizHawk.Client.Common.MovieConversionExtensions
tas.TasStateManager.Clear();
tas.ClearLagLog();
List<string> entries = old.GetLogEntries();
var entries = old.GetLogEntries();
tas.CopyVerificationLog(old.VerificationLog);
tas.CopyVerificationLog(entries);

View File

@ -11,8 +11,8 @@ namespace BizHawk.Client.Common
public class TasBranch
{
public int Frame { get; set; }
public byte[] CoreData { get; set; }
public List<string> InputLog { get; set; }
public byte[] CoreData { get; set; }
public IStringLog InputLog { get; set; }
public BitmapBuffer OSDFrameBuffer { get; set; }
public TasLagLog LagLog { get; set; }
public TasMovieChangeLog ChangeLog { get; set; }
@ -63,9 +63,10 @@ namespace BizHawk.Client.Common
});
bs.PutLump(ninput, delegate(TextWriter tw)
{
foreach (var line in b.InputLog)
tw.WriteLine(line);
{
int todo = b.InputLog.Count;
for (int i = 0; i < todo; i++)
tw.WriteLine(b.InputLog[i]);
});
bs.PutLump(nframebuffer, delegate(Stream s)
@ -145,8 +146,8 @@ namespace BizHawk.Client.Common
});
bl.GetLump(ninput, true, delegate(TextReader tr)
{
b.InputLog = new List<string>();
{
b.InputLog = StringLogUtil.MakeStringLog();
string line;
while ((line = tr.ReadLine()) != null)
b.InputLog.Add(line);

View File

@ -319,7 +319,7 @@ namespace BizHawk.Client.Common
ChangeLog.ClearLog();
}
private static string InputLogToString(List<string> log)
private static string InputLogToString(IStringLog log)
{
var sb = new StringBuilder();
foreach (var record in log)

View File

@ -21,7 +21,7 @@ namespace BizHawk.Client.Common
public readonly TasSession Session;
private readonly TasLagLog LagLog = new TasLagLog();
private readonly Dictionary<int, IController> InputStateCache = new Dictionary<int, IController>();
public readonly List<string> VerificationLog = new List<string>(); // For movies that do not begin with power-on, this is the input required to get into the initial state
public readonly IStringLog VerificationLog = StringLogUtil.MakeStringLog(); // For movies that do not begin with power-on, this is the input required to get into the initial state
public readonly TasBranchCollection Branches = new TasBranchCollection();
private BackgroundWorker _progressReportWorker = null;
@ -81,7 +81,7 @@ namespace BizHawk.Client.Common
}
public TasLagLog TasLagLog { get { return LagLog; } }
public List<string> InputLog { get { return _log; } }
public IStringLog InputLog { get { return _log; } }
public TasMovieMarkerList Markers { get; set; }
public bool BindMarkersToInput { get; set; }
public bool UseInputCache { get; set; }
@ -331,7 +331,7 @@ namespace BizHawk.Client.Common
}
}
public List<string> GetLogEntries()
public IStringLog GetLogEntries()
{
return _log;
}
@ -350,7 +350,7 @@ namespace BizHawk.Client.Common
{
TimelineBranchFrame = null;
if (Global.Config.EnableBackupMovies && MakeBackup && _log.Any())
if (Global.Config.EnableBackupMovies && MakeBackup && _log.Count != 0)
{
SaveBackup();
MakeBackup = false;
@ -500,7 +500,8 @@ namespace BizHawk.Client.Common
{
int? divergentPoint = DivergentPoint(_log, branch.InputLog);
_log = branch.InputLog.ToList();
if (_log != null) _log.Dispose();
_log = branch.InputLog.Clone();
//_changes = true;
// if there are branch states, they will be loaded anyway
@ -523,7 +524,7 @@ namespace BizHawk.Client.Common
}
// TODO: use LogGenerators rather than string comparisons
private int? DivergentPoint(List<string> currentLog, List<string> newLog)
private int? DivergentPoint(IStringLog currentLog, IStringLog newLog)
{
int max = newLog.Count;
if (currentLog.Count < newLog.Count)

View File

@ -2,6 +2,8 @@
using System.Collections.Generic;
using System.IO;
using BizHawk.Common;
namespace BizHawk.Client.Common
{
/// <summary>
@ -23,7 +25,7 @@ namespace BizHawk.Client.Common
_mCapacity = capacity;
if (onDisk)
{
var path = Path.Combine(Path.GetTempPath(), "bizhawk.rewindbuf-pid" + System.Diagnostics.Process.GetCurrentProcess().Id + "-" + Guid.NewGuid());
var path = TempFileCleaner.GetTempFilename("rewindbuf");
// 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.

View File

@ -59,13 +59,16 @@ namespace BizHawk.Client.EmuHawk
}
}
BizHawk.Client.Common.TempFileCleaner.Start();
BizHawk.Common.TempFileCleaner.Start();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
HawkFile.ArchiveHandlerFactory = new SevenZipSharpArchiveHandler();
string iniPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "config.ini");
Global.Config = ConfigService.Load<Config>(iniPath);
Global.Config.ResolveDefaults();
HawkFile.ArchiveHandlerFactory = new SevenZipSharpArchiveHandler();
BizHawk.Client.Common.StringLogUtil.DefaultToDisk = Global.Config.MoviesOnDisk;
//super hacky! this needs to be done first. still not worth the trouble to make this system fully proper
for (int i = 0; i < args.Length; i++)

View File

@ -230,7 +230,7 @@ namespace BizHawk.Client.EmuHawk
{
Frame = Global.Emulator.Frame,
CoreData = (byte[])((Global.Emulator as IStatable).SaveStateBinary().Clone()),
InputLog = Movie.InputLog.ToList(),
InputLog = Movie.InputLog.Clone(),
OSDFrameBuffer = GlobalWin.MainForm.CaptureOSD(),
LagLog = Movie.TasLagLog.Clone(),
ChangeLog = new TasMovieChangeLog(Movie),

View File

@ -76,6 +76,7 @@
<Compile Include="SimpleTime.cs" />
<Compile Include="Sprintf.cs" />
<Compile Include="SwitcherStream.cs" />
<Compile Include="TempFileManager.cs" />
<Compile Include="UndoHistory.cs" />
<Compile Include="UnmanagedResourceHeap.cs" />
<Compile Include="Util.cs" />

View File

@ -9,7 +9,7 @@ namespace BizHawk.Common
public InstanceDll(string dllPath)
{
//copy the dll to a temp directory
var path = Path.Combine(Path.GetTempPath(), "instancedll-pid" + System.Diagnostics.Process.GetCurrentProcess().Id + "-" + Guid.NewGuid()) + "-" + Path.GetFileName(dllPath);
var path = TempFileCleaner.GetTempFilename(string.Format("{0}", Path.GetFileNameWithoutExtension(dllPath)),".dll",false);
using (var stream = new FileStream(path, FileMode.Create, System.Security.AccessControl.FileSystemRights.FullControl, FileShare.ReadWrite | FileShare.Delete, 4 * 1024, FileOptions.None))
using (var sdll = File.OpenRead(dllPath))
sdll.CopyTo(stream);
@ -24,10 +24,8 @@ namespace BizHawk.Common
string envpath_new = Path.GetDirectoryName(path) + ";" + envpath;
Environment.SetEnvironmentVariable("PATH", envpath_new, EnvironmentVariableTarget.Process);
_hModule = LoadLibrary(path); //consider using LoadLibraryEx instead of shenanigans?
var newfname = Path.GetFileName(path);
newfname = "bizhawk.bizdelete-" + newfname;
var newpath = Path.Combine(Path.GetDirectoryName(path), newfname);
File.Move(path, newpath);
var newfname = TempFileCleaner.RenameTempFilenameForDelete(path);
File.Move(path, newfname);
}
finally
{

View File

@ -1,7 +1,7 @@
using System;
using System.IO;
namespace BizHawk.Client.Common
namespace BizHawk.Common
{
/// <summary>
/// Starts a thread which cleans any filenames in %temp% beginning with bizhawk.bizdelete.
@ -12,6 +12,23 @@ namespace BizHawk.Client.Common
{
//todo - manage paths other than %temp%, make not static, or allow adding multiple paths to static instance
public static string GetTempFilename(string friendlyname, string extension = null, bool delete = true)
{
string guidPart = Guid.NewGuid().ToString();
var fname = string.Format("biz-{0}-{1}-{2}{3}", System.Diagnostics.Process.GetCurrentProcess().Id, friendlyname, guidPart, extension ?? "");
if (delete) fname = RenameTempFilenameForDelete(fname);
return Path.Combine(Path.GetTempPath(), fname);
}
public static string RenameTempFilenameForDelete(string path)
{
string filename = Path.GetFileName(path);
string dir = Path.GetDirectoryName(path);
if (!filename.StartsWith("biz-")) throw new InvalidOperationException();
filename = "bizdelete-" + filename.Remove(0, 4);
return Path.Combine(dir, filename);
}
public static void Start()
{
lock (typeof(TempFileCleaner))
@ -31,7 +48,7 @@ namespace BizHawk.Client.Common
var di = new DirectoryInfo(Path.GetTempPath());
for (; ; )
{
var fis = di.GetFiles("bizhawk.bizdelete*");
var fis = di.GetFiles("bizdelete-*");
foreach (var fi in fis)
{
try

View File

@ -5,6 +5,8 @@ using System.Text;
using System.Runtime.InteropServices;
using System.Reflection;
#pragma warning disable 649, 169
using BizHawk.Common;
namespace BizHawk.Emulation.Cores

View File

@ -3,8 +3,10 @@ next
=========================================
*EmuHawk
**Add libretro player, compatible with selected cores
**Support Code-Data Logger for GB/GBC, SMS/GG, SNES, and Genesis
**Add GameShark cheat converter
**Add custom exception display box, so exception info can be clipboarded out
**Support Code-Data Logger for GB/GBC, SMS/GG, and Genesis
**Cheat Dialog: Fix flakiness in value-editing
**Stop FP precision conflicts between lua scripts and D3D Display method
**DispMethod D3D: More leniency in compilation of optional shaders (so it's able to run on more low spec systems)
@ -12,8 +14,13 @@ next
**Validate user shaders at selection time
**Support user custom AR selection
**Add --load-state commandline
**Streamline editing RAM Watches
**Tidy main form context menu
**Add more options for U+D/L+R forbid/mutex
**Fix #525 - Memorywatch hex textbox now remembers values across memdomain switches
**Fix #526 - Hex editor repainting fails and garbage rendering
**Fix #535 - domain list does not update when changing cores
**Fix #537 - Annoyance with "always on top"
**Tastudio (TODO - editorialize this section)
***color stated frames on WasLag too.
@ -33,6 +40,8 @@ next
**Lua
**Fix gameExtraPadding coordinate translation
**Clarify script pause/stop state in UI and logic
**Fix forms.destroyall() and call it when lua console closes
**Fix error in sizing of lua draw buffers with SetGameExtraPadding (and probably ClientExtraPadding) use
*PSX
**Fix #530 "AV Resizing shows black screen with PSX"
@ -40,6 +49,7 @@ next
*SNES
**Fix crashes in GFX debugger (including fix #529)
**Recommend proper SNES PAR
**Build dlls without msvcrt14 dependencies (to run on more systems)
*Genesis
**Fix missing scrollbars in VDP viewer