Class: Ocran::InnoSetupScriptBuilder

Inherits:
Object
  • Object
show all
Extended by:
WindowsCommandEscaping
Includes:
WindowsCommandEscaping
Defined in:
lib/ocran/inno_setup_script_builder.rb

Constant Summary collapse

ISCC_CMD =
"ISCC"
ISCC_SUCCESS =
0
ISCC_INVALID_PARAMS =
1
ISCC_COMPILATION_FAILED =
2

Class Method Summary collapse

Instance Method Summary collapse

Methods included from WindowsCommandEscaping

escape_double_quotes, quote_and_escape

Constructor Details

#initialize(inno_setup_script) ⇒ InnoSetupScriptBuilder

Returns a new instance of InnoSetupScriptBuilder.



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/ocran/inno_setup_script_builder.rb', line 41

def initialize(inno_setup_script)
  # ISSC generates the installer files relative to the directory of the
  # ISS file. Therefore, it is necessary to create Tempfiles in the
  # working directory.
  @build_file = Tempfile.new("", Dir.pwd)
  if inno_setup_script
    IO.copy_stream(inno_setup_script, @build_file)
  end
  @dirs = FilePathSet.new
  @files = FilePathSet.new
end

Class Method Details

.compile(iss_filename, quiet: false) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ocran/inno_setup_script_builder.rb', line 16

def compile(iss_filename, quiet: false)
  unless system("where #{quote_and_escape(ISCC_CMD)} >NUL 2>&1")
    raise "ISCC command not found. Is the InnoSetup directory in your PATH?"
  end

  cmd_line = [ISCC_CMD]
  cmd_line << "/Q" if quiet
  cmd_line << iss_filename
  system(*cmd_line)

  case $?&.exitstatus
  when ISCC_SUCCESS
    # ISCC reported success
  when ISCC_INVALID_PARAMS
    raise "ISCC reports invalid command line parameters"
  when ISCC_COMPILATION_FAILED
    raise "ISCC reports that compilation failed"
  else
    raise "ISCC failed to run"
  end
end

Instance Method Details

#buildObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/ocran/inno_setup_script_builder.rb', line 53

def build
  @build_file.tap do |f|
    if @dirs.any?
      f.puts
      f.puts "[Dirs]"
      @dirs.each { |_source, target| f.puts build_dir_item(target) }
    end

    if @files.any?
      f.puts
      f.puts "[Files]"
      @files.each { |source, target| f.puts build_file_item(source, target) }
    end
  end.close
  path
end

#compile(verbose: false) ⇒ Object



74
75
76
# File 'lib/ocran/inno_setup_script_builder.rb', line 74

def compile(verbose: false)
  InnoSetupScriptBuilder.compile(path, quiet: !verbose)
end

#cp(source, target) ⇒ Object



82
83
84
85
86
87
88
# File 'lib/ocran/inno_setup_script_builder.rb', line 82

def cp(source, target)
  unless File.exist?(source)
    raise "The file does not exist (#{source})"
  end

  @files.add?(source, target)
end

#mkdir(target) ⇒ Object



78
79
80
# File 'lib/ocran/inno_setup_script_builder.rb', line 78

def mkdir(target)
  @dirs.add?("/", target)
end

#pathObject



70
71
72
# File 'lib/ocran/inno_setup_script_builder.rb', line 70

def path
  @build_file.to_path
end