Class: Wix

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

Class Method Summary collapse

Class Method Details

.get_build_commands(wxs_file) ⇒ Object


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/apps/wix.rb', line 13

def self.get_build_commands(wxs_file)
  build_commands = nil
  if File.exist?(wxs_file) && !defined?(NO_WIX) && Environment.windows?
    ext = "msi"
    ext = "exe" if IO.read(wxs_file).include?("<Bundle")
    extensions = ""
    %w[WixNetFxExtension WixBalExtension WixUtilExtension WixUiExtension].each do |e|
      extensions = "#{extensions}-ext #{e} "
    end
    build_commands = [] if build_commands.nil?
    build_commands << "candle #{wxs_file} #{extensions}"

    if defined?(VERSION)
      build_commands << "light #{File.basename(wxs_file,
                                               ".*")}.wixobj -out #{File.basename(wxs_file,
                                                                                  ".*")}-#{VERSION}.#{ext} #{extensions}"
    else
      build_commands << "light #{File.basename(wxs_file, ".*")}.wixobj #{extensions}"
    end
  end
  build_commands
end

.get_wix_with_files(wxs_template_text, component_id, filenames) ⇒ Object


36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/apps/wix.rb', line 36

def self.get_wix_with_files(wxs_template_text, component_id, filenames)
  # <Component[-\s\w="]+Id="ApplicationFiles"[-"\s\w=]+>([-<="\/.>\s\w]+)<\/C
  search = wxs_template_text.scan(%r{<Component[-\s\w="]+Id="ApplicationFiles"[-"\s\w=]+>([-<="/.>\s\w]+)</C})[0][0]
  replace = ""
  index = 0
  filenames.each do |f|
    replace += "\n                 <File Id=\"#{component_id}#{index}\" Source=\"#{f}\"/>"
    index += 1
  end
  replace += "\n"
  wxs_template_text.gsub(search, replace)
end

.update_wix_files(wxs_filename, component_id, filenames) ⇒ Object


49
50
51
52
53
# File 'lib/apps/wix.rb', line 49

def self.update_wix_files(wxs_filename, component_id, filenames)
  wix_text = IO.read(wxs_filename)
  new_text = get_wix_with_files(wix_text, component_id, filenames)
  File.open(wxs_filename, "w") { |f| f.write(new_text) } if wix_text != new_text
end