From 3ec314d20bef555efdce452c2e4f32407e454016 Mon Sep 17 00:00:00 2001 From: zeromus Date: Wed, 5 Aug 2015 16:36:44 -0500 Subject: [PATCH] TasStateManager: don't touch disk unless opened for 'write access' --- .../movie/tasproj/TasStateManager.cs | 16 +++++++++++++--- .../tools/TAStudio/TAStudio.cs | 4 +++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/BizHawk.Client.Common/movie/tasproj/TasStateManager.cs b/BizHawk.Client.Common/movie/tasproj/TasStateManager.cs index cf357adb9b..2e155a7db4 100644 --- a/BizHawk.Client.Common/movie/tasproj/TasStateManager.cs +++ b/BizHawk.Client.Common/movie/tasproj/TasStateManager.cs @@ -35,12 +35,14 @@ namespace BizHawk.Client.Common } } + private Guid guid = Guid.NewGuid(); private readonly SortedList States = new SortedList(); private string statePath { get { - return PathManager.MakeAbsolutePath(Global.Config.PathEntries["Global", "TAStudio states"].Path, null); + var basePath = PathManager.MakeAbsolutePath(Global.Config.PathEntries["Global", "TAStudio states"].Path, null); + return Path.Combine(basePath, guid.ToString()); } } @@ -88,12 +90,20 @@ namespace BizHawk.Client.Common } States = new SortedList(limit); + + accessed = new List(); + } + + /// + /// Mounts this instance for write access. Prior to that it's read-only + /// + public void MountWriteAccess() + { if (Directory.Exists(statePath)) { Directory.Delete(statePath, true); // To delete old files that may still exist. } Directory.CreateDirectory(statePath); - accessed = new List(); } public TasStateManagerSettings Settings { get; set; } @@ -393,7 +403,7 @@ namespace BizHawk.Client.Common } private void clearDiskStates() { - string path = PathManager.MakeAbsolutePath(Global.Config.PathEntries["Global", "TAStudio states"].Path, null); + string path = statePath; if (Directory.Exists(path)) { Directory.Delete(path, true); diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs index c37973cdd2..bd74a44af8 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs @@ -432,7 +432,9 @@ namespace BizHawk.Client.EmuHawk if (AskSaveChanges()) { Global.MovieSession.Movie = new TasMovie(false, _saveBackgroundWorker); - (Global.MovieSession.Movie as TasMovie).TasStateManager.InvalidateCallback = GreenzoneInvalidated; + var stateManager = (Global.MovieSession.Movie as TasMovie).TasStateManager; + stateManager.MountWriteAccess(); + stateManager.InvalidateCallback = GreenzoneInvalidated; CurrentTasMovie.PropertyChanged += new PropertyChangedEventHandler(this.TasMovie_OnPropertyChanged); CurrentTasMovie.Filename = DefaultTasProjName(); // TODO don't do this, take over any mainform actions that can crash without a filename CurrentTasMovie.PopulateWithDefaultHeaderValues();