From 5196fc6b70fb026a56e484ed255afac9196fe769 Mon Sep 17 00:00:00 2001 From: zeromus Date: Tue, 17 Nov 2015 17:10:27 -0600 Subject: [PATCH] Revert "common logic for tempfiles" This reverts commit 5afa44bbece22c105e250f3510a4852d0625e65a. and also "fix regression in libretro core loading and streamline open advanced libretro ui" 59048264cd70202484f021b742b4428bbed52970 but tortoisegit didn't put that in the commit message. --- .../BizHawk.Client.Common.csproj | 1 + .../TempFileCleaner.cs | 21 ++----------------- BizHawk.Client.Common/movie/bk2/StringLogs.cs | 4 +--- .../rewind/StreamBlobDatabase.cs | 4 +--- BizHawk.Client.EmuHawk/MainForm.Events.cs | 6 ++---- BizHawk.Client.EmuHawk/OpenAdvancedChooser.cs | 4 ++-- BizHawk.Client.EmuHawk/Program.cs | 2 +- BizHawk.Common/BizHawk.Common.csproj | 1 - BizHawk.Common/InstanceDll.cs | 10 +++++---- 9 files changed, 16 insertions(+), 37 deletions(-) rename BizHawk.Common/TempFileManager.cs => BizHawk.Client.Common/TempFileCleaner.cs (60%) diff --git a/BizHawk.Client.Common/BizHawk.Client.Common.csproj b/BizHawk.Client.Common/BizHawk.Client.Common.csproj index c35c7ad9d1..821672cd53 100644 --- a/BizHawk.Client.Common/BizHawk.Client.Common.csproj +++ b/BizHawk.Client.Common/BizHawk.Client.Common.csproj @@ -230,6 +230,7 @@ + diff --git a/BizHawk.Common/TempFileManager.cs b/BizHawk.Client.Common/TempFileCleaner.cs similarity index 60% rename from BizHawk.Common/TempFileManager.cs rename to BizHawk.Client.Common/TempFileCleaner.cs index 2c927f6ab5..b6a7f0eda6 100644 --- a/BizHawk.Common/TempFileManager.cs +++ b/BizHawk.Client.Common/TempFileCleaner.cs @@ -1,7 +1,7 @@ using System; using System.IO; -namespace BizHawk.Common +namespace BizHawk.Client.Common { /// /// Starts a thread which cleans any filenames in %temp% beginning with bizhawk.bizdelete. @@ -12,23 +12,6 @@ namespace BizHawk.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)) @@ -48,7 +31,7 @@ namespace BizHawk.Common var di = new DirectoryInfo(Path.GetTempPath()); for (; ; ) { - var fis = di.GetFiles("bizdelete-*"); + var fis = di.GetFiles("bizhawk.bizdelete*"); foreach (var fi in fis) { try diff --git a/BizHawk.Client.Common/movie/bk2/StringLogs.cs b/BizHawk.Client.Common/movie/bk2/StringLogs.cs index 355efdc9ef..b11db3a210 100644 --- a/BizHawk.Client.Common/movie/bk2/StringLogs.cs +++ b/BizHawk.Client.Common/movie/bk2/StringLogs.cs @@ -5,8 +5,6 @@ using System.IO; using System.Linq; using System.Text; -using BizHawk.Common; - namespace BizHawk.Client.Common { public static class StringLogUtil @@ -64,7 +62,7 @@ namespace BizHawk.Client.Common FileStream stream; public DiskStringLog() { - var path = TempFileCleaner.GetTempFilename("movieOnDisk"); + var path = Path.Combine(Path.GetTempPath(), "bizhawk.disklist-pid" + System.Diagnostics.Process.GetCurrentProcess().Id + "-" + Guid.NewGuid()); 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); diff --git a/BizHawk.Client.Common/rewind/StreamBlobDatabase.cs b/BizHawk.Client.Common/rewind/StreamBlobDatabase.cs index 50dbc74333..1ec2f9e157 100644 --- a/BizHawk.Client.Common/rewind/StreamBlobDatabase.cs +++ b/BizHawk.Client.Common/rewind/StreamBlobDatabase.cs @@ -2,8 +2,6 @@ using System.Collections.Generic; using System.IO; -using BizHawk.Common; - namespace BizHawk.Client.Common { /// @@ -25,7 +23,7 @@ namespace BizHawk.Client.Common _mCapacity = capacity; if (onDisk) { - var path = TempFileCleaner.GetTempFilename("rewindbuf"); + var path = Path.Combine(Path.GetTempPath(), "bizhawk.rewindbuf-pid" + System.Diagnostics.Process.GetCurrentProcess().Id + "-" + Guid.NewGuid()); // 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. diff --git a/BizHawk.Client.EmuHawk/MainForm.Events.cs b/BizHawk.Client.EmuHawk/MainForm.Events.cs index 72c9d8adb1..42ef3a00a7 100644 --- a/BizHawk.Client.EmuHawk/MainForm.Events.cs +++ b/BizHawk.Client.EmuHawk/MainForm.Events.cs @@ -1185,7 +1185,7 @@ namespace BizHawk.Client.EmuHawk ThrottleMessage(); } - public bool RunLibretroCoreChooser() + public void RunLibretroCoreChooser() { var ofd = new OpenFileDialog(); @@ -1203,11 +1203,9 @@ namespace BizHawk.Client.EmuHawk ofd.Filter = "Libretro Cores (*.dll)|*.dll"; if (ofd.ShowDialog() == DialogResult.Cancel) - return false; + return; Global.Config.LibretroCore = ofd.FileName; - - return true; } private void setLibretroCoreToolStripMenuItem_Click(object sender, EventArgs e) diff --git a/BizHawk.Client.EmuHawk/OpenAdvancedChooser.cs b/BizHawk.Client.EmuHawk/OpenAdvancedChooser.cs index c75d82be1a..a1e6ee192e 100644 --- a/BizHawk.Client.EmuHawk/OpenAdvancedChooser.cs +++ b/BizHawk.Client.EmuHawk/OpenAdvancedChooser.cs @@ -51,8 +51,8 @@ namespace BizHawk.Client.EmuHawk private void btnSetLibretroCore_Click(object sender, EventArgs e) { - if(mainForm.RunLibretroCoreChooser()) - RefreshLibretroCore(false); + mainForm.RunLibretroCoreChooser(); + RefreshLibretroCore(false); } LibRetroEmulator.RetroDescription CurrentDescription; diff --git a/BizHawk.Client.EmuHawk/Program.cs b/BizHawk.Client.EmuHawk/Program.cs index 96c37c97c6..09a44a0c86 100644 --- a/BizHawk.Client.EmuHawk/Program.cs +++ b/BizHawk.Client.EmuHawk/Program.cs @@ -59,7 +59,7 @@ namespace BizHawk.Client.EmuHawk } } - BizHawk.Common.TempFileCleaner.Start(); + BizHawk.Client.Common.TempFileCleaner.Start(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); diff --git a/BizHawk.Common/BizHawk.Common.csproj b/BizHawk.Common/BizHawk.Common.csproj index eaeabf9830..825675481d 100644 --- a/BizHawk.Common/BizHawk.Common.csproj +++ b/BizHawk.Common/BizHawk.Common.csproj @@ -76,7 +76,6 @@ - diff --git a/BizHawk.Common/InstanceDll.cs b/BizHawk.Common/InstanceDll.cs index aa02cd3230..5f4ae2b744 100644 --- a/BizHawk.Common/InstanceDll.cs +++ b/BizHawk.Common/InstanceDll.cs @@ -9,7 +9,7 @@ namespace BizHawk.Common public InstanceDll(string dllPath) { //copy the dll to a temp directory - var path = TempFileCleaner.GetTempFilename(string.Format("{0}", Path.GetFileNameWithoutExtension(dllPath)),".dll",false); + var path = Path.Combine(Path.GetTempPath(), "instancedll-pid" + System.Diagnostics.Process.GetCurrentProcess().Id + "-" + Guid.NewGuid()) + "-" + Path.GetFileName(dllPath); 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); @@ -21,11 +21,13 @@ namespace BizHawk.Common var envpath = Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.Process); try { - string envpath_new = Path.GetDirectoryName(dllPath) + ";" + envpath; + 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 = TempFileCleaner.RenameTempFilenameForDelete(path); - File.Move(path, newfname); + var newfname = Path.GetFileName(path); + newfname = "bizhawk.bizdelete-" + newfname; + var newpath = Path.Combine(Path.GetDirectoryName(path), newfname); + File.Move(path, newpath); } finally {