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