Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: KSP-CKAN/CKAN
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 12b1af47ffe2
Choose a base ref
...
head repository: KSP-CKAN/CKAN
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 3f438ffd830b
Choose a head ref
  • 2 commits
  • 45 files changed
  • 2 contributors

Commits on Oct 9, 2018

  1. Copy the full SHA
    30b4370 View commit details

Commits on Oct 13, 2018

  1. Copy the full SHA
    3f438ff View commit details
Showing with 1,058 additions and 395 deletions.
  1. +1 −0 CHANGELOG.md
  2. +193 −0 Cmdline/Action/Cache.cs
  3. +6 −4 Cmdline/Action/Import.cs
  4. +18 −3 Cmdline/Action/Install.cs
  5. +17 −3 Cmdline/Action/Remove.cs
  6. +17 −2 Cmdline/Action/Update.cs
  7. +19 −5 Cmdline/Action/Upgrade.cs
  8. +1 −0 Cmdline/CKAN-cmdline.csproj
  9. +12 −8 Cmdline/Main.cs
  10. +3 −0 Cmdline/Options.cs
  11. +3 −2 ConsoleUI/DownloadImportDialog.cs
  12. +1 −1 ConsoleUI/InstallScreen.cs
  13. +4 −4 ConsoleUI/ModInfoScreen.cs
  14. +2 −1 ConsoleUI/ModListScreen.cs
  15. +1 −52 Core/KSP.cs
  16. +73 −1 Core/KSPManager.cs
  17. +11 −17 Core/ModuleInstaller.cs
  18. +150 −17 Core/Net/NetFileCache.cs
  19. +17 −4 Core/Net/NetModuleCache.cs
  20. +4 −4 Core/Net/Repo.cs
  21. +40 −1 Core/Win32Registry.cs
  22. +5 −2 GUI/GUIMod.cs
  23. +1 −1 GUI/Main.cs
  24. +1 −1 GUI/MainChangeset.cs
  25. +1 −1 GUI/MainImport.cs
  26. +5 −5 GUI/MainInstall.cs
  27. +2 −2 GUI/MainModInfo.cs
  28. +1 −1 GUI/MainRepo.cs
  29. +142 −83 GUI/SettingsDialog.Designer.cs
  30. +63 −34 GUI/SettingsDialog.cs
  31. +8 −6 Netkan/Program.cs
  32. +1 −4 Tests/Core/Cache.cs
  33. +122 −0 Tests/Core/FakeWin32Registry.cs
  34. +0 −1 Tests/Core/KSP.cs
  35. +11 −71 Tests/Core/KSPManager.cs
  36. +47 −22 Tests/Core/ModuleInstaller.cs
  37. +4 −2 Tests/Core/ModuleInstallerDirTest.cs
  38. +13 −12 Tests/Core/Net/NetAsyncModulesDownloader.cs
  39. +0 −2 Tests/Data/DisposableKSP.cs
  40. +7 −4 Tests/GUI/GH1866.cs
  41. +6 −1 Tests/GUI/GUIMod.cs
  42. +14 −3 Tests/GUI/MainModList.cs
  43. +5 −4 Tests/NetKAN/Sources/Curse/CurseApiTests.cs
  44. +5 −4 Tests/NetKAN/Sources/Spacedock/SpacedockApiTests.cs
  45. +1 −0 Tests/Tests.csproj
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ All notable changes to this project will be documented in this file.
- [Multiple] Add download count column to GUI (#2518 by: HebaruSan; reviewed: politas)
- [Netkan] Catch invalid $kref in Netkan (#2516 by: HebaruSan; reviewed: politas)
- [Netkan] Handle KSP-AVC krefs (#2517 by: HebaruSan; reviewed: politas)
- [Multiple] One Cache to Rule Them All (#2535 by: HebaruSan; reviewed: politas)

### Bugfixes
- [GUI] Show innermost download exceptions (#2528 by: HebaruSan; reviewed: politas)
193 changes: 193 additions & 0 deletions Cmdline/Action/Cache.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
using System;
using System.Linq;
using CommandLine;
using CommandLine.Text;
using log4net;
using CKAN.Versioning;

namespace CKAN.CmdLine
{
public class Cache : ISubCommand
{
public Cache() { }

private class CacheSubOptions : VerbCommandOptions
{
[VerbOption("list", HelpText = "List the download cache path")]
public CommonOptions ListOptions { get; set; }

[VerbOption("set", HelpText = "Set the download cache path")]
public SetOptions SetOptions { get; set; }

[VerbOption("clear", HelpText = "Clear the download cache directory")]
public CommonOptions ClearOptions { get; set; }

[VerbOption("reset", HelpText = "Set the download cache path to the default")]
public CommonOptions ResetOptions { get; set; }

[HelpVerbOption]
public string GetUsage(string verb)
{
HelpText ht = HelpText.AutoBuild(this, verb);
// Add a usage prefix line
ht.AddPreOptionsLine(" ");
if (string.IsNullOrEmpty(verb))
{
ht.AddPreOptionsLine("ckan cache - Manage the download cache path of CKAN");
ht.AddPreOptionsLine($"Usage: ckan cache <command> [options]");
}
else
{
ht.AddPreOptionsLine("cache " + verb + " - " + GetDescription(verb));
switch (verb)
{
// First the commands with one string argument
case "set":
ht.AddPreOptionsLine($"Usage: ckan cache {verb} [options] path");
break;

// Now the commands with only --flag type options
case "list":
case "clear":
case "reset":
default:
ht.AddPreOptionsLine($"Usage: ckan cache {verb} [options]");
break;
}
}
return ht;
}
}

private class SetOptions : CommonOptions
{
[ValueOption(0)]
public string Path { get; set; }
}

/// <summary>
/// Execute a cache subcommand
/// </summary>
/// <param name="mgr">KSPManager object containing our instances and cache</param>
/// <param name="opts">Command line options object</param>
/// <param name="unparsed">Raw command line options</param>
/// <returns>
/// Exit code for shell environment
/// </returns>
public int RunSubCommand(KSPManager mgr, CommonOptions opts, SubCommandOptions unparsed)
{
string[] args = unparsed.options.ToArray();

int exitCode = Exit.OK;
// Parse and process our sub-verbs
Parser.Default.ParseArgumentsStrict(args, new CacheSubOptions(), (string option, object suboptions) =>
{
// ParseArgumentsStrict calls us unconditionally, even with bad arguments
if (!string.IsNullOrEmpty(option) && suboptions != null)
{
CommonOptions options = (CommonOptions)suboptions;
options.Merge(opts);
user = new ConsoleUser(options.Headless);
manager = mgr ?? new KSPManager(user);
exitCode = options.Handle(manager, user);
if (exitCode != Exit.OK)
return;

switch (option)
{
case "list":
exitCode = ListCacheDirectory((CommonOptions)suboptions);
break;

case "set":
exitCode = SetCacheDirectory((SetOptions)suboptions);
break;

case "clear":
exitCode = ClearCacheDirectory((CommonOptions)suboptions);
break;

case "reset":
exitCode = ResetCacheDirectory((CommonOptions)suboptions);
break;

default:
user.RaiseMessage("Unknown command: cache {0}", option);
exitCode = Exit.BADOPT;
break;
}
}
}, () => { exitCode = MainClass.AfterHelp(); });
return exitCode;
}

private int ListCacheDirectory(CommonOptions options)
{
IWin32Registry winReg = new Win32Registry();
user.RaiseMessage(winReg.DownloadCacheDir);
printCacheInfo();
return Exit.OK;
}

private int SetCacheDirectory(SetOptions options)
{
if (string.IsNullOrEmpty(options.Path))
{
user.RaiseError("set <path> - argument missing, perhaps you forgot it?");
return Exit.BADOPT;
}

string failReason;
if (manager.TrySetupCache(options.Path, out failReason))
{
IWin32Registry winReg = new Win32Registry();
user.RaiseMessage($"Download cache set to {winReg.DownloadCacheDir}");
printCacheInfo();
return Exit.OK;
}
else
{
user.RaiseError($"Invalid path: {failReason}");
return Exit.BADOPT;
}
}

private int ClearCacheDirectory(CommonOptions options)
{
manager.Cache.RemoveAll();
user.RaiseMessage("Download cache cleared.");
printCacheInfo();
return Exit.OK;
}

private int ResetCacheDirectory(CommonOptions options)
{
string failReason;
if (manager.TrySetupCache("", out failReason))
{
IWin32Registry winReg = new Win32Registry();
user.RaiseMessage($"Download cache reset to {winReg.DownloadCacheDir}");
printCacheInfo();
}
else
{
user.RaiseError($"Can't reset cache path: {failReason}");
}
return Exit.OK;
}

private void printCacheInfo()
{
int fileCount;
long bytes;
manager.Cache.GetSizeInfo(out fileCount, out bytes);
user.RaiseMessage($"{fileCount} files, {CkanModule.FmtSize(bytes)}");
}

private KSPManager manager;
private IUser user;

private static readonly ILog log = LogManager.GetLogger(typeof(Cache));
}

}
10 changes: 6 additions & 4 deletions Cmdline/Action/Import.cs
Original file line number Diff line number Diff line change
@@ -17,8 +17,9 @@ public class Import : ICommand
/// Initialize the command
/// </summary>
/// <param name="user">IUser object for user interaction</param>
public Import(IUser user)
public Import(KSPManager mgr, IUser user)
{
manager = mgr;
this.user = user;
}

@@ -45,7 +46,7 @@ public int RunCommand(CKAN.KSP ksp, object options)
{
log.InfoFormat("Importing {0} files", toImport.Count);
List<string> toInstall = new List<string>();
ModuleInstaller inst = ModuleInstaller.GetInstance(ksp, user);
ModuleInstaller inst = ModuleInstaller.GetInstance(ksp, manager.Cache, user);
inst.ImportFiles(toImport, user, mod => toInstall.Add(mod.identifier), !opts.Headless);
if (toInstall.Count > 0)
{
@@ -99,8 +100,9 @@ private void AddFile(HashSet<FileInfo> files, string filename)
}
}

private readonly IUser user;
private static readonly ILog log = LogManager.GetLogger(typeof(Import));
private readonly KSPManager manager;
private readonly IUser user;
private static readonly ILog log = LogManager.GetLogger(typeof(Import));
}

}
21 changes: 18 additions & 3 deletions Cmdline/Action/Install.cs
Original file line number Diff line number Diff line change
@@ -9,12 +9,27 @@ public class Install : ICommand
private static readonly ILog log = LogManager.GetLogger(typeof(Install));

public IUser user { get; set; }
private KSPManager manager;

public Install(IUser user)
/// <summary>
/// Initialize the install command object
/// </summary>
/// <param name="mgr">KSPManager containing our instances</param>
/// <param name="user">IUser object for interaction</param>
public Install(KSPManager mgr, IUser user)
{
manager = mgr;
this.user = user;
}

/// <summary>
/// Installs a module, if available
/// </summary>
/// <param name="ksp">Game instance into which to install</param>
/// <param name="raw_options">Command line options object</param>
/// <returns>
/// Exit code for shell environment
/// </returns>
public int RunCommand(CKAN.KSP ksp, object raw_options)
{
InstallOptions options = (InstallOptions) raw_options;
@@ -113,7 +128,7 @@ public int RunCommand(CKAN.KSP ksp, object raw_options)
// Install everything requested. :)
try
{
var installer = ModuleInstaller.GetInstance(ksp, user);
var installer = ModuleInstaller.GetInstance(ksp, manager.Cache, user);
installer.InstallList(options.modules, install_ops);
}
catch (DependencyNotSatisfiedKraken ex)
@@ -187,7 +202,7 @@ public int RunCommand(CKAN.KSP ksp, object raw_options)
// Add the module to the list.
options.modules.Add(ex.modules[result].identifier);

return (new Install(user).RunCommand(ksp, options));
return (new Install(manager, user).RunCommand(ksp, options));
}
catch (FileExistsKraken ex)
{
20 changes: 17 additions & 3 deletions Cmdline/Action/Remove.cs
Original file line number Diff line number Diff line change
@@ -10,13 +10,27 @@ public class Remove : ICommand
private static readonly ILog log = LogManager.GetLogger(typeof(Remove));

public IUser user { get; set; }
private KSPManager manager;

public Remove(IUser user)
/// <summary>
/// Initialize the remove command object
/// </summary>
/// <param name="mgr">KSPManager containing our instances</param>
/// <param name="user">IUser object for interaction</param>
public Remove(KSPManager mgr, IUser user)
{
manager = mgr;
this.user = user;
}

// Uninstalls a module, if it exists.
/// <summary>
/// Uninstalls a module, if it exists.
/// </summary>
/// <param name="ksp">Game instance from which to remove</param>
/// <param name="raw_options">Command line options object</param>
/// <returns>
/// Exit code for shell environment
/// </returns>
public int RunCommand(CKAN.KSP ksp, object raw_options)
{

@@ -62,7 +76,7 @@ public int RunCommand(CKAN.KSP ksp, object raw_options)
{
try
{
var installer = ModuleInstaller.GetInstance(ksp, user);
var installer = ModuleInstaller.GetInstance(ksp, manager.Cache, user);
Search.AdjustModulesCase(ksp, options.modules);
installer.UninstallList(options.modules);
}
19 changes: 17 additions & 2 deletions Cmdline/Action/Update.cs
Original file line number Diff line number Diff line change
@@ -6,12 +6,27 @@ namespace CKAN.CmdLine
public class Update : ICommand
{
public IUser user { get; set; }
private KSPManager manager;

public Update(IUser user)
/// <summary>
/// Initialize the update command object
/// </summary>
/// <param name="mgr">KSPManager containing our instances</param>
/// <param name="user">IUser object for interaction</param>
public Update(KSPManager mgr, IUser user)
{
manager = mgr;
this.user = user;
}

/// <summary>
/// Update the registry
/// </summary>
/// <param name="ksp">Game instance to update</param>
/// <param name="raw_options">Command line options object</param>
/// <returns>
/// Exit code for shell environment
/// </returns>
public int RunCommand(CKAN.KSP ksp, object raw_options)
{
UpdateOptions options = (UpdateOptions) raw_options;
@@ -135,7 +150,7 @@ private void UpdateRepository(CKAN.KSP ksp, string repository = null)
RegistryManager registry_manager = RegistryManager.Instance(ksp);

var updated = repository == null
? CKAN.Repo.UpdateAllRepositories(registry_manager, ksp, user)
? CKAN.Repo.UpdateAllRepositories(registry_manager, ksp, manager.Cache, user)
: CKAN.Repo.Update(registry_manager, ksp, user, repository);

user.RaiseMessage("Updated information on {0} available modules", updated);
Loading