From 93a607310e6aadb537dfbf411a4b6d0530bd882f Mon Sep 17 00:00:00 2001 From: Lars Lawoko Date: Sat, 5 Sep 2015 14:44:25 +1000 Subject: [PATCH 1/3] If the steam game isn't found in the default spot. Parse the steam config file to get the path. --- Core/KSPPathUtils.cs | 69 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 59 insertions(+), 10 deletions(-) diff --git a/Core/KSPPathUtils.cs b/Core/KSPPathUtils.cs index 42f25ba417..01287ba5df 100644 --- a/Core/KSPPathUtils.cs +++ b/Core/KSPPathUtils.cs @@ -84,19 +84,12 @@ public static string SteamPath() } /// - /// Finds the KSP path under Steam. Returns null if the folder cannot be located. + /// Finds the KSP path under a Steam Libary. Returns null if the folder cannot be located. /// + /// Steam Libary Path /// The KSP path. - public static string KSPSteamPath() + public static string KSPDirectory(string steam_path) { - // Attempt to get the Steam path. - string steam_path = SteamPath(); - - if (steam_path == null) - { - return null; - } - // There are several possibilities for the path under Linux. // Try with the uppercase version. string ksp_path = Path.Combine(steam_path, "SteamApps", "common", "Kerbal Space Program"); @@ -114,6 +107,62 @@ public static string KSPSteamPath() return ksp_path; } + return null; + + } + + /// + /// Finds the Steam KSP path. Returns null if the folder cannot be located. + /// + /// The KSP path. + public static string KSPSteamPath() + { + // Attempt to get the Steam path. + string steam_path = SteamPath(); + + if (steam_path == null) + { + return null; + } + + //Default steam libary + string ksp_path = KSPDirectory(steam_path); + if(ksp_path != null) + { + return ksp_path; + } + + //Attempt to find through config file + string config_path = Path.Combine(steam_path, "config", "config.vdf"); + if (File.Exists(config_path)) + { + log.InfoFormat("Found Steam config file at {0}", config_path); + StreamReader reader = new StreamReader(config_path); + string line; + while ((line = reader.ReadLine()) != null) + { + // Found Steam library + if (line.Contains("BaseInstallFolder")) + { + + //TODO: more robust parsing (currently assumes config file is valid) + string[] split_line = line.Split('"'); + + log.DebugFormat("Found a Steam Libary Location at {0}", split_line[3]); + + ksp_path = KSPDirectory(split_line[3]); + if (ksp_path!= null) + { + log.InfoFormat("Found a KSP install at {0}", ksp_path); + return ksp_path; + } + + } + } + + } + + // Could not locate the folder. return null; } From 7c9aafeae270bb01bedb59865c4961228335ee21 Mon Sep 17 00:00:00 2001 From: Paul Fenwick Date: Sun, 27 Sep 2015 14:58:52 +1000 Subject: [PATCH 2/3] Added guards on Steam install detection (#1444) --- Core/KSPPathUtils.cs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Core/KSPPathUtils.cs b/Core/KSPPathUtils.cs index 01287ba5df..819be738a7 100644 --- a/Core/KSPPathUtils.cs +++ b/Core/KSPPathUtils.cs @@ -145,23 +145,23 @@ public static string KSPSteamPath() if (line.Contains("BaseInstallFolder")) { - //TODO: more robust parsing (currently assumes config file is valid) + // This assumes config file is valid, we just skip it if it looks funny. string[] split_line = line.Split('"'); - log.DebugFormat("Found a Steam Libary Location at {0}", split_line[3]); - - ksp_path = KSPDirectory(split_line[3]); - if (ksp_path!= null) + if (split_line.Length > 3) { - log.InfoFormat("Found a KSP install at {0}", ksp_path); - return ksp_path; + log.DebugFormat("Found a Steam Libary Location at {0}", split_line[3]); + + ksp_path = KSPDirectory(split_line[3]); + if (ksp_path != null) + { + log.InfoFormat("Found a KSP install at {0}", ksp_path); + return ksp_path; + } } - } } - } - // Could not locate the folder. return null; From ea84ed3529057b31cd4ad2b6a0fa020a6ccf1ed7 Mon Sep 17 00:00:00 2001 From: Paul Fenwick Date: Sun, 27 Sep 2015 15:02:15 +1000 Subject: [PATCH 3/3] Changelog joy for Steam location fixes (#1444, #1481) --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f0bbaaafe..ad129ea641 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ All notable changes to this project will be documented in this file. - [All] When installing and uninstalling mods, the mod name and version will be used rather than the internal identifier. (Postremus, #1401) - [GUI] The GUI changeset screen now provides explanations as to why changes are being made. (Postremus, #1412) +- [Core] Better detectio of KSP installs in non-standard Steam locations (LarsOL #1444, pjf #1481) ### Internal