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

Better handling for DLC with missing readme.txt #3935

Merged
merged 1 commit into from
Dec 4, 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
6 changes: 2 additions & 4 deletions Core/Registry/Registry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -964,10 +964,8 @@ public bool SetDlcs(Dictionary<string, ModuleVersion> dlcs)
installed_modules.Remove(identifier);
}

foreach (var kvp in dlcs)
foreach ((string identifier, ModuleVersion version) in dlcs)
{
var identifier = kvp.Key;
var version = kvp.Value;
// Overwrite everything in case there are version differences
installed_modules[identifier] =
new InstalledModule(null,
Expand All @@ -980,7 +978,7 @@ public bool SetDlcs(Dictionary<string, ModuleVersion> dlcs)
null,
new List<string>() { "SQUAD" },
new List<License>() { new License("restricted") },
version,
version ?? new UnmanagedModuleVersion(null),
null,
"dlc"),
Enumerable.Empty<string>(), false);
Expand Down
14 changes: 2 additions & 12 deletions Core/Relationships/RelationshipResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -875,12 +875,7 @@ public override int GetHashCode()
public class Installed : SelectionReason
{
public override CkanModule Parent
{
get
{
throw new Exception("Should never be called on Installed");
}
}
=> throw new Exception("Should never be called on Installed");

public override string ToString()
=> Properties.Resources.RelationshipResolverInstalledReason;
Expand All @@ -889,12 +884,7 @@ public override string ToString()
public class UserRequested : SelectionReason
{
public override CkanModule Parent
{
get
{
throw new Exception("Should never be called on UserRequested");
}
}
=> throw new Exception("Should never be called on UserRequested");

public override string ToString()
=> Properties.Resources.RelationshipResolverUserReason;
Expand Down
19 changes: 6 additions & 13 deletions Tests/Core/Net/NetAsyncModulesDownloaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Linq;

using log4net;
using NUnit.Framework;

using Tests.Data;
Expand All @@ -17,15 +16,12 @@ namespace Tests.Core.Net
[TestFixture]
public class NetAsyncModulesDownloaderTests
{
private GameInstanceManager manager;
private RegistryManager registry_manager;
private CKAN.Registry registry;
private DisposableKSP ksp;
private IDownloader async;
private NetModuleCache cache;
private TemporaryRepositoryData repoData;

private static readonly ILog log = LogManager.GetLogger(typeof(NetAsyncModulesDownloaderTests));
private GameInstanceManager manager;
private RegistryManager registry_manager;
private CKAN.Registry registry;
private DisposableKSP ksp;
private NetModuleCache cache;
private TemporaryRepositoryData repoData;

[SetUp]
public void Setup()
Expand All @@ -51,9 +47,6 @@ public void Setup()
// Make sure we have a registry we can use.
registry.RepositoriesSet(repos);

// Ready our downloader.
async = new NetAsyncModulesDownloader(user, manager.Cache);

// General shortcuts
cache = manager.Cache;
}
Expand Down
13 changes: 13 additions & 0 deletions Tests/Core/Registry/Registry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,19 @@ public void CompatibleModules_MH100Installed_ExcludesModulesDependingOnMH110()
}
}

[Test]
public void SetDLCs_NullVersion_DoesNotThrow()
{
var registry = CKAN.Registry.Empty();
Assert.DoesNotThrow(() =>
{
registry.SetDlcs(new Dictionary<string, ModuleVersion>
{
{ "MissingVersion", null },
});
}, "Missing readme.txt in a DLC shouldn't trigger an exception");
}

[Test]
public void CompatibleModules_PastAndFutureCompatibility_ReturnsCurrentOnly()
{
Expand Down
Loading