ehbrs-tools 0.3.1 → 0.5.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.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/exe/ehbrs +2 -2
  3. data/lib/ehbrs/executables.rb +8 -7
  4. data/lib/ehbrs/runner.rb +33 -0
  5. data/lib/ehbrs/runner/vg.rb +19 -0
  6. data/lib/ehbrs/runner/vg/ips.rb +88 -0
  7. data/lib/ehbrs/runner/vg/wii.rb +75 -0
  8. data/lib/ehbrs/runner/videos.rb +23 -0
  9. data/lib/ehbrs/runner/videos/unsupported.rb +63 -0
  10. data/lib/ehbrs/tools/version.rb +1 -1
  11. data/lib/ehbrs/vg.rb +9 -0
  12. data/lib/ehbrs/vg/wii.rb +11 -0
  13. data/lib/ehbrs/vg/wii/file_move.rb +89 -0
  14. data/lib/ehbrs/vg/wii/game_file.rb +64 -0
  15. data/lib/ehbrs/vg/wii/wit.rb +13 -0
  16. data/lib/ehbrs/vg/wii/wit/image_format.rb +46 -0
  17. data/lib/ehbrs/vg/wii/wit/parsers/dump.rb +62 -0
  18. data/lib/ehbrs/vg/wii/wit/parsers/info.rb +39 -0
  19. data/lib/ehbrs/vg/wii/wit/path.rb +55 -0
  20. data/lib/ehbrs/videos/unsupported/search.rb +13 -10
  21. data/vendor/eac_ruby_utils/lib/eac_ruby_utils.rb +1 -19
  22. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/by_reference.rb +1 -1
  23. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/custom_format.rb +53 -0
  24. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command.rb +7 -0
  25. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/spawn.rb +32 -0
  26. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs.rb +9 -0
  27. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/traversable.rb +47 -0
  28. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/traverser.rb +74 -0
  29. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/class/common_constructor.rb +2 -2
  30. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
  31. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/custom_format_spec.rb +60 -0
  32. metadata +37 -8
  33. data/lib/ehbrs/tools/runner.rb +0 -35
  34. data/lib/ehbrs/tools/runner/vg.rb +0 -26
  35. data/lib/ehbrs/tools/runner/vg/ips.rb +0 -90
  36. data/lib/ehbrs/tools/runner/videos.rb +0 -25
  37. data/lib/ehbrs/tools/runner/videos/unsupported.rb +0 -65
  38. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/filesystem_traverser.rb +0 -56
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacRubyUtils
4
+ module Envs
5
+ class Spawn
6
+ attr_reader :command, :pid
7
+
8
+ def initialize(command)
9
+ @command = command
10
+ @pid = ::Process.spawn(command)
11
+ end
12
+
13
+ def kill(signal)
14
+ ::Process.kill(signal, pid)
15
+ end
16
+
17
+ def kill_at_end(&block)
18
+ block.call(self)
19
+ ensure
20
+ kill('KILL')
21
+ end
22
+
23
+ def to_h
24
+ { command: command, pid: pid }
25
+ end
26
+
27
+ def wait
28
+ ::Process.wait pid
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/require_sub'
4
+
5
+ module EacRubyUtils
6
+ module Fs
7
+ ::EacRubyUtils.require_sub __FILE__
8
+ end
9
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/fs/traverser'
4
+
5
+ module EacRubyUtils
6
+ module Fs
7
+ module Traversable
8
+ PROP_METHOD_PREFIX = 'traverser_'
9
+ BOOLEAN_PROPS = %i[hidden_directories recursive sort].freeze
10
+ PATH_PROPS = %i[check_directory check_file].freeze
11
+
12
+ class << self
13
+ def prop_method_name(prop)
14
+ "#{PROP_METHOD_PREFIX}#{prop}"
15
+ end
16
+ end
17
+
18
+ PATH_PROPS.each do |method|
19
+ define_method(::EacRubyUtils::Fs::Traversable.prop_method_name(method)) do |_path|
20
+ nil
21
+ end
22
+ end
23
+
24
+ BOOLEAN_PROPS.each do |method|
25
+ define_method(::EacRubyUtils::Fs::Traversable.prop_method_name(method)) do
26
+ false
27
+ end
28
+
29
+ define_method("#{::EacRubyUtils::Fs::Traversable.prop_method_name(method)}?") do
30
+ send(method_name)
31
+ end
32
+ end
33
+
34
+ def traverser_check_path(path)
35
+ traverser_new.check_path(path)
36
+ end
37
+
38
+ def traverser_new
39
+ r = ::EacRubyUtils::Fs::Traverser.new
40
+ (BOOLEAN_PROPS + PATH_PROPS).each do |prop|
41
+ r.send("#{prop}=", method(::EacRubyUtils::Fs::Traversable.prop_method_name(prop)))
42
+ end
43
+ r
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacRubyUtils
4
+ module Fs
5
+ class Traverser
6
+ attr_accessor :check_directory, :check_file, :recursive, :hidden_directories, :sort
7
+
8
+ def check_path(path)
9
+ path = ::Pathname.new(path.to_s) unless path.is_a?(::Pathname)
10
+ internal_check_path(path, 0)
11
+ end
12
+
13
+ def hidden_directories?
14
+ boolean_value(hidden_directories)
15
+ end
16
+
17
+ def recursive?
18
+ boolean_value(recursive)
19
+ end
20
+
21
+ def sort?
22
+ boolean_value(sort)
23
+ end
24
+
25
+ private
26
+
27
+ def boolean_value(source_value)
28
+ source_value = source_value.call if source_value.respond_to?(:call)
29
+ source_value ? true : false
30
+ end
31
+
32
+ def each_child(dir, &block)
33
+ if sort?
34
+ dir.each_child.sort_by { |p| [p.to_s] }.each(&block)
35
+ else
36
+ dir.each_child(&block)
37
+ end
38
+ end
39
+
40
+ def process_directory?(level)
41
+ level.zero? || recursive?
42
+ end
43
+
44
+ def inner_check_directory(dir, level)
45
+ return unless process_directory?(level)
46
+
47
+ user_check_directory(dir)
48
+ each_child(dir) do |e|
49
+ next unless !e.basename.to_s.start_with?('.') || hidden_directories?
50
+
51
+ internal_check_path(e, level + 1)
52
+ end
53
+ end
54
+
55
+ def internal_check_path(path, level)
56
+ if path.file?
57
+ user_check_file(path)
58
+ elsif path.directory?
59
+ inner_check_directory(path, level)
60
+ else
61
+ raise "Unknown filesystem object: #{path}"
62
+ end
63
+ end
64
+
65
+ def user_check_file(path)
66
+ check_file&.call(path)
67
+ end
68
+
69
+ def user_check_directory(path)
70
+ check_directory&.call(path)
71
+ end
72
+ end
73
+ end
74
+ end
@@ -3,7 +3,7 @@
3
3
  require 'eac_ruby_utils/common_constructor'
