Revert "common logic for tempfiles"

This reverts commit 5afa44bbec.

and also "fix regression in libretro core loading and streamline open advanced libretro ui"
59048264cd but tortoisegit didn't put that in the commit message.
This commit is contained in:
zeromus 2015-11-17 17:10:27 -06:00
parent 59048264cd
commit 5196fc6b70
9 changed files with 16 additions and 37 deletions

View File

@ -230,6 +230,7 @@
<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

@ -1,7 +1,7 @@
using System;
using System.IO;
namespace BizHawk.Common
namespace BizHawk.Client.Common
{
/// <summary>
/// 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

View File

@ -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);

View File

@ -2,8 +2,6 @@
using System.Collections.Generic;
using System.IO;
using BizHawk.Common;
namespace BizHawk.Client.Common
{
/// <summary>
@ -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.

View File

@ -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)

View File

@ -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;

View File

@ -59,7 +59,7 @@ namespace BizHawk.Client.EmuHawk
}
}
BizHawk.Common.TempFileCleaner.Start();
BizHawk.Client.Common.TempFileCleaner.Start();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);

View File

@ -76,7 +76,6 @@
<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 = 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
{