Skip to content
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
5 changes: 4 additions & 1 deletion Cmdline/Action/Install.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public int RunCommand(CKAN.GameInstance instance, object raw_options)
without_enforce_consistency = user.Headless,
};

var autoInstalled = new HashSet<CkanModule>();
for (bool done = false; !done; )
{
// Install everything requested. :)
Expand All @@ -129,7 +130,8 @@ public int RunCommand(CKAN.GameInstance instance, object raw_options)
new InstalledFilesDeduplicator(instance,
manager.Instances.Values,
repoData),
options?.NetUserAgent);
options?.NetUserAgent,
null, autoInstalled);
user.RaiseMessage("");
done = true;
}
Expand Down Expand Up @@ -165,6 +167,7 @@ public int RunCommand(CKAN.GameInstance instance, object raw_options)

// Add the module to the list.
modules.Add(choices[result]);
autoInstalled.Add(choices[result]);
// DON'T return so we can loop around and try again
}
catch (CancelledActionKraken k)
Expand Down
13 changes: 7 additions & 6 deletions Cmdline/Action/Upgrade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,10 @@ private void UpgradeModules(NetModuleCache cache,
{
UpgradeModules(
cache, userAgent, user, instance, repoData,
(ModuleInstaller installer, NetAsyncModulesDownloader downloader, RegistryManager regMgr, ref HashSet<string>? possibleConfigOnlyDirs) =>
(ModuleInstaller installer, NetAsyncModulesDownloader downloader, RegistryManager regMgr, ref HashSet<string>? possibleConfigOnlyDirs, ISet<CkanModule> autoInstalled) =>
installer.Upgrade(modules, downloader,
ref possibleConfigOnlyDirs,
regMgr, deduper, true, true),
regMgr, deduper, autoInstalled, true, true),
modules.Add);
}