4
4
 
5
5
  class Class
6
- def common_constructor(*args)
7
- ::EacRubyUtils::CommonConstructor.new(*args).setup_class(self)
6
+ def common_constructor(*args, &block)
7
+ ::EacRubyUtils::CommonConstructor.new(*args, &block).setup_class(self)
8
8
  end
9
9
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyUtils
4
- VERSION = '0.25.0'
4
+ VERSION = '0.28.0'
5
5
  end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/custom_format'
4
+
5
+ class StubObjectData
6
+ def x_value
7
+ 'X1'
8
+ end
9
+
10
+ def y_value
11
+ 'Y1'
12
+ end
13
+ end
14
+
15
+ RSpec.describe ::EacRubyUtils::CustomFormat do
16
+ let(:instance) { described_class.new(x: :x_value, y: :y_value, z: :unexistent) }
17
+ let(:ok_format) { instance.format('|%%|%y|%x|%y|') } # rubocop:disable Style/FormatStringToken
18
+ let(:ok_string_expected) { '|%|Y1|X1|Y1|' }
19
+ let(:fail_format) { instance.format('|%z|') }
20
+
21
+ it do
22
+ expect(ok_format.sequences).to include(:x, :y)
23
+ end
24
+
25
+ it do
26
+ expect(fail_format.sequences).to include(:z)
27
+ end
28
+
29
+ context 'when object source is a hash' do
30
+ let(:object_source) { { x_value: 'X1', y_value: 'Y1' } }
31
+
32
+ context 'when hash has all keys' do
33
+ it do
34
+ expect(ok_format.with(object_source)).to eq(ok_string_expected)
35
+ end
36
+ end
37
+
38
+ context 'when hash has not all keys' do
39
+ it do
40
+ expect(fail_format.with(object_source)).to eq('||')
41
+ end
42
+ end
43
+ end
44
+
45
+ context 'when object source is not a hash' do
46
+ let(:object_source) { ::StubObjectData.new }
47
+
48
+ context 'when object has all methods' do
49
+ it do
50
+ expect(ok_format.with(object_source)).to eq(ok_string_expected)
51
+ end
52
+ end
53
+
54
+ context 'when object has not all methods' do
55
+ it do
56
+ expect { fail_format.with(object_source) }.to raise_error(::ArgumentError)
57
+ end
58
+ end
59
+ end
60
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ehbrs-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esquilo Azul Company
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-20 00:00:00.000000000 Z
11
+ date: 2020-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eac_ruby_utils
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0.19'
27
+ - !ruby/object:Gem::Dependency
28
+ name: inifile
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: eac_ruby_gem_support
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -49,13 +63,23 @@ files:
49
63
  - exe/ehbrs
