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



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/shortcut.rb', line 55

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_icon_element(shortcut_element) ⇒ Object



48
49
50
51
52
53
# File 'lib/shortcut.rb', line 48

def create_icon_element(shortcut_element)
  icon_element = shortcut_element.add_element 'Icon'  
  icon_element.attributes['Id'] = File.basename(@hash[:icon])
  icon_element.attributes['SourceFile'] = ".\\#{@hash[:icon].gsub(/\//, '\\')}"
  return icon_element
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
# 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)
  if(@hash.has_key?(:name))
 shortcut_name = @hash[:name] 
  else
 @hash[:name] = shortcut_name
  end
  shortcut_element.attributes['Name'] = shortcut_name

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