diff --git a/BizHawk.Client.Common/PathManager.cs b/BizHawk.Client.Common/PathManager.cs
index a84563484a..9479e05e5c 100644
--- a/BizHawk.Client.Common/PathManager.cs
+++ b/BizHawk.Client.Common/PathManager.cs
@@ -140,7 +140,7 @@ namespace BizHawk.Client.Common
//handling of initial .. was removed (Path.GetFullPath can handle it)
//handling of file:// or file:\\ was removed (can Path.GetFullPath handle it? not sure)
- // all pad paths default to EXE
+ // all bad paths default to EXE
return GetExeDirectoryAbsolute();
}
@@ -461,5 +461,19 @@ namespace BizHawk.Client.Common
return entry;
}
+
+ ///
+ /// Puts the currently configured temp path into the environment for use as actual temp directory
+ ///
+ public static void RefreshTempPath()
+ {
+ if (Global.Config.PathEntries.TempFilesFragment != "")
+ {
+ //TODO - BUG - needs to route through PathManager.MakeAbsolutePath or something similar, but how?
+ string target = Global.Config.PathEntries.TempFilesFragment;
+ BizHawk.Common.TempFileManager.HelperSetTempPath(target);
+ }
+ }
}
+
}
diff --git a/BizHawk.Client.Common/config/Config.cs b/BizHawk.Client.Common/config/Config.cs
index 4dea2406f2..aed9f909d4 100644
--- a/BizHawk.Client.Common/config/Config.cs
+++ b/BizHawk.Client.Common/config/Config.cs
@@ -37,6 +37,7 @@ namespace BizHawk.Client.Common
{
PathEntries.ResolveWithDefaults();
HotkeyBindings.ResolveWithDefaults();
+ PathManager.RefreshTempPath();
}
// Core preference for generic file extension, key: file extension, value: a systemID or empty if no preference
diff --git a/BizHawk.Client.Common/config/PathEntry.cs b/BizHawk.Client.Common/config/PathEntry.cs
index d8e070f950..5182bb28d8 100644
--- a/BizHawk.Client.Common/config/PathEntry.cs
+++ b/BizHawk.Client.Common/config/PathEntry.cs
@@ -165,6 +165,8 @@ namespace BizHawk.Client.Common
public string GlobalRomFragment => Global.Config.PathEntries["Global", "ROM"].Path;
+ public string TempFilesFragment => Global.Config.PathEntries["Global", "Temp Files"].Path;
+
// this one is special
public string GlobalBaseFragment => Global.Config.PathEntries["Global", "Base"].Path;
@@ -184,6 +186,7 @@ namespace BizHawk.Client.Common
new PathEntry { System = "Global_NULL", SystemDisplayName = "Global", Type = "TAStudio states", Path = Path.Combine(".", "Movies", "TAStudio states"), Ordinal = 12 },
new PathEntry { System = "Global_NULL", SystemDisplayName = "Global", Type = "Multi-Disk Bundles", Path = Path.Combine(".", ""), Ordinal = 13 },
new PathEntry { System = "Global_NULL", SystemDisplayName = "Global", Type = "External Tools", Path = Path.Combine(".", "ExternalTools"), Ordinal = 14 },
+ new PathEntry { System = "Global_NULL", SystemDisplayName = "Global", Type = "Temp Files", Path = "", Ordinal = 15 },
new PathEntry { System = "INTV", SystemDisplayName = "Intellivision", Type = "Base", Path = Path.Combine(".", "Intellivision"), Ordinal = 0 },
new PathEntry { System = "INTV", SystemDisplayName = "Intellivision", Type = "ROM", Path = ".", Ordinal = 1 },
diff --git a/BizHawk.Client.Common/movie/bk2/StringLogs.cs b/BizHawk.Client.Common/movie/bk2/StringLogs.cs
index f2893dc43c..0473ba7cf6 100644
--- a/BizHawk.Client.Common/movie/bk2/StringLogs.cs
+++ b/BizHawk.Client.Common/movie/bk2/StringLogs.cs
@@ -75,7 +75,7 @@ namespace BizHawk.Client.Common
_mDisk = disk;
if (disk)
{
- var path = TempFileCleaner.GetTempFilename("movieOnDisk");
+ var path = TempFileManager.GetTempFilename("movieOnDisk");
stream = new FileStream(path, FileMode.Create, System.Security.AccessControl.FileSystemRights.FullControl, FileShare.None, 4 * 1024, FileOptions.DeleteOnClose);
}
else
diff --git a/BizHawk.Client.Common/rewind/StreamBlobDatabase.cs b/BizHawk.Client.Common/rewind/StreamBlobDatabase.cs
index 24f7d3637e..c5472d7eef 100644
--- a/BizHawk.Client.Common/rewind/StreamBlobDatabase.cs
+++ b/BizHawk.Client.Common/rewind/StreamBlobDatabase.cs
@@ -27,7 +27,7 @@ namespace BizHawk.Client.Common
_mCapacity = capacity;
if (onDisk)
{
- var path = TempFileCleaner.GetTempFilename("rewindbuf");
+ var path = TempFileManager.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.
diff --git a/BizHawk.Client.EmuHawk/Program.cs b/BizHawk.Client.EmuHawk/Program.cs
index 47d97f0f1b..f663f8c31b 100644
--- a/BizHawk.Client.EmuHawk/Program.cs
+++ b/BizHawk.Client.EmuHawk/Program.cs
@@ -115,7 +115,7 @@ namespace BizHawk.Client.EmuHawk
}
}
- BizHawk.Common.TempFileCleaner.Start();
+ BizHawk.Common.TempFileManager.Start();
HawkFile.ArchiveHandlerFactory = new SevenZipSharpArchiveHandler();
diff --git a/BizHawk.Client.EmuHawk/config/PathConfig.cs b/BizHawk.Client.EmuHawk/config/PathConfig.cs
index 8489cd4337..c8eb7ed78e 100644
--- a/BizHawk.Client.EmuHawk/config/PathConfig.cs
+++ b/BizHawk.Client.EmuHawk/config/PathConfig.cs
@@ -308,6 +308,9 @@ namespace BizHawk.Client.EmuHawk
private void Ok_Click(object sender, EventArgs e)
{
SaveSettings();
+
+ PathManager.RefreshTempPath();
+
GlobalWin.OSD.AddMessage("Path settings saved");
Close();
}
diff --git a/BizHawk.Common/InstanceDll.cs b/BizHawk.Common/InstanceDll.cs
index f8e40ea96c..3bd1212e56 100644
--- a/BizHawk.Common/InstanceDll.cs
+++ b/BizHawk.Common/InstanceDll.cs
@@ -12,7 +12,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 = TempFileManager.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);
@@ -32,7 +32,7 @@ namespace BizHawk.Common
var lastError = GetLastError();
throw new InvalidOperationException($"Failed to load plugin {path}, error code: 0x{lastError:X}");
}
- var newfname = TempFileCleaner.RenameTempFilenameForDelete(path);
+ var newfname = TempFileManager.RenameTempFilenameForDelete(path);
File.Move(path, newfname);
}
finally
diff --git a/BizHawk.Common/TempFileManager.cs b/BizHawk.Common/TempFileManager.cs
index 14252983bf..255ab47a66 100644
--- a/BizHawk.Common/TempFileManager.cs
+++ b/BizHawk.Common/TempFileManager.cs
@@ -1,4 +1,6 @@
using System;
+using System.Linq;
+using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
@@ -10,7 +12,7 @@ namespace BizHawk.Common
/// Files shouldn't be named that unless they're safe to delete, but notably, they may stil be in use. That won't hurt this component.
/// When they're no longer in use, this component will then be able to delete them.
///
- public static class TempFileCleaner
+ public static class TempFileManager
{
// TODO - manage paths other than %temp%, make not static, or allow adding multiple paths to static instance
@@ -41,7 +43,7 @@ namespace BizHawk.Common
public static void Start()
{
- lock (typeof(TempFileCleaner))
+ lock (typeof(TempFileManager))
{
if (thread != null)
{
@@ -64,27 +66,49 @@ namespace BizHawk.Common
static void ThreadProc()
{
- var di = new DirectoryInfo(Path.GetTempPath());
+ //squirrely logic, trying not to create garbage
+ HashSet knownTempDirs = new HashSet();
+ List dis = new List();
for (;;)
{
- var fis = di.GetFiles("bizdelete-*");
- foreach (var fi in fis)
+ lock (typeof(TempFileManager))
{
+ knownTempDirs.Add(Path.GetTempPath());
+ if (dis.Count != knownTempDirs.Count)
+ dis = knownTempDirs.Select(x => new DirectoryInfo(x)).ToList();
+ }
+
+ foreach(var di in dis)
+ {
+ FileInfo[] fis = null;
try
{
- // SHUT. UP. THE. EXCEPTIONS.
- #if WINDOWS
- DeleteFileW(fi.FullName);
- #else
- fi.Delete();
- #endif
+ fis = di.GetFiles("bizdelete-*");
}
catch
{
}
+ if(fis != null)
+ {
+ foreach (var fi in fis)
+ {
+ try
+ {
+ // SHUT. UP. THE. EXCEPTIONS.
+ #if WINDOWS
+ DeleteFileW(fi.FullName);
+ #else
+ fi.Delete();
+ #endif
+ }
+ catch
+ {
+ }
- // try not to do more than one thing per frame
- Thread.Sleep(100);
+ // try not to do more than one thing per frame
+ Thread.Sleep(100);
+ }
+ }
}
// try not to slam the filesystem too hard, we dont want this to cause any hiccups
@@ -97,5 +121,13 @@ namespace BizHawk.Common
}
static Thread thread;
+
+ public static void HelperSetTempPath(string path)
+ {
+ //yes... this is how we're doing it, for now, until it's proven to be troublesome
+ Directory.CreateDirectory(path);
+ Environment.SetEnvironmentVariable("TMP", path);
+ Environment.SetEnvironmentVariable("TEMP", path);
+ }
}
}
\ No newline at end of file