Class: RegistryKey

Inherits:
Object
  • Object
show all
Defined in:
lib/registry_key.rb

Overview

Instance Method Summary collapse

Constructor Details

#initialize(xml_doc, input) ⇒ RegistryKey

Returns a new instance of RegistryKey.



8
9
10
11
# File 'lib/registry_key.rb', line 8

def initialize(xml_doc, input)
  @xml_doc = xml_doc
  @input = input
end

Instance Method Details

#add(registry_key) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/registry_key.rb', line 12

def add(registry_key)
 unless(registry_key.key?(:root) && registry_key.key?(:key) && registry_key.key?(:value))
   raise 'Registry key must have root, key, and value elements' 
	end

	key_value = registry_key[:value]
 unless(key_value.key?(:name) || key_value.key?(:value) || key_value.key?(:type))
		raise 'Registry value must have name, value, and type elements' 
	end

	#registry_keys_component = REXML::XPath.match(@xml_doc, "//Component[@Id='RegistryKeys']")
	#if(registry_keys_component.size == 0)
		wix_element = REXML::XPath.match(@xml_doc, "/Wix")[0]
		fragment = wix_element.add_element 'Fragment'
		component_group = fragment.add_element 'ComponentGroup'
		component_group.attributes['Id'] = "rk_#{SecureRandom.uuid.gsub(/-/,'')}"

		default_feature = REXML::XPath.match(@xml_doc, '//Wix/Product/Feature')
		component_ref = default_feature[0].add_element 'ComponentGroupRef', 'Id' => component_group.attributes['Id']

		component = component_group.add_element 'Component'
		component.attributes['Id'] = "RegistryKey_#{SecureRandom.uuid.gsub(/-/,'')}"
		component.attributes['Directory'] = 'INSTALLDIR'
	#else
		#puts "component: #{registry_keys_component.to_s}"
	#	component = registry_keys_component[0]
	#end

	registry_key_element = component.add_element 'RegistryKey', { 'Root' => registry_key[:root], 'Key' => registry_key[:key] }
	value_element = registry_key_element.add_element 'RegistryValue', { 'Action' => 'write', 'Name' => key_value[:name], 'Value' => key_value[:value], 'Type' => key_value[:type] }
end