Skip to content

Commit b45f9dd

Browse files
committed
fixed dependencies and incompatibilities, added unit tests
1 parent 600ceec commit b45f9dd

File tree

8 files changed

+680
-64
lines changed

8 files changed

+680
-64
lines changed

src/Mods/Addons/Addon.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Mods.Addons
88
/// <summary>
99
/// Base class for campaigns and maps
1010
/// </summary>
11-
public class Addon : IAddon
11+
public abstract class Addon : IAddon
1212
{
1313
/// <inheritdoc/>
1414
public required AddonTypeEnum Type { get; init; }

src/Mods/Providers/InstalledAddonsProvider.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,11 @@ newAddon.Version is not null &&
425425
{
426426
var isEnabled = !_config.DisabledAutoloadMods.Contains(id);
427427

428+
if (mainDef is not null)
429+
{
430+
ThrowHelper.ArgumentException($"Autoload mod can't have Main DEF");
431+
}
432+
428433
addon = new AutoloadMod()
429434
{
430435
Id = id,
@@ -436,7 +441,7 @@ newAddon.Version is not null &&
436441
Author = author,
437442
IsEnabled = isEnabled,
438443
PathToFile = pathToFile,
439-
MainDef = mainDef,
444+
MainDef = null,
440445
AdditionalDefs = addDefs,
441446
AdditionalCons = addCons,
442447
SupportedGame = new(supportedGame, gameVersion, gameCrc),

src/Ports/Ports/BasePort.cs

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -214,28 +214,50 @@ protected bool ValidateAutoloadMod(AutoloadMod autoloadMod, IAddon campaign, Dic
214214

215215
if (autoloadMod.DependentAddons is not null)
216216
{
217-
foreach (var dep in autoloadMod.DependentAddons)
217+
foreach (var dependantAddon in autoloadMod.DependentAddons)
218218
{
219-
if (!addons.ContainsKey(new(dep.Key, dep.Value)) &&
220-
!campaign.Id.Equals(dep.Key, StringComparison.OrdinalIgnoreCase))
219+
foreach (var addon in addons)
221220
{
222-
//skipping mod that doesn't have every dependency
223-
return false;
221+
if (dependantAddon.Key != addon.Key.Id)
222+
{
223+
continue;
224+
}
225+
else if (dependantAddon.Value is null)
226+
{
227+
return true;
228+
}
229+
else if (VersionComparer.Compare(addon.Key.Version, dependantAddon.Value))
230+
{
231+
return true;
232+
}
224233
}
225234
}
235+
236+
return false;
226237
}
227238

228239
if (autoloadMod.IncompatibleAddons is not null)
229240
{
230-
foreach (var dep in autoloadMod.IncompatibleAddons)
241+
foreach (var incompatibleAddon in autoloadMod.IncompatibleAddons)
231242
{
232-
if (addons.ContainsKey(new(dep.Key, dep.Value)) ||
233-
campaign.Id.Equals(dep.Key, StringComparison.OrdinalIgnoreCase))
243+
foreach (var addon in addons)
234244
{
235-
//skipping incompatible mods
236-
return false;
245+
if (incompatibleAddon.Key != addon.Key.Id)
246+
{
247+
continue;
248+
}
249+
else if (incompatibleAddon.Value is null)
250+
{
251+
return false;
252+
}
253+
else if (VersionComparer.Compare(addon.Key.Version, incompatibleAddon.Value))
254+
{
255+
return false;
256+
}
237257
}
238258
}
259+
260+
return true;
239261
}
240262

241263
return true;

0 commit comments

Comments
 (0)