Skip to content

Commit

Permalink
added some stuff to core (check description)
Browse files Browse the repository at this point in the history
- Added List<string> FindReverseDependencies(string modName) to
Registry, so we can handle reverse dependencies on uninstall
- Registry.Available() now checks if all dependencies are present before
declaring a mod available
- Added Registry.Incompatible() which returns the list of incompatible
mods
- Some GUI additions
  • Loading branch information
AlexanderDzhoganov committed Oct 16, 2014
1 parent 0e36c20 commit 306cc03
Show file tree
Hide file tree
Showing 5 changed files with 296 additions and 68 deletions.
38 changes: 36 additions & 2 deletions CKAN/CKAN/ModuleInstaller.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Runtime.InteropServices;

namespace CKAN {

using System;
Expand Down Expand Up @@ -291,10 +293,43 @@ public class ModuleInstaller {
return;
}

public List<string> FindReverseDependencies(string modName) {
var rootMod = registry_manager.registry.installed_modules[modName].source_module;

List<string> reverseDependencies = new List<string>();

foreach (var keyValue in registry_manager.registry.installed_modules) {
var mod = keyValue.Value.source_module;
bool isDependency = false;

if (mod.depends != null)
{
foreach (dynamic dependency in mod.depends)
{
if (dependency.name == modName)
{
isDependency = true;
break;
}
}
}

if (isDependency) {
reverseDependencies.Add(mod.identifier);
}
}

return reverseDependencies;
}

public void Uninstall(string modName) {
// Find all mods that depend on this one
var reverseDependencies = FindReverseDependencies(modName);
foreach (var reverseDependency in reverseDependencies) {
Uninstall(reverseDependency);
}

// Walk our registry to find all files for this mod.

Dictionary<string, InstalledModuleFile> files = registry_manager.registry.installed_modules [modName].installed_files;

foreach (string file in files.Keys) {
Expand Down Expand Up @@ -333,7 +368,6 @@ public class ModuleInstaller {
registry_manager.Save ();

// And we're done! :)

return;
}
}
Expand Down
63 changes: 61 additions & 2 deletions CKAN/CKAN/Registry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,72 @@ public class Registry {
CkanModule available = LatestAvailable (candidate, ksp_version);

if (available != null) {
compatible.Add (available);
// we need to check that we can get everything we depend on
bool failedDepedency = false;

if (available.depends != null)
{
foreach (dynamic dependency in available.depends)
{
try
{
if (LatestAvailable((string)dependency.name, ksp_version) == null)
{
failedDepedency = true;
break;
}
}
catch (ModuleNotFoundException)
{
failedDepedency = true;
break;
}
}
}

if (!failedDepedency) {
compatible.Add(available);
}
}
}

return compatible;
}

/// <summary>
/// Returns a simple array of all incompatible modules for
/// the specified version of KSP (installed version by default)
/// </summary>

public List<CkanModule> Incompatible(KSPVersion ksp_version = null)
{

// Default to the user's current KSP install for version.
if (ksp_version == null)
{
ksp_version = KSP.Version();
}

var candidates = new List<string>(available_modules.Keys);
var incompatible = new List<CkanModule>();

// It's nice to see things in alphabetical order, so sort our keys first.
candidates.Sort();

// Now find what we can give our user.
foreach (string candidate in candidates)
{
CkanModule available = LatestAvailable(candidate, ksp_version);

if (available == null)
{
incompatible.Add(LatestAvailable(candidate, null));
}
}

return incompatible;
}

/// <summary>
/// Returns the latest available version of a module that
/// satisifes the specified version.
Expand All @@ -121,7 +180,7 @@ public class Registry {
return available_modules[module].Latest(ksp_version);
}
catch (KeyNotFoundException) {
throw new ModuleNotFoundException (module);
throw new ModuleNotFoundException(module);
}
}

Expand Down
3 changes: 2 additions & 1 deletion CKAN/CKAN/RelationshipResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,11 @@ public class RelationshipResolver {
try {
candidate = registry.LatestAvailable (dep_name);
}
catch (KeyNotFoundException) {
catch (ModuleNotFoundException) {
log.ErrorFormat ("Dependency on {0} found, but nothing provides it.", dep_name);
throw new ModuleNotFoundException (dep_name);
}

Add(candidate);
Resolve (candidate, options);
}
Expand Down
103 changes: 50 additions & 53 deletions CKAN/GUI/Main.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 306cc03

Please sign in to comment.