/
extract_utils.rake
52 lines (43 loc) · 1.46 KB
/
extract_utils.rake
1
2
3
4
5
6
7
8
9
10
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
require 'rake/contrib/unzip'
namespace(:extract_utils) do
package = RubyInstaller::ExtractUtils
directory package.target
CLEAN.include(package.target)
# Put files for the :download task
package.files.each do |k,v|
v.each do |f|
#TODO handle exception when no corresponding URL defined on package
file_source = "#{package.send(k)}/#{f}"
file_target = "downloads/#{f}"
download file_target => file_source
# depend on downloads directory
file file_target => "downloads"
# download task need these files as pre-requisites
task :download => file_target
end
end
task :extract_utils => [:download, package.target] do
msi_regex = /\.msi$/
msis = []
zips = []
package.files.each do |k,v|
v.each do |f|
msis << f if f =~ msi_regex
zips << f unless f =~ msi_regex
end
end
fail 'Only one .msi allowed for RubyInstaller::ExtractUtils.files' if msis.length != 1
zips.each do |f|
filename = "downloads/#{f}"
Zip.fake_unzip(filename, /\.exe|\.dll$/, package.target)
end
# assume 7za.exe can extract individual files from MSI's
unless File.exist?("#{package.target}/7z.sfx")
msi = "downloads/#{msis.first}"
seven_zip_get(msi, '_7z.sfx', package.target)
File.rename("#{package.target}/_7z.sfx", "#{package.target}/7z.sfx")
end
end
end
task :download => ['extract_utils:download']
task :extract_utils => ['extract_utils:extract_utils']