Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use shared installer code in GUI and fix reinstall problems #2233

Merged
merged 4 commits into from
Jan 2, 2018
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
27 changes: 5 additions & 22 deletions Core/ModuleInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,12 @@ public void InstallList(
{
if (!ksp.Cache.IsCachedZip(module.download))
{
User.RaiseMessage(" * {0} {1}", module.name, module.version);
User.RaiseMessage(" * {0} {1} ({2})", module.name, module.version, module.download.Host);
downloads.Add(module);
}
else
{
User.RaiseMessage(" * {0} {1}(cached)", module.name, module.version);
User.RaiseMessage(" * {0} {1} (cached)", module.name, module.version);
}
}

Expand Down Expand Up @@ -255,23 +255,6 @@ public void InstallList(
User.RaiseProgress("Done!\r\n", 100);
}

public ModuleResolution ResolveModules(IEnumerable<CkanModule> modules, RelationshipResolverOptions options)
{
var resolver = new RelationshipResolver(modules, options, registry_manager.registry, ksp.VersionCriteria());
return new ModuleResolution(resolver.ModList(), m => ksp.Cache.IsCachedZip(m.download));
}

public void EnsureCache(List<CkanModule> modules, IDownloader downloader = null)
{
if (!modules.Any())
{
return;
}

downloader = downloader ?? new NetAsyncModulesDownloader(User);
downloader.DownloadModules(ksp.Cache, modules);
}

public void InstallList(ModuleResolution modules, RelationshipResolverOptions options)
{
// We're about to install all our mods; so begin our transaction.
Expand Down Expand Up @@ -1037,7 +1020,7 @@ public void AddRemove(IEnumerable<CkanModule> add = null, IEnumerable<string> re
/// Will *re-install* with warning even if an upgrade is not available.
/// Throws ModuleNotFoundKraken if module is not installed, or not available.
/// </summary>
public void Upgrade(IEnumerable<string> identifiers, NetAsyncModulesDownloader netAsyncDownloader, bool enforceConsistency = true)
public void Upgrade(IEnumerable<string> identifiers, IDownloader netAsyncDownloader, bool enforceConsistency = true)
{
var options = new RelationshipResolverOptions();

Expand All @@ -1054,7 +1037,7 @@ public void Upgrade(IEnumerable<string> identifiers, NetAsyncModulesDownloader n
/// Will *re-install* or *downgrade* (with a warning) as well as upgrade.
/// Throws ModuleNotFoundKraken if a module is not installed.
/// </summary>
public void Upgrade(IEnumerable<CkanModule> modules, NetAsyncModulesDownloader netAsyncDownloader, bool enforceConsistency = true)
public void Upgrade(IEnumerable<CkanModule> modules, IDownloader netAsyncDownloader, bool enforceConsistency = true)
{
// Start by making sure we've downloaded everything.
DownloadModules(modules, netAsyncDownloader);
Expand Down Expand Up @@ -1114,7 +1097,7 @@ public void Upgrade(IEnumerable<CkanModule> modules, NetAsyncModulesDownloader n
/// <summary>
/// Makes sure all the specified mods are downloaded.
/// </summary>
private void DownloadModules(IEnumerable<CkanModule> mods, NetAsyncModulesDownloader downloader)
private void DownloadModules(IEnumerable<CkanModule> mods, IDownloader downloader)
{
List<CkanModule> downloads = mods.Where(module => !ksp.Cache.IsCachedZip(module.download)).ToList();

Expand Down
2 changes: 1 addition & 1 deletion Core/Net/AutoUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ internal Tuple<Uri, long> RetrieveUrl(dynamic response, int whichOne)
internal dynamic MakeRequest(Uri url)
{
var web = new WebClient();
web.Headers.Add("user-agent", Net.UserAgentString);
web.Headers.Add("User-Agent", Net.UserAgentString);

try
{
Expand Down
2 changes: 1 addition & 1 deletion Core/Net/NetAsyncDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public NetAsyncDownloaderDownloadPart(Uri url, long expectedSize, string path =
size = expectedSize;
lastProgressUpdateTime = DateTime.Now;

agent.Headers.Add("user-agent", Net.UserAgentString);
agent.Headers.Add("User-Agent", Net.UserAgentString);
}
}

Expand Down
39 changes: 26 additions & 13 deletions GUI/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using CKAN.Versioning;
using CKAN.Exporters;
using CKAN.Properties;
using CKAN.Types;
Expand Down Expand Up @@ -1142,7 +1143,7 @@ private void ModList_MouseDown(object sender, MouseEventArgs e)

private void reinstallToolStripMenuItem_Click(object sender, EventArgs e)
{
var module = ModInfoTabControl.SelectedModule;
GUIMod module = ModInfoTabControl.SelectedModule;
if (module == null || !module.IsCKAN)
return;

Expand All @@ -1151,21 +1152,33 @@ private void reinstallToolStripMenuItem_Click(object sender, EventArgs e)
if (reinstallDialog.ShowYesNoDialog(confirmationText) == DialogResult.No)
return;

ModuleInstaller installer = ModuleInstaller.GetInstance(CurrentInstance, currentUser);
var resolvedMod = installer.ResolveModules(toInstall, new RelationshipResolverOptions());
IRegistryQuerier registry = RegistryManager.Instance(CurrentInstance).registry;
KspVersionCriteria versCrit = CurrentInstance.VersionCriteria();

using (var transaction = CkanTransaction.CreateTransactionScope())
// Build the list of changes, first the mod to remove:
List<ModChange> toReinstall = new List<ModChange>()
{
SetDescription($"Uninstalling {module.Name}");
if (!WasSuccessful(() => installer.UninstallList(module.Identifier)))
return;

SetDescription($"Installing {module.Name}");
if (!WasSuccessful(() => installer.InstallList(resolvedMod, new RelationshipResolverOptions())))
return;

transaction.Complete();
new ModChange(module, GUIModChangeType.Remove, null)
};
// Then everything we need to re-install:
HashSet<string> goners = registry.FindReverseDependencies(
new List<string>() { module.Identifier }
);
foreach (string id in goners)
{
toReinstall.Add(new ModChange(
mainModList.full_list_of_mod_rows[id]?.Tag as GUIMod,
GUIModChangeType.Install,
null
));
}
// Hand off to centralized [un]installer code
installWorker.RunWorkerAsync(
new KeyValuePair<List<ModChange>, RelationshipResolverOptions>(
toReinstall,
RelationshipResolver.DefaultOpts()
)
);
}

private void downloadContentsToolStripMenuItem_Click(object sender, EventArgs e)
Expand Down
Loading