From 92c50a43b884a24b141bef60b3fdc3268898bc41 Mon Sep 17 00:00:00 2001 From: amazingalek Date: Sun, 5 Jan 2020 20:50:30 +0100 Subject: [PATCH] fixes for pathfinder and config (#49) --- OWML.Launcher/App.cs | 5 +++-- OWML.Launcher/PathFinder.cs | 16 ++++++++++------ OWML.ModHelper/ModConfig.cs | 19 +++++++++++++++---- .../OWML.EnableDebugMode/manifest.json | 2 +- .../OWML.LoadCustomAssets/manifest.json | 2 +- 5 files changed, 30 insertions(+), 14 deletions(-) diff --git a/OWML.Launcher/App.cs b/OWML.Launcher/App.cs index b149d5e02..575f17515 100644 --- a/OWML.Launcher/App.cs +++ b/OWML.Launcher/App.cs @@ -10,7 +10,7 @@ namespace OWML.Launcher { public class App { - private const string Version = "0.3.13"; + private const string Version = "0.3.14"; private readonly IOwmlConfig _config; private readonly IModConsole _writer; @@ -50,6 +50,7 @@ public void Run() private void LocateGamePath() { var gamePath = _pathFinder.FindGamePath(); + _writer.WriteLine("Game found in " + gamePath); if (gamePath != _config.GamePath) { _config.GamePath = gamePath; @@ -98,7 +99,7 @@ private void ListenForOutput() private void OnOutput(string s) { - var lines = s.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).ToList(); + var lines = s.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); foreach (var line in lines) { _writer.WriteLine(line); diff --git a/OWML.Launcher/PathFinder.cs b/OWML.Launcher/PathFinder.cs index 7598da7fa..b3236ea96 100644 --- a/OWML.Launcher/PathFinder.cs +++ b/OWML.Launcher/PathFinder.cs @@ -21,23 +21,23 @@ public string FindGamePath() { if (IsValidGamePath(_config.GamePath)) { - _writer.WriteLine("Game path is correct in config"); return _config.GamePath; } + _writer.WriteLine("Game path is not correct."); var gamePath = FindInDefaultFolders(); if (!string.IsNullOrEmpty(gamePath)) { - _writer.WriteLine("Game path was found in default paths: " + gamePath); return gamePath; } + _writer.WriteLine("Game not found in default folders."); gamePath = FindInRegistry(); if (!string.IsNullOrEmpty(gamePath)) { - _writer.WriteLine("Game path was found in registry: " + gamePath); return gamePath; } + _writer.WriteLine("Game not found in registry."); return PromptGamePath(); } @@ -49,8 +49,12 @@ private string FindInDefaultFolders() AppDomain.CurrentDomain.BaseDirectory + "..", "C:/Program Files/Epic Games/OuterWilds", "D:/Program Files/Epic Games/OuterWilds", + "E:/Program Files/Epic Games/OuterWilds", + "F:/Program Files/Epic Games/OuterWilds", "C:/Program Files (x86)/Outer Wilds", - "D:/Program Files (x86)/Outer Wilds" + "D:/Program Files (x86)/Outer Wilds", + "E:/Program Files (x86)/Outer Wilds", + "F:/Program Files (x86)/Outer Wilds" }; return paths.FirstOrDefault(IsValidGamePath); } @@ -64,7 +68,7 @@ private string FindInRegistry() private string PromptGamePath() { - var gamePath = ""; + var gamePath = _config.GamePath; while (!IsValidGamePath(gamePath)) { _writer.WriteLine("Game not found at " + gamePath); @@ -77,7 +81,7 @@ private string PromptGamePath() private bool IsValidGamePath(string gamePath) { - return !string.IsNullOrEmpty(gamePath) && + return !string.IsNullOrEmpty(gamePath) && Directory.Exists(gamePath) && Directory.Exists($"{gamePath}/OuterWilds_Data/Managed") && File.Exists($"{gamePath}/OuterWilds.exe"); diff --git a/OWML.ModHelper/ModConfig.cs b/OWML.ModHelper/ModConfig.cs index 56b47aa7d..5e8b704d1 100644 --- a/OWML.ModHelper/ModConfig.cs +++ b/OWML.ModHelper/ModConfig.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Newtonsoft.Json; using OWML.Common; @@ -16,11 +17,21 @@ public ModConfig() public T GetSetting(string key) { - if (Settings.ContainsKey(key)) + if (!Settings.ContainsKey(key)) { - return (T)Settings[key]; + ModConsole.Instance.WriteLine("Error: setting not found: " + key); + return default; + } + var setting = Settings[key]; + try + { + return (T)setting; + } + catch (InvalidCastException) + { + ModConsole.Instance.WriteLine($"Error when getting setting '{key}': can't cast {setting.GetType()} to {typeof(T)}"); + return default; } - return default; } } diff --git a/OWML.SampleMods/OWML.EnableDebugMode/manifest.json b/OWML.SampleMods/OWML.EnableDebugMode/manifest.json index a542efc09..76c242bb1 100644 --- a/OWML.SampleMods/OWML.EnableDebugMode/manifest.json +++ b/OWML.SampleMods/OWML.EnableDebugMode/manifest.json @@ -4,6 +4,6 @@ "name": "EnableDebugMode", "uniqueName": "Alek.EnableDebugMode", "version": "0.2", - "owmlVersion": "0.3.13", + "owmlVersion": "0.3.14", "enabled": false } \ No newline at end of file diff --git a/OWML.SampleMods/OWML.LoadCustomAssets/manifest.json b/OWML.SampleMods/OWML.LoadCustomAssets/manifest.json index 018a327e0..f1b8d27d3 100644 --- a/OWML.SampleMods/OWML.LoadCustomAssets/manifest.json +++ b/OWML.SampleMods/OWML.LoadCustomAssets/manifest.json @@ -4,6 +4,6 @@ "name": "LoadCustomAssets", "uniqueName": "Alek.LoadCustomAssets", "version": "0.4", - "owmlVersion": "0.3.13", + "owmlVersion": "0.3.14", "enabled": false } \ No newline at end of file