Skip to content

Commit

Permalink
(GH-305) Uninstaller confirm when not silent
Browse files Browse the repository at this point in the history
When not silent, the uninstaller should confirm with the user or skip
the attempt if confirm is already selected.
  • Loading branch information
ferventcoder committed Jun 4, 2015
1 parent c8d9630 commit b5bef7c
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public override void Context()
service = new AutomaticUninstallerService(packageInfoService.Object, fileSystem.Object, registryService.Object, commandExecutor.Object);
service.WaitForCleanup = false;
config.Features.AutoUninstaller = true;
config.PromptForConfirmation = false;
package.Setup(p => p.Id).Returns("regular");
package.Setup(p => p.Version).Returns(new SemanticVersion("1.2.0"));
packageResult = new PackageResult(package.Object, null);
Expand All @@ -68,8 +69,9 @@ public override void Context()
{
InstallLocation = @"C:\Program Files (x86)\WinDirStat",
UninstallString = originalUninstallString,
HasQuietUninstall = false,
HasQuietUninstall = true,
KeyPath = @"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\WinDirStat",
InstallerType = installerType.InstallerType,
});
packageInformation.RegistrySnapshot = new Registry("123", registryKeys);
packageInfoService.Setup(s => s.get_package_information(package.Object)).Returns(packageInformation);
Expand Down Expand Up @@ -203,7 +205,7 @@ public override void Context()
{
InstallLocation = string.Empty,
UninstallString = originalUninstallString,
HasQuietUninstall = false,
HasQuietUninstall = true,
KeyPath = @"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\WinDirStat"
});
packageInformation.RegistrySnapshot = new Registry("123", registryKeys);
Expand Down Expand Up @@ -303,6 +305,47 @@ public void should_call_command_executor()
commandExecutor.Verify(c => c.execute(expectedUninstallString, installerType.build_uninstall_command_arguments().trim_safe(), It.IsAny<int>(), It.IsAny<Action<object, DataReceivedEventArgs>>(), It.IsAny<Action<object, DataReceivedEventArgs>>(), It.IsAny<bool>()), Times.Once);
}
}

public class when_AutomaticUninstallerService_cannot_determine_silent_install_arguments : AutomaticUninstallerServiceSpecsBase
{

public override void Context()
{
base.Context();
registryKeys.Clear();
commandExecutor.ResetCalls();
registryKeys.Add(new RegistryApplicationKey
{
InstallLocation = @"C:\Program Files (x86)\WinDirStat",
UninstallString = "{0} {1}".format_with(originalUninstallString, "/bob"),
HasQuietUninstall = false,
KeyPath = @"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\WinDirStat",
InstallerType = InstallerType.Unknown,
});
packageInformation.RegistrySnapshot = new Registry("123", registryKeys);
fileSystem.Setup(x => x.combine_paths(config.CacheLocation, It.IsAny<string>(), It.IsAny<string>())).Returns("");

}

// under normal circumstances, it prompts so the user can decide, but if -y is passed it will skip

public override void Because()
{
service.run(packageResult, config);
}

[Fact]
public void should_log_why_it_skips_auto_uninstaller()
{
MockLogger.Verify(l => l.Info(" Skipping auto uninstaller - Installer type was not detected and no silent uninstall key exists."), Times.Once);
}

[Fact]
public void should_not_call_command_executor()
{
commandExecutor.Verify(c => c.execute(It.IsAny<String>(), It.IsAny<String>(), It.IsAny<int>(), It.IsAny<Action<object, DataReceivedEventArgs>>(), It.IsAny<Action<object, DataReceivedEventArgs>>(), It.IsAny<bool>()), Times.Never);
}
}

public class when_AutomaticUninstallerService_defines_uninstall_switches : AutomaticUninstallerServiceSpecsBase
{
Expand Down Expand Up @@ -345,11 +388,11 @@ private void test_installertype(IInstaller installer, bool hasQuietUninstallStri
commandExecutor.Verify(c => c.execute(expectedUninstallString, uninstallArgs.trim_safe(), It.IsAny<int>(), It.IsAny<Action<object, DataReceivedEventArgs>>(), It.IsAny<Action<object, DataReceivedEventArgs>>(), It.IsAny<bool>()), Times.Once);
}

[Fact]
public void should_use_CustomInstaller_uninstall_args_when_installtype_is_unknown_and_has_quiet_uninstall_is_false()
{
test_installertype(new CustomInstaller(), hasQuietUninstallString: false);
}
//[Fact]
//public void should_use_CustomInstaller_uninstall_args_when_installtype_is_unknown_and_has_quiet_uninstall_is_false()
//{
// test_installertype(new CustomInstaller(), hasQuietUninstallString: false);
//}

[Fact]
public void should_use_registry_uninstall_args_when_installtype_is_unknown_and_has_quiet_uninstall_is_true()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace chocolatey.infrastructure.app.services
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using commandline;
using configuration;
using domain;
using filesystem;
Expand Down Expand Up @@ -133,6 +134,22 @@ public void run(PackageResult packageResult, ChocolateyConfiguration config)

this.Log().Debug(() => " Args are '{0}'".format_with(uninstallArgs));

if (!key.HasQuietUninstall && installer.GetType() == typeof(CustomInstaller))
{
var skipUninstaller = true;
if (config.PromptForConfirmation)
{
var selection = InteractivePrompt.prompt_for_confirmation("Uninstall may not be silent (could not detect). Proceed?", new[] {"yes", "no"}, defaultChoice: null, requireAnswer: true);
if (selection.is_equal_to("no")) skipUninstaller = false;
}

if (skipUninstaller)
{
this.Log().Info(" Skipping auto uninstaller - Installer type was not detected and no silent uninstall key exists.");
return;
}
}

var exitCode = _commandExecutor.execute(
uninstallExe,
uninstallArgs.trim_safe(),
Expand Down

0 comments on commit b5bef7c

Please sign in to comment.