Skip to content

Commit

Permalink
Merge branch 'stable'
Browse files Browse the repository at this point in the history
* stable:
  (GH-305) Uninstaller confirm when not silent
  (maint) formatting
  • Loading branch information
ferventcoder committed Jun 4, 2015
2 parents d32c591 + b5bef7c commit 161c18b
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 11 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 @@ -15,9 +15,7 @@

namespace chocolatey.infrastructure.app.domain
{
using System;
using System.Collections.Generic;
using System.Text;

/// <summary>
/// InstallShield Installer Options
Expand All @@ -40,8 +38,8 @@ public InstallShieldInstaller()
SilentUninstall = "/uninst /s";
OtherUninstallOptions = "/sms";
// http://helpnet.installshield.com/installshield18helplib/IHelpSetup_EXEErrors.htm
ValidInstallExitCodes = new List<int> { 0, 1641, 3010 };
ValidUninstallExitCodes = new List<int> { 0, 1641, 3010 };
ValidInstallExitCodes = new List<int> {0, 1641, 3010};
ValidUninstallExitCodes = new List<int> {0, 1641, 3010};
}

public override InstallerType InstallerType
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 161c18b

Please sign in to comment.