-
-
Notifications
You must be signed in to change notification settings - Fork 345
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support detecting real MakingHistory DLC
- Loading branch information
Showing
5 changed files
with
140 additions
and
3 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,39 @@ | ||
using CKAN.Versioning; | ||
|
||
namespace CKAN.DLC | ||
{ | ||
/// <summary> | ||
/// Represents an object that can detect the presence of official DLC in a KSP installation. | ||
/// </summary> | ||
public interface IDlcDetector | ||
{ | ||
/// <summary> | ||
/// Checks if the relevant DLC is installed in the specific KSP installation. | ||
/// </summary> | ||
/// <param name="ksp">The KSP installation to check.</param> | ||
/// <param name="identifier"> | ||
/// The identifier to use for the DLC's psuedo-module. Value is undefined if this method is undefined. | ||
/// </param> | ||
/// <param name="version"> | ||
/// The version of the installed DLC. May be <c>null</c> if it is not possible to get the specific version of | ||
/// the DLC. Value is undefined if this method returns <c>false</c>. | ||
/// </param> | ||
/// <returns> | ||
/// <list type="bullet"> | ||
/// <item> | ||
/// <term><c>true</c></term> | ||
/// <description> | ||
/// When the relevant DLC is installed in the installation specified by <paramref name="ksp"/>. | ||
/// </description> | ||
/// </item> | ||
/// <item> | ||
/// <term><c>false</c></term> | ||
/// <description> | ||
/// When the relevant DLC is not installed in the installation specified by <paramref name="ksp"/>. | ||
/// </description> | ||
/// </item> | ||
/// </list> | ||
/// </returns> | ||
bool IsInstalled(KSP ksp, out string identifier, out UnmanagedModuleVersion version); | ||
} | ||
} |
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,62 @@ | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text.RegularExpressions; | ||
using CKAN.Versioning; | ||
|
||
namespace CKAN.DLC | ||
{ | ||
/// <summary> | ||
/// Represents an object that can detect the presence of the official Making History DLC in a KSP installation. | ||
/// </summary> | ||
public sealed class MakingHistoryDlcDetector : IDlcDetector | ||
{ | ||
private const string Identifier = "MakingHistory-DLC"; | ||
|
||
private static readonly Dictionary<string, string> CanonicalVersions = new Dictionary<string, string>() | ||
{ | ||
{ "1.0", "1.0.0" } | ||
}; | ||
|
||
private static readonly Regex VersionPattern = new Regex( | ||
@"^Version\s+(?<version>\S+)$", | ||
RegexOptions.Compiled | RegexOptions.IgnoreCase | ||
); | ||
|
||
public bool IsInstalled(KSP ksp, out string identifier, out UnmanagedModuleVersion version) | ||
{ | ||
identifier = Identifier; | ||
version = null; | ||
|
||
var directoryPath = Path.Combine(ksp.GameData(), "SquadExpansion", "MakingHistory"); | ||
if (Directory.Exists(directoryPath)) | ||
{ | ||
var readmeFilePath = Path.Combine(directoryPath, "readme.txt"); | ||
|
||
if (File.Exists(readmeFilePath)) | ||
{ | ||
foreach (var line in File.ReadAllLines(readmeFilePath)) | ||
{ | ||
var match = VersionPattern.Match(line); | ||
|
||
if (match.Success) | ||
{ | ||
var versionStr = match.Groups["version"].Value; | ||
|
||
if (CanonicalVersions.ContainsKey(versionStr)) | ||
versionStr = CanonicalVersions[versionStr]; | ||
|
||
version = new UnmanagedModuleVersion(versionStr); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
else | ||
{ | ||
return false; | ||
} | ||
} | ||
} | ||
} |
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