diff --git a/Sharp.BSA.BA2/BA2Util/BA2.cs b/Sharp.BSA.BA2/BA2Util/BA2.cs index 413c7dd..d605d38 100644 --- a/Sharp.BSA.BA2/BA2Util/BA2.cs +++ b/Sharp.BSA.BA2/BA2Util/BA2.cs @@ -1,5 +1,6 @@ using SharpBSABA2.Enums; using SharpBSABA2.Extensions; +using SharpBSABA2.Utils; using System; using System.IO; using System.Text; @@ -48,7 +49,9 @@ protected override void Open(string filePath) for (int i = 0; i < this.FileCount; i++) try { - this.Files[i].FullPath = BinaryReader.ReadString(BinaryReader.ReadInt16()); + string fullPath = BinaryReader.ReadString(BinaryReader.ReadInt16()); + + this.Files[i].FullPath = PathUtils.NormalizePath(fullPath); this.Files[i].FullPathOriginal = this.Files[i].FullPath; } catch (Exception ex) diff --git a/Sharp.BSA.BA2/BSAUtil/BSA.cs b/Sharp.BSA.BA2/BSAUtil/BSA.cs index eca85a2..bd93e00 100644 --- a/Sharp.BSA.BA2/BSAUtil/BSA.cs +++ b/Sharp.BSA.BA2/BSAUtil/BSA.cs @@ -146,7 +146,7 @@ protected override void Open(string filePath) for (int i = 0; i < header.FileCount; i++) { if (hasNameTableMW) - this.Files[i].FullPath = this.BinaryReader.ReadStringTo('\0'); + this.Files[i].FullPath = PathUtils.NormalizePath(this.BinaryReader.ReadStringTo('\0')); else { ulong hash = this.BinaryReader.ReadUInt64(); @@ -237,9 +237,8 @@ protected override void Open(string filePath) // Read name table for (int i = 0; i < header.FileCount; i++) { - this.Files[i].FullPath = Path.Combine( - this.Files[i].FullPath, - this.BinaryReader.ReadStringTo('\0')); + string fullPath = Path.Combine(this.Files[i].FullPath, this.BinaryReader.ReadStringTo('\0')); + this.Files[i].FullPath = PathUtils.NormalizePath(fullPath); this.Files[i].FullPathOriginal = this.Files[i].FullPath; } } diff --git a/Sharp.BSA.BA2/Sharp.BSA.BA2.csproj b/Sharp.BSA.BA2/Sharp.BSA.BA2.csproj index 42e5ba7..85dd183 100644 --- a/Sharp.BSA.BA2/Sharp.BSA.BA2.csproj +++ b/Sharp.BSA.BA2/Sharp.BSA.BA2.csproj @@ -74,6 +74,7 @@ + diff --git a/Sharp.BSA.BA2/Utils/PathUtils.cs b/Sharp.BSA.BA2/Utils/PathUtils.cs new file mode 100644 index 0000000..73abb6c --- /dev/null +++ b/Sharp.BSA.BA2/Utils/PathUtils.cs @@ -0,0 +1,29 @@ +using System.IO; + +namespace SharpBSABA2.Utils +{ + public static class PathUtils + { + /// + /// Returns the path with the directory separator character normalized to the platform's default. + /// + /// The path to normalize. + public static string NormalizePath(string path) => NormalizePath(path, Path.DirectorySeparatorChar); + + /// + /// Returns the path with the directory separator character normalized to the specified character. + /// + /// The path to normalize. + /// The character to normalize the directory separator to. + public static string NormalizePath(string path, char directorySeparatorChar) + { + // Replace forward slashes with backward slashes + path = path.Replace('/', directorySeparatorChar); + + // Replace backward slashes with forward slashes + path = path.Replace('\\', directorySeparatorChar); + + return path; + } + } +}