50
64
  - lib/ehbrs.rb
51
65
  - lib/ehbrs/executables.rb
66
+ - lib/ehbrs/runner.rb
67
+ - lib/ehbrs/runner/vg.rb
68
+ - lib/ehbrs/runner/vg/ips.rb
69
+ - lib/ehbrs/runner/vg/wii.rb
70
+ - lib/ehbrs/runner/videos.rb
71
+ - lib/ehbrs/runner/videos/unsupported.rb
52
72
  - lib/ehbrs/tools.rb
53
- - lib/ehbrs/tools/runner.rb
54
- - lib/ehbrs/tools/runner/vg.rb
55
- - lib/ehbrs/tools/runner/vg/ips.rb
56
- - lib/ehbrs/tools/runner/videos.rb
57
- - lib/ehbrs/tools/runner/videos/unsupported.rb
58
73
  - lib/ehbrs/tools/version.rb
74
+ - lib/ehbrs/vg.rb
75
+ - lib/ehbrs/vg/wii.rb
76
+ - lib/ehbrs/vg/wii/file_move.rb
77
+ - lib/ehbrs/vg/wii/game_file.rb
78
+ - lib/ehbrs/vg/wii/wit.rb
79
+ - lib/ehbrs/vg/wii/wit/image_format.rb
80
+ - lib/ehbrs/vg/wii/wit/parsers/dump.rb
81
+ - lib/ehbrs/vg/wii/wit/parsers/info.rb
82
+ - lib/ehbrs/vg/wii/wit/path.rb
59
83
  - lib/ehbrs/videos.rb
60
84
  - lib/ehbrs/videos/convert_job.rb
61
85
  - lib/ehbrs/videos/file.rb
@@ -120,6 +144,7 @@ files:
120
144
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/console/speaker/node.rb
121
145
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/contextualizable.rb
122
146
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/core_ext.rb
147
+ - vendor/eac_ruby_utils/lib/eac_ruby_utils/custom_format.rb
123
148
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/envs.rb
124
149
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/base_env.rb
125
150
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command.rb
@@ -128,9 +153,12 @@ files:
128
153
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/file.rb
129
154
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/local_env.rb
130
155
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/process.rb
156
+ - vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/spawn.rb
131
157
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/ssh_env.rb
132
158
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/filesystem_cache.rb
133
- - vendor/eac_ruby_utils/lib/eac_ruby_utils/filesystem_traverser.rb
159
+ - vendor/eac_ruby_utils/lib/eac_ruby_utils/fs.rb
160
+ - vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/traversable.rb
161
+ - vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/traverser.rb
134
162
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/fs_cache.rb
135
163
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/listable.rb
136
164
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/class_methods.rb
@@ -180,6 +208,7 @@ files:
180
208
  - vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/console/configs_spec.rb
181
209
  - vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/console/docopt_runner_spec.rb
182
210
  - vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/console/speaker_spec.rb
211
+ - vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/custom_format_spec.rb
183
212
  - vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/envs/executable_spec.rb
184
213
  - vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/envs/ssh_env_spec.rb
