diff --git a/BizHawk.Client.Common/CoreFileProvider.cs b/BizHawk.Client.Common/CoreFileProvider.cs
index 552edcf665..d5926ef9ed 100644
--- a/BizHawk.Client.Common/CoreFileProvider.cs
+++ b/BizHawk.Client.Common/CoreFileProvider.cs
@@ -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)
diff --git a/BizHawk.Client.Common/PathManager.cs b/BizHawk.Client.Common/PathManager.cs
index 32c707939b..c56819922a 100644
--- a/BizHawk.Client.Common/PathManager.cs
+++ b/BizHawk.Client.Common/PathManager.cs
@@ -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)
- ///
- /// Makes a path relative to the %exe% directory
- ///
- public static string MakeProgramRelativePath(string path)
- {
- return Path.Combine(GetExeDirectoryAbsolute(), path);
- }
-
- public static string GetDllDirectory()
- {
- return Path.Combine(GetExeDirectoryAbsolute(), "dll");
- }
-
///
/// The location of the default INI file
///
diff --git a/BizHawk.Client.Common/RomLoader.cs b/BizHawk.Client.Common/RomLoader.cs
index 344a81c489..2746bbe0fa 100644
--- a/BizHawk.Client.Common/RomLoader.cs
+++ b/BizHawk.Client.Common/RomLoader.cs
@@ -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(), GetCoreSyncSettings());
break;
case "C64":
diff --git a/BizHawk.Client.Common/config/Config.cs b/BizHawk.Client.Common/config/Config.cs
index 827a37bf39..313611570c 100644
--- a/BizHawk.Client.Common/config/Config.cs
+++ b/BizHawk.Client.Common/config/Config.cs
@@ -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()
{
diff --git a/BizHawk.Client.Common/config/PathEntryCollectionExtensions.cs b/BizHawk.Client.Common/config/PathEntryCollectionExtensions.cs
index c4e674be34..d44b8c8fcf 100644
--- a/BizHawk.Client.Common/config/PathEntryCollectionExtensions.cs
+++ b/BizHawk.Client.Common/config/PathEntryCollectionExtensions.cs
@@ -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)
diff --git a/BizHawk.Client.EmuHawk/AVOut/FFmpegWriter.cs b/BizHawk.Client.EmuHawk/AVOut/FFmpegWriter.cs
index b69a3de1ab..80f6642c9d 100644
--- a/BizHawk.Client.EmuHawk/AVOut/FFmpegWriter.cs
+++ b/BizHawk.Client.EmuHawk/AVOut/FFmpegWriter.cs
@@ -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
diff --git a/BizHawk.Client.EmuHawk/DisplayManager/DisplayManager.cs b/BizHawk.Client.EmuHawk/DisplayManager/DisplayManager.cs
index cdcb9cfdc0..fb710893c8 100644
--- a/BizHawk.Client.EmuHawk/DisplayManager/DisplayManager.cs
+++ b/BizHawk.Client.EmuHawk/DisplayManager/DisplayManager.cs
@@ -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"));
}
}
diff --git a/BizHawk.Client.EmuHawk/LogWindow.cs b/BizHawk.Client.EmuHawk/LogWindow.cs
index 8ecc7be4c3..f32fc4c195 100644
--- a/BizHawk.Client.EmuHawk/LogWindow.cs
+++ b/BizHawk.Client.EmuHawk/LogWindow.cs
@@ -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();
diff --git a/BizHawk.Client.EmuHawk/MainForm.cs b/BizHawk.Client.EmuHawk/MainForm.cs
index d72ba21497..38a3fb7a35 100644
--- a/BizHawk.Client.EmuHawk/MainForm.cs
+++ b/BizHawk.Client.EmuHawk/MainForm.cs
@@ -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 }
diff --git a/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs b/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs
index acb223c3d1..a444840d0c 100644
--- a/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs
+++ b/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs
@@ -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)
diff --git a/BizHawk.Common/Extensions/PathExtensions.cs b/BizHawk.Common/Extensions/PathExtensions.cs
index 780a44c6c2..1d4fcbbb2a 100644
--- a/BizHawk.Common/Extensions/PathExtensions.cs
+++ b/BizHawk.Common/Extensions/PathExtensions.cs
@@ -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)
+ ///
+ /// Makes a path relative to the %exe% directory
+ ///
+ 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");
+ }
}
}