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