Skip to content

Commit 07b29fb

Browse files
committed
Merge #4499 Mark virtual dependencies as auto-installed
2 parents 57351d3 + d19d753 commit 07b29fb

File tree

9 files changed

+34
-21
lines changed

9 files changed

+34
-21
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file.
77
### Features
88

99
- [Multiple] Translation updates (#4483 by: gongasss, vinix38; reviewed: HebaruSan)
10+
- [Multiple] Mark virtual dependencies as auto-installed (#4499 by: HebaruSan)
1011

1112
### Bugfixes
1213

Cmdline/Action/Install.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ public int RunCommand(CKAN.GameInstance instance, object raw_options)
118118
without_enforce_consistency = user.Headless,
119119
};
120120

121+
var autoInstalled = new HashSet<CkanModule>();
121122
for (bool done = false; !done; )
122123
{
123124
// Install everything requested. :)
@@ -129,7 +130,8 @@ public int RunCommand(CKAN.GameInstance instance, object raw_options)
129130
new InstalledFilesDeduplicator(instance,
130131
manager.Instances.Values,
131132
repoData),
132-
options?.NetUserAgent);
133+
options?.NetUserAgent,
134+
null, autoInstalled);
133135
user.RaiseMessage("");
134136
done = true;
135137
}
@@ -165,6 +167,7 @@ public int RunCommand(CKAN.GameInstance instance, object raw_options)
165167

166168
// Add the module to the list.
167169
modules.Add(choices[result]);
170+
autoInstalled.Add(choices[result]);
168171
// DON'T return so we can loop around and try again
169172
}
170173
catch (CancelledActionKraken k)

Cmdline/Action/Upgrade.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,10 @@ private void UpgradeModules(NetModuleCache cache,
187187
{
188188
UpgradeModules(
189189
cache, userAgent, user, instance, repoData,
190-
(ModuleInstaller installer, NetAsyncModulesDownloader downloader, RegistryManager regMgr, ref HashSet<string>? possibleConfigOnlyDirs) =>
190+
(ModuleInstaller installer, NetAsyncModulesDownloader downloader, RegistryManager regMgr, ref HashSet<string>? possibleConfigOnlyDirs, ISet<CkanModule> autoInstalled) =>
191191
installer.Upgrade(modules, downloader,
192192
ref possibleConfigOnlyDirs,
193-
regMgr, deduper, true, true),
193+
regMgr, deduper, autoInstalled, true, true),
194194
modules.Add);
195195
}
196196

