Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save and load game version for fake KSP2 instances #3986

Merged
merged 1 commit into from
Dec 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading