-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrake-innosetup.rb
99 lines (92 loc) · 3.17 KB
/
rake-innosetup.rb
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
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
require 'rake'
require 'albacore'
require 'win32ole'
require 'albacore/albacoretask'
require 'albacore/support/supportlinux'
require 'rake-filesystem.rb'
class InnoSetup
include Albacore::Task
include Rake::DSL
attr_accessor :ScriptFile
attr_accessor :OutputFileBaseName
attr_accessor :OutputFolder
attr_accessor :Defines
attr_accessor :ISCCBinary
def execute()
check_parameters()
cmd = build_commandline()
puts "InnoSetup command: " + cmd
system(cmd)
end
def build_commandline()
cmd = [@ISCCBinary, @ScriptFile]
@Defines.keys.each do |k|
cmd.push("/d" + k + "=" + @Defines[k])
end
if not @OutputFolder.nil?
cmd.push("/o" + @OutputFolder)
end
return "\"" + cmd.join("\" \"") + "\"";
end
def check_parameters()
if @ScriptFile.nil?
fail "InnoSetup task: ScriptFile not set"
end
if not File.exist?(@ScriptFile)
fail "InnoSetup task: Unable to find setup script at \"" + @ScriptFilePaht + "\" (did you perhaps forget to check it in?)"
end
if not @OutputFileBaseName.nil?
if @OutputFileBaseName.length < 5
puts red("InnoSetup task: WARNING: OutputFileBaseName set to something quite short: \"" + @OutputFileBaseName + "\"; using anyway, as requested")
end
end
if not @OutputFolder.nil?
if File.exist?(@OutputFolder) and not File.directory?(@OutputFolder)
fail "InnoSetup task: \"" + @OutputFolder + "\" exists but is not a folder... bailing out"
end
end
if @ISCCBinary.nil?
@ISCCBinary = find_iscc()
elsif not File.file?(@ISCCBinary)
puts "InnoSetup task: specified ISCC binary not found (" + @ISCCBinary + "), searching..."
@ISCCBinary = find_iscc()
end
if @Defines.nil?
@Defines = {}
end
if not @Defines.instance_of?(Hash)
fail "Defines must be a Hash (or nil). Use syntax like:\nsetup.Defines = {key=\"value\"}"
end
end
def find_iscc()
# look in search path
`set`.split("\n").each do |line|
if line =~ /(\w+)=(.+)/
var = $1
val = $2
if var.downcase() == "path"
val.split(";").each do |search|
check = File.join(search.gsub("\\", File::SEPARATOR), "iscc.exe")
if File.exist?(check)
puts "InnoSetup task: using ISCC binary in my path at \"" + check + "\""
return check
end
end
end
end
end
# look in expected installation folders
file_system = WIN32OLE.new("Scripting.FileSystemObject")
file_system.Drives.each do |drive|
["Program Files", "Program Files (x86)"].each do |search|
check = File.join(drive.DriveLetter + ":", search, "Inno Setup 5", "ISCC.exe")
if File.file?(check)
puts "InnoSetup task: using ISCC from expected install location at: \"" + check + "\""
return check
end
end
end
# give up
fail "InnoSetup task: Unable to find ISCC.exe. Please install InnoSetup to the default location or ensure that ISCC.exe is in the path. Look at http://www.jrsoftware.org/isdl.php (I suggest getting the QuickStart pack and installing everything (you NEED preprocessor, the rest is optional)"
end
end