Skip to content

Commit

Permalink
Merge #4252 Sort dependencies first in modpacks
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Nov 7, 2024
2 parents 3d17da3 + 5f5c81b commit bd2f866
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file.
- [Multiple] Translation updates from Crowdin (#4233 by: vixnig38, ambition, tinygrox; reviewed: HebaruSan)
- [Multiple] Cache migration and other fixes (#4240 by: HebaruSan)
- [Multiple] Start installing mods while downloads are still in progress (#4249 by: HebaruSan)
- [Multiple] Sort dependencies first in modpacks (#4252 by: HebaruSan)

### Bugfixes

Expand Down
30 changes: 19 additions & 11 deletions Core/Registry/RegistryManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -501,12 +501,20 @@ public CkanModule GenerateModpack(bool recommends = false, bool with_versions =
release_date = DateTime.Now,
};

var rels = registry.InstalledModules
.Where(inst => !inst.Module.IsDLC && !inst.AutoInstalled && IsAvailable(inst))
.OrderBy(inst => inst.identifier, StringComparer.OrdinalIgnoreCase)
.Select(with_versions ? (Func<InstalledModule, RelationshipDescriptor>) RelationshipWithVersion
: RelationshipWithoutVersion)
.ToList();
var mods = registry.InstalledModules
.Where(inst => !inst.Module.IsDLC && !inst.AutoInstalled && IsAvailable(inst))
.Select(inst => inst.Module)
.ToHashSet();
// Sort dependencies before dependers
var resolver = new RelationshipResolver(mods, null,
RelationshipResolverOptions.ConflictsOpts(),
registry, gameInstance.game, gameInstance.VersionCriteria());
var rels = resolver.ModList()
.Intersect(mods)
.Select(with_versions ? (Func<CkanModule, RelationshipDescriptor>)
RelationshipWithVersion
: RelationshipWithoutVersion)
.ToList();

if (recommends)
{
Expand Down Expand Up @@ -535,17 +543,17 @@ private bool IsAvailable(InstalledModule inst)
}
}

private RelationshipDescriptor RelationshipWithVersion(InstalledModule inst)
private RelationshipDescriptor RelationshipWithVersion(CkanModule mod)
=> new ModuleRelationshipDescriptor()
{
name = inst.identifier,
version = inst.Module.version,
name = mod.identifier,
version = mod.version,
};

private RelationshipDescriptor RelationshipWithoutVersion(InstalledModule inst)
private RelationshipDescriptor RelationshipWithoutVersion(CkanModule mod)
=> new ModuleRelationshipDescriptor()
{
name = inst.identifier,
name = mod.identifier,
};

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion GUI/Controls/EditModpack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ private void LoadRelationships(CkanModule module, IRegistryQuerier registry)
&& !module.recommends.Any(rel => rel.ContainsAny(ids))
&& !module.suggests.Any(rel => rel.ContainsAny(ids));
})
.OrderBy(kvp => kvp.Key)
.Select(kvp => (RelationshipDescriptor) new ModuleRelationshipDescriptor()
{
name = kvp.Key,
Expand Down Expand Up @@ -141,7 +142,6 @@ private void AddGroup(List<RelationshipDescriptor> relationships,
{
RelationshipsListView.Items.AddRange(
relationships.OfType<ModuleRelationshipDescriptor>()
.OrderBy(r => r.name)
.Select(r => new ListViewItem(new string[]
{
r.name,
Expand Down
8 changes: 5 additions & 3 deletions GUI/Controls/Wait.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,13 @@ public void SetProgress(string label,
pb.Text = rateCounter.Summary;
if (newVal >= 100)
{
var myLbl = progressLabels[label];
rateCounter.Stop();
ProgressBarTable.SuspendLayout();
for (int row = ProgressBarTable.GetPositionFromControl(pb).Row; row > 0; --row)
{
if (ProgressBarTable.GetControlFromPosition(1, row - 1) is LabeledProgressBar prevPb
&& ProgressBarTable.GetControlFromPosition(0, row) is Label myLbl
&& ProgressBarTable.GetControlFromPosition(0, row - 1) is Label prevLbl)
if (ProgressBarTable.GetControlFromPosition(0, row - 1) is Label prevLbl
&& ProgressBarTable.GetControlFromPosition(1, row - 1) is LabeledProgressBar prevPb)
{
if (prevPb.Value >= 100)
{
Expand All @@ -122,6 +123,7 @@ public void SetProgress(string label,
}
}
}
ProgressBarTable.ResumeLayout();
}
}
else
Expand Down

0 comments on commit bd2f866

Please sign in to comment.