neri 0.9.2 → 0.9.6

Sign up to get free protection for your applications and to get access to all the features.
data/lib/neri/dxruby.rb CHANGED
@@ -4,38 +4,28 @@ require "dxruby" unless defined? DXRuby
4
4
 
5
5
  module Neri
6
6
  module DXRubyImage
7
- def load(path, x=nil, y=nil, width=nil, height=nil)
8
- if Neri.exist_in_datafile?(path)
9
- image = load_from_file_in_memory(Neri.file_read(path))
10
- image = image.slice(x, y, width, height) if x && y && width && height
11
- return image
12
- else
13
- return super
14
- end
7
+ def load(path, x = nil, y = nil, width = nil, height = nil)
8
+ return super unless Neri.exist_in_datafile?(path)
9
+
10
+ image = load_from_file_in_memory(Neri.file_read(path))
11
+ image = image.slice(x, y, width, height) if x && y && width && height
12
+ image
15
13
  end
16
-
17
- def load_tiles(path, xcount, ycount, share_switch=true)
18
- if Neri.exist_in_datafile?(path) && !share_switch
19
- image = load_from_file_in_memory(Neri.file_read(path))
20
- return image.slice_tiles(xcount, ycount)
21
- else
22
- return super
23
- end
14
+
15
+ def load_tiles(path, xcount, ycount, share_switch = true)
16
+ return super unless Neri.exist_in_datafile?(path) && !share_switch
17
+
18
+ image = load_from_file_in_memory(Neri.file_read(path))
19
+ image.slice_tiles(xcount, ycount)
24
20
  end
25
21
  end
26
-
22
+
27
23
  module DXRubySound
28
24
  def new(path)
29
- if Neri.exist_in_datafile?(path)
30
- case File.extname(path)
31
- when ".mid"
32
- return load_from_memory(Neri.file_read(path), DXRuby::TYPE_MIDI)
33
- else
34
- return load_from_memory(Neri.file_read(path), DXRuby::TYPE_WAV)
35
- end
36
- else
37
- return super
38
- end
25
+ return super unless Neri.exist_in_datafile?(path)
26
+
27
+ load_from_memory(Neri.file_read(path),
28
+ File.extname(path) == ".mid" ? DXRuby::TYPE_MIDI : DXRuby::TYPE_WAV)
39
29
  end
40
30
  end
41
31
  end
@@ -46,7 +36,7 @@ module DXRuby
46
36
  prepend Neri::DXRubyImage
47
37
  end
48
38
  end
49
-
39
+
50
40
  class Sound
51
41
  class << self
52
42
  prepend Neri::DXRubySound
@@ -5,7 +5,7 @@ require "dxruby_tiled" unless defined? DXRuby::Tiled
5
5
  module DXRuby
6
6
  module Tiled
7
7
  module_function
8
-
8
+
9
9
  def read_file(file, encoding = Encoding::UTF_8)
10
10
  Neri.file_read(file, encoding)
11
11
  end
data/lib/neri/runtime.rb CHANGED
@@ -1,146 +1,164 @@
1
1
  require "neri/version"
2
+ require "pathname"
2
3
 
3
- alias :_neri_orig_require :require
4
- alias :_neri_orig_load :load
4
+ module Kernel
5
+ unless defined?(neri_original_require)
6
+ alias neri_original_require require
7
+ private :neri_original_require
8
+ end
5
9
 
6
- def require(feature)
7
- Neri.require(feature)
8
- end
10
+ unless defined?(neri_original_load)
11
+ alias neri_original_load load
12
+ private :neri_original_load
13
+ end
9
14
 
10
- def load(file, priv = false)
11
- Neri.load(file, priv)
15
+ def require(feature)
16
+ Neri.require(feature)
17
+ end
18
+
19
+ def load(file, priv = false)
20
+ Neri.load(file, priv)
21
+ end
12
22
  end
13
23
 
14
24
  module Neri
