diff --git a/project/code/LGS/ResourcePathManager.cs b/project/code/LGS/ResourcePathManager.cs index 34e61c3..d246cf3 100644 --- a/project/code/LGS/ResourcePathManager.cs +++ b/project/code/LGS/ResourcePathManager.cs @@ -62,6 +62,11 @@ public class ResourcePathManager _extractionPath = extractionPath; } + public static string ConvertSeparator(string path) + { + return path.Replace('\\', '/'); + } + public bool Init(string installPath) { // TODO: This can be done less awkwardly with the resource paths @@ -156,6 +161,7 @@ public class ResourcePathManager throw new ArgumentException("No campaign found with given name", nameof(campaignName)); } + // This expects resourceName to already have it's separator converted public (string, string) GetResourcePath( ResourceType type, string campaignName, @@ -206,11 +212,12 @@ public class ResourcePathManager { foreach (var path in Directory.EnumerateFiles(dir, "*", texOptions)) { - var ext = Path.GetExtension(path); + var convertedPath = ConvertSeparator(path); + var ext = Path.GetExtension(convertedPath); if (validExtensions.Contains(ext.ToLower())) { - var key = Path.GetFileNameWithoutExtension(path).ToLower(); - pathMap.TryAdd(key, path); + var key = Path.GetFileNameWithoutExtension(convertedPath).ToLower(); + pathMap.TryAdd(key, convertedPath); } } } @@ -234,11 +241,12 @@ public class ResourcePathManager { foreach (var path in Directory.EnumerateFiles(dir, "*", textureOptions)) { - var ext = Path.GetExtension(path); + var convertedPath = ConvertSeparator(path); + var ext = Path.GetExtension(convertedPath); if (validExtensions.Contains(ext.ToLower())) { - var key = Path.GetRelativePath(root, path)[..^ext.Length].ToLower(); - pathMap.TryAdd(key, path); + var key = Path.GetRelativePath(root, convertedPath)[..^ext.Length].ToLower(); + pathMap.TryAdd(key, convertedPath); } } } @@ -260,8 +268,9 @@ public class ResourcePathManager { foreach (var path in Directory.EnumerateFiles(dir, "*.bin", binOptions)) { - var key = Path.GetRelativePath(dir, path).ToLower(); - pathMap.TryAdd(key, path); + var convertedPath = ConvertSeparator(path); + var key = Path.GetRelativePath(dir, convertedPath).ToLower(); + pathMap.TryAdd(key, convertedPath); } } @@ -277,8 +286,8 @@ public class ResourcePathManager { if (line.StartsWith("load_path")) { - // TODO: Do we only need to replace on systems with a different path separator? - var path = line.Split(" ")[1].Replace("\\", "/"); + // TODO: This can have multiple paths I think + var path = ConvertSeparator(line.Split(" ")[1]); omsPath = Path.GetFullPath(root + path); break; } @@ -294,8 +303,9 @@ public class ResourcePathManager }; foreach (var path in Directory.GetFiles(omsPath, "*.mis", searchOptions)) { - var baseName = Path.GetFileName(path).ToLower(); - map.Add(baseName, path); + var convertedPath = ConvertSeparator(path); + var baseName = Path.GetFileName(convertedPath).ToLower(); + map.Add(baseName, convertedPath); } return true; @@ -329,7 +339,7 @@ public class ResourcePathManager if (line.StartsWith("fm_path")) { // TODO: I think this can technically contain multiple paths - var path = line.Split(" ")[1].Replace("\\", "/"); + var path = ConvertSeparator(line.Split(" ")[1]); fmsPath = Path.GetFullPath(root + path); break; } @@ -344,10 +354,11 @@ public class ResourcePathManager var campaignMap = new Dictionary(); foreach (var path in Directory.GetFiles(dir)) { - if (extensions.Contains(Path.GetExtension(path).ToLower())) + var convertedPath = ConvertSeparator(path); + if (extensions.Contains(Path.GetExtension(convertedPath).ToLower())) { - var baseName = Path.GetFileName(path).ToLower(); - campaignMap.Add(baseName, path); + var baseName = Path.GetFileName(convertedPath).ToLower(); + campaignMap.Add(baseName, ConvertSeparator(path)); } } diff --git a/project/code/TMV/Mission.cs b/project/code/TMV/Mission.cs index d766aeb..bd90891 100644 --- a/project/code/TMV/Mission.cs +++ b/project/code/TMV/Mission.cs @@ -278,7 +278,8 @@ public partial class Mission : Node3D else { var resType = ResourceType.ObjectTexture; - var resName = Path.GetFileNameWithoutExtension(prop.value); + var convertedValue = ResourcePathManager.ConvertSeparator(prop.value); + var resName = Path.GetFileNameWithoutExtension(convertedValue); path = pathManager.GetResourcePath(resType, _campaignName, resName).Item2; } diff --git a/project/code/TMV/ModelLoader.cs b/project/code/TMV/ModelLoader.cs index c42b727..d2b243f 100644 --- a/project/code/TMV/ModelLoader.cs +++ b/project/code/TMV/ModelLoader.cs @@ -52,7 +52,8 @@ public class ModelLoader { if (material.Type == 0) { - var resName = Path.GetFileNameWithoutExtension(material.Name); + var convertedName = ResourcePathManager.ConvertSeparator(material.Name); + var resName = Path.GetFileNameWithoutExtension(convertedName); var (_, path) = pathManager.GetResourcePath(ResourceType.ObjectTexture, campaignName, resName); if (path == null) {