Expand All @@ -210,7 +210,7 @@ private void UpgradeModules(NetModuleCache cache,
{
UpgradeModules(
cache, userAgent, user, instance, repoData,
(ModuleInstaller installer, NetAsyncModulesDownloader downloader, RegistryManager regMgr, ref HashSet<string>? possibleConfigOnlyDirs) =>
(ModuleInstaller installer, NetAsyncModulesDownloader downloader, RegistryManager regMgr, ref HashSet<string>? possibleConfigOnlyDirs, ISet<CkanModule> autoInstalled) =>
{
var crit = instance.VersionCriteria();
var registry = regMgr.registry;
Expand Down Expand Up @@ -251,7 +251,7 @@ private void UpgradeModules(NetModuleCache cache,
if (to_upgrade.Count > 0)
{
installer.Upgrade(to_upgrade, downloader,
ref possibleConfigOnlyDirs, regMgr, deduper, true);
ref possibleConfigOnlyDirs, regMgr, deduper, autoInstalled, true);
}
},
m => identsAndVersions.Add(m.identifier));
Expand All @@ -265,7 +265,7 @@ private static string UpTo(string orig, int pos)
: orig;

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

/// <summary>
/// The core of the module upgrading logic, with callbacks to
Expand All @@ -292,12 +292,13 @@ private void UpgradeModules(NetModuleCache cache,
var downloader = new NetAsyncModulesDownloader(user, cache, userAgent);
var regMgr = RegistryManager.Instance(instance, repoData);
HashSet<string>? possibleConfigOnlyDirs = null;
var autoInstalled = new HashSet<CkanModule>();
bool done = false;
while (!done)
{
try
{
attemptUpgradeCallback?.Invoke(installer, downloader, regMgr, ref possibleConfigOnlyDirs);
attemptUpgradeCallback?.Invoke(installer, downloader, regMgr, ref possibleConfigOnlyDirs, autoInstalled);
transact.Complete();
done = true;
}
Expand Down
6 changes: 4 additions & 2 deletions ConsoleUI/InstallScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public override void Run(Action? process = null)
if (manager.CurrentInstance != null && manager.Cache != null)
{
using (TransactionScope trans = CkanTransaction.CreateTransactionScope()) {
var autoInstalled = new HashSet<CkanModule>();
bool retry = false;
do {
Draw();
Expand Down Expand Up @@ -109,7 +110,7 @@ public override void Run(Action? process = null)
?? m)
.ToArray();
inst.InstallList(iList, resolvOpts(stabilityTolerance), regMgr,
ref possibleConfigOnlyDirs, deduper, userAgent, dl);
ref possibleConfigOnlyDirs, deduper, userAgent, dl, autoInstalled);
plan.Install.Clear();
}
if (plan.Upgrade.Count > 0) {
Expand All @@ -120,7 +121,7 @@ public override void Run(Action? process = null)
.Keys
.Except(plan.Upgrade)
.ToHashSet());
inst.Upgrade(upgGroups[true], dl, ref possibleConfigOnlyDirs, regMgr, deduper);
inst.Upgrade(upgGroups[true], dl, ref possibleConfigOnlyDirs, regMgr, deduper, autoInstalled);
plan.Upgrade.Clear();
}
if (plan.Replace.Count > 0) {
Expand Down Expand Up @@ -148,6 +149,7 @@ public override void Run(Action? process = null)
if (chosen != null) {
// Use chosen to continue installing
plan.Install.Add(chosen);
autoInstalled.Add(chosen);
retry = true;
}

Expand Down
14 changes: 9 additions & 5 deletions Core/IO/ModuleInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public void InstallList(IReadOnlyCollection<CkanModule> modules,
InstalledFilesDeduplicator? deduper = null,
string? userAgent = null,
IDownloader? downloader = null,
ISet<CkanModule>? autoInstalled = null,
bool ConfirmPrompt = true)
{
if (modules.Count == 0)
Expand Down Expand Up @@ -141,7 +142,8 @@ public void InstallList(IReadOnlyCollection<CkanModule> modules,
// Re-check that there's enough free space in case game dir and cache are on same drive
CKANPathUtils.CheckFreeSpace(gameDir, mod.install_size,
Properties.Resources.NotEnoughSpaceToInstall);
Install(mod, resolver.IsAutoInstalled(mod),
Install(mod,
(autoInstalled?.Contains(mod) ?? false) || resolver.IsAutoInstalled(mod),
registry_manager.registry,
deduper?.ModuleCandidateDuplicates(mod.identifier, mod.version),
ref possibleConfigOnlyDirs,
Expand Down Expand Up @@ -1173,7 +1175,7 @@ private void AddRemove(ref HashSet<string>? possibleConfigOnlyDi
RegistryManager registry_manager,
RelationshipResolver resolver,
IReadOnlyCollection<CkanModule> add,
IDictionary<CkanModule, bool> autoInstalled,
ISet<CkanModule> autoInstalled,
IReadOnlyCollection<InstalledModule> remove,
IDownloader downloader,
bool enforceConsistency,
Expand Down Expand Up @@ -1242,7 +1244,7 @@ private void AddRemove(ref HashSet<string>? possibleConfigOnlyDi
// for replacing, new modules are the replacements and should not be marked auto-installed
remove?.FirstOrDefault(im => im.Module.identifier == mod.identifier)
?.AutoInstalled
?? autoInstalled[mod],
?? autoInstalled.Contains(mod),
registry_manager.registry,
deduper?.ModuleCandidateDuplicates(mod.identifier, mod.version),
ref possibleConfigOnlyDirs,
Expand Down Expand Up @@ -1277,6 +1279,7 @@ public void Upgrade(in IReadOnlyCollection<CkanModule> modules,
ref HashSet<string>? possibleConfigOnlyDirs,
RegistryManager registry_manager,
InstalledFilesDeduplicator? deduper = null,
ISet<CkanModule>? autoInstalled = null,
bool enforceConsistency = true,
bool ConfirmPrompt = true)
{
Expand Down Expand Up @@ -1316,7 +1319,8 @@ public void Upgrade(in IReadOnlyCollection<CkanModule> modules,
.Select(im => im.Module)
.Except(modules))
.ToArray();
var autoInstalled = toInstall.ToDictionary(m => m, resolver.IsAutoInstalled);
autoInstalled ??= new HashSet<CkanModule>();
autoInstalled.UnionWith(toInstall.Where(resolver.IsAutoInstalled));

User.RaiseMessage(Properties.Resources.ModuleInstallerAboutToUpgrade);
User.RaiseMessage("");
Expand Down Expand Up @@ -1526,7 +1530,7 @@ public void Replace(IEnumerable<ModuleReplacement> replacements,
registry_manager,
resolver,
resolvedModsToInstall,
resolvedModsToInstall.ToDictionary(m => m, m => false),
new HashSet<CkanModule>(),
modsToRemove,
downloader,
enforceConsistency,
Expand Down
6 changes: 4 additions & 2 deletions GUI/Main/MainInstall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ private void InstallMods(object? sender, DoWorkEventArgs? e)

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

Expand Down Expand Up @@ -253,13 +254,13 @@ private void InstallMods(object? sender, DoWorkEventArgs? e)
if (!canceled && toInstall.Count > 0)
{
installer.InstallList(toInstall, options, registry_manager, ref possibleConfigOnlyDirs,
deduper, userAgent, downloader, false);
deduper, userAgent, downloader, autoInstalled, false);
toInstall.Clear();
}
if (!canceled && toUpgrade.Count > 0)
{
installer.Upgrade(toUpgrade, downloader, ref possibleConfigOnlyDirs, registry_manager,
deduper, true, false);
deduper, autoInstalled, true, false);
toUpgrade.Clear();
}
if (canceled)
Expand Down Expand Up @@ -345,6 +346,7 @@ private void InstallMods(object? sender, DoWorkEventArgs? e)
{
// User picked a mod, queue it up for installation
toInstall.Add(chosen);
autoInstalled.Add(chosen);
// DON'T return so we can loop around and try the above InstallList call again
tabController.ShowTab(WaitTabPage.Name);
Util.Invoke(this, () => StatusProgress.Visible = true);
Expand Down
2 changes: 1 addition & 1 deletion Tests/Core/IO/ModuleInstallerDirTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void SetUp()
_manager.Cache?.Store(_testModule!, testModFile, new Progress<long>(bytes => {}));
HashSet<string>? possibleConfigOnlyDirs = null;
_installer.InstallList(
new List<CkanModule>() { _testModule! },
new CkanModule[] { _testModule! },
new RelationshipResolverOptions(_instance.KSP.StabilityToleranceConfig),
_registryManager,
ref possibleConfigOnlyDirs);
Expand Down
4 changes: 2 additions & 2 deletions Tests/Core/IO/ModuleInstallerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1608,7 +1608,7 @@ public void Upgrade_WithAutoInst_RemovesAutoRemovable(string[] regularMods,
registry.LatestAvailable(ident, inst.KSP.StabilityToleranceConfig, inst.KSP.VersionCriteria()))
.OfType<CkanModule>()
.ToArray(),
downloader, ref possibleConfigOnlyDirs, regMgr, null, false);
downloader, ref possibleConfigOnlyDirs, regMgr, null, null, false);

// Assert
CollectionAssert.AreEquivalent(correctRemainingIdentifiers,
Expand Down Expand Up @@ -1706,7 +1706,7 @@ public void Upgrade_WithUnstableAutoinstDep_NotRemoved(string[] regularInstalled
installer.Upgrade(toUpgrade.Select(CkanModule.FromJson)
.ToArray(),
downloader, ref possibleConfigOnlyDirs,
regMgr, null, false);
regMgr, null, null, false);
});
CollectionAssert.AreEquivalent(registry.InstalledModules.Select(im => im.Module),
autoInstalled.Select(CkanModule.FromJson)
Expand Down
4 changes: 2 additions & 2 deletions Tests/GUI/Model/ModList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ public void InstallAndSortByCompat_WithAnyCompat_NoCrash()

HashSet<string>? possibleConfigOnlyDirs = null;
installer.InstallList(
new List<CkanModule> { anyVersionModule },
new CkanModule[] { anyVersionModule },
new RelationshipResolverOptions(instance.KSP.StabilityToleranceConfig),
regMgr,
ref possibleConfigOnlyDirs,
Expand Down Expand Up @@ -825,7 +825,7 @@ public void InstallAndSortByCompat_WithAnyCompat_NoCrash()
installer.InstallList(
modList.ComputeUserChangeSet(Registry.Empty(repoData.Manager), inst2.KSP, null, null)
.Select(change => change.Mod)
.ToList(),
.ToArray(),
new RelationshipResolverOptions(inst2.KSP.StabilityToleranceConfig),
regMgr,
ref possibleConfigOnlyDirs,
Expand Down