Skip to content

Commit

Permalink
Merge #3935 Better handling for DLC with missing readme.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Dec 4, 2023
2 parents 5684cd6 + 3543052 commit 2c137f6
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 30 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ All notable changes to this project will be documented in this file.
- [Multiple] Show recommendations of full changeset with opt-out (#3892 by: HebaruSan; reviewed: techman83)
- [Multiple] Dutch translation and icon duplication guardrails (#3897 by: HebaruSan; reviewed: techman83)
- [GUI] Shorten toolbar button labels (#3903 by: HebaruSan; reviewed: techman83)
- [Multiple] Refactor repository and available module handling (#3904, #3907, #3908 by: HebaruSan; reviewed: techman83)
- [Multiple] Refactor repository and available module handling (#3904, #3907, #3908, #3935 by: HebaruSan; reviewed: techman83)
- [Multiple] Parallelize for performance, relationship resolver improvements (#3917 by: HebaruSan; reviewed: techman83)
- [Multiple] Modernize administrator and Mono version checks (#3933 by: HebaruSan; reviewed: techman83)

Expand Down
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

0 comments on commit 2c137f6

Please sign in to comment.