Skip to content

Commit

Permalink
fixes for pathfinder and config (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
amazingalek authored Jan 5, 2020
1 parent 688aa4d commit 92c50a4
Showing 5 changed files with 30 additions and 14 deletions.
5 changes: 3 additions & 2 deletions OWML.Launcher/App.cs
Original file line number Diff line number Diff line change
@@ -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);
16 changes: 10 additions & 6 deletions OWML.Launcher/PathFinder.cs
Original file line number Diff line number Diff line change
@@ -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");
19 changes: 15 additions & 4 deletions OWML.ModHelper/ModConfig.cs
Original file line number Diff line number Diff line change
@@ -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<T>(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;
}

}
2 changes: 1 addition & 1 deletion OWML.SampleMods/OWML.EnableDebugMode/manifest.json
Original file line number Diff line number Diff line change
@@ -4,6 +4,6 @@
"name": "EnableDebugMode",
"uniqueName": "Alek.EnableDebugMode",
"version": "0.2",
"owmlVersion": "0.3.13",
"owmlVersion": "0.3.14",
"enabled": false
}
2 changes: 1 addition & 1 deletion OWML.SampleMods/OWML.LoadCustomAssets/manifest.json
Original file line number Diff line number Diff line change
@@ -4,6 +4,6 @@
"name": "LoadCustomAssets",
"uniqueName": "Alek.LoadCustomAssets",
"version": "0.4",
"owmlVersion": "0.3.13",
"owmlVersion": "0.3.14",
"enabled": false
}

0 comments on commit 92c50a4

Please sign in to comment.