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

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, replace_forward_slashes, with_key

Methods included from Enumerable

#uniq

Methods included from Util::Errors

#adderrorcontext, #devfail, #error_context, #exceptwrap, #fail

Methods included from Util::Windows::Registry

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

Methods included from FFI::Library

#attach_function_private

Constructor Details

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

Returns a new instance of MsiPackage.



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

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



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/puppet/provider/package/windows/msi_package.rb', line 18

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



54
55
56
# File 'lib/puppet/provider/package/windows/msi_package.rb', line 54

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



12
13
14
15
# File 'lib/puppet/provider/package/windows/msi_package.rb', line 12

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?

Returns:

  • (Boolean)


32
33
34
35
36
37
38
# File 'lib/puppet/provider/package/windows/msi_package.rb', line 32

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?

Returns:

  • (Boolean)


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

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

#uninstall_commandObject



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

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