Skip to content

Commit

Permalink
Fix dialog on CLI replace command
Browse files Browse the repository at this point in the history
  • Loading branch information
politas committed Nov 29, 2017
1 parent d0e6ad2 commit 3ea1902
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 9 deletions.
45 changes: 38 additions & 7 deletions Cmdline/Action/Replace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public int RunCommand(CKAN.KSP ksp, object raw_options)
return Exit.BADOPT;
}

User.RaiseMessage("\r\nReplacing modules...\r\n");
var registry = RegistryManager.Instance(ksp).registry;
var to_replace = new List<ModuleReplacement>();

Expand Down Expand Up @@ -90,7 +89,7 @@ public int RunCommand(CKAN.KSP ksp, object raw_options)
try
{
// Check if replacement is available
ModuleReplacement replacement = registry.GetReplacement(mod, ksp.VersionCriteria());
ModuleReplacement replacement = registry.GetReplacement(modToReplace.identifier, ksp.VersionCriteria());
if (replacement != null)
{
// Replaceable
Expand All @@ -99,8 +98,16 @@ public int RunCommand(CKAN.KSP ksp, object raw_options)
replacement.ToReplace.identifier, replacement.ToReplace.version);
to_replace.Add(replacement);
}
log.InfoFormat("Attempt to replace {0} failed, replacement {1} is not compatible",
mod, modToReplace.replaced_by.name);
if (modToReplace.replaced_by != null)
{
log.InfoFormat("Attempt to replace {0} failed, replacement {1} is not compatible",
mod, modToReplace.replaced_by.name);
}
else
{
log.InfoFormat("Mod {0} has no replacement defined for the current version {1}",
modToReplace.identifier, modToReplace.version);
}
}
catch (ModuleNotFoundKraken)
{
Expand All @@ -115,9 +122,33 @@ public int RunCommand(CKAN.KSP ksp, object raw_options)
}
}
}
// TODO: These instances all need to go.
ModuleInstaller.GetInstance(ksp, User).Replace(to_replace, new NetAsyncModulesDownloader(User));
User.RaiseMessage("\r\nDone!\r\n");
if (to_replace.Count() != 0)
{
User.RaiseMessage("\r\nReplacing modules...\r\n");
foreach (ModuleReplacement r in to_replace)
{
User.RaiseMessage("Replacement {0} {1} found for {2} {3}",
r.ReplaceWith.identifier, r.ReplaceWith.version,
r.ToReplace.identifier, r.ToReplace.version);
}

bool ok = User.RaiseYesNoDialog("\r\nContinue?");

if (!ok)
{
User.RaiseMessage("Replacements canceled at user request.");
return Exit.ERROR;
}

// TODO: These instances all need to go.
ModuleInstaller.GetInstance(ksp, User).Replace(to_replace, new NetAsyncModulesDownloader(User));
User.RaiseMessage("\r\nDone!\r\n");
}
else
{
User.RaiseMessage("No replacements found.");
return Exit.OK;
}

return Exit.OK;
}
Expand Down
6 changes: 4 additions & 2 deletions Core/Registry/IRegistryQuerier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public interface IRegistryQuerier
/// Helpers for <see cref="IRegistryQuerier"/>
/// </summary>
public static class IRegistryQuerierHelpers
{
{
/// <summary>
/// Helper to call <see cref="IRegistryQuerier.GetModuleByVersion(string, Version)"/>
/// </summary>
Expand Down Expand Up @@ -175,8 +175,10 @@ public static ModuleReplacement GetReplacement( this IRegistryQuerier querier, s
}
if (installedVersion == null) return null; // Mod is not installed, so we don't care about replacements
//get the identifier from the replaced_by relationship, if it exists
RelationshipDescriptor replacedBy = installedVersion.replaced_by;
if (installedVersion.replaced_by == null) return null; // No replaced_by relationship

RelationshipDescriptor replacedBy = installedVersion.replaced_by;

// Now we need to see if there is a compatible version of the replacement
try
{
Expand Down

0 comments on commit 3ea1902

Please sign in to comment.