185
214
  - vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/filesystem_cache_spec.rb
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'eac_ruby_utils/core_ext'
4
- require 'eac_ruby_utils/console/docopt_runner'
5
- require 'ehbrs/tools/version'
6
-
7
- module Ehbrs
8
- module Tools
9
- class Runner < ::EacRubyUtils::Console::DocoptRunner
10
- require_sub __FILE__
11
- enable_console_speaker
12
-
13
- DOC = <<~DOCOPT
14
- Tools for EHB/RS.
15
-
16
- Usage:
17
- __PROGRAM__ [options] __SUBCOMMANDS__
18
- __PROGRAM__ --version
19
- __PROGRAM__ -h | --help
20
-
21
- Options:
22
- -h --help Show this screen.
23
- -V --version Show version.
24
- DOCOPT
25
-
26
- def run
27
- if options.fetch('--version')
28
- out(::Ehbrs::Tools::VERSION + "\n")
29
- else
30
- run_with_subcommand
31
- end
32
- end
33
- end
34
- end
35
- end
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'eac_ruby_utils/core_ext'
4
- require 'eac_ruby_utils/console/docopt_runner'
5
-
6
- module Ehbrs
7
- module Tools
8
- class Runner < ::EacRubyUtils::Console::DocoptRunner
9
- class Vg < ::EacRubyUtils::Console::DocoptRunner
10
- require_sub __FILE__
11
- enable_console_speaker
12
-
13
- DOC = <<~DOCOPT
14
- Videogame tools.
15
-
16
- Usage:
17
- __PROGRAM__ [options] __SUBCOMMANDS__
18
- __PROGRAM__ -h | --help
19
-
20
- Options:
21
- -h --help Show this screen.
22
- DOCOPT
23
- end
24
- end
25
- end
26
- end
@@ -1,90 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'eac_cli/runner'
4
- require 'eac_cli/default_runner'
5
- require 'eac_ruby_utils/core_ext'
6
- require 'eac_ruby_utils/console/docopt_runner'
7
- require 'ehbrs/executables'
8
-
9
- module Ehbrs
10
- module Tools
11
- class Runner < ::EacRubyUtils::Console::DocoptRunner
12
- class Vg < ::EacRubyUtils::Console::DocoptRunner
13
- class Ips < ::EacRubyUtils::Console::DocoptRunner
14
- include ::EacCli::DefaultRunner
15
-
16
- runner_definition do
17
- desc 'Aplica patches IPS em roms.'
18
- arg_opt '-o', '--output-file', ' Saída no arquivo <output-file>.'
19
- bool_opt '-w', '--overwrite', 'Sobrescreve o arquivo de saída se existente.'
20
- pos_arg 'source-file'
21
- pos_arg 'ips-file'
22
- end
23
-
24
- def run
25
- validate
26
- end
27
-
28
- private
29
-
30
- def run_patch
31
- ::Ehbrs::Executables.floating_ips.command
32
- .append(['--apply', ips_file, source_file, output_file]).system!
33
- end
34
-
35
- def source_file
36
- options.fetch('<source-file>')
37
- end
38
-
39
- def start_banner
40
- infov 'Source file', source_file
41
- infov 'IPS file', ips_file
42
- infov 'Output file', output_file
43
- end
44
-
45
- def ips_file
46
- options.fetch('<ips-file>')
47
- end
48
-
49
- def output_file
50
- options.fetch('--output-file') || default_output_file
51
- end
52
-
53
- def default_output_file
54
- ::File.join(
55
- ::File.dirname(ips_file),
56
- ::File.basename(ips_file, '.*') + ::File.extname(source_file)
57
- )
58
- end
59
-
60
- def validate
61
- validate_source_file
62
- validate_ips_file
63
- validate_output_file
64
- start_banner
65
- run_patch
66
- end
67
-
68
- def validate_source_file
69
- return if ::File.exist?(source_file)
70
-
71
- fatal_error("Arquivo fonte \"#{source_file}\" não existe")
72
- end
73
-
74
- def validate_ips_file
75
- return if ::File.exist?(ips_file)
76
-
77
- fatal_error("Arquivo IPS \"#{ips_file}\" não existe")
78
- end
79
-
80
- def validate_output_file
81
- return unless ::File.exist?(output_file)
82
- return if options.fetch('--overwrite')
83
-
84
- fatal_error("Arquivo de saída \"#{output_file}\" já existe")
85
- end
86
- end
87
- end
88
- end
89
- end
90
- end