Class: Wixgem::Shortcut

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

Instance Method Summary collapse

Constructor Details

#initialize(file, hash) ⇒ Shortcut

Returns a new instance of Shortcut.



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

def initialize(file, hash)
  @file = file
	@hash = hash
end

Instance Method Details

#create(xml_doc) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/shortcut.rb', line 13

def create(xml_doc)
	raise "Shortcut #{@file} does not exist" unless(File.exists?(@file))
	
	file_elements = REXML::XPath.match(xml_doc, "//File[@Source='.\\#{@file.gsub(/\//,'\\')}']")
	raise "Shortcut #{@file} does not match an installation file" if(file_elements.length == 0)
	create_shortcut_element(file_elements[0])
	create_directory(xml_doc, @hash[:directory]) if(@hash.has_key?(:directory))
	
	return xml_doc
end

#create_directory(xml_doc, directory) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/shortcut.rb', line 50

def create_directory(xml_doc, directory)
	raise 'Currently only supporting desktop shortcuts' unless(directory == :desktop)
	if(directory == :desktop)
 desktop_elements = REXML::XPath.match(xml_doc, "//DesktopFolder")
 if(desktop_elements.length == 0)
wix_elements = REXML::XPath.match(xml_doc, "//Wix")
fragment_element = wix_elements[0].add_element 'Fragment'
target_dir = fragment_element.add_element 'DirectoryRef', { 'Id' => 'TARGETDIR' }
target_dir.add_element 'Directory', { 'Id' => 'DesktopFolder', 'Name' => 'Desktop' }
 end
	end
end

#create_shortcut_element(file_element) ⇒ Object



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
# File 'lib/shortcut.rb', line 24

def create_shortcut_element(file_element)
  shortcut_element = file_element.add_element 'Shortcut'
	
	shortcut_element.attributes['Id'] = "Shortcut_#{SecureRandom.uuid.gsub(/-/,'')}"
	shortcut_element.attributes['Arguments'] = @hash[:arguments] if(@hash.has_key?(:arguments))
	
	shortcut_name = File.basename(@file)
	shortcut_name = @hash[:name] if(@hash.has_key?(:name))
	shortcut_element.attributes['Name'] = shortcut_name

	shortcut_element.attributes['Description'] = @hash[:description] if(@hash.has_key?(:description))
	if(@hash.has_key?(:directory)) 
 case @hash[:directory]
 when :desktop
shortcut_element.attributes['Directory'] = 'DesktopFolder'
 else
   shortcut_element.attributes['Directory'] = @hash[:directory] 
 end
	end
	
	shortcut_element.attributes['Advertise']="yes"
	shortcut_element.attributes['Advertise'] = "no" if(@hash.has_key?(:advertise) && !@hash[:advertise])
	
	return shortcut_element
end