From a364ec9a116efee79dd6549aed54a26c7ff28fef Mon Sep 17 00:00:00 2001 From: Morilli <35152647+Morilli@users.noreply.github.com> Date: Mon, 17 Jun 2024 00:58:31 +0200 Subject: [PATCH] Allow creating MultiDiskBundler xmls with absolute paths --- .../MultiDiskBundler/MultiDiskBundler.cs | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/BizHawk.Client.EmuHawk/tools/MultiDiskBundler/MultiDiskBundler.cs b/src/BizHawk.Client.EmuHawk/tools/MultiDiskBundler/MultiDiskBundler.cs index b39fdf1f09..fe1c288fca 100644 --- a/src/BizHawk.Client.EmuHawk/tools/MultiDiskBundler/MultiDiskBundler.cs +++ b/src/BizHawk.Client.EmuHawk/tools/MultiDiskBundler/MultiDiskBundler.cs @@ -214,21 +214,32 @@ namespace BizHawk.Client.EmuHawk throw new Exception("System Id can not be blank"); } - var basePath = Path.GetDirectoryName(name.SubstringBefore('|')); - if (string.IsNullOrEmpty(basePath)) - { - var fileInfo = new FileInfo(name); - basePath = Path.GetDirectoryName(fileInfo.FullName); - } + var basePath = Path.GetDirectoryName(Path.GetFullPath(name.SubstringBefore('|'))); _currentXml = new XElement("BizHawk-XMLGame", new XAttribute("System", system), new XAttribute("Name", Path.GetFileNameWithoutExtension(name)), new XElement("LoadAssets", - names.Select(n => new XElement( - "Asset", - new XAttribute("FileName", PathExtensions.GetRelativePath(basePath, n)) - )) + names.Select(n => + { + string currentRomPath = Path.GetFullPath(n); + string fileName; + + try + { + fileName = PathExtensions.GetRelativePath(basePath, currentRomPath)!; + } + catch (ArgumentException) + { + // if a relative path cannot be constructed, use an absolute path + fileName = currentRomPath; + } + + return new XElement( + "Asset", + new XAttribute("FileName", fileName) + ); + }) ) );