Skip to content

Commit

Permalink
Merge "Improved steam detection with guards" (#1481)
Browse files Browse the repository at this point in the history
* 1444_adjust:
  Changelog joy for Steam location fixes (#1444, #1481)
  Added guards on Steam install detection (#1444)
  If the steam game isn't found in the default spot. Parse the steam config file to get the path.
  • Loading branch information
pjf committed Oct 21, 2015
2 parents c481428 + 0dd553b commit 78d0371
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ All notable changes to this project will be documented in this file.

### Features

- [Core] Better detection of KSP installs in non-standard Steam locations (LarsOL #1444, pjf #1481)

### Internal

- [NetKAN] `netkan.exe` will now sort `conflicts` relationships next to other relationships. (dbent)
Expand Down
69 changes: 59 additions & 10 deletions Core/KSPPathUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,12 @@ public static string SteamPath()
}

/// <summary>
/// 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.
/// </summary>
/// <param name="steam_path">Steam Libary Path</param>
/// <returns>The KSP path.</returns>
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");
Expand All @@ -114,6 +107,62 @@ public static string KSPSteamPath()
return ksp_path;
}

return null;

}

/// <summary>
/// Finds the Steam KSP path. Returns null if the folder cannot be located.
/// </summary>
/// <returns>The KSP path.</returns>
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"))
{

// This assumes config file is valid, we just skip it if it looks funny.
string[] split_line = line.Split('"');

if (split_line.Length > 3)
{
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;
}
Expand Down

0 comments on commit 78d0371

Please sign in to comment.