neri 0.9.2 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/neri/ayame.rb +3 -6
- data/lib/neri/build.rb +218 -233
- data/lib/neri/dxruby.rb +18 -28
- data/lib/neri/dxruby_tiled.rb +1 -1
- data/lib/neri/runtime.rb +74 -72
- data/lib/neri/version.rb +1 -1
- data/neri.gemspec +3 -3
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9c11506aa1729506a8f2386ea1a37e45c6ef5f72cec65e3677931ef6f18910f
|
4
|
+
data.tar.gz: fb4307dd5e026985659ab652e27436759bd60531f1b9044ab6ca82f6d28eab22
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2d6307c498084b7327d96fb041304b6df4f2aca8756a81f90d6065b1a5b966eef64056d76ca6917267bd75f531ec1bead1e987195fc7379276d0de3233af7aa
|
7
|
+
data.tar.gz: b2002fe10dc92c4c87ddf7e961d77c5bddda93f0b9782b41e87e2b4ae5cc969b11123217b98f4d91d75a25c64db934a3db8eab6ed39be6072f3c046214923811
|
data/lib/neri/ayame.rb
CHANGED
@@ -5,12 +5,9 @@ require "ayame" unless defined? Ayame
|
|
5
5
|
module Neri
|
6
6
|
module Ayame
|
7
7
|
def new(filename)
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
else
|
12
|
-
return super
|
13
|
-
end
|
8
|
+
return super unless Neri.exist_in_datafile?(filename)
|
9
|
+
|
10
|
+
load_from_memory(Neri.file_read(filename))
|
14
11
|
end
|
15
12
|
end
|
16
13
|
end
|
data/lib/neri/build.rb
CHANGED
@@ -1,39 +1,38 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
2
|
|
4
3
|
require "neri"
|
5
4
|
|
6
5
|
module Neri
|
7
6
|
@data_files = []
|
8
|
-
|
7
|
+
|
9
8
|
@options = {
|
10
9
|
quiet: false,
|
11
10
|
verbose: false,
|
12
|
-
|
11
|
+
|
13
12
|
external_encoding: nil,
|
14
|
-
|
13
|
+
|
15
14
|
dlls: [],
|
16
15
|
libs: [],
|
17
16
|
gems: [],
|
18
17
|
encoding: "*",
|
19
|
-
|
18
|
+
|
20
19
|
enable_gems: false,
|
21
20
|
enable_did_you_mean: false,
|
22
21
|
chdir_first: false,
|
23
22
|
pause_last: nil,
|
24
23
|
pause_text: nil,
|
25
|
-
|
24
|
+
|
26
25
|
output_dir: "./",
|
27
26
|
system_dir: "system",
|
28
|
-
|
27
|
+
|
29
28
|
datafile: nil,
|
30
29
|
encryption_key: nil,
|
31
|
-
|
30
|
+
|
32
31
|
no_exe: false,
|
33
32
|
use_b2ec: false,
|
34
33
|
b2ec_path: "Bat_To_Exe_Converter",
|
35
34
|
b2ec: {
|
36
|
-
icon:
|
35
|
+
icon: File.expand_path("#{File.dirname(__FILE__)}/../../share/default.ico"),
|
37
36
|
invisible: nil,
|
38
37
|
x64: nil,
|
39
38
|
uac_admin: nil,
|
@@ -50,50 +49,49 @@ module Neri
|
|
50
49
|
specialbuild: nil,
|
51
50
|
comments: nil
|
52
51
|
},
|
53
|
-
|
52
|
+
|
54
53
|
use_upx: false,
|
55
54
|
upx_path: "upx",
|
56
55
|
upx_targets: ["bin/**/*.dll"],
|
57
56
|
upx_options: "",
|
58
|
-
|
57
|
+
|
59
58
|
zipfile: nil,
|
60
59
|
sevenzip_path: "7z",
|
61
|
-
|
60
|
+
|
62
61
|
inno_script: nil,
|
63
|
-
iscc_path: "iscc"
|
62
|
+
iscc_path: "iscc"
|
64
63
|
}
|
65
64
|
@rubyopt = ENV["RUBYOPT"].to_s
|
66
65
|
@args = ""
|
67
66
|
@encryption_key = nil
|
68
|
-
|
67
|
+
|
69
68
|
@use_dxruby = false
|
70
69
|
@use_dxruby_tiled = false
|
71
70
|
@use_ayame = false
|
72
|
-
|
71
|
+
|
73
72
|
class << self
|
74
|
-
|
75
73
|
attr_reader :options
|
76
|
-
|
77
|
-
def relative_path(path, basedir=rubydir, prepath = "")
|
74
|
+
|
75
|
+
def relative_path(path, basedir = rubydir, prepath = "")
|
78
76
|
basedir.concat(File::SEPARATOR) unless basedir.end_with?(File::SEPARATOR)
|
79
|
-
|
77
|
+
path.start_with?(basedir) ? path.sub(basedir, prepath) : path
|
80
78
|
end
|
81
|
-
|
79
|
+
|
82
80
|
def to_winpath(path)
|
83
|
-
|
81
|
+
File::ALT_SEPARATOR ? path.tr(File::SEPARATOR, File::ALT_SEPARATOR) : path
|
84
82
|
end
|
85
|
-
|
86
|
-
def bindir
|
87
|
-
def rubydir
|
88
|
-
def rubyexe
|
89
|
-
def scriptfile
|
90
|
-
def basename
|
91
|
-
def basepath
|
92
|
-
def datafile
|
93
|
-
|
83
|
+
|
84
|
+
def bindir ; RbConfig::CONFIG["bindir"] || File.join(rubydir, "bin"); end
|
85
|
+
def rubydir ; File.join(RbConfig::TOPDIR, ""); end
|
86
|
+
def rubyexe ; RbConfig.ruby; end
|
87
|
+
def scriptfile; @data_files.first; end
|
88
|
+
def basename ; File.basename(scriptfile, ".*"); end
|
89
|
+
def basepath ; File.join(options[:output_dir], basename); end
|
90
|
+
def datafile ; File.join(options[:output_dir], options[:system_dir], options[:datafile]); end
|
91
|
+
|
94
92
|
# --help
|
95
93
|
def output_help
|
96
|
-
puts <<-
|
94
|
+
puts <<-HELP_MESSAGE
|
97
95
|
usage: neri [options] script.rb (other_files...) -- script_arguments
|
98
96
|
|
99
97
|
options:
|
@@ -101,28 +99,28 @@ options:
|
|
101
99
|
--version or -v
|
102
100
|
--quiet
|
103
101
|
--verbose
|
104
|
-
|
102
|
+
|
105
103
|
--external-encoding <encoding>
|
106
|
-
|
104
|
+
|
107
105
|
--dll <dll1>,<dll2>,...
|
108
106
|
--lib <lib1>,<lib2>,...
|
109
107
|
--gem <gem1>,<gem2>,...
|
110
|
-
|
108
|
+
|
111
109
|
--no-enc
|
112
110
|
--encoding <enc1>,<enc2>,...
|
113
|
-
|
111
|
+
|
114
112
|
--enable-gems
|
115
113
|
--enable-did-you-mean
|
116
114
|
--chdir-first
|
117
115
|
--pause-last
|
118
116
|
--no-pause-last
|
119
117
|
--pause-text <text>
|
120
|
-
|
118
|
+
|
121
119
|
--output-dir <dirname>
|
122
120
|
--system-dir <dirname>
|
123
121
|
--datafile <filename>
|
124
122
|
--encryption-key <key>
|
125
|
-
|
123
|
+
|
126
124
|
--no-exe
|
127
125
|
--use-b2ec
|
128
126
|
--b2ec-path <bat_to_exe_converter_path>
|
@@ -143,28 +141,28 @@ options:
|
|
143
141
|
--privatebuild <string>
|
144
142
|
--specialbuild <string>
|
145
143
|
--comments <string>
|
146
|
-
|
144
|
+
|
147
145
|
--use-upx
|
148
146
|
--upx-path <upx path>
|
149
147
|
--upx_targets '<glob>' # ex) 'bin/**/*.dll'
|
150
148
|
--upx-options <options>
|
151
|
-
|
149
|
+
|
152
150
|
--zipfile <filename>
|
153
151
|
--7zip-path <7-zip path>
|
154
|
-
|
152
|
+
|
155
153
|
--innosetup <inno_script>
|
156
154
|
--iscc-path <iscc path>
|
157
|
-
|
155
|
+
|
158
156
|
--create-recipe <recipefile>
|
159
157
|
--recipe <recipefile>
|
160
|
-
|
158
|
+
HELP_MESSAGE
|
161
159
|
end
|
162
|
-
|
160
|
+
|
163
161
|
# --version
|
164
162
|
def output_version
|
165
163
|
puts "Neri #{Neri::VERSION}"
|
166
164
|
end
|
167
|
-
|
165
|
+
|
168
166
|
# --create-recipe
|
169
167
|
def create_recipe(file, hash = options, pre = "Neri.options")
|
170
168
|
hash.each_pair do |key, value|
|
@@ -180,8 +178,7 @@ options:
|
|
180
178
|
end
|
181
179
|
end
|
182
180
|
end
|
183
|
-
|
184
|
-
|
181
|
+
|
185
182
|
def check_options
|
186
183
|
nputs_v "Checking Neri options."
|
187
184
|
while arg = ARGV.shift
|
@@ -194,7 +191,7 @@ options:
|
|
194
191
|
exit
|
195
192
|
when "--quiet", "-q"
|
196
193
|
options[:quiet] = true
|
197
|
-
when "--verbose"
|
194
|
+
when "--verbose"
|
198
195
|
options[:verbose] = true
|
199
196
|
when "--external_encoding"
|
200
197
|
options[:external_encoding] = ARGV.shift
|
@@ -278,7 +275,7 @@ options:
|
|
278
275
|
when "--upx-options"
|
279
276
|
options[:upx_options] = ARGV.shift
|
280
277
|
when "--zipfile"
|
281
|
-
options[:zipfile] = ARGV.shift.encode(
|
278
|
+
options[:zipfile] = "#{ARGV.shift.encode('utf-8').sub(/\.zip$/, '')}.zip"
|
282
279
|
when "--7zip-path"
|
283
280
|
options[:sevenzip_path] = ARGV.shift.encode("utf-8")
|
284
281
|
when "--innosetup"
|
@@ -289,7 +286,7 @@ options:
|
|
289
286
|
require "json"
|
290
287
|
filename = ARGV.shift.encode("utf-8")
|
291
288
|
nputs "Creating recipe_file '#{filename}'."
|
292
|
-
open(filename, "w:utf-8"){ |file| create_recipe(file) }
|
289
|
+
File.open(filename, "w:utf-8") { |file| create_recipe(file) }
|
293
290
|
exit
|
294
291
|
when "--recipe"
|
295
292
|
filename = ARGV.shift.encode("utf-8")
|
@@ -305,116 +302,115 @@ options:
|
|
305
302
|
@data_files.push(arg.encode("utf-8"))
|
306
303
|
end
|
307
304
|
end
|
308
|
-
|
305
|
+
|
309
306
|
if @data_files.empty?
|
310
307
|
error "No Script File!"
|
311
308
|
output_help
|
312
309
|
exit
|
313
310
|
end
|
314
|
-
|
315
|
-
@args = ARGV.map{ |
|
316
|
-
@options[:external_encoding] ||= Encoding
|
317
|
-
unless options[:enable_gems]
|
318
|
-
@rubyopt += " --disable-gems"
|
311
|
+
|
312
|
+
@args = ARGV.map { |a| %( "#{a}") }.join("")
|
313
|
+
@options[:external_encoding] ||= Encoding.default_external.name
|
314
|
+
unless options[:enable_gems] || @rubyopt.index("--disable-gems")
|
315
|
+
@rubyopt += " --disable-gems"
|
319
316
|
end
|
320
|
-
unless options[:enable_did_you_mean]
|
321
|
-
@rubyopt += " --disable-did_you_mean"
|
317
|
+
unless options[:enable_did_you_mean] || @rubyopt.index("--disable-did_you_mean")
|
318
|
+
@rubyopt += " --disable-did_you_mean"
|
322
319
|
end
|
323
320
|
if @data_files.size > 1 || options[:encryption_key]
|
324
|
-
options[:datafile] ||= basename
|
321
|
+
options[:datafile] ||= "#{basename}.dat"
|
325
322
|
end
|
326
323
|
end
|
327
|
-
|
328
|
-
|
324
|
+
|
329
325
|
# check dependencies
|
330
|
-
def rb_dependencies
|
331
|
-
|
326
|
+
def rb_dependencies
|
327
|
+
$LOADED_FEATURES.uniq
|
332
328
|
end
|
333
|
-
|
334
|
-
def dll_dependencies
|
329
|
+
|
330
|
+
def dll_dependencies
|
335
331
|
require "Win32API"
|
336
|
-
|
332
|
+
|
337
333
|
enumprocessmodules = Win32API.new("psapi" , "EnumProcessModules", ["L","P","L","P"], "L")
|
338
334
|
getmodulefilename = Win32API.new("kernel32", "GetModuleFileNameW", ["L","P","L"], "L")
|
339
335
|
getcurrentprocess = Win32API.new("kernel32", "GetCurrentProcess" , [], "L")
|
340
|
-
|
336
|
+
|
341
337
|
bytes_needed = 4 * 32
|
342
338
|
module_handle_buffer = nil
|
343
|
-
process_handle = getcurrentprocess.call
|
339
|
+
process_handle = getcurrentprocess.call
|
344
340
|
loop do
|
345
341
|
module_handle_buffer = "\x00" * bytes_needed
|
346
342
|
bytes_needed_buffer = [0].pack("I")
|
347
|
-
|
348
|
-
bytes_needed = bytes_needed_buffer.
|
343
|
+
enumprocessmodules.call(process_handle, module_handle_buffer, module_handle_buffer.size, bytes_needed_buffer)
|
344
|
+
bytes_needed = bytes_needed_buffer.unpack1("I")
|
349
345
|
break if bytes_needed <= module_handle_buffer.size
|
350
346
|
end
|
351
|
-
|
347
|
+
|
352
348
|
handles = module_handle_buffer.unpack("I*")
|
353
349
|
dependencies = handles.select { |handle| handle > 0 }.map do |handle|
|
354
350
|
str = "\x00\x00" * 256
|
355
351
|
modulefilename_length = getmodulefilename.call(handle, str, str.size)
|
356
|
-
|
357
|
-
end
|
358
|
-
|
359
|
-
dependencies.map!{|dep| dep.sub(/^\\\\\?\\/, "")}
|
360
|
-
if File::ALT_SEPARATOR
|
361
|
-
dependencies.map!{|dep| dep.tr(File::ALT_SEPARATOR, File::SEPARATOR)}
|
352
|
+
str[0, modulefilename_length * 2].force_encoding("UTF-16LE").encode("UTF-8")
|
362
353
|
end
|
354
|
+
|
355
|
+
dependencies.map! { |dep| dep.sub(/^\\\\\?\\/, "") }
|
356
|
+
dependencies.map! { |dep| dep.tr(File::ALT_SEPARATOR, File::SEPARATOR) } if File::ALT_SEPARATOR
|
363
357
|
dependencies.delete(rubyexe)
|
364
|
-
|
365
|
-
|
358
|
+
|
359
|
+
dependencies.uniq
|
366
360
|
end
|
367
|
-
|
368
|
-
def ruby_dependencies
|
361
|
+
|
362
|
+
def ruby_dependencies
|
369
363
|
dependencies = Dir.glob(File.join(bindir, "**", "*.manifest"))
|
370
364
|
dependencies.push(rubyexe)
|
371
|
-
|
365
|
+
dependencies.uniq
|
372
366
|
end
|
373
|
-
|
374
|
-
def additional_dlls_dependencies
|
367
|
+
|
368
|
+
def additional_dlls_dependencies
|
375
369
|
dependencies = []
|
376
370
|
options[:dlls].each do |dll|
|
377
371
|
dependencies += Dir.glob(File.join(bindir, "**", dll))
|
378
|
-
dependencies += Dir.glob(File.join(bindir, "**", dll
|
372
|
+
dependencies += Dir.glob(File.join(bindir, "**", "#{dll}.*"))
|
379
373
|
end
|
380
|
-
|
374
|
+
dependencies.uniq
|
381
375
|
end
|
382
|
-
|
383
|
-
def additional_libs_dependencies
|
376
|
+
|
377
|
+
def additional_libs_dependencies
|
384
378
|
dependencies = []
|
385
379
|
options[:libs].each do |lib|
|
386
380
|
$LOAD_PATH.each do |path|
|
387
381
|
dependencies += Dir.glob(File.join(path, lib))
|
388
|
-
dependencies += Dir.glob(File.join(path, lib
|
382
|
+
dependencies += Dir.glob(File.join(path, "#{lib}.*"))
|
389
383
|
dependencies += Dir.glob(File.join(path, lib, "**", "*"))
|
390
384
|
end
|
391
385
|
end
|
392
|
-
|
386
|
+
dependencies.uniq
|
393
387
|
end
|
394
|
-
|
395
|
-
def additional_gems_dependencies
|
388
|
+
|
389
|
+
def additional_gems_dependencies
|
396
390
|
require "rubygems"
|
397
391
|
dependencies = []
|
398
392
|
rubygems_dir = File.join(Gem.dir, "gems")
|
399
393
|
options[:gems].each do |gem|
|
400
|
-
gem.sub!(
|
401
|
-
targets =
|
394
|
+
gem.sub!(/:(.+)/, "")
|
395
|
+
targets = Regexp.last_match(1).to_s.split("|")
|
402
396
|
targets.push("lib/**/*")
|
403
397
|
gem += "-*" unless gem.match("-")
|
404
|
-
gemdir = Dir.glob(File.join(rubygems_dir, gem)).
|
398
|
+
gemdir = Dir.glob(File.join(rubygems_dir, gem)).max
|
405
399
|
next unless gemdir
|
400
|
+
|
406
401
|
targets.each do |target|
|
407
402
|
dependencies += Dir.glob(File.join(gemdir, target))
|
408
403
|
end
|
409
404
|
end
|
410
|
-
|
405
|
+
dependencies.uniq
|
411
406
|
end
|
412
|
-
|
413
|
-
def encoding_dependencies
|
407
|
+
|
408
|
+
def encoding_dependencies
|
414
409
|
return [] unless options[:encoding]
|
410
|
+
|
415
411
|
dependencies = []
|
416
412
|
enc_dir = Dir.glob(File.join(RbConfig::CONFIG["archdir"] || RbConfig::TOPDIR, "**", "enc")).first
|
417
|
-
|
413
|
+
|
418
414
|
options[:encoding].split(",").map(&:strip).each do |enc|
|
419
415
|
case enc
|
420
416
|
when "ja"
|
@@ -423,21 +419,21 @@ options:
|
|
423
419
|
end
|
424
420
|
else
|
425
421
|
dependencies += Dir.glob(File.join(enc_dir, "**", enc))
|
426
|
-
dependencies += Dir.glob(File.join(enc_dir, "**", enc
|
422
|
+
dependencies += Dir.glob(File.join(enc_dir, "**", "#{enc}.*"))
|
427
423
|
end
|
428
424
|
end
|
429
|
-
|
430
|
-
|
425
|
+
|
426
|
+
dependencies.uniq
|
431
427
|
end
|
432
|
-
|
433
|
-
def check_dependencies
|
428
|
+
|
429
|
+
def check_dependencies
|
434
430
|
nputs "Running script '#{scriptfile}' to check dependencies."
|
435
431
|
begin
|
436
432
|
load File.expand_path(scriptfile)
|
437
433
|
rescue SystemExit, Interrupt
|
438
434
|
end
|
439
435
|
nputs "Script '#{scriptfile}' end."
|
440
|
-
|
436
|
+
|
441
437
|
if defined? DXRuby
|
442
438
|
require "neri/dxruby"
|
443
439
|
@use_dxruby = true
|
@@ -450,15 +446,15 @@ options:
|
|
450
446
|
require "neri/ayame"
|
451
447
|
@use_ayame = true
|
452
448
|
end
|
453
|
-
|
454
|
-
if options[:b2ec][:invisible]
|
449
|
+
|
450
|
+
if options[:b2ec][:invisible].nil? &&
|
455
451
|
(File.extname(scriptfile) == ".rbw" || @use_dxruby)
|
456
452
|
options[:b2ec][:invisible] = true
|
457
453
|
end
|
458
|
-
if options[:pause_last]
|
459
|
-
options[:pause_last] = true
|
454
|
+
if options[:pause_last].nil? && !options[:b2ec][:invisible]
|
455
|
+
options[:pause_last] = true
|
460
456
|
end
|
461
|
-
|
457
|
+
|
462
458
|
require "rbconfig"
|
463
459
|
dependencies = []
|
464
460
|
dependencies += rb_dependencies
|
@@ -469,59 +465,58 @@ options:
|
|
469
465
|
dependencies += additional_gems_dependencies
|
470
466
|
dependencies += encoding_dependencies
|
471
467
|
dependencies = select_dependencies(dependencies)
|
472
|
-
|
473
|
-
size = dependencies.map{|d| File.size(d)}.inject(&:+)
|
468
|
+
|
469
|
+
size = dependencies.map { |d| File.size(d) }.inject(&:+)
|
474
470
|
nputs "#{dependencies.size} files, #{size} bytes dependencies."
|
475
471
|
if options[:verbose]
|
476
472
|
dependencies.each do |dependency|
|
477
473
|
nputs_v " - #{dependency}"
|
478
474
|
end
|
479
475
|
end
|
480
|
-
|
481
|
-
|
476
|
+
|
477
|
+
dependencies
|
482
478
|
end
|
483
|
-
|
479
|
+
|
484
480
|
def select_dependencies(dependencies)
|
485
481
|
dependencies.select! do |dependency|
|
486
482
|
dependency.start_with?(rubydir)
|
487
483
|
end
|
488
|
-
|
484
|
+
|
489
485
|
@data_files.each do |file|
|
490
486
|
dependencies.delete(File.expand_path(file))
|
491
487
|
end
|
492
|
-
|
488
|
+
|
493
489
|
unless options[:enable_gems]
|
494
490
|
dependencies.delete_if do |dependency|
|
495
491
|
File.basename(dependency) == "rubygems.rb" ||
|
496
|
-
|
492
|
+
dependency.split(File::SEPARATOR).index("rubygems")
|
497
493
|
end
|
498
494
|
end
|
499
495
|
unless options[:enable_did_you_mean]
|
500
496
|
dependencies.delete_if do |dependency|
|
501
497
|
File.basename(dependency) == "did_you_mean.rb" ||
|
502
|
-
|
498
|
+
dependency.split(File::SEPARATOR).index("did_you_mean")
|
503
499
|
end
|
504
500
|
end
|
505
|
-
|
506
|
-
|
501
|
+
|
502
|
+
dependencies.uniq
|
507
503
|
end
|
508
|
-
|
509
|
-
|
504
|
+
|
510
505
|
def copy_files(dependencies)
|
511
506
|
nputs "Copying dependencies."
|
512
507
|
require "fileutils"
|
513
508
|
src_dir = rubydir
|
514
509
|
desc_dir = File.join(options[:output_dir], options[:system_dir], "")
|
515
|
-
|
510
|
+
|
516
511
|
system_files = dependencies.map do |file|
|
517
512
|
[file, file.sub(src_dir, desc_dir)]
|
518
513
|
end
|
519
514
|
unless options[:enable_gems]
|
520
|
-
system_files.each do |
|
521
|
-
desc.sub!(
|
515
|
+
system_files.each do |_src, desc|
|
516
|
+
desc.sub!(%r{/gems(/\d+\.\d+\.\d+/)gems/(.+?)-[^/]+/lib/}, "/vendor_ruby\\1")
|
522
517
|
end
|
523
518
|
end
|
524
|
-
|
519
|
+
|
525
520
|
system_files.each do |src, desc|
|
526
521
|
FileUtils.makedirs(File.dirname(desc))
|
527
522
|
if File.file?(src)
|
@@ -531,49 +526,47 @@ options:
|
|
531
526
|
end
|
532
527
|
FileUtils.copy(scriptfile, desc_dir) unless options[:datafile]
|
533
528
|
end
|
534
|
-
|
535
|
-
|
536
|
-
def create_datafile()
|
537
|
-
if @data_files.size > 1 || options[:encryption_key]
|
538
|
-
options[:datafile] ||= basename + ".dat"
|
539
|
-
end
|
529
|
+
|
530
|
+
def create_datafile
|
540
531
|
return unless options[:datafile]
|
541
|
-
|
532
|
+
|
542
533
|
nputs "Creating datafile '#{datafile}'."
|
543
534
|
data_files = @data_files.select { |file| File.file? file }
|
544
535
|
@data_files.select { |file| File.directory? file }.each do |dir|
|
545
|
-
data_files += Dir.glob(dir
|
536
|
+
data_files += Dir.glob("#{dir}/**/*").select { |file| File.file? file }
|
546
537
|
end
|
547
538
|
if options[:encryption_key]
|
548
539
|
require "digest/sha2"
|
549
540
|
@encryption_key = Digest::SHA2.hexdigest(options[:encryption_key])
|
550
541
|
end
|
551
542
|
Neri.key = @encryption_key || "0" * 64
|
552
|
-
open(datafile, "wb") do |f|
|
543
|
+
File.open(datafile, "wb") do |f|
|
553
544
|
pos = 0
|
554
|
-
files_str = data_files.map{|file|
|
555
|
-
|
556
|
-
filename =
|
557
|
-
|
545
|
+
files_str = data_files.map { |file|
|
546
|
+
fullpath = File.expand_path(file)
|
547
|
+
filename = if fullpath.start_with?(rubydir)
|
548
|
+
relative_path(fullpath, rubydir, "*neri*#{File::SEPARATOR}")
|
549
|
+
else
|
550
|
+
file
|
551
|
+
end
|
558
552
|
filedata = [filename, File.size(file), pos]
|
559
553
|
pos += File.size(file)
|
560
554
|
pos += BLOCK_LENGTH - pos % BLOCK_LENGTH unless pos % BLOCK_LENGTH == 0
|
561
555
|
nputs_v " - #{filename}:#{File.size(file)} bytes"
|
562
556
|
filedata.join("\t")
|
563
557
|
}.join("\n").encode(Encoding::UTF_8)
|
564
|
-
|
565
|
-
f.write(
|
558
|
+
|
559
|
+
f.write(format("%#{BLOCK_LENGTH}d", files_str.bytesize))
|
566
560
|
f.write(xor(files_str))
|
567
561
|
data_files.each do |file|
|
568
562
|
f.write(xor(File.binread(file)))
|
569
563
|
end
|
570
564
|
end
|
571
565
|
end
|
572
|
-
|
573
|
-
|
574
|
-
def create_batfile()
|
566
|
+
|
567
|
+
def create_batfile
|
575
568
|
nputs "Creating batch_file '#{basepath}.bat'."
|
576
|
-
|
569
|
+
|
577
570
|
pause_command = ""
|
578
571
|
if options[:pause_last]
|
579
572
|
pause_command += "echo.\n"
|
@@ -585,37 +578,37 @@ options:
|
|
585
578
|
end
|
586
579
|
end
|
587
580
|
chdir = options[:chdir_first] ? 'cd /d "%~dp0"' : ""
|
588
|
-
|
589
|
-
open(basepath
|
590
|
-
f.puts <<-
|
581
|
+
|
582
|
+
File.open("#{basepath}.bat", "w:#{options[:external_encoding]}") do |f|
|
583
|
+
f.puts <<-BATCH
|
591
584
|
@echo off
|
592
585
|
setlocal
|
593
586
|
set PATH=%~dp0#{options[:system_dir]}\\#{relative_path(bindir)};%PATH%
|
594
587
|
set NERI_EXECUTABLE=%~0
|
595
588
|
#{chdir}
|
596
589
|
if %~x0 == .exe ( shift )
|
597
|
-
#{ruby_command(options[:chdir_first] ?
|
590
|
+
#{ruby_command(options[:chdir_first] ? '' : '%~dp0')} %1 %2 %3 %4 %5 %6 %7 %8 %9
|
598
591
|
#{pause_command}
|
599
592
|
endlocal
|
600
|
-
|
593
|
+
BATCH
|
601
594
|
end
|
602
595
|
end
|
603
|
-
|
604
|
-
def create_exefile
|
596
|
+
|
597
|
+
def create_exefile
|
605
598
|
unless system("gcc --version >nul 2>&1 && windres --version >nul 2>&1")
|
606
599
|
error "gcc or windres not found !"
|
607
600
|
create_batfile
|
608
601
|
return
|
609
602
|
end
|
610
|
-
|
611
|
-
exe_file = to_winpath(basepath
|
612
|
-
c_file = to_winpath(basepath
|
613
|
-
o_file = to_winpath(basepath
|
614
|
-
rc_file = to_winpath(basepath
|
603
|
+
|
604
|
+
exe_file = to_winpath("#{basepath}.exe" )
|
605
|
+
c_file = to_winpath("#{basepath}_tmp.c" )
|
606
|
+
o_file = to_winpath("#{basepath}_tmp.o" )
|
607
|
+
rc_file = to_winpath("#{basepath}_tmp.rc")
|
615
608
|
system_dir = escape_cstr(to_winpath(File.join(options[:system_dir], "")))
|
616
609
|
nputs "Creating exe_file '#{exe_file}'."
|
617
|
-
open(c_file, "w:#{options[:external_encoding]}") do |f|
|
618
|
-
f.puts <<-
|
610
|
+
File.open(c_file, "w:#{options[:external_encoding]}") do |f|
|
611
|
+
f.puts <<-CFILE
|
619
612
|
#include <stdio.h>
|
620
613
|
#include <stdlib.h>
|
621
614
|
#include <windows.h>
|
@@ -623,17 +616,17 @@ endlocal
|
|
623
616
|
|
624
617
|
int main(int argc, char *argv[])
|
625
618
|
{
|
626
|
-
char exepath[_MAX_PATH * 2 + 1],
|
619
|
+
char exepath[_MAX_PATH * 2 + 1],
|
627
620
|
drive [_MAX_DRIVE + 1],
|
628
621
|
dir [_MAX_DIR * 2 + 1],
|
629
622
|
fname [_MAX_FNAME * 2 + 1],
|
630
623
|
ext [_MAX_EXT * 2 + 1],
|
631
624
|
paths [_MAX_PATH * 32 + 1],
|
632
625
|
runruby[_MAX_PATH * 32 + 1];
|
633
|
-
PROCESS_INFORMATION pi;
|
626
|
+
PROCESS_INFORMATION pi;
|
634
627
|
STARTUPINFO si;
|
635
628
|
ZeroMemory(&si, sizeof(STARTUPINFO));
|
636
|
-
|
629
|
+
|
637
630
|
if(GetModuleFileName(NULL, exepath, MAX_PATH * 2) != 0){
|
638
631
|
_splitpath_s(exepath, drive, _MAX_DRIVE, dir, _MAX_DIR * 2, fname, _MAX_FNAME * 2, ext, _MAX_EXT * 2);
|
639
632
|
} else {
|
@@ -644,8 +637,8 @@ int main(int argc, char *argv[])
|
|
644
637
|
snprintf(paths, sizeof(paths), "PATH=%s%s#{system_dir}bin;%s", drive, dir, getenv("PATH"));
|
645
638
|
putenv(paths);
|
646
639
|
#{options[:chdir_first] ? 'snprintf(paths, sizeof(paths), "%s%s", drive, dir);chdir(paths);' : ''}
|
647
|
-
snprintf(runruby, sizeof(runruby), "#{escape_cstr(ruby_command(options[:chdir_first] ?
|
648
|
-
#{options[:chdir_first] ?
|
640
|
+
snprintf(runruby, sizeof(runruby), "#{escape_cstr(ruby_command(options[:chdir_first] ? '' : '%s%s'))} %s %s %s %s %s %s %s %s %s",
|
641
|
+
#{options[:chdir_first] ? '' : 'drive, dir,'}
|
649
642
|
argc > 1 ? argv[1] : "",
|
650
643
|
argc > 2 ? argv[2] : "",
|
651
644
|
argc > 3 ? argv[3] : "",
|
@@ -656,7 +649,7 @@ int main(int argc, char *argv[])
|
|
656
649
|
argc > 8 ? argv[8] : "",
|
657
650
|
argc > 9 ? argv[9] : ""
|
658
651
|
);
|
659
|
-
|
652
|
+
CFILE
|
660
653
|
if options[:b2ec][:invisible]
|
661
654
|
f.puts %[ CreateProcess(NULL, runruby, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS | CREATE_NO_WINDOW, NULL, NULL, &si, &pi);]
|
662
655
|
else
|
@@ -673,14 +666,14 @@ int main(int argc, char *argv[])
|
|
673
666
|
end
|
674
667
|
f.puts " return 0;\n}"
|
675
668
|
end
|
676
|
-
|
677
|
-
open(rc_file, "w:#{options[:external_encoding]}") do |f|
|
678
|
-
f.puts <<-
|
669
|
+
|
670
|
+
File.open(rc_file, "w:#{options[:external_encoding]}") do |f|
|
671
|
+
f.puts <<-RCFILE
|
679
672
|
#include <winver.h>
|
680
673
|
|
681
674
|
1 VERSIONINFO
|
682
|
-
#{options[:b2ec][:fileversion ] ? "FILEVERSION
|
683
|
-
#{options[:b2ec][:productversion] ? "PRODUCTVERSION
|
675
|
+
#{options[:b2ec][:fileversion ] ? "FILEVERSION #{escape_cstr(options[:b2ec][:fileversion ])}" : ""}
|
676
|
+
#{options[:b2ec][:productversion] ? "PRODUCTVERSION #{escape_cstr(options[:b2ec][:productversion])}" : ""}
|
684
677
|
FILETYPE VFT_APP
|
685
678
|
BEGIN
|
686
679
|
BLOCK "StringFileInfo"
|
@@ -709,16 +702,16 @@ BEGIN
|
|
709
702
|
END
|
710
703
|
|
711
704
|
2 ICON "#{escape_cstr(options[:b2ec][:icon])}"
|
712
|
-
|
705
|
+
RCFILE
|
713
706
|
end
|
714
|
-
nsystem(%
|
715
|
-
nsystem(%
|
716
|
-
nsystem(%
|
707
|
+
nsystem(%(windres -o "#{o_file}" "#{rc_file}"))
|
708
|
+
nsystem(%(gcc#{options[:b2ec][:invisible] ? ' -mwindows' : ''} -o "#{exe_file}" "#{c_file}" "#{o_file}"))
|
709
|
+
nsystem(%(strip "#{exe_file}"))
|
717
710
|
File.delete(c_file, rc_file, o_file)
|
718
711
|
end
|
719
|
-
|
712
|
+
|
720
713
|
def ruby_command(path)
|
721
|
-
system_dir = "#{path}#{File.join(options[:system_dir],
|
714
|
+
system_dir = "#{path}#{File.join(options[:system_dir], '')}"
|
722
715
|
ruby_code = ""
|
723
716
|
ruby_code = "Neri.key='#{@encryption_key}';" if @encryption_key
|
724
717
|
if options[:datafile]
|
@@ -727,18 +720,17 @@ END
|
|
727
720
|
else
|
728
721
|
ruby_code += "load File.expand_path('#{system_dir}' + #{unpack_filename(scriptfile)})"
|
729
722
|
end
|
730
|
-
|
723
|
+
|
731
724
|
r = " -rneri"
|
732
725
|
r += " -rneri/dxruby" if @use_dxruby
|
733
726
|
r += " -rneri/dxruby_tiled" if @use_dxruby_tiled
|
734
727
|
r += " -rneri/ayame" if @use_ayame
|
735
|
-
|
728
|
+
|
736
729
|
ruby = to_winpath(relative_path(rubyexe, bindir))
|
737
|
-
|
730
|
+
%(#{ruby}#{r} #{@rubyopt} -e "# coding:utf-8" -e "#{ruby_code}" #{@args})
|
738
731
|
end
|
739
|
-
|
740
|
-
|
741
|
-
def bat_to_exe_converter()
|
732
|
+
|
733
|
+
def bat_to_exe_converter
|
742
734
|
create_batfile
|
743
735
|
begin
|
744
736
|
`#{options[:b2ec_path]} /help`
|
@@ -746,36 +738,32 @@ END
|
|
746
738
|
error "Bat To Exe Converter not found !"
|
747
739
|
return
|
748
740
|
end
|
749
|
-
|
750
|
-
batch_file = basepath
|
751
|
-
exe_file = basepath
|
741
|
+
|
742
|
+
batch_file = "#{basepath}.bat"
|
743
|
+
exe_file = "#{basepath}.exe"
|
752
744
|
nputs "Creating exe_file '#{exe_file}' with Bat To Exe Converter."
|
753
745
|
File.delete(exe_file) if File.exist?(exe_file)
|
754
|
-
if options[:b2ec][:x64]
|
755
|
-
options[:b2ec][:x64] = true
|
746
|
+
if options[:b2ec][:x64].nil? && RbConfig::CONFIG["target"].to_s.index("64")
|
747
|
+
options[:b2ec][:x64] = true
|
756
748
|
end
|
757
|
-
args = %
|
758
|
-
args += options[:b2ec].map{|key, value|
|
749
|
+
args = %( /bat "#{batch_file}" /exe "#{exe_file}")
|
750
|
+
args += options[:b2ec].map { |key, value|
|
759
751
|
case value
|
760
|
-
when String
|
761
|
-
when true
|
762
|
-
else;
|
752
|
+
when String then %( /#{key.to_s.tr('_', '-')} "#{value}")
|
753
|
+
when true then %( /#{key.to_s.tr('_', '-')})
|
754
|
+
else; %()
|
763
755
|
end
|
764
756
|
}.join("")
|
765
|
-
|
766
|
-
|
767
|
-
unless nsystem "#{options[:b2ec_path]}#{args}"
|
768
|
-
error "Failed to create exe_file !"
|
769
|
-
end
|
757
|
+
|
758
|
+
error "Failed to create exe_file !" unless nsystem "#{options[:b2ec_path]}#{args}"
|
770
759
|
end
|
771
|
-
|
772
|
-
|
773
|
-
def upx()
|
760
|
+
|
761
|
+
def upx
|
774
762
|
unless system("#{options[:upx_path]} --version >nul 2>&1")
|
775
763
|
error "UPX not found !"
|
776
764
|
return
|
777
765
|
end
|
778
|
-
|
766
|
+
|
779
767
|
nputs "Compressing with UPX."
|
780
768
|
options[:upx_targets].each do |target|
|
781
769
|
Dir.glob(File.join(options[:output_dir], options[:system_dir], target)).each do |target_path|
|
@@ -784,78 +772,76 @@ END
|
|
784
772
|
end
|
785
773
|
end
|
786
774
|
end
|
787
|
-
|
788
|
-
|
789
|
-
def create_zipfile()
|
775
|
+
|
776
|
+
def create_zipfile
|
790
777
|
unless system("#{options[:sevenzip_path]} >nul 2>&1")
|
791
778
|
error "7-Zip not found !"
|
792
779
|
return
|
793
780
|
end
|
794
|
-
|
781
|
+
|
795
782
|
nputs "Creating zip_file '#{options[:zipfile]}'."
|
796
783
|
File.delete(options[:zipfile]) if File.exist?(options[:zipfile])
|
797
784
|
files = []
|
798
785
|
if options[:output_dir] == "./"
|
799
786
|
files.push(options[:system_dir])
|
800
|
-
files.push(File.exist?(basepath
|
787
|
+
files.push(File.exist?("#{basepath}.exe") ? "#{basepath}.exe" : "#{basepath}.bat")
|
801
788
|
else
|
802
789
|
files.push(options[:output_dir])
|
803
790
|
end
|
804
791
|
command = %("#{options[:sevenzip_path]}" a "#{options[:zipfile]}" "#{files.join('" "')}")
|
805
792
|
nsystem command
|
806
793
|
end
|
807
|
-
|
808
|
-
|
809
|
-
def inno_setup()
|
794
|
+
|
795
|
+
def inno_setup
|
810
796
|
unless system("#{options[:iscc_path]} /? >nul 2>&1")
|
811
797
|
error("Inno Setup not found !")
|
812
798
|
return
|
813
799
|
end
|
814
|
-
|
800
|
+
|
815
801
|
filename = options[:inno_script]
|
816
802
|
nputs "Creating Installer '#{filename}'."
|
817
803
|
script = "[Setup]\n"
|
818
804
|
if File.exist?(filename)
|
819
805
|
script = File.read(filename, encoding: Encoding::UTF_8)
|
820
|
-
filename = File.basename(filename,
|
806
|
+
filename = "#{File.basename(filename, '.*')}_tmp#{File.extname(filename)}"
|
821
807
|
end
|
822
|
-
|
808
|
+
|
823
809
|
version = options[:b2ec][:productversion] || options[:b2ec][:fileversion]
|
824
810
|
if !script.match(/^AppName=/) && options[:b2ec][:productname]
|
825
|
-
script.sub!(/^(\[Setup\])(\s+)/i){ "#{$1}\nAppName=#{options[:b2ec][:productname]}#{$2}" }
|
811
|
+
script.sub!(/^(\[Setup\])(\s+)/i) { "#{$1}\nAppName=#{options[:b2ec][:productname]}#{$2}" }
|
826
812
|
end
|
827
813
|
if !script.match(/^AppVersion=/) && version
|
828
|
-
script.sub!(/^(\[Setup\])(\s+)/i){ "#{$1}\nAppVersion=#{version}#{$2}" }
|
814
|
+
script.sub!(/^(\[Setup\])(\s+)/i) { "#{$1}\nAppVersion=#{version}#{$2}" }
|
829
815
|
end
|
830
816
|
if !script.match(/^AppVerName=/) && options[:b2ec][:productname] && version
|
831
|
-
script.sub!(/^(\[Setup\])(\s+)/i){ "#{$1}\nAppVerName=#{options[:b2ec][:productname]} #{version}#{$2}" }
|
817
|
+
script.sub!(/^(\[Setup\])(\s+)/i) { "#{$1}\nAppVerName=#{options[:b2ec][:productname]} #{version}#{$2}" }
|
832
818
|
end
|
833
819
|
if !script.match(/^AppPublisher=/) && options[:b2ec][:company]
|
834
|
-
script.sub!(/^(\[Setup\])(\s+)/i){ "#{$1}\nAppPublisher=#{options[:b2ec][:company]}#{$2}" }
|
820
|
+
script.sub!(/^(\[Setup\])(\s+)/i) { "#{$1}\nAppPublisher=#{options[:b2ec][:company]}#{$2}" }
|
835
821
|
end
|
836
822
|
if !script.match(/^AppCopyright=/) && options[:b2ec][:copyright]
|
837
|
-
script.sub!(/^(\[Setup\])(\s+)/i){ "#{$1}\nAppCopyright=#{options[:b2ec][:copyright]}#{$2}" }
|
823
|
+
script.sub!(/^(\[Setup\])(\s+)/i) { "#{$1}\nAppCopyright=#{options[:b2ec][:copyright]}#{$2}" }
|
838
824
|
end
|
839
|
-
|
825
|
+
|
840
826
|
script += "\n[Files]\n" unless script.match(/^\[Files\]/)
|
841
827
|
dir = File.expand_path(options[:output_dir])
|
842
828
|
files_str = ""
|
843
829
|
Dir.glob(File.join(dir, "**", "*")).each do |file|
|
844
830
|
next unless File.file? file
|
831
|
+
|
845
832
|
dist_dir = to_winpath(File::SEPARATOR + File.dirname(relative_path(file, dir)))
|
846
833
|
dist_dir = "" if dist_dir == "\\."
|
847
834
|
files_str += "\nSource: \"#{to_winpath(file)}\"; DistDir: \"{app}#{dist_dir}"
|
848
835
|
files_str += "; Flags: isreadme" if File.basename(file).match(/^readme/i)
|
849
836
|
end
|
850
|
-
script.sub!(/^(\[Files\])(\s*)/i){ "#{$1}#{files_str}#{$2}" }
|
851
|
-
|
837
|
+
script.sub!(/^(\[Files\])(\s*)/i) { "#{$1}#{files_str}#{$2}" }
|
838
|
+
|
852
839
|
File.write(filename, script)
|
853
840
|
command = %(#{options[:iscc_path]} "#{filename}")
|
854
841
|
nsystem command
|
855
842
|
end
|
856
|
-
|
857
|
-
|
858
|
-
def run()
|
843
|
+
|
844
|
+
def run
|
859
845
|
check_options
|
860
846
|
dependencies = check_dependencies
|
861
847
|
copy_files(dependencies)
|
@@ -870,34 +856,33 @@ END
|
|
870
856
|
inno_setup if options[:inno_script]
|
871
857
|
nputs "Neri Finished."
|
872
858
|
end
|
873
|
-
|
874
859
|
|
875
860
|
private
|
876
|
-
|
861
|
+
|
877
862
|
def nputs(str)
|
878
863
|
puts "=== #{str}" unless options[:quiet]
|
879
864
|
end
|
880
|
-
|
865
|
+
|
881
866
|
def nputs_v(str)
|
882
867
|
puts str if options[:verbose]
|
883
868
|
end
|
884
|
-
|
869
|
+
|
885
870
|
def error(str)
|
886
871
|
puts "\e[31m#{str}\e[0m"
|
887
872
|
end
|
888
|
-
|
873
|
+
|
889
874
|
def unpack_filename(filename)
|
890
|
-
"[
|
875
|
+
"[#{filename.unpack('U*').map(&:to_s).join(',')}].pack('U*')"
|
891
876
|
end
|
892
|
-
|
877
|
+
|
893
878
|
def escape_cstr(str)
|
894
|
-
str.gsub("\\"){ "\\\\" }.gsub('"'){ '\\"' }.gsub("'"){ "\\'" }
|
879
|
+
str.gsub("\\") { "\\\\" }.gsub('"') { '\\"' }.gsub("'") { "\\'" }
|
895
880
|
end
|
896
|
-
|
881
|
+
|
897
882
|
def nsystem(str)
|
898
883
|
nputs_v(str)
|
899
884
|
command = str.encode(options[:external_encoding])
|
900
|
-
|
885
|
+
system(command + (options[:quiet] ? " >nul 2>&1" : ""))
|
901
886
|
end
|
902
887
|
end
|
903
888
|
end
|
data/lib/neri/dxruby.rb
CHANGED
@@ -4,38 +4,28 @@ require "dxruby" unless defined? DXRuby
|
|
4
4
|
|
5
5
|
module Neri
|
6
6
|
module DXRubyImage
|
7
|
-
def load(path, x=nil, y=nil, width=nil, height=nil)
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
return super
|
14
|
-
end
|
7
|
+
def load(path, x = nil, y = nil, width = nil, height = nil)
|
8
|
+
return super unless Neri.exist_in_datafile?(path)
|
9
|
+
|
10
|
+
image = load_from_file_in_memory(Neri.file_read(path))
|
11
|
+
image = image.slice(x, y, width, height) if x && y && width && height
|
12
|
+
image
|
15
13
|
end
|
16
|
-
|
17
|
-
def load_tiles(path, xcount, ycount, share_switch=true)
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
return super
|
23
|
-
end
|
14
|
+
|
15
|
+
def load_tiles(path, xcount, ycount, share_switch = true)
|
16
|
+
return super unless Neri.exist_in_datafile?(path) && !share_switch
|
17
|
+
|
18
|
+
image = load_from_file_in_memory(Neri.file_read(path))
|
19
|
+
image.slice_tiles(xcount, ycount)
|
24
20
|
end
|
25
21
|
end
|
26
|
-
|
22
|
+
|
27
23
|
module DXRubySound
|
28
24
|
def new(path)
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
else
|
34
|
-
return load_from_memory(Neri.file_read(path), DXRuby::TYPE_WAV)
|
35
|
-
end
|
36
|
-
else
|
37
|
-
return super
|
38
|
-
end
|
25
|
+
return super unless Neri.exist_in_datafile?(path)
|
26
|
+
|
27
|
+
load_from_memory(Neri.file_read(path),
|
28
|
+
File.extname(path) == ".mid" ? DXRuby::TYPE_MIDI : DXRuby::TYPE_WAV)
|
39
29
|
end
|
40
30
|
end
|
41
31
|
end
|
@@ -46,7 +36,7 @@ module DXRuby
|
|
46
36
|
prepend Neri::DXRubyImage
|
47
37
|
end
|
48
38
|
end
|
49
|
-
|
39
|
+
|
50
40
|
class Sound
|
51
41
|
class << self
|
52
42
|
prepend Neri::DXRubySound
|
data/lib/neri/dxruby_tiled.rb
CHANGED
data/lib/neri/runtime.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "neri/version"
|
2
2
|
|
3
|
-
alias
|
4
|
-
alias
|
3
|
+
alias _neri_orig_require require
|
4
|
+
alias _neri_orig_load load
|
5
5
|
|
6
6
|
def require(feature)
|
7
7
|
Neri.require(feature)
|
@@ -16,12 +16,14 @@ module Neri
|
|
16
16
|
@datafile = nil
|
17
17
|
@system_dir = nil
|
18
18
|
@files = {}
|
19
|
+
@fullpath_files = nil
|
20
|
+
@current_directory = nil
|
19
21
|
@xor = nil
|
20
|
-
|
22
|
+
|
21
23
|
class << self
|
22
24
|
def datafile=(datafile)
|
23
|
-
@datafile = datafile
|
24
|
-
@system_dir = File.dirname(File.expand_path(datafile)) + File::SEPARATOR
|
25
|
+
@datafile = datafile.encode(Encoding::UTF_8)
|
26
|
+
@system_dir = File.dirname(File.expand_path(@datafile)) + File::SEPARATOR
|
25
27
|
files_length = File.binread(@datafile, BLOCK_LENGTH).to_i
|
26
28
|
files_str = read(files_length, BLOCK_LENGTH)
|
27
29
|
pos = files_length + BLOCK_LENGTH
|
@@ -31,116 +33,116 @@ module Neri
|
|
31
33
|
filename, length, offset = line.split("\t")
|
32
34
|
@files[filename] = [length.to_i, offset.to_i + pos]
|
33
35
|
end
|
36
|
+
@current_directory = nil
|
34
37
|
end
|
35
|
-
|
38
|
+
|
36
39
|
def key=(key)
|
37
|
-
@xor = key.scan(/../).map{|a| a.to_i(16)}.pack("c*")
|
40
|
+
@xor = key.scan(/../).map { |a| a.to_i(16) }.pack("c*")
|
38
41
|
end
|
39
|
-
|
42
|
+
|
40
43
|
def require(feature)
|
44
|
+
feature = feature.encode(Encoding::UTF_8)
|
41
45
|
filepath = nil
|
42
|
-
(feature.
|
46
|
+
(feature.start_with?(/[a-z]:/i, "\\", "/", ".") ? [""] : load_path).each do |path|
|
43
47
|
["", ".rb"].each do |ext|
|
44
|
-
|
45
|
-
filepath
|
48
|
+
tmp_path = path + feature + ext
|
49
|
+
filepath ||= tmp_path if exist_in_datafile?(tmp_path)
|
46
50
|
end
|
47
51
|
end
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
return _neri_orig_require(feature)
|
57
|
-
end
|
52
|
+
|
53
|
+
return _neri_orig_require(feature) unless filepath
|
54
|
+
return false if $LOADED_FEATURES.index(filepath)
|
55
|
+
|
56
|
+
code = load_code(filepath)
|
57
|
+
eval(code, TOPLEVEL_BINDING, filepath)
|
58
|
+
$LOADED_FEATURES.push(filepath)
|
59
|
+
true
|
58
60
|
end
|
59
|
-
|
61
|
+
|
60
62
|
def load(file, priv = false)
|
63
|
+
file = file.encode(Encoding::UTF_8)
|
61
64
|
filepath = nil
|
62
|
-
(load_path + [""]
|
63
|
-
|
65
|
+
paths = file.start_with?(/[a-z]:/i, "\\", "/", ".") ? [""] : load_path + [""]
|
66
|
+
paths.each do |path|
|
67
|
+
filepath ||= path + file if exist_in_datafile?(path + file)
|
64
68
|
end
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
eval(code, TOPLEVEL_BINDING, filepath)
|
72
|
-
end
|
69
|
+
|
70
|
+
return _neri_orig_load(file, priv) unless filepath
|
71
|
+
|
72
|
+
code = load_code(filepath)
|
73
|
+
if priv
|
74
|
+
Module.new.module_eval(code, filepath)
|
73
75
|
else
|
74
|
-
|
76
|
+
eval(code, TOPLEVEL_BINDING, filepath)
|
75
77
|
end
|
78
|
+
true
|
76
79
|
end
|
77
|
-
|
80
|
+
|
78
81
|
def file_exist?(filename)
|
79
|
-
|
82
|
+
exist_in_datafile?(filename) || File.exist?(filename)
|
80
83
|
end
|
81
|
-
|
84
|
+
|
82
85
|
def file_read(filename, encoding = Encoding::BINARY)
|
86
|
+
filename = filename.encode(Encoding::UTF_8)
|
83
87
|
str = nil
|
84
88
|
if exist_in_datafile?(filename)
|
85
|
-
length, offset =
|
89
|
+
length, offset = fullpath_files[File.expand_path(filename)]
|
86
90
|
str = read(length, offset)
|
87
91
|
else
|
88
92
|
str = File.binread(filename)
|
89
93
|
end
|
90
94
|
str.force_encoding(encoding)
|
91
|
-
return str
|
92
95
|
end
|
93
|
-
|
94
|
-
def files
|
95
|
-
|
96
|
+
|
97
|
+
def files
|
98
|
+
@files.keys
|
96
99
|
end
|
97
|
-
|
100
|
+
|
98
101
|
def exist_in_datafile?(filename)
|
99
|
-
|
102
|
+
fullpath_files.key?(File.expand_path(filename.encode(Encoding::UTF_8)))
|
100
103
|
end
|
101
|
-
|
104
|
+
|
102
105
|
private
|
103
|
-
|
104
|
-
def
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
end
|
109
|
-
if defined?(Xorcist)
|
110
|
-
return Xorcist.xor!(str, @xor * (str.bytesize / BLOCK_LENGTH))
|
111
|
-
else
|
112
|
-
s = []
|
113
|
-
str.unpack("Q*").zip((@xor * (str.bytesize / BLOCK_LENGTH)).unpack("Q*")){|a, b| s.push(a ^ b)}
|
114
|
-
return s.pack("Q*")
|
106
|
+
|
107
|
+
def fullpath_files
|
108
|
+
if @current_directory != Dir.pwd
|
109
|
+
@current_directory = Dir.pwd
|
110
|
+
@fullpath_files = @files.transform_keys { |k| File.expand_path(k) }
|
115
111
|
end
|
112
|
+
@fullpath_files
|
116
113
|
end
|
117
|
-
|
118
|
-
def
|
119
|
-
|
114
|
+
|
115
|
+
def xor(str)
|
116
|
+
str.force_encoding(Encoding::BINARY)
|
117
|
+
str << rand(256).chr while str.bytesize % BLOCK_LENGTH != 0
|
118
|
+
xor_str = @xor * (str.bytesize / BLOCK_LENGTH)
|
119
|
+
return Xorcist.xor!(str, xor_str) if defined?(Xorcist)
|
120
|
+
|
121
|
+
s = []
|
122
|
+
str.unpack("Q*").zip((xor_str).unpack("Q*")) { |a, b| s.push(a ^ b) }
|
123
|
+
s.pack("Q*")
|
120
124
|
end
|
121
|
-
|
125
|
+
|
122
126
|
def read(length, offset)
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
return File.binread(@datafile, length, offset)
|
129
|
-
end
|
127
|
+
return File.binread(@datafile, length, offset) unless @xor
|
128
|
+
|
129
|
+
tmp_length = length
|
130
|
+
tmp_length += BLOCK_LENGTH - length % BLOCK_LENGTH unless length % BLOCK_LENGTH == 0
|
131
|
+
xor(File.binread(@datafile, tmp_length, offset))[0, length]
|
130
132
|
end
|
131
|
-
|
132
|
-
def load_path
|
133
|
+
|
134
|
+
def load_path
|
133
135
|
paths = $LOAD_PATH.map { |path| path.encode(Encoding::UTF_8) }
|
134
136
|
return paths unless @system_dir
|
137
|
+
|
135
138
|
paths.map { |path| path.sub(@system_dir, "*neri*#{File::SEPARATOR}") + File::SEPARATOR }
|
136
139
|
end
|
137
|
-
|
140
|
+
|
138
141
|
def load_code(file)
|
139
142
|
code = file_read(file)
|
140
143
|
encoding = "UTF-8"
|
141
|
-
encoding =
|
144
|
+
encoding = Regexp.last_match(1) if code.lines[0..2].join("\n").match(/coding:\s*(\S+)/)
|
142
145
|
code.force_encoding(encoding)
|
143
|
-
return code
|
144
146
|
end
|
145
147
|
end
|
146
148
|
end
|
data/lib/neri/version.rb
CHANGED
data/neri.gemspec
CHANGED
@@ -8,11 +8,11 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.authors = ["nodai2hITC"]
|
9
9
|
spec.email = ["nodai2h.itc@gmail.com"]
|
10
10
|
|
11
|
-
spec.summary =
|
12
|
-
spec.description =
|
11
|
+
spec.summary = "One-Click Ruby Application Builder"
|
12
|
+
spec.description = "Neri builds Windows batfile or exefile from Ruby script."
|
13
13
|
spec.homepage = "https://github.com/nodai2hITC/neri"
|
14
14
|
spec.license = "MIT"
|
15
|
-
spec.required_ruby_version = ">= 2.
|
15
|
+
spec.required_ruby_version = ">= 2.5.0"
|
16
16
|
|
17
17
|
# spec.metadata["allowed_push_host"] = "TODO: Set to 'https://mygemserver.com'"
|
18
18
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: neri
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nodai2hITC
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-11-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: win32api
|
@@ -63,14 +63,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
63
63
|
requirements:
|
64
64
|
- - ">="
|
65
65
|
- !ruby/object:Gem::Version
|
66
|
-
version: 2.
|
66
|
+
version: 2.5.0
|
67
67
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
68
|
requirements:
|
69
69
|
- - ">="
|
70
70
|
- !ruby/object:Gem::Version
|
71
71
|
version: '0'
|
72
72
|
requirements: []
|
73
|
-
rubygems_version: 3.2.
|
73
|
+
rubygems_version: 3.2.30
|
74
74
|
signing_key:
|
75
75
|
specification_version: 4
|
76
76
|
summary: One-Click Ruby Application Builder
|