Skip to content

Commit

Permalink
Merge branch 'stable'
Browse files Browse the repository at this point in the history
* stable:
  (GH-296) add 1605 for valid MSI exit code
  (GH-305) Installer Type Validate Exit Code
  (GH-305) Find the installer type every time
  (maint) formatting
  (GH-304) Auto Installer allow system cleanup
  (GH-305) Clean up installer types
  • Loading branch information
ferventcoder committed Jun 4, 2015
2 parents e3a0016 + c1ff5e1 commit d32c591
Show file tree
Hide file tree
Showing 11 changed files with 145 additions and 159 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
1 change: 1 addition & 0 deletions src/chocolatey/chocolatey.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
<Compile Include="infrastructure.app\configuration\PackagesConfigFilePackageSetting.cs" />
<Compile Include="infrastructure.app\configuration\PackagesConfigFileSettings.cs" />
<Compile Include="infrastructure.app\domain\FeatureCommandType.cs" />
<Compile Include="infrastructure.app\domain\InstallerBase.cs" />
<Compile Include="infrastructure.app\domain\PackageFile.cs" />
<Compile Include="infrastructure.app\domain\PackageFiles.cs" />
<Compile Include="infrastructure.app\domain\PinCommandType.cs" />
Expand Down
31 changes: 11 additions & 20 deletions src/chocolatey/infrastructure.app/domain/CustomInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@

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

public class CustomInstaller : IInstaller
public class CustomInstaller : InstallerBase
{
public CustomInstaller()
{
Expand All @@ -32,34 +31,26 @@ public CustomInstaller()
UninstallExecutable = "\"{0}\"".format_with(InstallTokens.UNINSTALLER_LOCATION);
SilentUninstall = "/S";
OtherUninstallOptions = "";
ValidExitCodes = new List<int> {0};
ValidInstallExitCodes = new List<int> { 0 };
ValidUninstallExitCodes = new List<int> { 0 };
}

public InstallerType InstallerType
public override InstallerType InstallerType
{
get { return InstallerType.Custom; }
}

public string InstallExecutable { get; private set; }
public string SilentInstall { get; private set; }
public string NoReboot { get; private set; }
public string LogFile { get; private set; }
public string CustomInstallLocation { get; private set; }
public string Language { get; private set; }
public string OtherInstallOptions { get; private set; }
public string UninstallExecutable { get; private set; }
public string SilentUninstall { get; private set; }
public string OtherUninstallOptions { get; private set; }
public IEnumerable<int> ValidExitCodes { get; private set; }

public string build_install_command_arguments()
public override string build_install_command_arguments(bool customInstallLocation, bool languageRequested)
{
throw new NotImplementedException();
if (customInstallLocation) this.Log().Warn("CustomInstaller doesn't support custom install locations.");
if (languageRequested) this.Log().Warn("CustomInstaller doesn't support custom language options.");

return string.Empty;
}

public string build_uninstall_command_arguments()
public override string build_uninstall_command_arguments()
{
return "{0} {1}".format_with(SilentUninstall, OtherInstallOptions);
return string.Empty;
}
}
}
5 changes: 3 additions & 2 deletions src/chocolatey/infrastructure.app/domain/IInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ public interface IInstaller
string UninstallExecutable { get; }
string SilentUninstall { get; }
string OtherUninstallOptions { get; }
IEnumerable<int> ValidExitCodes { get; }
IEnumerable<int> ValidInstallExitCodes { get; }
IEnumerable<int> ValidUninstallExitCodes { get; }

string build_install_command_arguments();
string build_install_command_arguments(bool customInstallLocation, bool languageRequested);
string build_uninstall_command_arguments();
}
}
30 changes: 5 additions & 25 deletions src/chocolatey/infrastructure.app/domain/InnoSetupInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace chocolatey.infrastructure.app.domain
/// <remarks>
/// http://www.jrsoftware.org/ishelp/index.php?topic=setupcmdline
/// </remarks>
public class InnoSetupInstaller : IInstaller
public class InnoSetupInstaller : InstallerBase
{
public InnoSetupInstaller()
{
Expand All @@ -38,34 +38,14 @@ public InnoSetupInstaller()
UninstallExecutable = "\"{0}\"".format_with(InstallTokens.UNINSTALLER_LOCATION);
SilentUninstall = "/VERYSILENT";
OtherUninstallOptions = "/SUPPRESSMSGBOXES";
ValidExitCodes = new List<int> {0};
// http://www.jrsoftware.org/ishelp/index.php?topic=setupexitcodes
ValidInstallExitCodes = new List<int> { 0 };
ValidUninstallExitCodes = new List<int> { 0 };
}

public InstallerType InstallerType
public override InstallerType InstallerType
{
get { return InstallerType.InnoSetup; }
}

public string InstallExecutable { get; private set; }
public string SilentInstall { get; private set; }
public string NoReboot { get; private set; }
public string LogFile { get; private set; }
public string CustomInstallLocation { get; private set; }
public string Language { get; private set; }
public string OtherInstallOptions { get; private set; }
public string UninstallExecutable { get; private set; }
public string SilentUninstall { get; private set; }
public string OtherUninstallOptions { get; private set; }
public IEnumerable<int> ValidExitCodes { get; private set; }

public string build_install_command_arguments()
{
throw new NotImplementedException();
}

public string build_uninstall_command_arguments()
{
return "{0} {1} {2}".format_with(SilentUninstall, NoReboot, OtherUninstallOptions);
}
}
}
31 changes: 6 additions & 25 deletions src/chocolatey/infrastructure.app/domain/InstallShieldInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ namespace chocolatey.infrastructure.app.domain
{
using System;
using System.Collections.Generic;
using System.Text;

/// <summary>
/// InstallShield Installer Options
/// </summary>
/// <remarks>
/// http://helpnet.installshield.com/installshield18helplib/ihelpsetup_execmdline.htm
/// </remarks>
public class InstallShieldInstaller : IInstaller
public class InstallShieldInstaller : InstallerBase
{
public InstallShieldInstaller()
{
Expand All @@ -38,34 +39,14 @@ public InstallShieldInstaller()
UninstallExecutable = "\"{0}\"".format_with(InstallTokens.UNINSTALLER_LOCATION);
SilentUninstall = "/uninst /s";
OtherUninstallOptions = "/sms";
ValidExitCodes = new List<int> {0};
// http://helpnet.installshield.com/installshield18helplib/IHelpSetup_EXEErrors.htm
ValidInstallExitCodes = new List<int> { 0, 1641, 3010 };
ValidUninstallExitCodes = new List<int> { 0, 1641, 3010 };
}

public InstallerType InstallerType
public override InstallerType InstallerType
{
get { return InstallerType.InstallShield; }
}

public string InstallExecutable { get; private set; }
public string SilentInstall { get; private set; }
public string NoReboot { get; private set; }
public string LogFile { get; private set; }
public string CustomInstallLocation { get; private set; }
public string Language { get; private set; }
public string OtherInstallOptions { get; private set; }
public string UninstallExecutable { get; private set; }
public string SilentUninstall { get; private set; }
public string OtherUninstallOptions { get; private set; }
public IEnumerable<int> ValidExitCodes { get; private set; }

public string build_install_command_arguments()
{
throw new NotImplementedException();
}

public string build_uninstall_command_arguments()
{
return "{0} {1} {2}".format_with(SilentUninstall, NoReboot, OtherUninstallOptions);
}
}
}
56 changes: 56 additions & 0 deletions src/chocolatey/infrastructure.app/domain/InstallerBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright © 2011 - Present RealDimensions Software, LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
//
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

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