15
25
  BLOCK_LENGTH = 32
16
26
  @datafile = nil
17
- @system_dir = nil
18
- @files = {}
27
+ @file_informations = {}
28
+ @fullpath_files = {}
29
+ @virtual_files = {}
30
+ @virtual_directory = "."
19
31
  @xor = nil
20
-
32
+
21
33
  class << self
22
34
  def datafile=(datafile)
23
- @datafile = datafile
24
- @system_dir = File.dirname(File.expand_path(datafile)) + File::SEPARATOR
35
+ @datafile = datafile.encode(Encoding::UTF_8)
25
36
  files_length = File.binread(@datafile, BLOCK_LENGTH).to_i
26
37
  files_str = read(files_length, BLOCK_LENGTH)
27
38
  pos = files_length + BLOCK_LENGTH
28
39
  pos += BLOCK_LENGTH - pos % BLOCK_LENGTH unless pos % BLOCK_LENGTH == 0
29
40
  files_str.force_encoding(Encoding::UTF_8)
30
- files_str.split("\n").each do |line|
41
+ files_str.each_line do |line|
31
42
  filename, length, offset = line.split("\t")
32
- @files[filename] = [length.to_i, offset.to_i + pos]
43
+ @file_informations[filename] = [length.to_i, offset.to_i + pos]
33
44
  end
45
+ @fullpath_files = @file_informations.transform_keys { |k| File.expand_path(k) }
34
46
  end
35
-
47
+
36
48
  def key=(key)
37
- @xor = key.scan(/../).map{|a| a.to_i(16)}.pack("c*")
49
+ @xor ||= key.scan(/../).map { |a| a.to_i(16) }.pack("c*")
50
+ end
51
+
52
+ def virtual_directory=(path)
53
+ @virtual_directory = path
54
+ @virtual_files = @file_informations.transform_keys { |k| File.expand_path(k, path) }
38
55
  end
39
-
56
+
40
57
  def require(feature)
41
- filepath = nil
42
- (feature.match?(/\A([a-z]:|\\|\/|\.)/i) ? [""] : load_path).each do |path|
43
- ["", ".rb"].each do |ext|
44
- next unless exist_in_datafile?(path + feature + ext)
45
- filepath = adjust_path(path + feature + ext)
46
- end
47
- end
48
-
49
- if filepath
50
- return false if $LOADED_FEATURES.index(filepath)
51
- code = load_code(filepath)
52
- eval(code, TOPLEVEL_BINDING, filepath)
53
- $LOADED_FEATURES.push(filepath)
54
- return true
55
- else
56
- return _neri_orig_require(feature)
57
- end
58
+ feature_path = Pathname.new(feature.encode(Encoding::UTF_8))
59
+ feature_path = feature_path.sub_ext(".rb") if feature_path.extname == ""
60
+ return neri_original_require(feature) if feature_path.extname == ".so"
61
+
62
+ path_str = if feature_path.absolute? || feature.start_with?(".")
63
+ path_in_datafile(feature_path)
64
+ else
65
+ search_in_load_path(feature_path)
66
+ end
67
+
68
+ return neri_original_require(feature) unless path_str
69
+ return false if $LOADED_FEATURES.index(path_str)
70
+
71
+ code = load_code(path_str)
72
+ eval(code, TOPLEVEL_BINDING, path_str)
73
+ $LOADED_FEATURES.push(path_str)
74
+ true
58
75
  end
59
-
76
+
60
77
  def load(file, priv = false)
61
- filepath = nil
62
- (load_path + [""]).each do |path|
63
- filepath = path + file if exist_in_datafile?(path + file)
64
- end
65
-
66
- if filepath
67
- code = load_code(filepath)
68
- if priv
69
- Module.new.module_eval(code, filepath)
70
- else
71
- eval(code, TOPLEVEL_BINDING, filepath)
72
- end
78
+ file_path = Pathname.new(file.encode(Encoding::UTF_8))
79
+ path_str = search_in_load_path(file_path) if file_path.relative? && !file.start_with?(".")
80
+ path_str ||= path_in_datafile(file_path)
81
+
82
+ return neri_original_load(file, priv) unless path_str
83
+
84
+ code = load_code(path_str)
85
+ if priv
86
+ Module.new.module_eval(code, path_str)
73
87
  else
