Class: Puppet::Provider::Package::Windows::MsiPackage

Inherits:
Package show all
Defined in:
lib/puppet/provider/package/windows/msi_package.rb

Constant Summary collapse

INSTALLSTATE_DEFAULT =

From msi.h

5
INSTALLUILEVEL_NONE =

product is installed for the current user

2
REG_VALUE_NAMES =

registry values to load under each product entry in HKLMSOFTWAREMicrosoftWindowsCurrentVersionUninstall for this provider

[
  'DisplayVersion',
  'WindowsInstaller'
]

Constants inherited from Package

Package::REG_DISPLAY_VALUE_NAMES

Constants included from Util::Windows::Registry

Util::Windows::Registry::ERROR_NO_MORE_ITEMS, Util::Windows::Registry::KEY32, Util::Windows::Registry::KEY64, Util::Windows::Registry::KEY_ALL_ACCESS, Util::Windows::Registry::KEY_READ, Util::Windows::Registry::KEY_WRITE

Instance Attribute Summary collapse

Attributes inherited from Package

#name, #version

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Package

each, get_display_name, installer_class, munge, quote, reg_value_names_to_load, replace_forward_slashes, with_key

Methods included from Util::Windows::Registry

#delete_key, #delete_value, #each_key, #each_value, #keys, #open, #root, #values, #values_by_name

Methods included from FFI::Library

#attach_function_private

Methods included from Util::Errors

#adderrorcontext, #devfail, #error_context, error_location, error_location_with_space, error_location_with_unknowns, #exceptwrap, #fail

Methods included from Enumerable

#uniq

Constructor Details

#initialize(name, version, productcode, packagecode) ⇒ MsiPackage

Returns a new instance of MsiPackage


48
49
50
51
52
53
# File 'lib/puppet/provider/package/windows/msi_package.rb', line 48

def initialize(name, version, productcode, packagecode)
  super(name, version)

  @productcode = productcode
  @packagecode = packagecode
end

Instance Attribute Details

#packagecodeObject (readonly)


5
6
7
# File 'lib/puppet/provider/package/windows/msi_package.rb', line 5

def packagecode
  @packagecode
end

#productcodeObject (readonly)


5
6
7
# File 'lib/puppet/provider/package/windows/msi_package.rb', line 5

def productcode
  @productcode
end

Class Method Details

.from_registry(name, values) ⇒ Object

Return an instance of the package from the registry, or nil


26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/puppet/provider/package/windows/msi_package.rb', line 26

def self.from_registry(name, values)
  if valid?(name, values)
    inst = installer

    if inst.ProductState(name) == INSTALLSTATE_DEFAULT
      MsiPackage.new(get_display_name(values),
                     values['DisplayVersion'],
                     name, # productcode
                     inst.ProductInfo(name, 'PackageCode'))
    end
  end
end

.install_command(resource) ⇒ Object


62
63
64
# File 'lib/puppet/provider/package/windows/msi_package.rb', line 62

def self.install_command(resource)
  ['msiexec.exe', '/qn', '/norestart', '/i', munge(resource[:source])]
end

.installerObject

Get the COM installer object, it's in a separate method for testing


20
21
22
23
# File 'lib/puppet/provider/package/windows/msi_package.rb', line 20

def self.installer
  # REMIND: when does the COM release happen?
  WIN32OLE.new("WindowsInstaller.Installer")
end

.valid?(name, values) ⇒ Boolean

Is this a valid MSI package we should manage?


40
41
42
43
44
45
46
# File 'lib/puppet/provider/package/windows/msi_package.rb', line 40

def self.valid?(name, values)
  # See http://community.spiceworks.com/how_to/show/2238
  displayName = get_display_name(values)
  !!(displayName && displayName.length > 0 &&
     values['WindowsInstaller'] == 1 && # DWORD
     name =~ /\A\{[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\}\Z/i)
end

Instance Method Details

#match?(resource) ⇒ Boolean

Does this package match the resource?


56
57
58
59
60
# File 'lib/puppet/provider/package/windows/msi_package.rb', line 56

def match?(resource)
  resource[:name].casecmp(packagecode) == 0 ||
    resource[:name].casecmp(productcode) == 0 ||
    resource[:name] == name
end

#uninstall_commandObject


66
67
68
# File 'lib/puppet/provider/package/windows/msi_package.rb', line 66

def uninstall_command
  ['msiexec.exe', '/qn', '/norestart', '/x', productcode]
end