-
-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
477 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,200 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.IO; | ||
using System.Collections.Generic; | ||
|
||
using Autofac; | ||
using log4net; | ||
|
||
using CKAN.Versioning; | ||
|
||
namespace CKAN.Games | ||
{ | ||
public class KerbalSpaceProgram2 : IGame | ||
{ | ||
public string ShortName => "KSP2"; | ||
|
||
public bool GameInFolder(DirectoryInfo where) | ||
=> where.EnumerateFiles().Any(f => f.Name == "KSP2_x64.exe") | ||
&& where.EnumerateDirectories().Any(d => d.Name == "KSP2_x64_Data"); | ||
|
||
/// <summary> | ||
/// Finds the Steam KSP path. Returns null if the folder cannot be located. | ||
/// </summary> | ||
/// <returns>The KSP path.</returns> | ||
public string SteamPath() | ||
{ | ||
// Attempt to get the Steam path. | ||
string steamPath = CKANPathUtils.SteamPath(); | ||
|
||
if (steamPath == null) | ||
{ | ||
return null; | ||
} | ||
|
||
// Default steam library | ||
string installPath = GameDirectory(steamPath); | ||
if (installPath != null) | ||
{ | ||
return installPath; | ||
} | ||
|
||
// Attempt to find through config file | ||
string configPath = Path.Combine(steamPath, "config", "config.vdf"); | ||
if (File.Exists(configPath)) | ||
{ | ||
log.InfoFormat("Found Steam config file at {0}", configPath); | ||
StreamReader reader = new StreamReader(configPath); | ||
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]); | ||
|
||
installPath = GameDirectory(split_line[3]); | ||
if (installPath != null) | ||
{ | ||
log.InfoFormat("Found a KSP install at {0}", installPath); | ||
return installPath; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
// Could not locate the folder. | ||
return null; | ||
} | ||
|
||
/// <summary> | ||
/// Get the default non-Steam path to KSP on macOS | ||
/// </summary> | ||
/// <returns> | ||
/// "/Applications/Kerbal Space Program" if it exists and we're on a Mac, else null | ||
/// </returns> | ||
public string MacPath() | ||
{ | ||
if (Platform.IsMac) | ||
{ | ||
string installPath = Path.Combine( | ||
// This is "/Applications" in Mono on Mac | ||
Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), | ||
"Kerbal Space Program 2" | ||
); | ||
return Directory.Exists(installPath) ? installPath : null; | ||
} | ||
return null; | ||
} | ||
|
||
public string PrimaryModDirectoryRelative => "BepInEx/plugins"; | ||
|
||
public string PrimaryModDirectory(GameInstance inst) | ||
=> CKANPathUtils.NormalizePath( | ||
Path.Combine(inst.GameDir(), PrimaryModDirectoryRelative)); | ||
|
||
public string[] StockFolders => new string[] | ||
{ | ||
"KSP2_x64_Data", | ||
"MonoBleedingEdge", | ||
"PDLauncher", | ||
}; | ||
|
||
public string[] ReservedPaths => new string[] | ||
{ | ||
}; | ||
|
||
public string[] CreateableDirs => new string[] | ||
{ | ||
"BepInEx", | ||
"BepInEx/plugins", | ||
}; | ||
|
||
/// <summary> | ||
/// Checks the path against a list of reserved game directories | ||
/// </summary> | ||
/// <param name="path"></param> | ||
/// <returns></returns> | ||
public bool IsReservedDirectory(GameInstance inst, string path) | ||
=> path == inst.GameDir() || path == inst.CkanDir() | ||
|| path == PrimaryModDirectory(inst); | ||
|
||
public bool AllowInstallationIn(string name, out string path) | ||
=> allowedFolders.TryGetValue(name, out path); | ||
|
||
public void RebuildSubdirectories(GameInstance inst) | ||
{ | ||
} | ||
|
||
public string DefaultCommandLine => | ||
Platform.IsUnix ? "./KSP2.x86_64 -single-instance" | ||
: Platform.IsMac ? "./KSP2.app/Contents/MacOS/KSP" | ||
: "KSP2_x64.exe -single-instance"; | ||
|
||
public string[] AdjustCommandLine(string[] args, GameVersion installedVersion) | ||
=> args; | ||
|
||
public List<GameVersion> KnownVersions | ||
=> new List<GameVersion> | ||
{ | ||
new GameVersion(0, 1, 0, 0), | ||
}; | ||
|
||
public GameVersion DetectVersion(DirectoryInfo where) | ||
=> GameVersion.Parse( | ||
FileVersionInfo.GetVersionInfo( | ||
Path.Combine(where.FullName, "KSP2_x64.exe")).ProductVersion); | ||
|
||
public string CompatibleVersionsFile => "compatible_game_versions.json"; | ||
|
||
public string[] BuildIDFiles => new string[] | ||
{ | ||
"KSP2_x64.exe", | ||
}; | ||
|
||
public Uri DefaultRepositoryURL => new Uri("https://github.com/KSP-CKAN/KSP2-CKAN-meta/archive/master.tar.gz"); | ||
|
||
public Uri RepositoryListURL => new Uri("https://raw.githubusercontent.com/KSP-CKAN/KSP2-CKAN-meta/master/repositories.json"); | ||
|
||
private readonly Dictionary<string, string> allowedFolders = new Dictionary<string, string> | ||
{ | ||
{ "BepInEx", "BepInEx" }, | ||
{ "BepInEx/plugins", "BepInEx/plugins" }, | ||
}; | ||
|
||
/// <summary> | ||
/// Finds the KSP path under a Steam Library. Returns null if the folder cannot be located. | ||
/// </summary> | ||
/// <param name="steamPath">Steam Library Path</param> | ||
/// <returns>The KSP path.</returns> | ||
private static string GameDirectory(string steamPath) | ||
{ | ||
// There are several possibilities for the path under Linux. | ||
// Try with the uppercase version. | ||
string installPath = Path.Combine(steamPath, "SteamApps", "common", "Kerbal Space Program 2"); | ||
|
||
if (Directory.Exists(installPath)) | ||
{ | ||
return installPath; | ||
} | ||
|
||
// Try with the lowercase version. | ||
installPath = Path.Combine(steamPath, "steamapps", "common", "Kerbal Space Program 2"); | ||
|
||
if (Directory.Exists(installPath)) | ||
{ | ||
return installPath; | ||
} | ||
return null; | ||
} | ||
|
||
private static readonly ILog log = LogManager.GetLogger(typeof(KerbalSpaceProgram2)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.