@@ -210,7 +210,7 @@ private void UpgradeModules(NetModuleCache cache,
210210
{
211211
UpgradeModules(
212212
cache, userAgent, user, instance, repoData,
213-
(ModuleInstaller installer, NetAsyncModulesDownloader downloader, RegistryManager regMgr, ref HashSet<string>? possibleConfigOnlyDirs) =>
213+
(ModuleInstaller installer, NetAsyncModulesDownloader downloader, RegistryManager regMgr, ref HashSet<string>? possibleConfigOnlyDirs, ISet<CkanModule> autoInstalled) =>
214214
{
215215
var crit = instance.VersionCriteria();
216216
var registry = regMgr.registry;
@@ -251,7 +251,7 @@ private void UpgradeModules(NetModuleCache cache,
251251
if (to_upgrade.Count > 0)
252252
{
253253
installer.Upgrade(to_upgrade, downloader,
254-
ref possibleConfigOnlyDirs, regMgr, deduper, true);
254+
ref possibleConfigOnlyDirs, regMgr, deduper, autoInstalled, true);
255255
}
256256
},
257257
m => identsAndVersions.Add(m.identifier));
@@ -265,7 +265,7 @@ private static string UpTo(string orig, int pos)
265265
: orig;
266266

267267
// Action<ref T> isn't allowed
268-
private delegate void AttemptUpgradeAction(ModuleInstaller installer, NetAsyncModulesDownloader downloader, RegistryManager regMgr, ref HashSet<string>? possibleConfigOnlyDirs);
268+
private delegate void AttemptUpgradeAction(ModuleInstaller installer, NetAsyncModulesDownloader downloader, RegistryManager regMgr, ref HashSet<string>? possibleConfigOnlyDirs, ISet<CkanModule> autoInstalled);
269269

270270
/// <summary>
271271
/// The core of the module upgrading logic, with callbacks to
@@ -292,12 +292,13 @@ private void UpgradeModules(NetModuleCache cache,
292292
var downloader = new NetAsyncModulesDownloader(user, cache, userAgent);
293293
var regMgr = RegistryManager.Instance(instance, repoData);
294294
HashSet<string>? possibleConfigOnlyDirs = null;
295+
var autoInstalled = new HashSet<CkanModule>();
295296
bool done = false;
296297
while (!done)
297298
{
298299
try
299300
{
300-
attemptUpgradeCallback?.Invoke(installer, downloader, regMgr, ref possibleConfigOnlyDirs);
301+
attemptUpgradeCallback?.Invoke(installer, downloader, regMgr, ref possibleConfigOnlyDirs, autoInstalled);
301302
transact.Complete();
302303
done = true;
303304
}

ConsoleUI/InstallScreen.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public override void Run(Action? process = null)
5555
if (manager.CurrentInstance != null && manager.Cache != null)
5656
{
5757
using (TransactionScope trans = CkanTransaction.CreateTransactionScope()) {
58+
var autoInstalled = new HashSet<CkanModule>();
5859
bool retry = false;
5960
do {
6061
Draw();
@@ -109,7 +110,7 @@ public override void Run(Action? process = null)
109110
?? m)
110111
.ToArray();
111112
inst.InstallList(iList, resolvOpts(stabilityTolerance), regMgr,
112-
ref possibleConfigOnlyDirs, deduper, userAgent, dl);
113+
ref possibleConfigOnlyDirs, deduper, userAgent, dl, autoInstalled);
113114
plan.Install.Clear();
114115
}
115116
if (plan.Upgrade.Count > 0) {
@@ -120,7 +121,7 @@ public override void Run(Action? process = null)
120121
.Keys
121122
.Except(plan.Upgrade)
122123
.ToHashSet());
123-
inst.Upgrade(upgGroups[true], dl, ref possibleConfigOnlyDirs, regMgr, deduper);
124+
inst.Upgrade(upgGroups[true], dl, ref possibleConfigOnlyDirs, regMgr, deduper, autoInstalled);
124125
plan.Upgrade.Clear();
125126
}
126127
if (plan.Replace.Count > 0) {
@@ -148,6 +149,7 @@ public override void Run(Action? process = null)
148149
if (chosen != null) {
149150
// Use chosen to continue installing
150151
plan.Install.Add(chosen);
152+
autoInstalled.Add(chosen);
151153
retry = true;
152154
}
153155

Core/IO/ModuleInstaller.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public void InstallList(IReadOnlyCollection<CkanModule> modules,
6464
InstalledFilesDeduplicator? deduper = null,
6565
string? userAgent = null,
6666
IDownloader? downloader = null,
67+
ISet<CkanModule>? autoInstalled = null,
6768
bool ConfirmPrompt = true)
6869
{
6970
if (modules.Count == 0)
@@ -141,7 +142,8 @@ public void InstallList(IReadOnlyCollection<CkanModule> modules,
141142
// Re-check that there's enough free space in case game dir and cache are on same drive
142143
CKANPathUtils.CheckFreeSpace(gameDir, mod.install_size,
143144
Properties.Resources.NotEnoughSpaceToInstall);
144-
Install(mod, resolver.IsAutoInstalled(mod),
145+
Install(mod,
146+
(autoInstalled?.Contains(mod) ?? false) || resolver.IsAutoInstalled(mod),
145147
registry_manager.registry,
146148
deduper?.ModuleCandidateDuplicates(mod.identifier, mod.version),
147149
ref possibleConfigOnlyDirs,
@@ -1173,7 +1175,7 @@ private void AddRemove(ref HashSet<string>? possibleConfigOnlyDi
11731175
RegistryManager registry_manager,
11741176
RelationshipResolver resolver,
11751177
IReadOnlyCollection<CkanModule> add,
1176-
IDictionary<CkanModule, bool> autoInstalled,
1178+
ISet<CkanModule> autoInstalled,
11771179
IReadOnlyCollection<InstalledModule> remove,
11781180
IDownloader downloader,
11791181
bool enforceConsistency,
@@ -1242,7 +1244,7 @@ private void AddRemove(ref HashSet<string>? possibleConfigOnlyDi
12421244
// for replacing, new modules are the replacements and should not be marked auto-installed
12431245
remove?.FirstOrDefault(im => im.Module.identifier == mod.identifier)
12441246
?.AutoInstalled
1245-
?? autoInstalled[mod],
1247+
?? autoInstalled.Contains(mod),
12461248
registry_manager.registry,
12471249
deduper?.ModuleCandidateDuplicates(mod.identifier, mod.version),
12481250
ref possibleConfigOnlyDirs,
@@ -1277,6 +1279,7 @@ public void Upgrade(in IReadOnlyCollection<CkanModule> modules,
12771279
ref HashSet<string>? possibleConfigOnlyDirs,
12781280
RegistryManager registry_manager,
12791281
InstalledFilesDeduplicator? deduper = null,
1282+
ISet<CkanModule>? autoInstalled = null,
12801283
bool enforceConsistency = true,
12811284
bool ConfirmPrompt = true)
12821285
{
@@ -1316,7 +1319,8 @@ public void Upgrade(in IReadOnlyCollection<CkanModule> modules,
13161319
.Select(im => im.Module)
13171320
.Except(modules))
13181321
.ToArray();
1319-
var autoInstalled = toInstall.ToDictionary(m => m, resolver.IsAutoInstalled);
1322+
autoInstalled ??= new HashSet<CkanModule>();
1323+
autoInstalled.UnionWith(toInstall.Where(resolver.IsAutoInstalled));
13201324

13211325
User.RaiseMessage(Properties.Resources.ModuleInstallerAboutToUpgrade);
13221326
User.RaiseMessage("");
@@ -1526,7 +1530,7 @@ public void Replace(IEnumerable<ModuleReplacement> replacements,
15261530
registry_manager,
15271531
resolver,
15281532
resolvedModsToInstall,
1529-
resolvedModsToInstall.ToDictionary(m => m, m => false),
1533+
new HashSet<CkanModule>(),
15301534
modsToRemove,
15311535
downloader,
15321536
enforceConsistency,

GUI/Main/MainInstall.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ private void InstallMods(object? sender, DoWorkEventArgs? e)
112112

113113
// this will be the final list of mods we want to install
114114
var toInstall = new List<CkanModule>();
115+
var autoInstalled = new HashSet<CkanModule>();
115116
var toUninstall = new HashSet<CkanModule>();
116117
var toUpgrade = new HashSet<CkanModule>();
117118

@@ -253,13 +254,13 @@ private void InstallMods(object? sender, DoWorkEventArgs? e)
253254
if (!canceled && toInstall.Count > 0)
254255
{
255256
installer.InstallList(toInstall, options, registry_manager, ref possibleConfigOnlyDirs,
256-
deduper, userAgent, downloader, false);
257+
deduper, userAgent, downloader, autoInstalled, false);
257258
toInstall.Clear();
258259
}
259260
if (!canceled && toUpgrade.Count > 0)
260261
{
261262
installer.Upgrade(toUpgrade, downloader, ref possibleConfigOnlyDirs, registry_manager,
262-
deduper, true, false);
263+
deduper, autoInstalled, true, false);
263264
toUpgrade.Clear();
264265
}
265266
if (canceled)
@@ -345,6 +346,7 @@ private void InstallMods(object? sender, DoWorkEventArgs? e)
345346
{
346347
// User picked a mod, queue it up for installation
347348
toInstall.Add(chosen);
349+
autoInstalled.Add(chosen);
348350
// DON'T return so we can loop around and try the above InstallList call again
349351
tabController.ShowTab(WaitTabPage.Name);
350352
Util.Invoke(this, () => StatusProgress.Visible = true);

Tests/Core/IO/ModuleInstallerDirTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public void SetUp()
6060
_manager.Cache?.Store(_testModule!, testModFile, new Progress<long>(bytes => {}));
6161
HashSet<string>? possibleConfigOnlyDirs = null;
6262
_installer.InstallList(
63-
new List<CkanModule>() { _testModule! },
63+
new CkanModule[] { _testModule! },
6464
new RelationshipResolverOptions(_instance.KSP.StabilityToleranceConfig),
6565
_registryManager,
6666
ref possibleConfigOnlyDirs);

Tests/Core/IO/ModuleInstallerTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,7 +1608,7 @@ public void Upgrade_WithAutoInst_RemovesAutoRemovable(string[] regularMods,
16081608
registry.LatestAvailable(ident, inst.KSP.StabilityToleranceConfig, inst.KSP.VersionCriteria()))
16091609
.OfType<CkanModule>()
16101610
.ToArray(),
1611-
downloader, ref possibleConfigOnlyDirs, regMgr, null, false);
1611+
downloader, ref possibleConfigOnlyDirs, regMgr, null, null, false);
16121612

16131613
// Assert
16141614
CollectionAssert.AreEquivalent(correctRemainingIdentifiers,
@@ -1706,7 +1706,7 @@ public void Upgrade_WithUnstableAutoinstDep_NotRemoved(string[] regularInstalled
17061706
installer.Upgrade(toUpgrade.Select(CkanModule.FromJson)
17071707
.ToArray(),
17081708
downloader, ref possibleConfigOnlyDirs,
1709-
regMgr, null, false);
1709+
regMgr, null, null, false);
17101710
});
17111711
CollectionAssert.AreEquivalent(registry.InstalledModules.Select(im => im.Module),
17121712
autoInstalled.Select(CkanModule.FromJson)

Tests/GUI/Model/ModList.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ public void InstallAndSortByCompat_WithAnyCompat_NoCrash()
777777

778778
HashSet<string>? possibleConfigOnlyDirs = null;
779779
installer.InstallList(
780-
new List<CkanModule> { anyVersionModule },
780+
new CkanModule[] { anyVersionModule },
781781
new RelationshipResolverOptions(instance.KSP.StabilityToleranceConfig),
782782
regMgr,
783783
ref possibleConfigOnlyDirs,
@@ -825,7 +825,7 @@ public void InstallAndSortByCompat_WithAnyCompat_NoCrash()
825825
installer.InstallList(
826826
modList.ComputeUserChangeSet(Registry.Empty(repoData.Manager), inst2.KSP, null, null)
827827
.Select(change => change.Mod)
828-
.ToList(),
828+
.ToArray(),
829829
new RelationshipResolverOptions(inst2.KSP.StabilityToleranceConfig),
830830
regMgr,
831831
ref possibleConfigOnlyDirs,

0 commit comments

Comments
 (0)