neri 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d67c3f127bbba240b418a1b67837d975daba02a4
4
- data.tar.gz: cd358a431ceca298b9e292ab56a5fd50570782cf
3
+ metadata.gz: b6cb041288c1942341b776e35972c8acfe2d0795
4
+ data.tar.gz: 7b139e1faa036adef2ad529d2d2b093dd05a863c
5
5
  SHA512:
6
- metadata.gz: e74b0b82312e4d867b05ad514c5e74ff1793677b154984c6d7634ebbe841eb1f67897cd22153c38c9c4e7a846f0247baa3dedce82b505efeef8ee00323fdee2d
7
- data.tar.gz: 9563978e91ea32666f1252a51077997b783d24a7289715ee0f982488ecbcf9e82bbd4526e0a5f6b21c58abbf5a007d2a49b0bc20ac89d1de4120812770077a8c
6
+ metadata.gz: d9b21cbe796bedd13e7797083cf4b9ca18ca72589fa8d0ed086f99b106ff89ebb7096709553954d3dbc0f2dd3b476ad0eee2efd3430ceef659057089271e7473
7
+ data.tar.gz: 4787a66bf519443605548e935291ca486667ca14f6288a032523062e95e1645387d578a61753ad621d4042211818b2af080d01946f3a4eaedc4a3cd8edf7324a
data/exe/neri CHANGED
@@ -2,6 +2,6 @@
2
2
  # encoding: UTF-8
3
3
 
4
4
  require "neri"
5
- require "neri/build.rb"
5
+ load "neri/build.rb"
6
6
 
7
7
  Neri.run()
data/lib/neri/build.rb ADDED
@@ -0,0 +1,695 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ require "neri"
5
+
6
+ module Neri
7
+ @data_files = []
8
+ @system_files = []
9
+
10
+ @options = {
11
+ quiet: false,
12
+ verbose: false,
13
+
14
+ dlls: [],
15
+ libs: [],
16
+ gems: [],
17
+ encoding: "*",
18
+
19
+ enable_gems: false,
20
+ enable_did_you_mean: false,
21
+ chdir_first: false,
22
+ pause_last: nil,
23
+ pause_text: nil,
24
+
25
+ output_dir: nil,
26
+ system_dir: "system",
27
+
28
+ data_file: nil,
29
+ encryption_key: nil,
30
+
31
+ no_exe: false,
32
+ b2ec_path: "Bat_To_Exe_Converter.exe",
33
+ b2ec: {
34
+ icon: "#{File.expand_path(File.dirname(__FILE__) + '/../../share/default.ico')}",
35
+ invisible: nil,
36
+ x64: nil,
37
+ admin: nil,
38
+ fileversion: nil,
39
+ productversion: nil,
40
+ company: nil,
41
+ productname: nil,
42
+ internalname: nil,
43
+ description: nil,
44
+ copyright: nil
45
+ },
46
+
47
+ use_upx: false,
48
+ upx_path: "upx.exe",
49
+ upx_targets: ["bin/**/*.dll"],
50
+ upx_options: "",
51
+
52
+ zipfile: nil,
53
+ sevenzip_path: "7z.exe",
54
+
55
+ inno_script: nil,
56
+ iscc_path: "iscc",
57
+ }
58
+ @rubyopt = ENV["RUBYOPT"].to_s
59
+ @encryption_key = nil
60
+
61
+ @use_dxruby = false
62
+ @use_dxruby_tiled = false
63
+ @use_ayame = false
64
+
65
+ class << self
66
+
67
+ attr_reader :options
68
+
69
+ def relative_path(path, basedir=rubydir, prepath = "")
70
+ basedir.concat(File::SEPARATOR) unless basedir.end_with?(File::SEPARATOR)
71
+ return path.start_with?(basedir) ? path.sub(basedir, prepath) : path
72
+ end
73
+
74
+ def to_winpath(path)
75
+ return File::ALT_SEPARATOR ? path.tr(File::SEPARATOR, File::ALT_SEPARATOR) : path
76
+ end
77
+
78
+ def bindir( ); RbConfig::CONFIG["bindir"] || File.join(rubydir, "bin"); end
79
+ def rubydir( ); RbConfig::TOPDIR; end
80
+ def rubyexe( ); RbConfig.ruby; end
81
+ def batchfile(); File.join(options[:output_dir], "#{File.basename(@data_files.first, ".*")}.bat"); end
82
+ def datafile( ); File.join(options[:output_dir], options[:system_dir], options[:data_file]); end
83
+
84
+ # --help
85
+ def output_help
86
+ puts <<-EOF
87
+ usage: neri [options] script.rb (other_files...) -- script_arguments
88
+
89
+ options:
90
+ --help or -h
91
+ --version or -v
92
+ --quiet
93
+ --verbose
94
+
95
+ --dll <dll1>,<dll2>,...
96
+ --lib <lib1>,<lib2>,...
97
+ --gem <gem1>,<gem2>,...
98
+
99
+ --no-enc
100
+ --encoding <enc1>,<enc2>,...
101
+
102
+ --enable-gems
103
+ --enable-did-you-mean
104
+ --chdir-first
105
+ --pause-last
106
+ --no-pause-last
107
+ --pause-text <text>
108
+
109
+ --output-dir <dirname>
110
+ --system-dir <dirname>
111
+ --data-file <filename>
112
+ --encryption-key <key>
113
+
114
+ --no-exe
115
+ --b2ec-path <bat_to_exe_converter_path>
116
+ --icon <iconfile>
117
+ --windows or --invisible
118
+ --console or --visible
119
+ --x64
120
+ --admin
121
+ --fileversion <version> # ex) 1,2,3,4
122
+ --productversion <version> # ex) 1,2,3,4
123
+ --company <company_name>
124
+ --productname <name>
125
+ --internalname <name>
126
+ --description <description>
127
+ --copyright <copyright>
128
+
129
+ --use-upx
130
+ --upx-path <upx path>
131
+ --upx_targets '<glob>' # ex) 'bin/**/*.dll'
132
+ --upx-options <options>
133
+
134
+ --zipfile <filename>
135
+ --7zip-path <7-zip path>
136
+
137
+ --innosetup <inno_script>
138
+ --iscc-path <iscc path>
139
+
140
+ --create-recipe <recipefile>
141
+ --recipe <recipefile>
142
+ EOF
143
+ end
144
+
145
+ # --version
146
+ def output_version
147
+ puts "Neri #{Neri::VERSION}"
148
+ end
149
+
150
+ # --create-recipe
151
+ def create_recipe(file, hash = options, pre = "Neri.options")
152
+ hash.each_pair do |key, value|
153
+ case value
154
+ when Hash
155
+ create_recipe(file, value, pre + "[:#{key}]")
156
+ when Numeric, TrueClass, FalseClass
157
+ file.puts "#{pre}[:#{key}] = #{value}"
158
+ when NilClass
159
+ file.puts "#{pre}[:#{key}] = nil"
160
+ when String
161
+ file.puts "#{pre}[:#{key}] = '#{value.gsub("\\", "\\\\").gsub("'", "\\'")}'"
162
+ when Array
163
+ file.puts "#{pre}[:#{key}] = " + JSON.generate(value)
164
+ end
165
+ end
166
+ end
167
+
168
+
169
+ def check_options
170
+ nputs_v "Checking Neri options."
171
+ while arg = ARGV.shift
172
+ case arg
173
+ when "--help", "-h"
174
+ output_help
175
+ exit
176
+ when "--version", "-v"
177
+ output_version
178
+ exit
179
+ when "--quiet", "-q"
180
+ options[:quiet] = true
181
+ when "--verbose", "-v"
182
+ options[:verbose] = true
183
+ when "--dll"
184
+ options[:dlls] += ARGV.shift.split(/\s*,\s*/)
185
+ when "--lib"
186
+ options[:libs] += ARGV.shift.split(/\s*,\s*/)
187
+ when "--gem"
188
+ options[:gems] += ARGV.shift.split(/\s*,\s*/)
189
+ when "--no-enc"
190
+ options[:encoding] = nil
191
+ when "--encoding"
192
+ options[:encoding] = ARGV.shift
193
+ when "--enable-gems"
194
+ options[:enable_gems] = true
195
+ when "--enable-did-you-mean"
196
+ options[:enable_did_you_mean] = true
197
+ when "--chdir-first"
198
+ options[:chdir_first] = true
199
+ when "--pause-last"
200
+ options[:pause_last] = true
201
+ when "--no-pause-last"
202
+ options[:pause_last] = false
203
+ when "--pause-text"
204
+ options[:pause_text] = ARGV.shift
205
+ options[:pause_last] = true
206
+ when "--output-dir"
207
+ options[:output_dir] = ARGV.shift
208
+ when "--system-dir"
209
+ options[:system_dir] = ARGV.shift
210
+ when "--data-file"
211
+ options[:data_file] = ARGV.shift
212
+ when "--encryption-key"
213
+ options[:encryption_key] = ARGV.shift
214
+ when "--no-exe"
215
+ options[:no_exe] = true
216
+ when "--b2ec-path"
217
+ options[:b2ec_path] = ARGV.shift
218
+ when "--icon"
219
+ options[:b2ec][:icon] = ARGV.shift
220
+ when "--windows", "--invisible"
221
+ options[:b2ec][:invisible] = true
222
+ when "--console", "--visible"
223
+ options[:b2ec][:invisible] = false
224
+ when "--x64"
225
+ options[:b2ec][:x64] = true
226
+ when "--admin"
227
+ options[:b2ec][:admin] = true
228
+ when "--fileversion"
229
+ options[:b2ec][:fileversion] = ARGV.shift
230
+ when "--productversion"
231
+ options[:b2ec][:productversion] = ARGV.shift
232
+ when "--company"
233
+ options[:b2ec][:company] = ARGV.shift
234
+ when "--productname"
235
+ options[:b2ec][:productname] = ARGV.shift
236
+ when "--internalname"
237
+ options[:b2ec][:internalname] = ARGV.shift
238
+ when "--description"
239
+ options[:b2ec][:description] = ARGV.shift
240
+ when "--copyright"
241
+ options[:b2ec][:copyright] = ARGV.shift
242
+ when "--use-upx"
243
+ options[:use_upx] = true
244
+ when "--upx-path"
245
+ options[:upx_path] = ARGV.shift
246
+ when "--upx-targets"
247
+ options[:upx_targets] += ARGV.shift.split(/\s*,\s*/)
248
+ when "--upx-options"
249
+ options[:upx_options] = ARGV.shift
250
+ when "--zipfile"
251
+ options[:zipfile] = ARGV.shift
252
+ when "--7zip-path"
253
+ options[:sevenzip_path] = ARGV.shift
254
+ when "--innosetup"
255
+ options[:inno_script] = ARGV.shift
256
+ when "--iscc-path"
257
+ options[:iscc_path] = ARGV.shift
258
+ when "--create-recipe"
259
+ require "json"
260
+ filename = ARGV.shift
261
+ nputs "Creating recipe_file '#{filename}'."
262
+ open(filename, "w:utf-8"){|file| create_recipe(file)}
263
+ exit
264
+ when "--recipe"
265
+ filename = ARGV.shift
266
+ nputs_v "Loading recipe_file '#{filename}'."
267
+ load filename
268
+ when "--"
269
+ break
270
+ when /^(--.+)/
271
+ puts "** Invalid Option '#{arg}'! **"
272
+ output_help
273
+ exit
274
+ else
275
+ @data_files.push(arg)
276
+ end
277
+ end
278
+
279
+ if @data_files.empty?
280
+ puts "** No Script File! **"
281
+ output_help
282
+ exit
283
+ end
284
+
285
+ if @data_files.size > 1 || options[:encryption_key]
286
+ options[:data_file] ||= File.basename(@data_files.first, ".*") + ".dat"
287
+ end
288
+ end
289
+
290
+
291
+ # check dependencies
292
+ def rb_dependencies()
293
+ return $LOADED_FEATURES.uniq
294
+ end
295
+
296
+ def dll_dependencies()
297
+ require "Win32API"
298
+
299
+ enumprocessmodules = Win32API.new("psapi" , "EnumProcessModules", ["L","P","L","P"], "L")
300
+ getmodulefilename = Win32API.new("kernel32", "GetModuleFileNameW", ["L","P","L"], "L")
301
+ getcurrentprocess = Win32API.new("kernel32", "GetCurrentProcess" , [], "L")
302
+
303
+ bytes_needed = 4 * 32
304
+ module_handle_buffer = nil
305
+ process_handle = getcurrentprocess.call()
306
+ loop do
307
+ module_handle_buffer = "\x00" * bytes_needed
308
+ bytes_needed_buffer = [0].pack("I")
309
+ r = enumprocessmodules.call(process_handle, module_handle_buffer, module_handle_buffer.size, bytes_needed_buffer)
310
+ bytes_needed = bytes_needed_buffer.unpack("I")[0]
311
+ break if bytes_needed <= module_handle_buffer.size
312
+ end
313
+
314
+ handles = module_handle_buffer.unpack("I*")
315
+ dependencies = handles.select { |handle| handle > 0 }.map do |handle|
316
+ str = "\x00\x00" * 256
317
+ modulefilename_length = getmodulefilename.call(handle, str, str.size)
318
+ modulefilename = str[0, modulefilename_length * 2].force_encoding("UTF-16LE").encode("UTF-8")
319
+ end
320
+
321
+ dependencies.map!{|dep| dep.sub(/^\\\\\?\\/, "")}
322
+ if File::ALT_SEPARATOR
323
+ dependencies.map!{|dep| dep.tr(File::ALT_SEPARATOR, File::SEPARATOR)}
324
+ end
325
+ dependencies.delete(rubyexe)
326
+
327
+ return dependencies.uniq
328
+ end
329
+
330
+ def ruby_dependencies()
331
+ dependencies = Dir.glob(File.join(bindir, "**", "*.manifest"))
332
+ dependencies.push(rubyexe)
333
+ return dependencies.uniq
334
+ end
335
+
336
+ def additional_dlls_dependencies()
337
+ dependencies = []
338
+ options[:dlls].each do |dll|
339
+ dependencies += Dir.glob(File.join(bindir, "**", dll))
340
+ dependencies += Dir.glob(File.join(bindir, "**", dll + ".*"))
341
+ end
342
+ return dependencies.uniq
343
+ end
344
+
345
+ def additional_libs_dependencies()
346
+ dependencies = []
347
+ options[:libs].each do |lib|
348
+ $LOAD_PATH.each do |path|
349
+ dependencies += Dir.glob(File.join(path, lib))
350
+ dependencies += Dir.glob(File.join(path, lib + ".*"))
351
+ dependencies += Dir.glob(File.join(path, lib, "**", "*"))
352
+ end
353
+ end
354
+ return dependencies.uniq
355
+ end
356
+
357
+ def additional_gems_dependencies()
358
+ require "rubygems"
359
+ dependencies = []
360
+ rubygems_dir = File.join(Gem.dir, "gems")
361
+ options[:gems].each do |gem|
362
+ gem.sub!(/\:(.+)/, "")
363
+ targets = $1.to_s.split("|")
364
+ targets.push("lib/**/*")
365
+ gem += "-*" unless gem.match("-")
366
+ gemdir = Dir.glob(File.join(rubygems_dir, gem)).sort.last
367
+ next unless gemdir
368
+ targets.each do |target|
369
+ dependencies += Dir.glob(File.join(gemdir, target))
370
+ end
371
+ end
372
+ return dependencies.uniq
373
+ end
374
+
375
+ def encoding_dependencies()
376
+ return [] unless options[:encoding]
377
+ dependencies = []
378
+ enc_dir = Dir.glob(File.join(RbConfig::CONFIG["archdir"] || RbConfig::TOPDIR, "**", "enc")).first
379
+
380
+ options[:encoding].split(/\s*,\s*/).each do |enc|
381
+ case enc
382
+ when "ja"
383
+ %w[windows_31j.so japanese_sjis.so encdb.so].each do |enc_name|
384
+ dependencies += Dir.glob(File.join(enc_dir, "**", enc_name))
385
+ end
386
+ else
387
+ dependencies += Dir.glob(File.join(enc_dir, "**", enc))
388
+ dependencies += Dir.glob(File.join(enc_dir, "**", enc + ".*"))
389
+ end
390
+ end
391
+
392
+ return dependencies.uniq
393
+ end
394
+
395
+ def check_dependencies()
396
+ nputs "Running script '#{@data_files.first}' to check dependencies."
397
+ begin
398
+ load @data_files.first
399
+ rescue SystemExit
400
+ end
401
+ nputs "Script '#{@data_files.first}' end."
402
+
403
+ if defined? DXRuby
404
+ require "neri/dxruby"
405
+ @use_dxruby = true
406
+ options[:b2ec][:invisible] = true if options[:b2ec][:invisible] == nil
407
+ end
408
+ if defined? DXRuby::Tiled
409
+ require "neri/dxruby_tiled"
410
+ @use_dxruby_tiled = true
411
+ end
412
+ if defined? Ayame
413
+ require "neri/ayame"
414
+ @use_ayame = true
415
+ end
416
+
417
+ if options[:b2ec][:invisible] == nil
418
+ options[:b2ec][:invisible] = true if File.extname(@data_files.first) == ".rbw"
419
+ end
420
+ if options[:pause_last] == nil
421
+ options[:pause_last] = true unless options[:b2ec][:invisible]
422
+ end
423
+
424
+ require "rbconfig"
425
+ dependencies = []
426
+ dependencies += rb_dependencies
427
+ dependencies += dll_dependencies
428
+ dependencies += ruby_dependencies
429
+ dependencies += additional_dlls_dependencies
430
+ dependencies += additional_libs_dependencies
431
+ dependencies += additional_gems_dependencies
432
+ dependencies += encoding_dependencies
433
+ dependencies = select_dependencies(dependencies)
434
+
435
+ size = dependencies.map{|d| File.size(d)}.inject(&:+)
436
+ nputs "#{dependencies.size} files, #{size} bytes dependencies."
437
+ if options[:verbose]
438
+ dependencies.each do |dependency|
439
+ nputs_v " - #{dependency}"
440
+ end
441
+ end
442
+
443
+ return dependencies
444
+ end
445
+
446
+ def select_dependencies(dependencies)
447
+ dependencies.select! do |dependency|
448
+ dependency.start_with?(rubydir + File::SEPARATOR)
449
+ end
450
+
451
+ @data_files.each do |file|
452
+ dependencies.delete(File.expand_path(file))
453
+ end
454
+
455
+ unless options[:enable_gems]
456
+ dependencies.delete_if do |dependency|
457
+ File.basename(dependency) == "rubygems.rb" ||
458
+ dependency.split(File::SEPARATOR).index("rubygems")
459
+ end
460
+ end
461
+ unless options[:enable_did_you_mean]
462
+ dependencies.delete_if do |dependency|
463
+ File.basename(dependency) == "did_you_mean.rb" ||
464
+ dependency.split(File::SEPARATOR).index("did_you_mean")
465
+ end
466
+ end
467
+
468
+ return dependencies.uniq
469
+ end
470
+
471
+
472
+ def copy_files(dependencies)
473
+ nputs "Copying dependencies."
474
+ require "fileutils"
475
+ options[:output_dir] ||= File.basename(@data_files.first, ".*")
476
+ src_dir = File.join(rubydir, "")
477
+ desc_dir = File.join(options[:output_dir], options[:system_dir], "")
478
+
479
+ @system_files = dependencies.map do |file|
480
+ [file, file.sub(src_dir, desc_dir)]
481
+ end
482
+ unless options[:enable_gems]
483
+ @system_files.each do |src, desc|
484
+ desc.sub!(/\/gems(\/\d+\.\d+\.\d+\/)gems\/(.+?)\-[^\/]+\/lib\//, "/vendor_ruby\\1")
485
+ end
486
+ end
487
+
488
+ @system_files.each do |src, desc|
489
+ FileUtils.makedirs(File.dirname(desc))
490
+ if File.file?(src)
491
+ FileUtils.copy(src, desc)
492
+ nputs_v " #{src}\n -> #{desc}"
493
+ end
494
+ end
495
+ FileUtils.copy(@data_files.first, desc_dir) unless options[:data_file]
496
+ end
497
+
498
+
499
+ def create_batch()
500
+ nputs "Creating batch_file '#{batchfile}'."
501
+
502
+ enc = system(%(ruby --disable-gems -e "'#{@data_files.first}'" >NUL 2>&1)) ?
503
+ '' : ' -e "# coding: utf-8"'
504
+
505
+ unless options[:enable_gems]
506
+ @rubyopt += " --disable-gems" unless @rubyopt.match("--disable-gems")
507
+ end
508
+
509
+ ruby_code = ""
510
+ if options[:encryption_key]
511
+ require "digest/sha2"
512
+ @encryption_key = Digest::SHA2.hexdigest(options[:encryption_key])
513
+ ruby_code = "Neri.key='#{@encryption_key}';"
514
+ end
515
+ if options[:data_file]
516
+ data_file = "%~dp0#{options[:system_dir]}#{File::ALT_SEPARATOR || File::SEPARATOR}#{options[:data_file]}"
517
+ ruby_code += "Neri.datafile='#{data_file}';"
518
+ ruby_code += "load '#{File.basename(@data_files.first)}'"
519
+ else
520
+ ruby_code += "load '%~dp0#{options[:system_dir]}#{File::ALT_SEPARATOR}#{File.basename(@data_files.first)}'"
521
+ end
522
+
523
+ pause_code = ""
524
+ if options[:pause_last]
525
+ if options[:pause_text]
526
+ pause_code = "echo.\necho #{options[:pause_text]}\npause > nul"
527
+ else
528
+ pause_code = "echo.\npause"
529
+ end
530
+ end
531
+
532
+ r = " -rneri"
533
+ r += " -rneri/dxruby" if @use_dxruby
534
+ r += " -rneri/dxruby_tiled" if @use_dxruby_tiled
535
+ r += " -rneri/ayame" if @use_ayame
536
+
537
+ open(batchfile, "w:#{Encoding.default_external.name}") do |f|
538
+ f.puts <<-EOF
539
+ @echo off
540
+ setlocal
541
+ set PATH=%~dp0#{options[:system_dir]}\\#{relative_path(bindir)};%PATH%
542
+ #{options[:chdir_first] ? 'cd /d "%~dp0"' : ''}
543
+ if %~x0 == .exe ( shift )
544
+ #{relative_path(rubyexe, bindir)}#{r} #{@rubyopt}#{enc} -e "#{ruby_code}"
545
+ #{pause_code}
546
+ endlocal
547
+ EOF
548
+ end
549
+ end
550
+
551
+
552
+ def create_datafile()
553
+ nputs "Creating data_file '#{datafile}'."
554
+ Neri.key = @encryption_key || "0" * 64
555
+ open(datafile, "wb") do |f|
556
+ pos = 0
557
+ files_str = @data_files.map{|file|
558
+ filename = File.expand_path(file)
559
+ filename = relative_path(filename, rubydir, "*neri*" + File::SEPARATOR)
560
+ filename = relative_path(filename, Dir.pwd)
561
+ filedata = [filename, File.size(file), pos]
562
+ pos += File.size(file)
563
+ pos += BLOCK_LENGTH - pos % BLOCK_LENGTH unless pos % BLOCK_LENGTH == 0
564
+ nputs_v " - #{filename}:#{File.size(file)} bytes"
565
+ filedata.join("\t")
566
+ }.join("\n").encode(Encoding::UTF_8)
567
+
568
+ f.write(sprintf("%#{BLOCK_LENGTH}d", files_str.bytesize))
569
+ f.write(xor(files_str))
570
+ @data_files.each do |file|
571
+ f.write(xor(File.binread(file)))
572
+ end
573
+ end
574
+ end
575
+
576
+
577
+ def bat_to_exe_converter()
578
+ exefile = batchfile.sub(/\.bat$/, ".exe")
579
+ nputs "Creating exe_file '#{exefile}'."
580
+ File.delete(exefile) if File.exist?(exefile)
581
+ options[:b2ec][:bat] = batchfile
582
+ options[:b2ec][:save] = exefile
583
+ if options[:b2ec][:x64] == nil
584
+ options[:b2ec][:x64] = true if RbConfig::CONFIG["target"].to_s.index("64")
585
+ end
586
+
587
+ args = options[:b2ec].map{|key, value|
588
+ case value
589
+ when String; " -#{key.to_s} \"#{value}\""
590
+ when true; " -#{key.to_s}"
591
+ else; ""
592
+ end
593
+ }.join("")
594
+ begin
595
+ exec = %(#{options[:b2ec_path]}#{args})
596
+ nputs_v exec
597
+ options[:quiet] ? `#{exec}` : system(exec)
598
+ rescue SystemCallError
599
+ end
600
+ if File.exist?(exefile)
601
+ File.delete(batchfile)
602
+ else
603
+ nputs "Failed to create exe_file."
604
+ end
605
+ end
606
+
607
+
608
+ def upx()
609
+ nputs "Compressing with UPX."
610
+ options[:upx_targets].each do |target|
611
+ Dir.glob(File.join(options[:output_dir], options[:system_dir], target)).each do |target_path|
612
+ exec = %(#{options[:upx_path]} #{options[:upx_options]} "#{target_path}")
613
+ nputs_v exec
614
+ options[:quiet] ? `#{exec}` : system(exec)
615
+ end
616
+ end
617
+ end
618
+
619
+
620
+ def create_zipfile()
621
+ nputs "Creating zip_file '#{options[:zipfile]}'."
622
+ File.delete(options[:zipfile]) if File.exist?(options[:zipfile])
623
+ exec = %(#{options[:sevenzip_path]} a #{options[:zipfile]} "#{options[:output_dir]}")
624
+ nputs_v exec
625
+ options[:quiet] ? `#{exec}` : system(exec)
626
+ end
627
+
628
+
629
+ def inno_setup()
630
+ filename = options[:inno_script]
631
+ script = "[Setup]\n"
632
+ if File.exist?(filename)
633
+ script = File.read(filename, encoding: Encoding::UTF_8)
634
+ filename = File.basename(filename, ".*") + "_tmp" + File.extname(filename)
635
+ end
636
+
637
+ version = options[:b2ec][:productversion] || options[:b2ec][:fileversion]
638
+ if !script.match(/^AppName=/) && options[:b2ec][:productname]
639
+ script.sub!(/^(\[Setup\])(\s+)/i){ "#{$1}\nAppName=#{options[:b2ec][:productname]}#{$2}" }
640
+ end
641
+ if !script.match(/^AppVersion=/) && version
642
+ script.sub!(/^(\[Setup\])(\s+)/i){ "#{$1}\nAppVersion=#{version}#{$2}" }
643
+ end
644
+ if !script.match(/^AppVerName=/) && options[:b2ec][:productname] && version
645
+ script.sub!(/^(\[Setup\])(\s+)/i){ "#{$1}\nAppVerName=#{options[:b2ec][:productname]} #{version}#{$2}" }
646
+ end
647
+ if !script.match(/^AppPublisher=/) && options[:b2ec][:company]
648
+ script.sub!(/^(\[Setup\])(\s+)/i){ "#{$1}\nAppPublisher=#{options[:b2ec][:company]}#{$2}" }
649
+ end
650
+ if !script.match(/^AppCopyright=/) && options[:b2ec][:copyright]
651
+ script.sub!(/^(\[Setup\])(\s+)/i){ "#{$1}\nAppCopyright=#{options[:b2ec][:copyright]}#{$2}" }
652
+ end
653
+
654
+ script += "\n[Files]\n" unless script.match(/^\[Files\]/)
655
+ dir = File.expand_path(options[:output_dir])
656
+ files_str = ""
657
+ Dir.glob(File.join(dir, "**", "*")).each do |file|
658
+ next unless File.file? file
659
+ dist_dir = to_winpath(File::SEPARATOR + File.dirname(relative_path(file, dir)))
660
+ dist_dir = "" if dist_dir == "\\."
661
+ files_str += "\nSource: \"#{to_winpath(file)}\"; DistDir: \"{app}#{dist_dir}\""
662
+ files_str += "; Flags: isreadme" if File.basename(file).match(/^readme/i)
663
+ end
664
+ script.sub!(/^(\[Files\])(\s*)/i){ "#{$1}#{files_str}#{$2}" }
665
+
666
+ File.write(filename, script)
667
+ exec = %(#{options[:iscc_path]} "#{filename}")
668
+ nputs_v exec
669
+ options[:quiet] ? `#{exec}` : system(exec)
670
+ end
671
+
672
+ def run()
673
+ check_options
674
+ dependencies = check_dependencies
675
+ copy_files(dependencies)
676
+ create_batch
677
+ create_datafile if options[:data_file]
678
+ bat_to_exe_converter unless options[:no_exe]
679
+ upx if options[:use_upx]
680
+ create_zipfile if options[:zipfile]
681
+ inno_setup if options[:inno_script]
682
+ nputs "Neri Finished."
683
+ end
684
+
685
+ private
686
+
687
+ def nputs(str)
688
+ puts "=== #{str}" unless options[:quiet]
689
+ end
690
+
691
+ def nputs_v(str)
692
+ puts str if options[:verbose]
693
+ end
694
+ end
695
+ end
data/lib/neri/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Neri
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neri
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - nodai2hITC
@@ -71,6 +71,7 @@ files:
71
71
  - exe/neri
72
72
  - lib/neri.rb
73
73
  - lib/neri/ayame.rb
74
+ - lib/neri/build.rb
74
75
  - lib/neri/dxruby.rb
75
76
  - lib/neri/dxruby_tiled.rb
76
77
  - lib/neri/runtime.rb