74
- _neri_orig_load(filepath || file, priv)
88
+ eval(code, TOPLEVEL_BINDING, path_str)
75
89
  end
90
+ true
76
91
  end
77
-
92
+
78
93
  def file_exist?(filename)
79
- return exist_in_datafile?(filename) || File.exist?(filename)
94
+ exist_in_datafile?(filename) || File.exist?(filename)
80
95
  end
81
-
96
+
82
97
  def file_read(filename, encoding = Encoding::BINARY)
83
- str = nil
84
- if exist_in_datafile?(filename)
85
- length, offset = @files[adjust_path(filename.encode(Encoding::UTF_8))]
86
- str = read(length, offset)
87
- else
88
- str = File.binread(filename)
89
- end
98
+ filename = filename.encode(Encoding::UTF_8)
99
+ length, offset = file_information(filename)
100
+ str = length ? read(length, offset) : File.binread(filename)
90
101
  str.force_encoding(encoding)
91
- return str
92
102
  end
93
-
94
- def files()
95
- return @files.keys
103
+
104
+ def files
105
+ @file_informations.keys
96
106
  end
97
-
107
+
98
108
  def exist_in_datafile?(filename)
99
- return @files.has_key?(adjust_path(filename.encode(Encoding::UTF_8)))
109
+ file_information(filename) != nil
100
110
  end
101
-
111
+
102
112
  private
103
-
113
+
114
+ def file_information(filename)
115
+ fullpath = File.expand_path(filename)
116
+ return @fullpath_files[fullpath] if @fullpath_files.key?(fullpath)
117
+
118
+ @virtual_files[File.expand_path(filename, @virtual_directory)]
119
+ end
120
+
104
121
  def xor(str)
105
122
  str.force_encoding(Encoding::BINARY)
