Make everything use Path.Combine instead of concat for Linux

This commit is contained in:
Nick 2022-09-15 18:47:26 -04:00
parent e5bc06dace
commit 126547be6f
12 changed files with 28 additions and 25 deletions

View File

@ -87,7 +87,7 @@ namespace NewHorizons.Builder.Props
var dialogueTree = conversationZone.AddComponent<CharacterDialogueTree>(); var dialogueTree = conversationZone.AddComponent<CharacterDialogueTree>();
var xml = File.ReadAllText(mod.Manifest.ModFolderPath + info.xmlFile); var xml = File.ReadAllText(Path.Combine(mod.Manifest.ModFolderPath, info.xmlFile));
var text = new TextAsset(xml); var text = new TextAsset(xml);
// Text assets need a name to be used with VoiceMod // Text assets need a name to be used with VoiceMod

View File

@ -2,12 +2,12 @@ using NewHorizons.External.Modules;
using NewHorizons.Handlers; using NewHorizons.Handlers;
using NewHorizons.Utility; using NewHorizons.Utility;
using OWML.Common; using OWML.Common;
using Enum = System.Enum;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Xml; using System.Xml;
using UnityEngine; using UnityEngine;
using Enum = System.Enum;
using Logger = NewHorizons.Utility.Logger; using Logger = NewHorizons.Utility.Logger;
using Random = UnityEngine.Random; using Random = UnityEngine.Random;
namespace NewHorizons.Builder.Props namespace NewHorizons.Builder.Props
@ -108,7 +108,7 @@ namespace NewHorizons.Builder.Props
{ {
if (_scrollPrefab == null) InitPrefabs(); if (_scrollPrefab == null) InitPrefabs();
var xmlPath = File.ReadAllText(mod.ModHelper.Manifest.ModFolderPath + info.xmlFile); var xmlPath = File.ReadAllText(Path.Combine(mod.ModHelper.Manifest.ModFolderPath, info.xmlFile));
switch (info.type) switch (info.type)
{ {

View File

@ -4,6 +4,7 @@ using NewHorizons.Utility;
using OWML.Common; using OWML.Common;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Threading; using System.Threading;
using UnityEngine; using UnityEngine;
using static NewHorizons.External.Modules.PropModule; using static NewHorizons.External.Modules.PropModule;
@ -346,8 +347,7 @@ namespace NewHorizons.Builder.Props
} }
else else
{ {
// Don't use Path.Combine here else you break the Vision imageLoader.PathsToLoad.Add((i, Path.Combine(mod.ModHelper.Manifest.ModFolderPath, slideInfo.imagePath)));
imageLoader.PathsToLoad.Add((i, mod.ModHelper.Manifest.ModFolderPath + slideInfo.imagePath));
} }
AddModules(slideInfo, ref slide, mod); AddModules(slideInfo, ref slide, mod);

View File

@ -4,6 +4,7 @@ using NewHorizons.Handlers;
using NewHorizons.Utility; using NewHorizons.Utility;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Xml.Linq; using System.Xml.Linq;
using UnityEngine; using UnityEngine;
using Logger = NewHorizons.Utility.Logger; using Logger = NewHorizons.Utility.Logger;
@ -53,7 +54,7 @@ namespace NewHorizons.Builder.ShipLog
public static void AddBodyToShipLog(ShipLogManager manager, NewHorizonsBody body) public static void AddBodyToShipLog(ShipLogManager manager, NewHorizonsBody body)
{ {
string systemName = body.Config.starSystem; string systemName = body.Config.starSystem;
XElement astroBodyFile = XElement.Load(body.Mod.ModHelper.Manifest.ModFolderPath + "/" + body.Config.ShipLog.xmlFile); XElement astroBodyFile = XElement.Load(Path.Combine(body.Mod.ModHelper.Manifest.ModFolderPath, body.Config.ShipLog.xmlFile));
XElement astroBodyId = astroBodyFile.Element("ID"); XElement astroBodyId = astroBodyFile.Element("ID");
if (astroBodyId == null) if (astroBodyId == null)
{ {

View File

@ -2,6 +2,7 @@ using NewHorizons.Utility;
using OWML.Common; using OWML.Common;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using UnityEngine; using UnityEngine;
using Logger = NewHorizons.Utility.Logger; using Logger = NewHorizons.Utility.Logger;
@ -65,7 +66,7 @@ namespace NewHorizons.Handlers
var id = mod.ModHelper.Manifest.UniqueName + "_" + audioPath; var id = mod.ModHelper.Manifest.UniqueName + "_" + audioPath;
if (_customAudioTypes.TryGetValue(id, out audioType)) return audioType; if (_customAudioTypes.TryGetValue(id, out audioType)) return audioType;
var audioClip = AudioUtilities.LoadAudio(mod.ModHelper.Manifest.ModFolderPath + "/" + audioPath); var audioClip = AudioUtilities.LoadAudio(Path.Combine(mod.ModHelper.Manifest.ModFolderPath, audioPath));
if (audioClip == null) if (audioClip == null)
{ {

View File

@ -167,7 +167,7 @@ namespace NewHorizons
TextTranslation.Get().SetLanguage(TextTranslation.Get().GetLanguage()); TextTranslation.Get().SetLanguage(TextTranslation.Get().GetLanguage());
} }
LoadTranslations(Instance.ModHelper.Manifest.ModFolderPath + "Assets/", this); LoadTranslations(Path.Combine(Instance.ModHelper.Manifest.ModFolderPath, "Assets/"), this);
} }
public void Awake() public void Awake()

View File

@ -36,10 +36,10 @@ namespace NewHorizons
if (name == null) return; if (name == null) return;
var relativePath = $"temp/{name}.json"; var relativePath = $"temp/{name}.json";
var fullPath = Main.Instance.ModHelper.Manifest.ModFolderPath + relativePath; var fullPath = Path.Combine(Main.Instance.ModHelper.Manifest.ModFolderPath, relativePath);
if (!Directory.Exists(Main.Instance.ModHelper.Manifest.ModFolderPath + "temp")) if (!Directory.Exists(Path.Combine(Main.Instance.ModHelper.Manifest.ModFolderPath, "temp")))
{ {
Directory.CreateDirectory(Main.Instance.ModHelper.Manifest.ModFolderPath + "temp"); Directory.CreateDirectory(Path.Combine(Main.Instance.ModHelper.Manifest.ModFolderPath, "temp"));
} }
JsonHelper.SaveJsonObject(fullPath, config); JsonHelper.SaveJsonObject(fullPath, config);
var body = Main.Instance.LoadConfig(Main.Instance, relativePath); var body = Main.Instance.LoadConfig(Main.Instance, relativePath);
@ -126,7 +126,7 @@ namespace NewHorizons
var planet = Main.BodyDict[Main.Instance.CurrentStarSystem].Find((b) => b.Config.name == bodyName); var planet = Main.BodyDict[Main.Instance.CurrentStarSystem].Find((b) => b.Config.name == bodyName);
return planet == null return planet == null
? null ? null
: QueryJson(outType, planet.Mod.ModHelper.Manifest.ModFolderPath + planet.RelativePath, jsonPath); : QueryJson(outType, Path.Combine(planet.Mod.ModHelper.Manifest.ModFolderPath, planet.RelativePath), jsonPath);
} }
public object QuerySystem(Type outType, string jsonPath) public object QuerySystem(Type outType, string jsonPath)
@ -134,7 +134,7 @@ namespace NewHorizons
var system = Main.SystemDict[Main.Instance.CurrentStarSystem]; var system = Main.SystemDict[Main.Instance.CurrentStarSystem];
return system == null return system == null
? null ? null
: QueryJson(outType, system.Mod.ModHelper.Manifest.ModFolderPath + system.RelativePath, jsonPath); : QueryJson(outType, Path.Combine(system.Mod.ModHelper.Manifest.ModFolderPath, system.RelativePath), jsonPath);
} }
public GameObject SpawnObject(GameObject planet, Sector sector, string propToCopyPath, Vector3 position, Vector3 eulerAngles, public GameObject SpawnObject(GameObject planet, Sector sector, string propToCopyPath, Vector3 position, Vector3 eulerAngles,

View File

@ -38,10 +38,10 @@ namespace NewHorizons.OtherMods.VoiceActing
{ {
foreach (var mod in Main.Instance.GetDependants().Append(Main.Instance)) foreach (var mod in Main.Instance.GetDependants().Append(Main.Instance))
{ {
var folder = $"{mod.ModHelper.Manifest.ModFolderPath}voicemod"; var folder = Path.Combine(mod.ModHelper.Manifest.ModFolderPath, "voicemod");
if (!Directory.Exists(folder)) { if (!Directory.Exists(folder)) {
// Fallback to PascalCase bc it used to be like that // Fallback to PascalCase bc it used to be like that
folder = $"{mod.ModHelper.Manifest.ModFolderPath}VoiceMod"; folder = Path.Combine(mod.ModHelper.Manifest.ModFolderPath, "VoiceMod");
} }
if (Directory.Exists(folder)) if (Directory.Exists(folder))
{ {

View File

@ -1,4 +1,4 @@
using OWML.Common; using OWML.Common;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
@ -34,7 +34,7 @@ namespace NewHorizons.Utility
} }
else else
{ {
var completePath = mod.ModHelper.Manifest.ModFolderPath + assetBundleRelativeDir; var completePath = Path.Combine(mod.ModHelper.Manifest.ModFolderPath, assetBundleRelativeDir);
bundle = AssetBundle.LoadFromFile(completePath); bundle = AssetBundle.LoadFromFile(completePath);
if (bundle == null) if (bundle == null)
{ {

View File

@ -1,6 +1,7 @@
using OWML.Common; using OWML.Common;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using UnityEngine; using UnityEngine;
@ -19,7 +20,7 @@ namespace NewHorizons.Utility
{ {
try try
{ {
var clip = LoadAudio(mod.ModHelper.Manifest.ModFolderPath + "/" + audio); var clip = LoadAudio(Path.Combine(mod.ModHelper.Manifest.ModFolderPath, audio));
source._audioLibraryClip = AudioType.None; source._audioLibraryClip = AudioType.None;
source._clipArrayIndex = 0; source._clipArrayIndex = 0;
source._clipArrayLength = 0; source._clipArrayLength = 0;

View File

@ -210,7 +210,7 @@ namespace NewHorizons.Utility.DebugMenu
continue; continue;
} }
loadedConfigFiles[folder + body.RelativePath] = body.Config; loadedConfigFiles[Path.Combine(folder, body.RelativePath)] = body.Config;
submenus.ForEach(submenu => submenu.LoadConfigFile(this, body.Config)); submenus.ForEach(submenu => submenu.LoadConfigFile(this, body.Config));
} }
} }
@ -235,9 +235,9 @@ namespace NewHorizons.Utility.DebugMenu
try try
{ {
var path = loadedMod.ModHelper.Manifest.ModFolderPath + backupFolderName + relativePath; var path = Path.Combine(loadedMod.ModHelper.Manifest.ModFolderPath, backupFolderName, relativePath);
Logger.LogVerbose($"Backing up... {relativePath} to {path}"); Logger.LogVerbose($"Backing up... {relativePath} to {path}");
var oldPath = loadedMod.ModHelper.Manifest.ModFolderPath + relativePath; var oldPath = Path.Combine(loadedMod.ModHelper.Manifest.ModFolderPath, relativePath);
var directoryName = Path.GetDirectoryName(path); var directoryName = Path.GetDirectoryName(path);
Directory.CreateDirectory(directoryName); Directory.CreateDirectory(directoryName);
@ -254,7 +254,7 @@ namespace NewHorizons.Utility.DebugMenu
try try
{ {
Logger.Log($"Saving... {relativePath} to {filePath}"); Logger.Log($"Saving... {relativePath} to {filePath}");
var path = loadedMod.ModHelper.Manifest.ModFolderPath + relativePath; var path = Path.Combine(loadedMod.ModHelper.Manifest.ModFolderPath, relativePath);
var directoryName = Path.GetDirectoryName(path); var directoryName = Path.GetDirectoryName(path);
Directory.CreateDirectory(directoryName); Directory.CreateDirectory(directoryName);

View File

@ -17,14 +17,14 @@ namespace NewHorizons.Utility
public static bool IsTextureLoaded(IModBehaviour mod, string filename) public static bool IsTextureLoaded(IModBehaviour mod, string filename)
{ {
var path = mod.ModHelper.Manifest.ModFolderPath + filename; var path = Path.Combine(mod.ModHelper.Manifest.ModFolderPath, filename);
return _loadedTextures.ContainsKey(path); return _loadedTextures.ContainsKey(path);
} }
public static Texture2D GetTexture(IModBehaviour mod, string filename, bool useMipmaps = true, bool wrap = false) public static Texture2D GetTexture(IModBehaviour mod, string filename, bool useMipmaps = true, bool wrap = false)
{ {
// Copied from OWML but without the print statement lol // Copied from OWML but without the print statement lol
var path = mod.ModHelper.Manifest.ModFolderPath + filename; var path = Path.Combine(mod.ModHelper.Manifest.ModFolderPath, filename);
if (_loadedTextures.ContainsKey(path)) if (_loadedTextures.ContainsKey(path))
{ {
Logger.LogVerbose($"Already loaded image at path: {path}"); Logger.LogVerbose($"Already loaded image at path: {path}");
@ -53,7 +53,7 @@ namespace NewHorizons.Utility
public static void DeleteTexture(IModBehaviour mod, string filename, Texture2D texture) public static void DeleteTexture(IModBehaviour mod, string filename, Texture2D texture)
{ {
var path = mod.ModHelper.Manifest.ModFolderPath + filename; var path = Path.Combine(mod.ModHelper.Manifest.ModFolderPath, filename);
if (_loadedTextures.ContainsKey(path)) if (_loadedTextures.ContainsKey(path))
{ {
if (_loadedTextures[path] == texture) if (_loadedTextures[path] == texture)