public abstract class InstallerBase : IInstaller
{
public abstract InstallerType InstallerType { get; }

public string InstallExecutable { get; protected set; }
public string SilentInstall { get; protected set; }
public string NoReboot { get; protected set; }
public string LogFile { get; protected set; }
public string OtherInstallOptions { get; protected set; }
public string CustomInstallLocation { get; protected set; }
public string Language { get; protected set; }
public string UninstallExecutable { get; protected set; }
public string SilentUninstall { get; protected set; }
public string OtherUninstallOptions { get; protected set; }
public IEnumerable<int> ValidInstallExitCodes { get; protected set; }
public IEnumerable<int> ValidUninstallExitCodes { get; protected set; }

public virtual string build_install_command_arguments(bool customInstallLocation, bool languageRequested)
{
var args = new StringBuilder();
args.AppendFormat("{0} {1} {2}", SilentInstall, NoReboot, LogFile);
if (languageRequested) args.AppendFormat(" {0}", Language);
args.AppendFormat(" {0}", OtherInstallOptions);

// custom install location must be last for NSIS
if (customInstallLocation) args.AppendFormat(" {0}", CustomInstallLocation);

return args.ToString();
}

public virtual string build_uninstall_command_arguments()
{
return "{0} {1} {2} {3}".format_with(SilentUninstall, NoReboot, LogFile, OtherUninstallOptions);
}
}
}
35 changes: 9 additions & 26 deletions src/chocolatey/infrastructure.app/domain/MsiInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

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

/// <summary>
Expand All @@ -28,7 +27,7 @@ namespace chocolatey.infrastructure.app.domain
/// http://www.advancedinstaller.com/user-guide/msiexec.html
/// 1603 search for return value 3 http://blogs.msdn.com/b/astebner/archive/2005/08/01/446328.aspx
/// </remarks>
public class MsiInstaller : IInstaller
public class MsiInstaller : InstallerBase
{
public MsiInstaller()
{
Expand All @@ -44,37 +43,21 @@ public MsiInstaller()
// http://msdn.microsoft.com/en-us/library/aa367559.aspx
OtherInstallOptions = "ALLUSERS=1 DISABLEDESKTOPSHORTCUT=1 ADDDESKTOPICON=0 ADDSTARTMENU=0";
UninstallExecutable = "msiexec.exe";
//todo: eventually will need this
//SilentUninstall = "/qn /x{0}".format_with(InstallTokens.UNINSTALLER_LOCATION);
SilentUninstall = "/qn";
OtherUninstallOptions = "";
ValidExitCodes = new List<int> {0, 3010};
// https://msdn.microsoft.com/en-us/library/aa376931.aspx
// https://support.microsoft.com/en-us/kb/290158
ValidInstallExitCodes = new List<int> {0, 1641, 3010};
// we allow unknown 1605/1614 b/c it may have already been uninstalled
// and that's okay
ValidUninstallExitCodes = new List<int> {0, 1605, 1614, 1641, 3010};
}

public InstallerType InstallerType
public override InstallerType InstallerType
{
get { return InstallerType.Msi; }
}

public string InstallExecutable { get; private set; }
public string SilentInstall { get; private set; }
public string NoReboot { get; private set; }
public string LogFile { get; private set; }
public string OtherInstallOptions { get; private set; }
public string CustomInstallLocation { get; private set; }
public string Language { get; private set; }
public string UninstallExecutable { get; private set; }
public string SilentUninstall { get; private set; }
public string OtherUninstallOptions { get; private set; }
public IEnumerable<int> ValidExitCodes { get; private set; }

public string build_install_command_arguments()
{
throw new NotImplementedException();
}

public string build_uninstall_command_arguments()
{
return "{0} {1} {2}".format_with(SilentUninstall, NoReboot, OtherUninstallOptions);
}
}
}
Loading

0 comments on commit d32c591

Please sign in to comment.