Class: Wixgem::CustomAction

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

Instance Method Summary collapse

Constructor Details

#initialize(xml_doc, input) ⇒ CustomAction

Returns a new instance of CustomAction.



7
8
9
10
# File 'lib/custom_action.rb', line 7

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

Instance Method Details

#add(custom_action) ⇒ Object



11
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/custom_action.rb', line 11

def add(custom_action)
  unless(custom_action.key?(:file) || custom_action.key?(:binary_key) || custom_action.key?(:property))
    raise 'Currently, only supported custom actions work with installed executable, binary key, or property' 
	end
	
	file_key=nil
	if(custom_action.key?(:file))
    install_path = ".\\#{custom_action[:file].gsub(/\//,'\\')}"
 file_elements = REXML::XPath.match(@xml_doc, "//File[@Source='#{install_path}']")
 raise "Unable to locate installation file '#{custom_action[:file]} for custom action'" if(file_elements.nil? || (file_elements.size == 0))
	
 file_key = file_elements[0].attributes['Id']
	end
	
	id = "ca_#{SecureRandom.uuid.gsub(/-/,'')}"
	id = custom_action[:id] if(custom_action.key?(:id))
	
	cmd_line = ''
	cmd_line = custom_action[:exe_command] if(custom_action.key?(:exe_command))
	
	impersonate = 'yes'
	impersonate = custom_action[:impersonate] if(custom_action.key?(:impersonate))
	
	condition='NOT Installed AND NOT REMOVE'
	condition='1' if(custom_action.key?(:binary_key))
	condition = custom_action[:condition] if(custom_action.key?(:condition))
	
	execute='deferred'
	execute = custom_action[:execute] if(custom_action.key?(:execute))
	
	ret='check'
	ret = custom_action[:return] if(custom_action.key?(:return))
	
	wix_element = REXML::XPath.match(@xml_doc, "/Wix")[0]
	fragment = wix_element.add_element 'Fragment'
	
	action = fragment.add_element 'CustomAction', { 'Id' => id, 'Impersonate' => impersonate, 'Return' => ret, 'HideTarget' => 'no', 'Execute' => execute }
	if(custom_action.key?(:binary_key))
 action.attributes['BinaryKey'] = custom_action[:binary_key]
	else
 action.attributes['FileKey'] = file_key
	end
	
	action.attributes['ExeCommand'] = cmd_line if(custom_action.key?(:exe_command))

	action.attributes['DllEntry'] = custom_action[:dll_entry] if(custom_action.key?(:dll_entry))

	if(custom_action.key?(:property))
 raise "Custom action property '#{custom_action[:property]} must have a value!" unless(custom_action.key?(:value))
 action.attributes.delete('ExeCommand')
 action.attributes.delete('Return')
 action.attributes['Property'] = custom_action[:property]
 action.attributes['Value'] = custom_action[:value]	  
	end
	
  install_execute_sequence = fragment.add_element 'InstallExecuteSequence'

	custom_action[:before] = 'InstallFinalize' if(!custom_action.key?(:after) && !custom_action.key?(:before))
	if(custom_action.key?(:after))
  action = install_execute_sequence.add_element 'Custom', { 'Action' => id, 'After' => custom_action[:after] }
    action.text = condition
	else
  action = install_execute_sequence.add_element 'Custom', { 'Action' => id, 'Before' => custom_action[:before] }
    action.text = condition
	end
	
	control=nil
	elements = REXML::XPath.match(@xml_doc, "/Wix/Product")
	elements = REXML::XPath.match(@xml_doc, "/Wix/Module") if(elements.nil? || elements.size == 0)
	
	elements[0].add_element 'CustomActionRef', { 'Id' => id }

end