Revert "Revert "common logic for tempfiles""
This reverts commit 5196fc6b70
.
This commit is contained in:
parent
5196fc6b70
commit
28eae0dcb1
|
@ -230,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" />
|
||||
|
|
|
@ -5,6 +5,8 @@ using System.IO;
|
|||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using BizHawk.Common;
|
||||
|
||||
namespace BizHawk.Client.Common
|
||||
{
|
||||
public static class StringLogUtil
|
||||
|
@ -62,7 +64,7 @@ namespace BizHawk.Client.Common
|
|||
FileStream stream;
|
||||
public DiskStringLog()
|
||||
{
|
||||
var path = Path.Combine(Path.GetTempPath(), "bizhawk.disklist-pid" + System.Diagnostics.Process.GetCurrentProcess().Id + "-" + Guid.NewGuid());
|
||||
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);
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -1185,7 +1185,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
ThrottleMessage();
|
||||
}
|
||||
|
||||
public void RunLibretroCoreChooser()
|
||||
public bool RunLibretroCoreChooser()
|
||||
{
|
||||
var ofd = new OpenFileDialog();
|
||||
|
||||
|
@ -1203,9 +1203,11 @@ namespace BizHawk.Client.EmuHawk
|
|||
ofd.Filter = "Libretro Cores (*.dll)|*.dll";
|
||||
|
||||
if (ofd.ShowDialog() == DialogResult.Cancel)
|
||||
return;
|
||||
return false;
|
||||
|
||||
Global.Config.LibretroCore = ofd.FileName;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void setLibretroCoreToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
|
|
|
@ -51,8 +51,8 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
private void btnSetLibretroCore_Click(object sender, EventArgs e)
|
||||
{
|
||||
mainForm.RunLibretroCoreChooser();
|
||||
RefreshLibretroCore(false);
|
||||
if(mainForm.RunLibretroCoreChooser())
|
||||
RefreshLibretroCore(false);
|
||||
}
|
||||
|
||||
LibRetroEmulator.RetroDescription CurrentDescription;
|
||||
|
|
|
@ -59,7 +59,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
BizHawk.Client.Common.TempFileCleaner.Start();
|
||||
BizHawk.Common.TempFileCleaner.Start();
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
|
||||
|
|
|
@ -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" />
|
||||
|
|
|
@ -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);
|
||||
|
@ -21,13 +21,11 @@ namespace BizHawk.Common
|
|||
var envpath = Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.Process);
|
||||
try
|
||||
{
|
||||
string envpath_new = Path.GetDirectoryName(path) + ";" + envpath;
|
||||
string envpath_new = Path.GetDirectoryName(dllPath) + ";" + 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
|
||||
{
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue