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