106
- while str.bytesize % BLOCK_LENGTH != 0
107
- str << rand(256).chr
108
- end
109
- if defined?(Xorcist)
110
- return Xorcist.xor!(str, @xor * (str.bytesize / BLOCK_LENGTH))
111
- else
112
- s = []
113
- str.unpack("Q*").zip((@xor * (str.bytesize / BLOCK_LENGTH)).unpack("Q*")){|a, b| s.push(a ^ b)}
114
- return s.pack("Q*")
115
- end
116
- end
117
-
118
- def adjust_path(path)
119
- return path.sub(/^\.\//, "")
123
+ str << rand(256).chr while str.bytesize % BLOCK_LENGTH != 0
124
+ xor_str = @xor * (str.bytesize / BLOCK_LENGTH)
125
+ return Xorcist.xor!(str, xor_str) if defined?(Xorcist)
126
+
127
+ s = []
128
+ str.unpack("Q*").zip((xor_str).unpack("Q*")) { |a, b| s.push(a ^ b) }
129
+ s.pack("Q*")
120
130
  end
121
-
131
+
122
132
  def read(length, offset)
123
- if @xor
124
- tmp_length = length
125
- tmp_length += BLOCK_LENGTH - length % BLOCK_LENGTH unless length % BLOCK_LENGTH == 0
126
- return xor(File.binread(@datafile, tmp_length, offset))[0, length]
127
- else
128
- return File.binread(@datafile, length, offset)
133
+ return File.binread(@datafile, length, offset) unless @xor
134
+
135
+ tmp_length = length
136
+ tmp_length += BLOCK_LENGTH - length % BLOCK_LENGTH unless length % BLOCK_LENGTH == 0
137
+ xor(File.binread(@datafile, tmp_length, offset))[0, length]
138
+ end
139
+
140
+ def search_in_load_path(file_path)
141
+ $LOAD_PATH.each do |path_str|
142
+ load_path = Pathname.new(path_str.encode(Encoding::UTF_8))
143
+ candidate_path_str = path_in_datafile(load_path + file_path)
144
+ return candidate_path_str if candidate_path_str
129
145
  end
146
+ nil
130
147
  end
131
-
132
- def load_path()
133
- paths = $LOAD_PATH.map { |path| path.encode(Encoding::UTF_8) }
134
- return paths unless @system_dir
135
- paths.map { |path| path.sub(@system_dir, "*neri*#{File::SEPARATOR}") + File::SEPARATOR }
148
+
149
+ def path_in_datafile(file_path)
150
+ fullpath = File.expand_path(file_path.to_s)
151
+ return fullpath if exist_in_datafile?(fullpath)
152
+
153
+ virtual_path = File.expand_path(file_path.to_s, @virtual_directory)
154
+ exist_in_datafile?(virtual_path) ? virtual_path : nil
136
155
  end
137
-
156
+
138
157
  def load_code(file)
139
158
  code = file_read(file)
140
159
  encoding = "UTF-8"
141
- encoding = $1 if code.lines[0..2].join("\n").match(/coding:\s*(\S+)/)
160
+ encoding = Regexp.last_match(1) if code.lines[0..2].join("\n").match(/coding:\s*(\S+)/)
142
161
  code.force_encoding(encoding)
143
- return code
144
162
  end
145
163
  end
146
164
  end
data/lib/neri/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Neri
2
- VERSION = "0.9.2"
2
+ VERSION = -"0.9.6"
3
3
  end
data/neri.gemspec CHANGED
@@ -8,11 +8,11 @@ Gem::Specification.new do |spec|
8
8
  spec.authors = ["nodai2hITC"]
9
9
  spec.email = ["nodai2h.itc@gmail.com"]
10
10
 
11
- spec.summary = %q{One-Click Ruby Application Builder}
12
- spec.description = %q{Neri builds Windows batfile or exefile from Ruby script.}
11
+ spec.summary = "One-Click Ruby Application Builder"
12
+ spec.description = "Neri builds Windows batfile or exefile from Ruby script."
13
13
  spec.homepage = "https://github.com/nodai2hITC/neri"
14
14
  spec.license = "MIT"
15
- spec.required_ruby_version = ">= 2.4.0"
15
+ spec.required_ruby_version = ">= 2.5.0"
16
16
 
17
17
  # spec.metadata["allowed_push_host"] = "TODO: Set to 'https://mygemserver.com'"
18
18
 
@@ -30,6 +30,4 @@ Gem::Specification.new do |spec|
30
30
  spec.bindir = "exe"
31
31
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
32
32
  spec.require_paths = ["lib"]
33
-
34
- spec.add_dependency "win32api"
35
33
  end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neri
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - nodai2hITC
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-10-22 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: win32api
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
11
+ date: 2021-12-29 00:00:00.000000000 Z
12
+ dependencies: []
27
13
  description: Neri builds Windows batfile or exefile from Ruby script.
28
14
  email:
29
15
  - nodai2h.itc@gmail.com
@@ -63,14 +49,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
63
49
  requirements:
64
50
  - - ">="
65
51
  - !ruby/object:Gem::Version
66
- version: 2.4.0
52
+ version: 2.5.0
67
53
  required_rubygems_version: !ruby/object:Gem::Requirement
68
54
  requirements:
69
55
  - - ">="
70
56
  - !ruby/object:Gem::Version
71
57
  version: '0'
72
58
  requirements: []
73
- rubygems_version: 3.2.27
59
+ rubygems_version: 3.2.30
74
60
  signing_key:
75
61
  specification_version: 4
76
62
  summary: One-Click Ruby Application Builder