Skip to content

Commit

Permalink
Merge #3986 Save and load game version for fake KSP2 instances
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Dec 31, 2023
2 parents 71ee319 + 0dfc6b1 commit 563f16c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ All notable changes to this project will be documented in this file.
- [Netkan] Re-sort module properties after merging (#3957 by: HebaruSan)
- [Netkan] Update and optimize meta tester and inflator images (#3958, #3968 by: HebaruSan; reviewed: techman83)
- [Netkan] Generate schema compliant game versions from swinfo.json (#3969 by: HebaruSan)
- [Core] Save and load game version for fake KSP2 instances (#3986 by: HebaruSan)

## v1.34.2 (Minkowski²)

Expand Down
8 changes: 4 additions & 4 deletions Core/GameInstanceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,17 +281,17 @@ public void FakeInstance(IGame game, string newName, string newPath, GameVersion

foreach (var anchor in game.InstanceAnchorFiles)
{
fileMgr.WriteAllText(Path.Combine(newPath, anchor), "");
fileMgr.WriteAllText(Path.Combine(newPath, anchor),
version.WithoutBuild.ToString());
}

// Don't write the buildID.txts if we have no build, otherwise it would be -1.
if (version.IsBuildDefined && game is KerbalSpaceProgram)
{
foreach (var b in KspBuildIdVersionProvider.buildIDfilenames)
{
fileMgr.WriteAllText(
Path.Combine(newPath, b),
string.Format("build id = {0}", version.Build));
fileMgr.WriteAllText(Path.Combine(newPath, b),
string.Format("build id = {0}", version.Build));
}
}

Expand Down
11 changes: 7 additions & 4 deletions Core/Games/KerbalSpaceProgram2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,13 @@ public GameVersion DetectVersion(DirectoryInfo where)

private GameVersion VersionFromFile(string path)
=> File.Exists(path)
? GameVersion.Parse(
FileVersionInfo.GetVersionInfo(path).ProductVersion
?? versions.Last().ToString())
: null;
&& GameVersion.TryParse(FileVersionInfo.GetVersionInfo(path).ProductVersion
// Fake instances have an EXE containing just the version string
?? File.ReadAllText(path),
out GameVersion v)
? v
// Fall back to the most recent version
: KnownVersions.Last();

public string CompatibleVersionsFile => "compatible_game_versions.json";

Expand Down
1 change: 1 addition & 0 deletions Core/Registry/Registry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,7 @@ public IEnumerable<CkanModule> AvailableByIdentifier(string identifier)
{
log.DebugFormat("Finding all available versions for {0}", identifier);
return getAvail(identifier).SelectMany(am => am.AllAvailable())
.Distinct()
.OrderByDescending(m => m.version);
}

Expand Down

0 comments on commit 563f16c

Please sign in to comment.