move some PathManager methods to a PathUtils class in BizHawk.Common
This commit is contained in:
parent
9fa4bac8d4
commit
e16dc33722
|
@ -1,6 +1,6 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
|
||||
using BizHawk.Common.PathExtensions;
|
||||
using BizHawk.Emulation.Common;
|
||||
|
||||
namespace BizHawk.Client.Common
|
||||
|
@ -16,8 +16,7 @@ namespace BizHawk.Client.Common
|
|||
_firmwareManager = firmwareManager;
|
||||
}
|
||||
|
||||
public string DllPath()
|
||||
=> Path.Combine(PathManager.GetExeDirectoryAbsolute(), "dll");
|
||||
public string DllPath() => PathUtils.GetDllDirectory();
|
||||
|
||||
// Poop
|
||||
public string GetRetroSaveRAMDirectory(GameInfo game)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using System.IO;
|
||||
using System.Reflection;
|
||||
using BizHawk.Common.PathExtensions;
|
||||
|
||||
namespace BizHawk.Client.Common
|
||||
{
|
||||
|
@ -7,38 +8,10 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
static PathManager()
|
||||
{
|
||||
var defaultIni = Path.Combine(GetExeDirectoryAbsolute(), "config.ini");
|
||||
var defaultIni = Path.Combine(PathUtils.GetExeDirectoryAbsolute(), "config.ini");
|
||||
SetDefaultIniPath(defaultIni);
|
||||
}
|
||||
|
||||
public static string GetExeDirectoryAbsolute()
|
||||
{
|
||||
var path = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
||||
if (path.EndsWith(Path.DirectorySeparatorChar.ToString()))
|
||||
{
|
||||
path = path.Remove(path.Length - 1, 1);
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
// TODO: this always makes an absolute path!
|
||||
// Needs to be fixed, the intent was to turn an absolute path
|
||||
// into one relative to the exe
|
||||
// for instance: C:\BizHawk\Lua becomes .\Lua (if EmuHawk.Exe is in C:\BizHawk)
|
||||
/// <summary>
|
||||
/// Makes a path relative to the %exe% directory
|
||||
/// </summary>
|
||||
public static string MakeProgramRelativePath(string path)
|
||||
{
|
||||
return Path.Combine(GetExeDirectoryAbsolute(), path);
|
||||
}
|
||||
|
||||
public static string GetDllDirectory()
|
||||
{
|
||||
return Path.Combine(GetExeDirectoryAbsolute(), "dll");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The location of the default INI file
|
||||
/// </summary>
|
||||
|
|
|
@ -4,6 +4,7 @@ using System.IO;
|
|||
using System.Linq;
|
||||
|
||||
using BizHawk.Common;
|
||||
using BizHawk.Common.PathExtensions;
|
||||
using BizHawk.Emulation.Common;
|
||||
using BizHawk.Emulation.Cores;
|
||||
using BizHawk.Emulation.Cores.Libretro;
|
||||
|
@ -1081,7 +1082,7 @@ namespace BizHawk.Client.Common
|
|||
}
|
||||
break;
|
||||
case "A78":
|
||||
var gameDbPath = Path.Combine(PathManager.GetExeDirectoryAbsolute(), "gamedb", "gamedb_a7800.csv");
|
||||
var gameDbPath = Path.Combine(PathUtils.GetExeDirectoryAbsolute(), "gamedb", "gamedb_a7800.csv");
|
||||
nextEmulator = new A7800Hawk(nextComm, game, rom.RomData, gameDbPath, GetCoreSettings<A7800Hawk>(), GetCoreSyncSettings<A7800Hawk>());
|
||||
break;
|
||||
case "C64":
|
||||
|
|
|
@ -2,12 +2,13 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using BizHawk.Common;
|
||||
using BizHawk.Common.PathExtensions;
|
||||
|
||||
namespace BizHawk.Client.Common
|
||||
{
|
||||
public class Config
|
||||
{
|
||||
public static string ControlDefaultPath => Path.Combine(PathManager.GetExeDirectoryAbsolute(), "defctrl.json");
|
||||
public static string ControlDefaultPath => Path.Combine(PathUtils.GetExeDirectoryAbsolute(), "defctrl.json");
|
||||
|
||||
public Config()
|
||||
{
|
||||
|
|
|
@ -26,7 +26,7 @@ namespace BizHawk.Client.Common
|
|||
// if %exe% prefixed then substitute exe path and repeat
|
||||
if (globalBase.StartsWith("%exe%", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
globalBase = PathManager.GetExeDirectoryAbsolute() + globalBase.Substring(5);
|
||||
globalBase = PathUtils.GetExeDirectoryAbsolute() + globalBase.Substring(5);
|
||||
}
|
||||
|
||||
// rooted paths get returned without change
|
||||
|
@ -37,7 +37,7 @@ namespace BizHawk.Client.Common
|
|||
}
|
||||
|
||||
// not-rooted things are relative to exe path
|
||||
globalBase = Path.Combine(PathManager.GetExeDirectoryAbsolute(), globalBase);
|
||||
globalBase = Path.Combine(PathUtils.GetExeDirectoryAbsolute(), globalBase);
|
||||
return globalBase;
|
||||
}
|
||||
|
||||
|
@ -94,7 +94,7 @@ namespace BizHawk.Client.Common
|
|||
|
||||
if (path.StartsWith("%exe%"))
|
||||
{
|
||||
return PathManager.GetExeDirectoryAbsolute() + path.Substring(5);
|
||||
return PathUtils.GetExeDirectoryAbsolute() + path.Substring(5);
|
||||
}
|
||||
|
||||
if (path.StartsWith("%rom%"))
|
||||
|
@ -133,7 +133,7 @@ namespace BizHawk.Client.Common
|
|||
//handling of file:// or file:\\ was removed (can Path.GetFullPath handle it? not sure)
|
||||
|
||||
// all bad paths default to EXE
|
||||
return PathManager.GetExeDirectoryAbsolute();
|
||||
return PathUtils.GetExeDirectoryAbsolute();
|
||||
}
|
||||
|
||||
public static string MovieAbsolutePath(this PathEntryCollection collection)
|
||||
|
|
|
@ -7,6 +7,7 @@ using System.Windows.Forms;
|
|||
|
||||
using BizHawk.Client.Common;
|
||||
using BizHawk.Common;
|
||||
using BizHawk.Common.PathExtensions;
|
||||
using BizHawk.Emulation.Common;
|
||||
|
||||
namespace BizHawk.Client.EmuHawk
|
||||
|
@ -86,7 +87,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
try
|
||||
{
|
||||
_ffmpeg = OSTailoredCode.ConstructSubshell(
|
||||
OSTailoredCode.IsUnixHost ? "ffmpeg" : Path.Combine(PathManager.GetDllDirectory(), "ffmpeg.exe"),
|
||||
OSTailoredCode.IsUnixHost ? "ffmpeg" : Path.Combine(PathUtils.GetDllDirectory(), "ffmpeg.exe"),
|
||||
$"-y -f nut -i - {_token.Commandline} \"{_baseName}{(_segment == 0 ? string.Empty : $"_{_segment}")}{_ext}\"",
|
||||
checkStdout: false,
|
||||
checkStderr: true // ffmpeg sends informative display to stderr, and nothing to stdout
|
||||
|
|
|
@ -11,6 +11,7 @@ using System.Windows.Forms;
|
|||
using BizHawk.Bizware.BizwareGL;
|
||||
using BizHawk.Client.Common;
|
||||
using BizHawk.Client.EmuHawk.FilterManager;
|
||||
using BizHawk.Common.PathExtensions;
|
||||
using BizHawk.Emulation.Common;
|
||||
using BizHawk.Emulation.Cores.Sony.PSX;
|
||||
|
||||
|
@ -81,17 +82,17 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
if (GL is IGL_TK || GL is IGL_SlimDX9)
|
||||
{
|
||||
var fiHq2x = new FileInfo(Path.Combine(PathManager.GetExeDirectoryAbsolute(), "Shaders/BizHawk/hq2x.cgp"));
|
||||
var fiHq2x = new FileInfo(Path.Combine(PathUtils.GetExeDirectoryAbsolute(), "Shaders/BizHawk/hq2x.cgp"));
|
||||
if (fiHq2x.Exists)
|
||||
{
|
||||
using var stream = fiHq2x.OpenRead();
|
||||
ShaderChain_hq2x = new Filters.RetroShaderChain(GL, new Filters.RetroShaderPreset(stream), Path.Combine(PathManager.GetExeDirectoryAbsolute(), "Shaders/BizHawk"));
|
||||
ShaderChain_hq2x = new Filters.RetroShaderChain(GL, new Filters.RetroShaderPreset(stream), Path.Combine(PathUtils.GetExeDirectoryAbsolute(), "Shaders/BizHawk"));
|
||||
}
|
||||
var fiScanlines = new FileInfo(Path.Combine(PathManager.GetExeDirectoryAbsolute(), "Shaders/BizHawk/BizScanlines.cgp"));
|
||||
var fiScanlines = new FileInfo(Path.Combine(PathUtils.GetExeDirectoryAbsolute(), "Shaders/BizHawk/BizScanlines.cgp"));
|
||||
if (fiScanlines.Exists)
|
||||
{
|
||||
using var stream = fiScanlines.OpenRead();
|
||||
ShaderChain_scanlines = new Filters.RetroShaderChain(GL, new Filters.RetroShaderPreset(stream), Path.Combine(PathManager.GetExeDirectoryAbsolute(), "Shaders/BizHawk"));
|
||||
ShaderChain_scanlines = new Filters.RetroShaderChain(GL, new Filters.RetroShaderPreset(stream), Path.Combine(PathUtils.GetExeDirectoryAbsolute(), "Shaders/BizHawk"));
|
||||
}
|
||||
|
||||
string bicubicPath = "Shaders/BizHawk/bicubic-fast.cgp";
|
||||
|
@ -99,11 +100,11 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
bicubicPath = "Shaders/BizHawk/bicubic-normal.cgp";
|
||||
}
|
||||
var fiBicubic = new FileInfo(Path.Combine(PathManager.GetExeDirectoryAbsolute(), bicubicPath));
|
||||
var fiBicubic = new FileInfo(Path.Combine(PathUtils.GetExeDirectoryAbsolute(), bicubicPath));
|
||||
if (fiBicubic.Exists)
|
||||
{
|
||||
using var stream = fiBicubic.Open(FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
ShaderChain_bicubic = new Filters.RetroShaderChain(GL, new Filters.RetroShaderPreset(stream), Path.Combine(PathManager.GetExeDirectoryAbsolute(), "Shaders/BizHawk"));
|
||||
ShaderChain_bicubic = new Filters.RetroShaderChain(GL, new Filters.RetroShaderPreset(stream), Path.Combine(PathUtils.GetExeDirectoryAbsolute(), "Shaders/BizHawk"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ using System.Windows.Forms;
|
|||
using BizHawk.Common;
|
||||
using BizHawk.Emulation.Common;
|
||||
using BizHawk.Client.Common;
|
||||
using BizHawk.Common.PathExtensions;
|
||||
|
||||
// todo - perks - pause, copy to clipboard, backlog length limiting
|
||||
|
||||
|
@ -155,7 +156,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
if (result.IsOk())
|
||||
{
|
||||
var gameDbEntry = Emulator.AsGameDBEntryGenerator().GenerateGameDbEntry();
|
||||
var userDb = Path.Combine(PathManager.GetExeDirectoryAbsolute(), "gamedb", "gamedb_user.txt");
|
||||
var userDb = Path.Combine(PathUtils.GetExeDirectoryAbsolute(), "gamedb", "gamedb_user.txt");
|
||||
Global.Game.Status = gameDbEntry.Status = picker.PickedStatus;
|
||||
Database.SaveDatabaseEntry(userDb, gameDbEntry);
|
||||
MainForm.UpdateDumpIcon();
|
||||
|
|
|
@ -234,8 +234,8 @@ namespace BizHawk.Client.EmuHawk
|
|||
// we could background thread this later instead if we wanted to be real clever
|
||||
NES.BootGodDB.GetDatabaseBytes = () =>
|
||||
{
|
||||
string xmlPath = Path.Combine(PathManager.GetExeDirectoryAbsolute(), "gamedb", "NesCarts.xml");
|
||||
string x7zPath = Path.Combine(PathManager.GetExeDirectoryAbsolute(), "gamedb", "NesCarts.7z");
|
||||
string xmlPath = Path.Combine(PathUtils.GetExeDirectoryAbsolute(), "gamedb", "NesCarts.xml");
|
||||
string x7zPath = Path.Combine(PathUtils.GetExeDirectoryAbsolute(), "gamedb", "NesCarts.7z");
|
||||
bool loadXml = File.Exists(xmlPath);
|
||||
using var nesCartFile = new HawkFile(loadXml ? xmlPath : x7zPath);
|
||||
if (!loadXml)
|
||||
|
@ -256,11 +256,11 @@ namespace BizHawk.Client.EmuHawk
|
|||
MessageBox.Show(e.Message);
|
||||
}
|
||||
|
||||
Database.LoadDatabase(Path.Combine(PathManager.GetExeDirectoryAbsolute(), "gamedb", "gamedb.txt"));
|
||||
Database.LoadDatabase(Path.Combine(PathUtils.GetExeDirectoryAbsolute(), "gamedb", "gamedb.txt"));
|
||||
|
||||
// TODO GL - a lot of disorganized wiring-up here
|
||||
// installed separately on Unix (via package manager or from https://developer.nvidia.com/cg-toolkit-download), look in $PATH
|
||||
CGC.CGCBinPath = OSTailoredCode.IsUnixHost ? "cgc" : Path.Combine(PathManager.GetDllDirectory(), "cgc.exe");
|
||||
CGC.CGCBinPath = OSTailoredCode.IsUnixHost ? "cgc" : Path.Combine(PathUtils.GetDllDirectory(), "cgc.exe");
|
||||
PresentationPanel = new PresentationPanel(this, Config, GlobalWin.GL)
|
||||
{
|
||||
GraphicsControl = { MainWindow = true }
|
||||
|
|
|
@ -856,7 +856,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
string pathToLoad = Path.IsPathRooted(item.Path)
|
||||
? item.Path
|
||||
: PathManager.MakeProgramRelativePath(item.Path);
|
||||
: item.Path.MakeProgramRelativePath();
|
||||
|
||||
LuaImp.SpawnAndSetFileThread(pathToLoad, item);
|
||||
LuaSandbox.CreateSandbox(item.Thread, Path.GetDirectoryName(pathToLoad));
|
||||
|
@ -900,7 +900,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
return Path.IsPathRooted(path)
|
||||
? path
|
||||
: PathManager.MakeProgramRelativePath(path);
|
||||
: path.MakeProgramRelativePath();
|
||||
}
|
||||
|
||||
private void EditScriptMenuItem_Click(object sender, EventArgs e)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
|
||||
namespace BizHawk.Common.PathExtensions
|
||||
{
|
||||
|
@ -94,5 +95,37 @@ namespace BizHawk.Common.PathExtensions
|
|||
|
||||
return Path.Combine(filesystemDir, filesystemSafeName);
|
||||
}
|
||||
|
||||
|
||||
// TODO: this always makes an absolute path!
|
||||
// Needs to be fixed, the intent was to turn an absolute path
|
||||
// into one relative to the exe
|
||||
// for instance: C:\BizHawk\Lua becomes .\Lua (if EmuHawk.Exe is in C:\BizHawk)
|
||||
/// <summary>
|
||||
/// Makes a path relative to the %exe% directory
|
||||
/// </summary>
|
||||
public static string MakeProgramRelativePath(this string path)
|
||||
{
|
||||
return Path.Combine(PathUtils.GetExeDirectoryAbsolute(), path);
|
||||
}
|
||||
}
|
||||
|
||||
public static class PathUtils
|
||||
{
|
||||
public static string GetExeDirectoryAbsolute()
|
||||
{
|
||||
var path = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
||||
if (path.EndsWith(Path.DirectorySeparatorChar.ToString()))
|
||||
{
|
||||
path = path.Remove(path.Length - 1, 1);
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
public static string GetDllDirectory()
|
||||
{
|
||||
return Path.Combine(GetExeDirectoryAbsolute(), "dll");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue