neri 0.9.6 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/neri/build.rb CHANGED
@@ -2,12 +2,11 @@
2
2
 
3
3
  require "neri"
4
4
 
5
- module Neri
5
+ module NeriBuild
6
6
  @data_files = []
7
7
 
8
8
  @options = {
9
9
  quiet: false,
10
- verbose: false,
11
10
 
12
11
  external_encoding: nil,
13
12
 
@@ -16,7 +15,7 @@ module Neri
16
15
  gems: [],
17
16
  encoding: "*",
18
17
 
19
- enable_gems: false,
18
+ enable_gems: true,
20
19
  enable_did_you_mean: false,
21
20
  chdir_first: true,
22
21
  pause_last: nil,
@@ -30,39 +29,22 @@ module Neri
30
29
  virtual_directory: nil,
31
30
 
32
31
  no_exe: false,
33
- use_b2ec: false,
34
- b2ec_path: "Bat_To_Exe_Converter",
35
- b2ec: {
36
- icon: File.expand_path("#{File.dirname(__FILE__)}/../../share/default.ico"),
37
- invisible: nil,
38
- x64: nil,
39
- uac_admin: nil,
40
- fileversion: nil,
41
- productversion: nil,
42
- productname: nil,
43
- originalfilename: nil,
44
- internalname: nil,
45
- description: nil,
46
- company: nil,
47
- trademarks: nil,
48
- copyright: nil,
49
- privatebuild: nil,
50
- specialbuild: nil,
51
- comments: nil
52
- },
53
-
54
- use_upx: false,
55
- upx_path: "upx",
56
- upx_targets: ["bin/**/*.dll"],
57
- upx_options: "",
58
-
59
- zipfile: nil,
60
- sevenzip_path: "7z",
61
-
62
- inno_script: nil,
63
- iscc_path: "iscc"
32
+ icon: File.expand_path("#{File.dirname(__FILE__)}/../../share/default.ico"),
33
+ invisible: nil,
34
+ fileversion: nil,
35
+ productversion: nil,
36
+ productname: nil,
37
+ originalfilename: nil,
38
+ internalname: nil,
39
+ description: nil,
40
+ company: nil,
41
+ trademarks: nil,
42
+ copyright: nil,
43
+ privatebuild: nil,
44
+ specialbuild: nil,
45
+ comments: nil
64
46
  }
65
- @rubyopt = ENV["RUBYOPT"].to_s
47
+ @rubyopt = ENV["RUBYOPT"].to_s.encode(Encoding::UTF_8)
66
48
  @args = ""
67
49
  @encryption_key = nil
68
50
 
@@ -70,8 +52,33 @@ module Neri
70
52
  @use_dxruby_tiled = false
71
53
  @use_ayame = false
72
54
 
55
+ @require_paths = {}
56
+
73
57
  class << self
74
- attr_reader :options
58
+ def gemspec_path(file)
59
+ return nil unless file.match?(%r{/gems/\d+\.\d+\.\d+/gems/(.+?-[^/]+)/})
60
+
61
+ file.sub(%r{(/gems/\d+\.\d+\.\d+)/gems/(.+?-[^/]+)/.+\z}) do
62
+ "#{Regexp.last_match(1)}/specifications/#{Regexp.last_match(2)}.gemspec"
63
+ end
64
+ end
65
+
66
+ def gem_require_paths(file)
67
+ path = gemspec_path(file)
68
+ return nil unless path
69
+ return @require_paths[path] if @require_paths.key?(path)
70
+
71
+ @require_paths[path] = ["lib/"]
72
+ if File.exist?(path)
73
+ gemspec = File.binread(path)
74
+ if gemspec.match(/\.require_paths\s*=\s*\[([^\]]+)\]/)
75
+ @require_paths[path] = Regexp.last_match(1).scan(/['"]([^'"]+)['"]/).flatten.map do |p|
76
+ "#{p.delete_suffix('/')}/"
77
+ end
78
+ end
79
+ end
80
+ @require_paths[path]
81
+ end
75
82
 
76
83
  def relative_path(path, basedir = rubydir, prepath = "")
77
84
  basedir.concat(File::SEPARATOR) unless basedir.end_with?(File::SEPARATOR)
@@ -87,8 +94,8 @@ module Neri
87
94
  def rubyexe ; RbConfig.ruby; end
88
95
  def scriptfile; @data_files.first; end
89
96
  def basename ; File.basename(scriptfile, ".*"); end
90
- def basepath ; File.join(options[:output_dir], basename); end
91
- def datafile ; File.join(options[:output_dir], options[:system_dir], options[:datafile]); end
97
+ def basepath ; File.join(@options[:output_dir], basename); end
98
+ def datafile ; File.join(@options[:output_dir], @options[:system_dir], @options[:datafile]); end
92
99
 
93
100
  # --help
94
101
  def output_help
@@ -99,7 +106,6 @@ options:
99
106
  --help or -h
100
107
  --version or -v
101
108
  --quiet
102
- --verbose
103
109
 
104
110
  --external-encoding <encoding>
105
111
 
@@ -110,8 +116,8 @@ options:
110
116
  --no-enc
111
117
  --encoding <enc1>,<enc2>,...
112
118
 
113
- --enable-gems
114
- --enable-did-you-mean
119
+ --enable-gems / --disable-gems
120
+ --enable-did-you-mean / --disable-did-you-mean
115
121
  --no-chdir
116
122
  --pause-last
117
123
  --no-pause-last
@@ -121,15 +127,12 @@ options:
121
127
  --system-dir <dirname>
122
128
  --datafile <filename>
123
129
  --encryption-key <key>
130
+ --virtual-directory <string>
124
131
 
125
- --no-exe
126
- --use-b2ec
127
- --b2ec-path <bat_to_exe_converter_path>
132
+ --no-exe or --bat
128
133
  --icon <iconfile>
129
134
  --windows or --invisible
130
135
  --console or --visible
131
- --x64
132
- --uac-admin
133
136
  --fileversion <string> # ex) 1,2,3,4
134
137
  --productversion <string> # ex) 1,2,3,4
135
138
  --productname <string>
@@ -142,21 +145,6 @@ options:
142
145
  --privatebuild <string>
143
146
  --specialbuild <string>
144
147
  --comments <string>
145
-
146
- --use-upx
147
- --upx-path <upx path>
148
- --upx_targets '<glob>' # ex) 'bin/**/*.dll'
149
- --upx-options <options>
150
-
151
- --zipfile <filename>
152
- --7zip-path <7-zip path>
153
-
154
- --innosetup <inno_script>
155
- --iscc-path <iscc path>
156
-
157
- --create-recipe <recipefile>
158
- --recipe <recipefile>
159
- --virtual-directory <string>
160
148
  HELP_MESSAGE
161
149
  end
162
150
 
@@ -165,25 +153,9 @@ options:
165
153
  puts "Neri #{Neri::VERSION}"
166
154
  end
167
155
 
168
- # --create-recipe
169
- def create_recipe(file, hash = options, pre = "Neri.options")
170
- hash.each_pair do |key, value|
171
- case value
172
- when Hash
173
- create_recipe(file, value, pre + "[:#{key}]")
174
- when Numeric, TrueClass, FalseClass
175
- file.puts "#{pre}[:#{key}] = #{value}"
176
- when NilClass
177
- file.puts "#{pre}[:#{key}] = nil"
178
- when String, Array
179
- file.puts "#{pre}[:#{key}] = " + JSON.generate(value)
180
- end
181
- end
182
- end
183
-
184
- def check_options
185
- nputs_v "Checking Neri options."
186
- while arg = ARGV.shift
156
+ def load_options(argv)
157
+ until argv.empty?
158
+ arg = argv.shift
187
159
  case arg
188
160
  when "--help", "-h"
189
161
  output_help
@@ -192,112 +164,80 @@ options:
192
164
  output_version
193
165
  exit
194
166
  when "--quiet", "-q"
195
- options[:quiet] = true
196
- when "--verbose"
197
- options[:verbose] = true
198
- when "--external_encoding"
199
- options[:external_encoding] = ARGV.shift
167
+ @options[:quiet] = true
168
+ when "--external-encoding"
169
+ @options[:external_encoding] = argv.shift
200
170
  when "--dll"
201
- options[:dlls] += ARGV.shift.split(",").map(&:strip)
171
+ @options[:dlls] += argv.shift.split(",").map(&:strip)
202
172
  when "--lib"
203
- options[:libs] += ARGV.shift.split(",").map(&:strip)
173
+ @options[:libs] += argv.shift.split(",").map(&:strip)
204
174
  when "--gem"
205
- options[:gems] += ARGV.shift.split(",").map(&:strip)
175
+ @options[:gems] += argv.shift.split(",").map(&:strip)
206
176
  when "--no-enc"
207
- options[:encoding] = nil
177
+ @options[:encoding] = nil
208
178
  when "--encoding"
209
- options[:encoding] = ARGV.shift
179
+ @options[:encoding] = argv.shift
210
180
  when "--enable-gems"
211
- options[:enable_gems] = true
181
+ @options[:enable_gems] = true
182
+ when "--disale-gems"
183
+ @options[:enable_gems] = false
212
184
  when "--enable-did-you-mean"
213
- options[:enable_did_you_mean] = true
185
+ @options[:enable_did_you_mean] = true
186
+ when "--disale-did-you-mean"
187
+ @options[:enable_did_you_mean] = false
214
188
  when "--no-chdir"
215
- options[:chdir_first] = false
189
+ @options[:chdir_first] = false
216
190
  when "--chdir-first" # deprecated
217
- options[:chdir_first] = true
191
+ @options[:chdir_first] = true
218
192
  when "--pause-last"
219
- options[:pause_last] = true
193
+ @options[:pause_last] = true
220
194
  when "--no-pause-last"
221
- options[:pause_last] = false
195
+ @options[:pause_last] = false
222
196
  when "--pause-text"
223
- options[:pause_text] = ARGV.shift.encode("utf-8")
224
- options[:pause_last] = true
197
+ @options[:pause_text] = argv.shift
198
+ @options[:pause_last] = true
225
199
  when "--output-dir"
226
- options[:output_dir] = ARGV.shift.encode("utf-8")
200
+ @options[:output_dir] = argv.shift
227
201
  when "--system-dir"
228
- options[:system_dir] = ARGV.shift.encode("utf-8")
202
+ @options[:system_dir] = argv.shift
229
203
  when "--datafile"
230
- options[:datafile] = ARGV.shift.encode("utf-8")
204
+ @options[:datafile] = argv.shift
231
205
  when "--encryption-key"
232
- options[:encryption_key] = ARGV.shift.encode("utf-8")
233
- when "--no-exe"
234
- options[:no_exe] = true
235
- when "--use-b2ec"
236
- options[:use_b2ec] = true
237
- when "--b2ec-path"
238
- options[:b2ec_path] = ARGV.shift.encode("utf-8")
206
+ @options[:encryption_key] = argv.shift
207
+ when "--virtual-directory"
208
+ @options[:virtual_directory] = argv.shift
209
+ when "--no-exe", "--bat"
210
+ @options[:no_exe] = true
239
211
  when "--icon"
240
- options[:b2ec][:icon] = ARGV.shift.encode("utf-8")
212
+ @options[:icon] = argv.shift
241
213
  when "--windows", "--invisible"
242
- options[:b2ec][:invisible] = true
214
+ @options[:invisible] = true
243
215
  when "--console", "--visible"
244
- options[:b2ec][:invisible] = false
245
- when "--x64"
246
- options[:b2ec][:x64] = true
247
- when "--uac-admin"
248
- options[:b2ec][:uac_admin] = true
216
+ @options[:invisible] = false
249
217
  when "--fileversion"
250
- options[:b2ec][:fileversion] = ARGV.shift
218
+ @options[:fileversion] = argv.shift
251
219
  when "--productversion"
252
- options[:b2ec][:productversion] = ARGV.shift
220
+ @options[:productversion] = argv.shift
253
221
  when "--productname"
254
- options[:b2ec][:productname] = ARGV.shift.encode("utf-8")
222
+ @options[:productname] = argv.shift
255
223
  when "--originalfilename"
256
- options[:b2ec][:originalfilename] = ARGV.shift.encode("utf-8")
224
+ @options[:originalfilename] = argv.shift
257
225
  when "--internalname"
258
- options[:b2ec][:internalname] = ARGV.shift.encode("utf-8")
226
+ @options[:internalname] = argv.shift
259
227
  when "--description"
260
- options[:b2ec][:description] = ARGV.shift.encode("utf-8")
228
+ @options[:description] = argv.shift
261
229
  when "--company"
262
- options[:b2ec][:company] = ARGV.shift.encode("utf-8")
230
+ @options[:company] = argv.shift
263
231
  when "--trademarks"
264
- options[:b2ec][:trademarks] = ARGV.shift.encode("utf-8")
232
+ @options[:trademarks] = argv.shift
265
233
  when "--copyright"
266
- options[:b2ec][:copyright] = ARGV.shift.encode("utf-8")
234
+ @options[:copyright] = argv.shift
267
235
  when "--privatebuild"
268
- options[:b2ec][:privatebuild] = ARGV.shift.encode("utf-8")
236
+ @options[:privatebuild] = argv.shift
269
237
  when "--specialbuild"
270
- options[:b2ec][:specialbuild] = ARGV.shift.encode("utf-8")
238
+ @options[:specialbuild] = argv.shift
271
239
  when "--comments"
272
- options[:b2ec][:comments] = ARGV.shift.encode("utf-8")
273
- when "--use-upx"
274
- options[:use_upx] = true
275
- when "--upx-path"
276
- options[:upx_path] = ARGV.shift.encode("utf-8")
277
- when "--upx-targets"
278
- options[:upx_targets] += ARGV.shift.split(",").map(&:strip)
279
- when "--upx-options"
280
- options[:upx_options] = ARGV.shift
281
- when "--zipfile"
282
- options[:zipfile] = "#{ARGV.shift.encode('utf-8').sub(/\.zip$/, '')}.zip"
283
- when "--7zip-path"
284
- options[:sevenzip_path] = ARGV.shift.encode("utf-8")
285
- when "--innosetup"
286
- options[:inno_script] = ARGV.shift.encode("utf-8")
287
- when "--iscc-path"
288
- options[:iscc_path] = ARGV.shift.encode("utf-8")
289
- when "--create-recipe"
290
- require "json"
291
- filename = ARGV.shift.encode("utf-8")
292
- nputs "Creating recipe_file '#{filename}'."
293
- File.open(filename, "w:utf-8") { |file| create_recipe(file) }
294
- exit
295
- when "--recipe"
296
- filename = ARGV.shift.encode("utf-8")
297
- nputs_v "Loading recipe_file '#{filename}'."
298
- load File.expand_path(filename)
299
- when "--virtual-directory"
300
- options[:virtual_directory] = ARGV.shift.encode("utf-8")
240
+ @options[:comments] = argv.shift
301
241
  when "--"
302
242
  break
303
243
  when /^(--.+)/
@@ -305,26 +245,88 @@ options:
305
245
  output_help
306
246
  exit
307
247
  else
308
- @data_files.push(arg.encode("utf-8"))
248
+ if File.exist?(arg)
249
+ @data_files.push(arg)
250
+ else
251
+ error "File '#{arg}' not found!"
252
+ exit
253
+ end
309
254
  end
310
255
  end
311
256
 
257
+ @args += argv.map { |a| %( "#{a}") }.join("")
258
+ end
259
+
260
+ def load_options_from_file(file)
261
+ fullpath = File.expand_path(file)
262
+ return unless File.exist?(fullpath)
263
+
264
+ argv = File.read(fullpath, encoding: Encoding::UTF_8).lines.flat_map do |line|
265
+ line.strip.split(" ", 2)
266
+ end
267
+ load_options(argv)
268
+ end
269
+
270
+ def check_options
271
+ load_options_from_file("~/neri.config")
272
+ load_options_from_file("./neri.config")
273
+ tmp_data_files = @data_files
274
+ @data_files = []
275
+ load_options(ARGV.map { |arg| arg.encode(Encoding::UTF_8) })
276
+ until ARGV.empty?
277
+ break if ARGV.shift == "--"
278
+ end
279
+ @data_files += tmp_data_files
312
280
  if @data_files.empty?
313
281
  error "No Script File!"
314
282
  output_help
315
283
  exit
316
284
  end
317
285
 
318
- @args = ARGV.map { |a| %( "#{a}") }.join("")
319
286
  @options[:external_encoding] ||= Encoding.default_external.name
320
- unless options[:enable_gems] || @rubyopt.index("--disable-gems")
287
+ unless @options[:enable_gems] || @rubyopt.index("--disable-gems")
321
288
  @rubyopt += " --disable-gems"
322
289
  end
323
- unless options[:enable_did_you_mean] || @rubyopt.index("--disable-did_you_mean")
290
+ unless @options[:enable_did_you_mean] || @rubyopt.index("--disable-did_you_mean")
324
291
  @rubyopt += " --disable-did_you_mean"
325
292
  end
326
- if @data_files.size > 1 || options[:encryption_key]
327
- options[:datafile] ||= "#{basename}.dat"
293
+ @rubyopt.sub!(%r{-r\S+/bundler/setup}, "")
294
+ if @data_files.size > 1 || @options[:encryption_key]
295
+ @options[:datafile] ||= "#{basename}.dat"
296
+ end
297
+ end
298
+
299
+ def run_script
300
+ nputs "Running script '#{scriptfile}' to check dependencies."
301
+ begin
302
+ load File.expand_path(scriptfile)
303
+ rescue SystemExit, Interrupt
304
+ end
305
+ nputs "Script '#{scriptfile}' end."
306
+
307
+ if defined? DXRuby
308
+ require "neri/dxruby"
309
+ @use_dxruby = true
310
+ end
311
+ if defined? DXRuby::Tiled
312
+ require "neri/dxruby_tiled"
313
+ @use_dxruby_tiled = true
314
+ end
315
+ if defined? Ayame
316
+ require "neri/ayame"
317
+ @use_ayame = true
318
+ end
319
+
320
+ if @options[:invisible].nil?
321
+ if File.extname(scriptfile) == ".rbw" ||
322
+ defined?(DXRuby) ||
323
+ defined?(Gosu) ||
324
+ defined?(LibUI)
325
+ @options[:invisible] = true
326
+ end
327
+ end
328
+ if @options[:pause_last].nil? && !@options[:invisible]
329
+ @options[:pause_last] = true
328
330
  end
329
331
  end
330
332
 
@@ -336,18 +338,17 @@ options:
336
338
  def dll_dependencies
337
339
  require "fiddle/import"
338
340
 
339
- pointer_type = Fiddle::SIZEOF_VOIDP == Fiddle::SIZEOF_LONG_LONG ? 'q*' : 'l!*'
340
341
  psapi = Fiddle.dlopen("psapi.dll")
341
342
  kernel32 = Fiddle.dlopen("kernel32.dll")
342
343
  enumprocessmodules = Fiddle::Function.new(
343
344
  psapi["EnumProcessModules"],
344
- [Fiddle::TYPE_LONG, Fiddle::TYPE_VOIDP, Fiddle::TYPE_LONG, Fiddle::TYPE_VOIDP],
345
+ [Fiddle::TYPE_UINTPTR_T, Fiddle::TYPE_VOIDP, Fiddle::TYPE_LONG, Fiddle::TYPE_VOIDP],
345
346
  Fiddle::TYPE_LONG,
346
347
  Fiddle::Importer.const_get(:CALL_TYPE_TO_ABI)[:stdcall]
347
348
  )
348
349
  getmodulefilename = Fiddle::Function.new(
349
350
  kernel32["GetModuleFileNameW"],
350
- [Fiddle::TYPE_LONG, Fiddle::TYPE_VOIDP, Fiddle::TYPE_LONG],
351
+ [Fiddle::TYPE_UINTPTR_T, Fiddle::TYPE_VOIDP, Fiddle::TYPE_LONG],
351
352
  Fiddle::TYPE_LONG,
352
353
  Fiddle::Importer.const_get(:CALL_TYPE_TO_ABI)[:stdcall]
353
354
  )
@@ -357,7 +358,7 @@ options:
357
358
  Fiddle::TYPE_LONG,
358
359
  Fiddle::Importer.const_get(:CALL_TYPE_TO_ABI)[:stdcall]
359
360
  )
360
-
361
+
361
362
  bytes_needed = 4 * 32
362
363
  module_handle_buffer = nil
363
364
  process_handle = getcurrentprocess.call
@@ -365,28 +366,24 @@ options:
365
366
  module_handle_buffer = "\x00" * bytes_needed
366
367
  bytes_needed_buffer = [0].pack("I")
367
368
  enumprocessmodules.call(
368
- [process_handle].pack("I").unpack1("i"),
369
- [module_handle_buffer].pack("p").unpack1(pointer_type),
370
- [module_handle_buffer.size].pack("I").unpack1("i"),
371
- [bytes_needed_buffer].pack("p").unpack1(pointer_type)
369
+ process_handle,
370
+ module_handle_buffer,
371
+ module_handle_buffer.size,
372
+ bytes_needed_buffer
372
373
  )
373
374
  bytes_needed = bytes_needed_buffer.unpack1("I")
374
375
  break if bytes_needed <= module_handle_buffer.size
375
376
  end
376
-
377
+
377
378
  handles = module_handle_buffer.unpack("I*")
378
379
  dependencies = handles.select { |handle| handle > 0 }.map do |handle|
379
380
  str = "\x00\x00" * 256
380
- modulefilename_length = getmodulefilename.call(
381
- [handle].pack("I").unpack1("i"),
382
- [str].pack("p").unpack1(pointer_type),
383
- [str.size].pack("I").unpack1("i")
384
- )
381
+ modulefilename_length = getmodulefilename.call(handle, str, str.size)
385
382
  str[0, modulefilename_length * 2].force_encoding("UTF-16LE").encode("UTF-8")
386
383
  end
387
384
 
388
385
  dependencies.map! { |dep| dep.sub(/^\\\\\?\\/, "") }
389
- dependencies.map! { |dep| dep.tr(File::ALT_SEPARATOR, File::SEPARATOR) } if File::ALT_SEPARATOR
386
+ dependencies.map! { |dep| dep.tr("\\", "/") }
390
387
  dependencies.delete(rubyexe)
391
388
 
392
389
  dependencies.uniq
@@ -400,7 +397,8 @@ options:
400
397
 
401
398
  def additional_dlls_dependencies
402
399
  dependencies = []
403
- options[:dlls].each do |dll|
400
+ @options[:dlls].push("*.dll") if RbConfig::CONFIG["arch"].include?("x64")
401
+ @options[:dlls].each do |dll|
404
402
  dependencies += Dir.glob(File.join(bindir, "**", dll))
405
403
  dependencies += Dir.glob(File.join(bindir, "**", "#{dll}.*"))
406
404
  end
@@ -409,7 +407,7 @@ options:
409
407
 
410
408
  def additional_libs_dependencies
411
409
  dependencies = []
412
- options[:libs].each do |lib|
410
+ @options[:libs].each do |lib|
413
411
  $LOAD_PATH.each do |path|
414
412
  dependencies += Dir.glob(File.join(path, lib))
415
413
  dependencies += Dir.glob(File.join(path, "#{lib}.*"))
@@ -420,10 +418,9 @@ options:
420
418
  end
421
419
 
422
420
  def additional_gems_dependencies
423
- require "rubygems"
424
421
  dependencies = []
425
422
  rubygems_dir = File.join(Gem.dir, "gems")
426
- options[:gems].each do |gem|
423
+ @options[:gems].each do |gem|
427
424
  gem.sub!(/:(.+)/, "")
428
425
  targets = Regexp.last_match(1).to_s.split("|")
429
426
  targets.push("lib/**/*")
@@ -439,12 +436,12 @@ options:
439
436
  end
440
437
 
441
438
  def encoding_dependencies
442
- return [] unless options[:encoding]
439
+ return [] unless @options[:encoding]
443
440
 
444
441
  dependencies = []
445
442
  enc_dir = Dir.glob(File.join(RbConfig::CONFIG["archdir"] || RbConfig::TOPDIR, "**", "enc")).first
446
443
 
447
- options[:encoding].split(",").map(&:strip).each do |enc|
444
+ @options[:encoding].split(",").map(&:strip).each do |enc|
448
445
  case enc
449
446
  when "ja"
450
447
  %w[windows_31j.so japanese_sjis.so encdb.so].each do |enc_name|
@@ -459,35 +456,41 @@ options:
459
456
  dependencies.uniq
460
457
  end
461
458
 
462
- def check_dependencies
463
- nputs "Running script '#{scriptfile}' to check dependencies."
464
- begin
465
- load File.expand_path(scriptfile)
466
- rescue SystemExit, Interrupt
459
+ def select_dependencies(dependencies)
460
+ dependencies.select! do |dependency|
461
+ dependency.start_with?(rubydir)
467
462
  end
468
- nputs "Script '#{scriptfile}' end."
469
463
 
470
- if defined? DXRuby
471
- require "neri/dxruby"
472
- @use_dxruby = true
473
- end
474
- if defined? DXRuby::Tiled
475
- require "neri/dxruby_tiled"
476
- @use_dxruby_tiled = true
477
- end
478
- if defined? Ayame
479
- require "neri/ayame"
480
- @use_ayame = true
464
+ @data_files.each do |file|
465
+ dependencies.delete(File.expand_path(file))
481
466
  end
482
467
 
483
- if options[:b2ec][:invisible].nil? &&
484
- (File.extname(scriptfile) == ".rbw" || @use_dxruby)
485
- options[:b2ec][:invisible] = true
468
+ unless @options[:enable_gems]
469
+ dependencies.delete_if do |dependency|
470
+ File.basename(dependency) == "rubygems.rb" ||
471
+ dependency.split(File::SEPARATOR).index("rubygems")
472
+ end
486
473
  end
487
- if options[:pause_last].nil? && !options[:b2ec][:invisible]
488
- options[:pause_last] = true
474
+ unless @options[:enable_did_you_mean]
475
+ dependencies.delete_if do |dependency|
476
+ File.basename(dependency) == "did_you_mean.rb" ||
477
+ dependency.split(File::SEPARATOR).index("did_you_mean")
478
+ end
489
479
  end
490
480
 
481
+ dependencies.uniq
482
+ end
483
+
484
+ def gemspec_dependencies(dependencies)
485
+ default_gemspec_dir = Gem.default_specifications_dir.encode(Encoding::UTF_8)
486
+ gemspecs = Dir.glob("#{default_gemspec_dir}/**/*")
487
+ gemspecs += dependencies.map { |depend| gemspec_path(depend) }
488
+ gemspecs.compact.uniq
489
+ end
490
+
491
+ def check_dependencies
492
+ run_script
493
+
491
494
  require "rbconfig"
492
495
  dependencies = []
493
496
  dependencies += rb_dependencies
@@ -498,70 +501,50 @@ options:
498
501
  dependencies += additional_gems_dependencies
499
502
  dependencies += encoding_dependencies
500
503
  dependencies = select_dependencies(dependencies)
504
+ dependencies += gemspec_dependencies(dependencies) if @options[:enable_gems]
505
+ if dependencies.find { |dep| dep.end_with?("/net/https.rb") }
506
+ dependencies.push("#{rubydir}ssl/cert.pem")
507
+ end
501
508
 
502
509
  size = dependencies.map { |d| File.size(d) }.inject(&:+)
503
510
  nputs "#{dependencies.size} files, #{size} bytes dependencies."
504
- if options[:verbose]
505
- dependencies.each do |dependency|
506
- nputs_v " - #{dependency}"
507
- end
508
- end
509
511
 
510
512
  dependencies
511
513
  end
512
514
 
513
- def select_dependencies(dependencies)
514
- dependencies.select! do |dependency|
515
- dependency.start_with?(rubydir)
516
- end
517
-
518
- @data_files.each do |file|
519
- dependencies.delete(File.expand_path(file))
520
- end
521
-
522
- unless options[:enable_gems]
523
- dependencies.delete_if do |dependency|
524
- File.basename(dependency) == "rubygems.rb" ||
525
- dependency.split(File::SEPARATOR).index("rubygems")
526
- end
527
- end
528
- unless options[:enable_did_you_mean]
529
- dependencies.delete_if do |dependency|
530
- File.basename(dependency) == "did_you_mean.rb" ||
531
- dependency.split(File::SEPARATOR).index("did_you_mean")
532
- end
533
- end
534
-
535
- dependencies.uniq
536
- end
537
-
538
515
  def copy_files(dependencies)
539
516
  nputs "Copying dependencies."
540
517
  require "fileutils"
541
518
  src_dir = rubydir
542
- desc_dir = File.join(options[:output_dir], options[:system_dir], "")
519
+ desc_dir = File.join(@options[:output_dir], @options[:system_dir], "")
543
520
 
544
521
  system_files = dependencies.map do |file|
545
522
  [file, file.sub(src_dir, desc_dir)]
546
523
  end
547
- unless options[:enable_gems]
548
- system_files.each do |_src, desc|
549
- desc.sub!(%r{/gems(/\d+\.\d+\.\d+/)gems/(.+?)-[^/]+/lib/}, "/vendor_ruby\\1")
524
+ unless @options[:enable_gems]
525
+ system_files.each do |src, desc|
526
+ paths = gem_require_paths(src)
527
+ next unless paths
528
+
529
+ desc.sub!(%r{/gems/(\d+\.\d+\.\d+)/gems/.+?-[^/]+/(.+)\z}) do
530
+ version, file = Regexp.last_match(1), Regexp.last_match(2)
531
+ paths.each do |path|
532
+ file = file.sub(path, "#{version}/") if file.start_with?(path)
533
+ end
534
+ "/vendor_ruby/#{file}"
535
+ end
550
536
  end
551
537
  end
552
538
 
553
539
  system_files.each do |src, desc|
554
540
  FileUtils.makedirs(File.dirname(desc))
555
- if File.file?(src)
556
- FileUtils.copy(src, desc)
557
- nputs_v " #{src}\n -> #{desc}"
558
- end
541
+ FileUtils.copy(src, desc) if File.file?(src)
559
542
  end
560
- FileUtils.copy(scriptfile, desc_dir) unless options[:datafile]
543
+ FileUtils.copy(scriptfile, desc_dir) unless @options[:datafile]
561
544
  end
562
545
 
563
546
  def create_datafile
564
- return unless options[:datafile]
547
+ return unless @options[:datafile]
565
548
 
566
549
  nputs "Creating datafile '#{datafile}'."
567
550
  data_files = @data_files.select { |file| File.file? file }
@@ -570,21 +553,22 @@ options:
570
553
  end
571
554
  data_files.uniq! { |file| File.expand_path(file) }
572
555
 
573
- unless options[:virtual_directory]
556
+ unless @options[:virtual_directory]
574
557
  dir_pwd = Dir.pwd.encode(Encoding::UTF_8)
575
558
  virtual_directories = Pathname.new(dir_pwd).ascend.to_a.map(&:to_s)
576
559
  data_files.each do |file|
577
560
  fullpath = File.expand_path(file)
578
561
  next if fullpath.start_with?(rubydir) || Pathname.new(file).absolute?
562
+
579
563
  virtual_directories.shift until fullpath.start_with?(virtual_directories.first)
580
564
  end
581
- options[:virtual_directory] = relative_path(dir_pwd, virtual_directories.first, "/_neri_virtual_directory_/")
582
- nputs "virtual_directory: #{options[:virtual_directory]}"
565
+ @options[:virtual_directory] = relative_path(dir_pwd, virtual_directories.first, "/_neri_virtual_directory_/")
566
+ nputs "virtual_directory: #{@options[:virtual_directory]}"
583
567
  end
584
568
 
585
- if options[:encryption_key]
569
+ if @options[:encryption_key]
586
570
  require "digest/sha2"
587
- @encryption_key = Digest::SHA2.hexdigest(options[:encryption_key])
571
+ @encryption_key = Digest::SHA2.hexdigest(@options[:encryption_key])
588
572
  end
589
573
  Neri.key = @encryption_key || "0" * 64
590
574
  File.open(datafile, "wb") do |f|
@@ -592,19 +576,18 @@ options:
592
576
  file_informations = data_files.map do |file|
593
577
  fullpath = File.expand_path(file)
594
578
  filename = if fullpath.start_with?(rubydir)
595
- relative_path(fullpath, rubydir, "#{options[:system_dir]}#{File::SEPARATOR}")
579
+ relative_path(fullpath, rubydir, "#{@options[:system_dir]}#{File::SEPARATOR}")
596
580
  else
597
581
  file
598
582
  end
599
583
  filedata = [filename, File.size(file), pos].join("\t")
600
- nputs_v " - #{filename}:#{File.size(file)} bytes"
601
584
  pos += File.size(file)
602
- pos += BLOCK_LENGTH - pos % BLOCK_LENGTH unless pos % BLOCK_LENGTH == 0
585
+ pos += Neri::BLOCK_LENGTH - pos % Neri::BLOCK_LENGTH unless pos % Neri::BLOCK_LENGTH == 0
603
586
  filedata
604
587
  end
605
588
  files_str = file_informations.join("\n").encode(Encoding::UTF_8)
606
589
 
607
- f.write(format("%#{BLOCK_LENGTH}d", files_str.bytesize))
590
+ f.write(format("%#{Neri::BLOCK_LENGTH}d", files_str.bytesize))
608
591
  f.write(xor(files_str))
609
592
  data_files.each do |file|
610
593
  f.write(xor(File.binread(file)))
@@ -616,26 +599,26 @@ options:
616
599
  nputs "Creating batch_file '#{basepath}.bat'."
617
600
 
618
601
  pause_command = ""
619
- if options[:pause_last]
602
+ if @options[:pause_last]
620
603
  pause_command += "echo.\n"
621
- if options[:pause_text]
622
- pause_command += "echo #{options[:pause_text]}\n" +
623
- "pause > nul"
624
- else
625
- pause_command += "pause"
626
- end
604
+ pause_command +=
605
+ if @options[:pause_text]
606
+ "echo #{@options[:pause_text]}\npause > nul"
607
+ else
608
+ "pause"
609
+ end
627
610
  end
628
- chdir = options[:chdir_first] ? 'cd /d "%~dp0"' : ""
611
+ chdir = @options[:chdir_first] ? 'cd /d "%~dp0"' : ""
629
612
 
630
- File.open("#{basepath}.bat", "w:#{options[:external_encoding]}") do |f|
613
+ File.open("#{basepath}.bat", "w:#{@options[:external_encoding]}") do |f|
631
614
  f.puts <<-BATCH
632
615
  @echo off
633
616
  setlocal
634
- set PATH=%~dp0#{options[:system_dir]}\\#{relative_path(bindir)};%PATH%
617
+ set PATH=%~dp0#{@options[:system_dir]}\\#{relative_path(bindir)};%PATH%
635
618
  set NERI_EXECUTABLE=%~0
636
619
  #{chdir}
637
620
  if %~x0 == .exe ( shift )
638
- #{ruby_command(options[:chdir_first] ? '' : '%~dp0')} %1 %2 %3 %4 %5 %6 %7 %8 %9
621
+ #{ruby_command(@options[:chdir_first] ? '' : '%~dp0')} %1 %2 %3 %4 %5 %6 %7 %8 %9
639
622
  #{pause_command}
640
623
  endlocal
641
624
  BATCH
@@ -653,9 +636,9 @@ endlocal
653
636
  c_file = to_winpath("#{basepath}_tmp.c" )
654
637
  o_file = to_winpath("#{basepath}_tmp.o" )
655
638
  rc_file = to_winpath("#{basepath}_tmp.rc")
656
- system_dir = escape_cstr(to_winpath(File.join(options[:system_dir], "")))
639
+ system_dir = escape_cstr(to_winpath(File.join(@options[:system_dir], "")))
657
640
  nputs "Creating exe_file '#{exe_file}'."
658
- File.open(c_file, "w:#{options[:external_encoding]}") do |f|
641
+ File.open(c_file, "w:#{@options[:external_encoding]}") do |f|
659
642
  f.puts <<-CFILE
660
643
  #include <stdio.h>
661
644
  #include <stdlib.h>
@@ -684,9 +667,9 @@ int main(int argc, char *argv[])
684
667
  putenv(paths);
685
668
  snprintf(paths, sizeof(paths), "PATH=%s%s#{system_dir}bin;%s", drive, dir, getenv("PATH"));
686
669
  putenv(paths);
687
- #{options[:chdir_first] ? 'snprintf(paths, sizeof(paths), "%s%s", drive, dir);chdir(paths);' : ''}
688
- snprintf(runruby, sizeof(runruby), "#{escape_cstr(ruby_command(options[:chdir_first] ? '' : '%s%s'))} %s %s %s %s %s %s %s %s %s",
689
- #{options[:chdir_first] ? '' : 'drive, dir,'}
670
+ #{@options[:chdir_first] ? 'snprintf(paths, sizeof(paths), "%s%s", drive, dir);chdir(paths);' : ''}
671
+ snprintf(runruby, sizeof(runruby), "#{escape_cstr(ruby_command(@options[:chdir_first] ? '' : '%s%s'))} %s %s %s %s %s %s %s %s %s",
672
+ #{@options[:chdir_first] ? '' : 'drive, dir,'}
690
673
  argc > 1 ? argv[1] : "",
691
674
  argc > 2 ? argv[2] : "",
692
675
  argc > 3 ? argv[3] : "",
@@ -698,15 +681,15 @@ int main(int argc, char *argv[])
698
681
  argc > 9 ? argv[9] : ""
699
682
  );
700
683
  CFILE
701
- if options[:b2ec][:invisible]
684
+ if @options[:invisible]
702
685
  f.puts %[ CreateProcess(NULL, runruby, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS | CREATE_NO_WINDOW, NULL, NULL, &si, &pi);]
703
686
  else
704
687
  f.puts %[ system(runruby);]
705
688
  end
706
- if options[:pause_last]
689
+ if @options[:pause_last]
707
690
  f.puts %[ system("echo.");]
708
- if options[:pause_text]
709
- f.puts %[ system("echo #{escape_cstr(options[:pause_text])}");]
691
+ if @options[:pause_text]
692
+ f.puts %[ system("echo #{escape_cstr(@options[:pause_text])}");]
710
693
  f.puts %[ system("pause >nul");]
711
694
  else
712
695
  f.puts %[ system("pause");]
@@ -715,31 +698,31 @@ int main(int argc, char *argv[])
715
698
  f.puts " return 0;\n}"
716
699
  end
717
700
 
718
- File.open(rc_file, "w:#{options[:external_encoding]}") do |f|
701
+ File.open(rc_file, "w:#{@options[:external_encoding]}") do |f|
719
702
  f.puts <<-RCFILE
720
703
  #include <winver.h>
721
704
 
722
705
  1 VERSIONINFO
723
- #{options[:b2ec][:fileversion ] ? "FILEVERSION #{escape_cstr(options[:b2ec][:fileversion ])}" : ""}
724
- #{options[:b2ec][:productversion] ? "PRODUCTVERSION #{escape_cstr(options[:b2ec][:productversion])}" : ""}
706
+ #{@options[:fileversion ] ? "FILEVERSION #{escape_cstr(@options[:fileversion ])}" : ''}
707
+ #{@options[:productversion] ? "PRODUCTVERSION #{escape_cstr(@options[:productversion])}" : ''}
725
708
  FILETYPE VFT_APP
726
709
  BEGIN
727
710
  BLOCK "StringFileInfo"
728
711
  BEGIN
729
712
  BLOCK "000004b0"
730
713
  BEGIN
731
- #{options[:b2ec][:fileversion ] ? 'VALUE "FileVersion", "' + escape_cstr(options[:b2ec][:fileversion ]) + '\0"' : ''}
732
- #{options[:b2ec][:productversion ] ? 'VALUE "ProductVersion", "' + escape_cstr(options[:b2ec][:productversion ]) + '\0"' : ''}
733
- #{options[:b2ec][:productname ] ? 'VALUE "ProductName", "' + escape_cstr(options[:b2ec][:productname ]) + '\0"' : ''}
734
- #{options[:b2ec][:originalfilename] ? 'VALUE "OriginalFileName", "' + escape_cstr(options[:b2ec][:originalfilename]) + '\0"' : ''}
735
- #{options[:b2ec][:internalname ] ? 'VALUE "InternalName", "' + escape_cstr(options[:b2ec][:internalname ]) + '\0"' : ''}
736
- #{options[:b2ec][:description ] ? 'VALUE "FileDescription", "' + escape_cstr(options[:b2ec][:description ]) + '\0"' : ''}
737
- #{options[:b2ec][:company ] ? 'VALUE "CompanyName", "' + escape_cstr(options[:b2ec][:company ]) + '\0"' : ''}
738
- #{options[:b2ec][:trademarks ] ? 'VALUE "LegalTrademarks", "' + escape_cstr(options[:b2ec][:trademarks ]) + '\0"' : ''}
739
- #{options[:b2ec][:copyright ] ? 'VALUE "LegalCopyright", "' + escape_cstr(options[:b2ec][:copyright ]) + '\0"' : ''}
740
- #{options[:b2ec][:privatebuild ] ? 'VALUE "PrivateBuild", "' + escape_cstr(options[:b2ec][:privatebuild ]) + '\0"' : ''}
741
- #{options[:b2ec][:specialbuild ] ? 'VALUE "SpecialBuild", "' + escape_cstr(options[:b2ec][:specialbuild ]) + '\0"' : ''}
742
- #{options[:b2ec][:comments ] ? 'VALUE "Comments", "' + escape_cstr(options[:b2ec][:comments ]) + '\0"' : ''}
714
+ #{@options[:fileversion ] ? 'VALUE "FileVersion", "' + escape_cstr(@options[:fileversion ]) + '\0"' : ''}
715
+ #{@options[:productversion ] ? 'VALUE "ProductVersion", "' + escape_cstr(@options[:productversion ]) + '\0"' : ''}
716
+ #{@options[:productname ] ? 'VALUE "ProductName", "' + escape_cstr(@options[:productname ]) + '\0"' : ''}
717
+ #{@options[:originalfilename] ? 'VALUE "OriginalFileName", "' + escape_cstr(@options[:originalfilename]) + '\0"' : ''}
718
+ #{@options[:internalname ] ? 'VALUE "InternalName", "' + escape_cstr(@options[:internalname ]) + '\0"' : ''}
719
+ #{@options[:description ] ? 'VALUE "FileDescription", "' + escape_cstr(@options[:description ]) + '\0"' : ''}
720
+ #{@options[:company ] ? 'VALUE "CompanyName", "' + escape_cstr(@options[:company ]) + '\0"' : ''}
721
+ #{@options[:trademarks ] ? 'VALUE "LegalTrademarks", "' + escape_cstr(@options[:trademarks ]) + '\0"' : ''}
722
+ #{@options[:copyright ] ? 'VALUE "LegalCopyright", "' + escape_cstr(@options[:copyright ]) + '\0"' : ''}
723
+ #{@options[:privatebuild ] ? 'VALUE "PrivateBuild", "' + escape_cstr(@options[:privatebuild ]) + '\0"' : ''}
724
+ #{@options[:specialbuild ] ? 'VALUE "SpecialBuild", "' + escape_cstr(@options[:specialbuild ]) + '\0"' : ''}
725
+ #{@options[:comments ] ? 'VALUE "Comments", "' + escape_cstr(@options[:comments ]) + '\0"' : ''}
743
726
  END
744
727
  END
745
728
 
@@ -749,23 +732,23 @@ BEGIN
749
732
  END
750
733
  END
751
734
 
752
- 2 ICON "#{escape_cstr(options[:b2ec][:icon])}"
735
+ 2 ICON "#{escape_cstr(@options[:icon])}"
753
736
  RCFILE
754
737
  end
755
738
  nsystem(%(windres -o "#{o_file}" "#{rc_file}"))
756
- nsystem(%(gcc#{options[:b2ec][:invisible] ? ' -mwindows' : ''} -o "#{exe_file}" "#{c_file}" "#{o_file}"))
739
+ nsystem(%(gcc#{@options[:invisible] ? ' -mwindows' : ''} -o "#{exe_file}" "#{c_file}" "#{o_file}"))
757
740
  nsystem(%(strip "#{exe_file}"))
758
741
  File.delete(c_file, rc_file, o_file)
759
742
  end
760
743
 
761
744
  def ruby_command(path)
762
- system_dir = "#{path}#{File.join(options[:system_dir], '')}"
745
+ system_dir = "#{path}#{File.join(@options[:system_dir], '')}"
763
746
  ruby_code = ""
764
747
  ruby_code = "Neri.key='#{@encryption_key}';" if @encryption_key
765
- if options[:datafile]
766
- ruby_code += "Neri.datafile='#{system_dir}' + #{unpack_filename(options[:datafile])};"
767
- if options[:virtual_directory]
768
- ruby_code += "Neri.virtual_directory=#{unpack_filename(options[:virtual_directory])};"
748
+ if @options[:datafile]
749
+ ruby_code += "Neri.datafile='#{system_dir}' + #{unpack_filename(@options[:datafile])};"
750
+ if @options[:virtual_directory]
751
+ ruby_code += "Neri.virtual_directory=#{unpack_filename(@options[:virtual_directory])};"
769
752
  end
770
753
  ruby_code += "load #{unpack_filename(File.basename(scriptfile))}"
771
754
  else
@@ -781,141 +764,23 @@ END
781
764
  %(#{ruby}#{r} #{@rubyopt} -e "# coding:utf-8" -e "#{ruby_code}" #{@args})
782
765
  end
783
766
 
784
- def bat_to_exe_converter
785
- create_batfile
786
- begin
787
- `#{options[:b2ec_path]} /help`
788
- rescue
789
- error "Bat To Exe Converter not found !"
790
- return
791
- end
792
-
793
- batch_file = "#{basepath}.bat"
794
- exe_file = "#{basepath}.exe"
795
- nputs "Creating exe_file '#{exe_file}' with Bat To Exe Converter."
796
- File.delete(exe_file) if File.exist?(exe_file)
797
- if options[:b2ec][:x64].nil? && RbConfig::CONFIG["target"].to_s.index("64")
798
- options[:b2ec][:x64] = true
799
- end
800
- args = %( /bat "#{batch_file}" /exe "#{exe_file}")
801
- args += options[:b2ec].map { |key, value|
802
- case value
803
- when String then %( /#{key.to_s.tr('_', '-')} "#{value}")
804
- when true then %( /#{key.to_s.tr('_', '-')})
805
- else; %()
806
- end
807
- }.join("")
808
-
809
- error "Failed to create exe_file !" unless nsystem "#{options[:b2ec_path]}#{args}"
810
- end
811
-
812
- def upx
813
- unless system("#{options[:upx_path]} --version >nul 2>&1")
814
- error "UPX not found !"
815
- return
816
- end
817
-
818
- nputs "Compressing with UPX."
819
- options[:upx_targets].each do |target|
820
- Dir.glob(File.join(options[:output_dir], options[:system_dir], target)).each do |target_path|
821
- command = %("#{options[:upx_path]}" #{options[:upx_options]} "#{target_path}")
822
- nsystem command
823
- end
824
- end
825
- end
826
-
827
- def create_zipfile
828
- unless system("#{options[:sevenzip_path]} >nul 2>&1")
829
- error "7-Zip not found !"
830
- return
831
- end
832
-
833
- nputs "Creating zip_file '#{options[:zipfile]}'."
834
- File.delete(options[:zipfile]) if File.exist?(options[:zipfile])
835
- files = []
836
- if options[:output_dir] == "./"
837
- files.push(options[:system_dir])
838
- files.push(File.exist?("#{basepath}.exe") ? "#{basepath}.exe" : "#{basepath}.bat")
839
- else
840
- files.push(options[:output_dir])
841
- end
842
- command = %("#{options[:sevenzip_path]}" a "#{options[:zipfile]}" "#{files.join('" "')}")
843
- nsystem command
844
- end
845
-
846
- def inno_setup
847
- unless system("#{options[:iscc_path]} /? >nul 2>&1")
848
- error("Inno Setup not found !")
849
- return
850
- end
851
-
852
- filename = options[:inno_script]
853
- nputs "Creating Installer '#{filename}'."
854
- script = "[Setup]\n"
855
- if File.exist?(filename)
856
- script = File.read(filename, encoding: Encoding::UTF_8)
857
- filename = "#{File.basename(filename, '.*')}_tmp#{File.extname(filename)}"
858
- end
859
-
860
- version = options[:b2ec][:productversion] || options[:b2ec][:fileversion]
861
- if !script.match(/^AppName=/) && options[:b2ec][:productname]
862
- script.sub!(/^(\[Setup\])(\s+)/i) { "#{$1}\nAppName=#{options[:b2ec][:productname]}#{$2}" }
863
- end
864
- if !script.match(/^AppVersion=/) && version
865
- script.sub!(/^(\[Setup\])(\s+)/i) { "#{$1}\nAppVersion=#{version}#{$2}" }
866
- end
867
- if !script.match(/^AppVerName=/) && options[:b2ec][:productname] && version
868
- script.sub!(/^(\[Setup\])(\s+)/i) { "#{$1}\nAppVerName=#{options[:b2ec][:productname]} #{version}#{$2}" }
869
- end
870
- if !script.match(/^AppPublisher=/) && options[:b2ec][:company]
871
- script.sub!(/^(\[Setup\])(\s+)/i) { "#{$1}\nAppPublisher=#{options[:b2ec][:company]}#{$2}" }
872
- end
873
- if !script.match(/^AppCopyright=/) && options[:b2ec][:copyright]
874
- script.sub!(/^(\[Setup\])(\s+)/i) { "#{$1}\nAppCopyright=#{options[:b2ec][:copyright]}#{$2}" }
875
- end
876
-
877
- script += "\n[Files]\n" unless script.match(/^\[Files\]/)
878
- dir = File.expand_path(options[:output_dir])
879
- files_str = ""
880
- Dir.glob(File.join(dir, "**", "*")).each do |file|
881
- next unless File.file? file
882
-
883
- dist_dir = to_winpath(File::SEPARATOR + File.dirname(relative_path(file, dir)))
884
- dist_dir = "" if dist_dir == "\\."
885
- files_str += "\nSource: \"#{to_winpath(file)}\"; DistDir: \"{app}#{dist_dir}"
886
- files_str += "; Flags: isreadme" if File.basename(file).match(/^readme/i)
887
- end
888
- script.sub!(/^(\[Files\])(\s*)/i) { "#{$1}#{files_str}#{$2}" }
889
-
890
- File.write(filename, script)
891
- command = %(#{options[:iscc_path]} "#{filename}")
892
- nsystem command
893
- end
894
-
895
767
  def run
896
768
  check_options
897
769
  dependencies = check_dependencies
898
770
  copy_files(dependencies)
899
771
  create_datafile
900
- if options[:no_exe]
901
- create_batfile
902
- else
903
- options[:use_b2ec] ? bat_to_exe_converter : create_exefile
904
- end
905
- upx if options[:use_upx]
906
- create_zipfile if options[:zipfile]
907
- inno_setup if options[:inno_script]
772
+ @options[:no_exe] ? create_batfile : create_exefile
908
773
  nputs "Neri Finished."
909
774
  end
910
775
 
911
776
  private
912
777
 
913
- def nputs(str)
914
- puts "=== #{str}" unless options[:quiet]
778
+ def xor(str)
779
+ Neri.__send__(:xor, str)
915
780
  end
916
781
 
917
- def nputs_v(str)
918
- puts str if options[:verbose]
782
+ def nputs(str)
783
+ puts "=== #{str}" unless @options[:quiet]
919
784
  end
920
785
 
921
786
  def error(str)
@@ -931,9 +796,8 @@ END
931
796
  end
932
797
 
933
798
  def nsystem(str)
934
- nputs_v(str)
935
- command = str.encode(options[:external_encoding])
936
- system(command + (options[:quiet] ? " >nul 2>&1" : ""))
799
+ command = str.encode(@options[:external_encoding])
800
+ system(command + (@options[:quiet] ? " >nul 2>&1" : ""))
937
801
  end
938
802
  end
939
803
  end