Skip to content

Commit

Permalink
(GH-305) Find the installer type every time
Browse files Browse the repository at this point in the history
Only build uninstall command args if there is no silent uninstall key,
but allow setting up the proper uninstaller for other actions.
  • Loading branch information
ferventcoder committed Jun 4, 2015
1 parent 763ac49 commit 44431e6
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public override void Context()
CommandExecutor.initialize_with(new Lazy<IFileSystem>(() => fileSystem.Object), () => process.Object);

service = new AutomaticUninstallerService(packageInfoService.Object, fileSystem.Object, registryService.Object, commandExecutor.Object);
service.WaitForCleanup = false;
config.Features.AutoUninstaller = true;
package.Setup(p => p.Id).Returns("regular");
package.Setup(p => p.Version).Returns(new SemanticVersion("1.2.0"));
Expand Down Expand Up @@ -307,6 +308,7 @@ public class when_AutomaticUninstallerService_defines_uninstall_switches : Autom
{
private Action because;
private readonly string registryUninstallArgs = "/bob";
private readonly string logLocation = "c:\\yes\\dude\\1.2.3-beta";

public override void Because()
{
Expand All @@ -332,12 +334,15 @@ private void test_installertype(IInstaller installer, bool hasQuietUninstallStri
InstallerType = installer.InstallerType,
});
packageInformation.RegistrySnapshot = new Registry("123", registryKeys);
fileSystem.Setup(x => x.combine_paths(config.CacheLocation, It.IsAny<string>(), It.IsAny<string>())).Returns(logLocation);

because();

var uninstallArgs = !hasQuietUninstallString ? registryUninstallArgs.trim_safe() + " " + installer.build_uninstall_command_arguments().trim_safe() : registryUninstallArgs.trim_safe();
var installerTypeArgs = installer.build_uninstall_command_arguments().trim_safe().Replace(InstallTokens.PACKAGE_LOCATION, logLocation);

commandExecutor.Verify(c => c.execute(expectedUninstallString, uninstallArgs, It.IsAny<int>(), It.IsAny<Action<object, DataReceivedEventArgs>>(), It.IsAny<Action<object, DataReceivedEventArgs>>(), It.IsAny<bool>()), Times.Once);
var uninstallArgs = !hasQuietUninstallString ? registryUninstallArgs.trim_safe() + " " + installerTypeArgs : registryUninstallArgs.trim_safe();

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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ public AutomaticUninstallerService(IChocolateyPackageInformationService packageI
_fileSystem = fileSystem;
_registryService = registryService;
_commandExecutor = commandExecutor;
WaitForCleanup = true;
}

public bool WaitForCleanup { get; set; }

public void run(PackageResult packageResult, ChocolateyConfiguration config)
{
if (!config.Features.AutoUninstaller)
Expand All @@ -65,9 +68,12 @@ public void run(PackageResult packageResult, ChocolateyConfiguration config)
}

this.Log().Info(" Running auto uninstaller...");
this.Log().Debug("Sleeping for {0} seconds to allow Windows to finish cleaning up.".format_with(SLEEP_TIME));
Thread.Sleep((int)TimeSpan.FromSeconds(SLEEP_TIME).TotalMilliseconds);

if (WaitForCleanup)
{
this.Log().Debug("Sleeping for {0} seconds to allow Windows to finish cleaning up.".format_with(SLEEP_TIME));
Thread.Sleep((int)TimeSpan.FromSeconds(SLEEP_TIME).TotalMilliseconds);
}

foreach (var key in registryKeys.or_empty_list_if_null())
{
this.Log().Debug(() => " Preparing uninstall key '{0}'".format_with(key.UninstallString));
Expand All @@ -86,37 +92,28 @@ public void run(PackageResult packageResult, ChocolateyConfiguration config)
var uninstallArgs = key.UninstallString.to_string().Replace(uninstallExe.to_string(), string.Empty);
uninstallExe = uninstallExe.remove_surrounding_quotes();
this.Log().Debug(() => " Uninstaller path is '{0}'".format_with(uninstallExe));

if (!key.HasQuietUninstall)


IInstaller installer = new CustomInstaller();

switch (key.InstallerType)
{
IInstaller installer = new CustomInstaller();

switch (key.InstallerType)
{
case InstallerType.Msi:
installer = new MsiInstaller();
break;
case InstallerType.InnoSetup:
installer = new InnoSetupInstaller();
break;
case InstallerType.Nsis:
installer = new NsisInstaller();
break;
case InstallerType.InstallShield:
installer = new InstallShieldInstaller();
break;
default:
// skip
break;
}

this.Log().Debug(() => " Installer type is '{0}'".format_with(installer.GetType().Name));


//todo: ultimately we should merge keys with logging
uninstallArgs += " " + installer.build_uninstall_command_arguments();
case InstallerType.Msi:
installer = new MsiInstaller();
break;
case InstallerType.InnoSetup:
installer = new InnoSetupInstaller();
break;
case InstallerType.Nsis:
installer = new NsisInstaller();
break;
case InstallerType.InstallShield:
installer = new InstallShieldInstaller();
break;
}

this.Log().Debug(() => " Installer type is '{0}'".format_with(installer.GetType().Name));

if (key.InstallerType == InstallerType.Msi)
{
// because sometimes the key is set with /i to allow for modify :/
Expand All @@ -126,6 +123,14 @@ public void run(PackageResult packageResult, ChocolateyConfiguration config)
uninstallArgs = uninstallArgs.Replace("/i ", "/X ");
}

if (!key.HasQuietUninstall)
{
//todo: ultimately we should merge keys
uninstallArgs += " " + installer.build_uninstall_command_arguments();
var logLocation = _fileSystem.combine_paths(config.CacheLocation, pkgInfo.Package.Id, pkgInfo.Package.Version.to_string());
uninstallArgs = uninstallArgs.Replace(InstallTokens.PACKAGE_LOCATION, logLocation);
}

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

var exitCode = _commandExecutor.execute(
Expand Down Expand Up @@ -153,7 +158,7 @@ public void run(PackageResult packageResult, ChocolateyConfiguration config)
}
else
{
this.Log().Info(() => " Auto uninstaller has successfully uninstalled {0} from your machine.".format_with(packageResult.Package.Id));
this.Log().Info(() => " Auto uninstaller has successfully uninstalled {0} or detected previous uninstall.".format_with(packageResult.Package.Id));
}
}
}
Expand Down

0 comments on commit 44431e6

Please sign in to comment.