ehbrs-tools 0.3.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b438bde26af678d3677255f2d39bcc65ed81c12b76ae6cf511525162ca9ac817
4
- data.tar.gz: 73ef2123e1a77fdd3b243ff11b019410fdbd8eabf3017217cec8737b4ee7fe13
3
+ metadata.gz: fa659c13e85b5935fb4c1f79c3dacece337e2a2c4305d3696447a63585d8cf9f
4
+ data.tar.gz: 760fe597d4e550c63c5ecc5a6a94d22b5ee70d2d5ea73a3b036c7a21c7bf3d92
5
5
  SHA512:
6
- metadata.gz: 1658664c94ee2c08b6357756255a25007b8e161152d0f859ac3c90c8180cdc9defc268ed00f15f2b6409dd98c25e1a2e824d9313c657d8ad7b4cf05f21c4eb42
7
- data.tar.gz: 2c5db9ac476c19492481b080fcfd9ba883eb8aef29df3f619523071d5847d044d88cae271e1060a7c1801855e227095390278bdbcfeef55d5a9c85f944f62d69
6
+ metadata.gz: 84aaa531f252a3a05242866c3593056cb33df6cce824a186067d610cf51a2ad01b5077f61d726d23fd19b75218809df0a44bf7cab842780da47642e1f274a80d
7
+ data.tar.gz: 7ccbf1c9fe7be6a41a1a6acffdcabff9ca4c821ee313606e3ddaf8cc3d89daa3d7357ea77b972b0c824499e8c39836f9d97b5094eceac57b5f03b522a46294b5
data/exe/ehbrs CHANGED
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  $LOAD_PATH.unshift("#{__dir__}/../lib")
5
- require 'ehbrs/tools/runner'
6
- ::Ehbrs::Tools::Runner.run
5
+ require 'ehbrs/runner'
6
+ ::Ehbrs::Runner.run
@@ -12,15 +12,16 @@ module Ehbrs
12
12
  ::EacRubyUtils::Envs.local
13
13
  end
14
14
 
15
- def floating_ips
16
- @floating_ips ||= env.executable('flips-linux', '--version')
17
- end
18
-
19
15
  private
20
16
 
21
- %w[ffmpeg ffprobe].each do |command|
22
- define_method("#{command}_uncached") do
23
- env.executable(command, '-version')
17
+ {
18
+ '-version' => %w[ffmpeg ffprobe],
19
+ '--version' => %w[flips-linux wit]
20
+ }.each do |validate_arg, commands|
21
+ commands.each do |command|
22
+ define_method("#{command}_uncached") do
23
+ env.executable(command, validate_arg)
24
+ end
24
25
  end
25
26
  end
26
27
  end
@@ -0,0 +1,33 @@
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
+ class Runner < ::EacRubyUtils::Console::DocoptRunner
9
+ require_sub __FILE__
10
+ enable_console_speaker
11
+
12
+ DOC = <<~DOCOPT
13
+ Tools for EHB/RS.
14
+
15
+ Usage:
16
+ __PROGRAM__ [options] __SUBCOMMANDS__
17
+ __PROGRAM__ --version
18
+ __PROGRAM__ -h | --help
19
+
20
+ Options:
21
+ -h --help Show this screen.
22
+ -V --version Show version.
23
+ DOCOPT
24
+
25
+ def run
26
+ if options.fetch('--version')
27
+ out(::Ehbrs::Tools::VERSION + "\n")
28
+ else
29
+ run_with_subcommand
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/default_runner'
4
+ require 'eac_ruby_utils/core_ext'
5
+ require 'eac_ruby_utils/console/docopt_runner'
6
+
7
+ module Ehbrs
8
+ class Runner < ::EacRubyUtils::Console::DocoptRunner
9
+ class Vg < ::EacRubyUtils::Console::DocoptRunner
10
+ include ::EacCli::DefaultRunner
11
+ require_sub __FILE__
12
+
13
+ runner_definition do
14
+ desc 'Ferramentas para video game.'
15
+ subcommands
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,88 @@
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
+ class Runner < ::EacRubyUtils::Console::DocoptRunner
11
+ class Vg < ::EacRubyUtils::Console::DocoptRunner
12
+ class Ips < ::EacRubyUtils::Console::DocoptRunner
13
+ include ::EacCli::DefaultRunner
14
+
15
+ runner_definition do
16
+ desc 'Aplica patches IPS em roms.'
17
+ arg_opt '-o', '--output-file', ' Saída no arquivo <output-file>.'
18
+ bool_opt '-w', '--overwrite', 'Sobrescreve o arquivo de saída se existente.'
19
+ pos_arg 'source-file'
20
+ pos_arg 'ips-file'
21
+ end
22
+
23
+ def run
24
+ validate
25
+ end
26
+
27
+ private
28
+
29
+ def run_patch
30
+ ::Ehbrs::Executables.floating_ips.command
31
+ .append(['--apply', ips_file, source_file, output_file]).system!
32
+ end
33
+
34
+ def source_file
35
+ options.fetch('<source-file>')
36
+ end
37
+
38
+ def start_banner
39
+ infov 'Source file', source_file
40
+ infov 'IPS file', ips_file
41
+ infov 'Output file', output_file
42
+ end
43
+
44
+ def ips_file
45
+ options.fetch('<ips-file>')
46
+ end
47
+
48
+ def output_file
49
+ options.fetch('--output-file') || default_output_file
50
+ end
51
+
52
+ def default_output_file
53
+ ::File.join(
54
+ ::File.dirname(ips_file),
55
+ ::File.basename(ips_file, '.*') + ::File.extname(source_file)
56
+ )
57
+ end
58
+
59
+ def validate
60
+ validate_source_file
61
+ validate_ips_file
62
+ validate_output_file
63
+ start_banner
64
+ run_patch
65
+ end
66
+
67
+ def validate_source_file
68
+ return if ::File.exist?(source_file)
69
+
70
+ fatal_error("Arquivo fonte \"#{source_file}\" não existe")
71
+ end
72
+
73
+ def validate_ips_file
74
+ return if ::File.exist?(ips_file)
75
+
76
+ fatal_error("Arquivo IPS \"#{ips_file}\" não existe")
77
+ end
78
+
79
+ def validate_output_file
80
+ return unless ::File.exist?(output_file)
81
+ return if options.fetch('--overwrite')
82
+
83
+ fatal_error("Arquivo de saída \"#{output_file}\" já existe")
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/default_runner'
4
+ require 'eac_ruby_utils/core_ext'
5
+ require 'eac_ruby_utils/console/docopt_runner'
6
+ require 'eac_ruby_utils/fs/traversable'
7
+ require 'ehbrs/vg/wii/file_move'
8
+ require 'ehbrs/vg/wii/game_file'
9
+
10
+ module Ehbrs
11
+ class Runner < ::EacRubyUtils::Console::DocoptRunner
12
+ class Vg < ::EacRubyUtils::Console::DocoptRunner
13
+ class Wii < ::EacRubyUtils::Console::DocoptRunner
14
+ include ::EacCli::DefaultRunner
15
+ include ::EacRubyUtils::Fs::Traversable
16
+
17
+ runner_definition do
18
+ desc 'Manipulação de imagens de jogo Wii.'
19
+ bool_opt '-R', '--recursive', 'Busca arquivos recursivamente.'
20
+ bool_opt '-d', '--dump', 'Mostra todos os atributos do jogo.'
21
+ arg_opt '-m', '--move', 'Move o arquivo.'
22
+ bool_opt '-c', '--confirm', 'Confirma o movimento do arquivo.'
23
+ pos_arg 'paths', repeat: true
24
+ end
25
+
26
+ def run
27
+ infov 'Recursive?', traverser_new.recursive?
28
+ options.fetch('<paths>').each do |path|
29
+ traverser_check_path(path)
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def confirm?
36
+ options.fetch('--confirm')
37
+ end
38
+
39
+ def dump(game)
40
+ return unless options.fetch('--dump')
41
+
42
+ game.properties.each do |name, value|
43
+ infov " * #{name}", value
44
+ end
45
+ end
46
+
47
+ def move(game)
48
+ return if move_arg.blank?
49
+
50
+ file_move = ::Ehbrs::Vg::Wii::FileMove.new(game, game.format(move_arg))
51
+ infov ' * Target path',
52
+ file_move.target.to_s.colorize(file_move.change? ? :light_white : :light_black)
53
+ file_move.run if confirm?
54
+ end
55
+
56
+ def move_arg
57
+ options.fetch('--move')
58
+ end
59
+
60
+ def traverser_recursive
61
+ options.fetch('--recursive')
62
+ end
63
+
64
+ def traverser_check_file(path)
65
+ game = ::Ehbrs::Vg::Wii::GameFile.new(path)
66
+ return unless game.valid?
67
+
68
+ infom game.wit_path
69
+ dump(game)
70
+ move(game)
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,23 @@
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
+ class Runner < ::EacRubyUtils::Console::DocoptRunner
8
+ class Videos < ::EacRubyUtils::Console::DocoptRunner
9
+ require_sub __FILE__
10
+
11
+ DOC = <<~DOCOPT
12
+ Video tools for EHB/RS.
13
+
14
+ Usage:
15
+ __PROGRAM__ [options] __SUBCOMMANDS__
16
+ __PROGRAM__ -h | --help
17
+
18
+ Options:
19
+ -h --help Show this screen.
20
+ DOCOPT
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/default_runner'
4
+ require 'eac_ruby_utils/core_ext'
5
+ require 'eac_ruby_utils/console/docopt_runner'
6
+ require 'ehbrs/videos/unsupported/check_set'
7
+ require 'ehbrs/videos/unsupported/search'
8
+ require 'ehbrs/videos/unsupported/profiles'
9
+
10
+ module Ehbrs
11
+ class Runner < ::EacRubyUtils::Console::DocoptRunner
12
+ class Videos < ::EacRubyUtils::Console::DocoptRunner
13
+ class Unsupported < ::EacRubyUtils::Console::DocoptRunner
14
+ include ::EacCli::DefaultRunner
15
+
16
+ PROFILES = %w[philco samsung].freeze
17
+
18
+ runner_definition do
19
+ desc 'Procura e converte vídeos não suportados pelas TVs de EHB/RS.'
20
+ bool_opt '-f', '--fix', 'Converte vídeos para o formato apropriado.'
21
+ arg_opt '-p', '--profiles', "Seleciona os perfis (#{PROFILES.join(', ')})."
22
+ pos_arg 'paths', repeat: true
23
+ end
24
+
25
+ def run
26
+ infov 'Profiles', profiles.join(', ')
27
+ infov 'Paths', paths
28
+ paths.each do |d|
29
+ ::Ehbrs::Videos::Unsupported::Search.new(d, file_options)
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def file_check_set_uncached
36
+ ::Ehbrs::Videos::Unsupported::CheckSet.build(profiles, :file)
37
+ end
38
+
39
+ def track_check_set_uncached
40
+ ::Ehbrs::Videos::Unsupported::CheckSet.build(profiles, :track)
41
+ end
42
+
43
+ def paths
44
+ options.fetch('<paths>')
45
+ end
46
+
47
+ def file_options
48
+ { file_check_set: file_check_set, track_check_set: track_check_set,
49
+ fix: options.fetch('--fix') }
50
+ end
51
+
52
+ def profiles_uncached
53
+ options.fetch('--profiles').if_present(PROFILES) { |v| v.split(',').map(&:strip) }
54
+ .map { |name| profile_class(name).instance }
55
+ end
56
+
57
+ def profile_class(profile_name)
58
+ ::Ehbrs::Videos::Unsupported::Profiles.const_get(profile_name.camelize)
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Ehbrs
4
4
  module Tools
5
- VERSION = '0.3.1'
5
+ VERSION = '0.5.0'
6
6
  end
7
7
  end
data/lib/ehbrs/vg.rb ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Ehbrs
6
+ module Vg
7
+ require_sub __FILE__
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Ehbrs
6
+ module Vg
7
+ module Wii
8
+ require_sub __FILE__
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'ehbrs/executables'
5
+ require 'ehbrs/vg/wii/wit/image_format'
6
+ require 'ehbrs/vg/wii/wit/path'
7
+ require 'fileutils'
8
+
9
+ module Ehbrs
10
+ module Vg
11
+ module Wii
12
+ class FileMove
13
+ common_constructor :game, :target do
14
+ self.target = ::Ehbrs::Vg::Wii::Wit::Path.assert(target)
15
+ end
16
+
17
+ ['', 'path_', 'type_'].each do |prefix|
18
+ method_name = "#{prefix}change?"
19
+ define_method(method_name) do
20
+ source.send(method_name, target)
21
+ end
22
+ end
23
+
24
+ def run
25
+ [%w[path type], %w[path], %w[type]].each do |parts|
26
+ next unless parts.all? { |part| send("#{part}_change?") }
27
+
28
+ assert_target_dir
29
+ send("change_#{parts.join('_and_')}")
30
+ check_target
31
+ break
32
+ end
33
+ end
34
+
35
+ def source
36
+ game.wit_path
37
+ end
38
+
39
+ private
40
+
41
+ def assert_target_dir
42
+ target.path.parent.mkpath
43
+ end
44
+
45
+ def change_path
46
+ ::FileUtils.mv(source.path, target.path)
47
+ end
48
+
49
+ def change_path_and_type
50
+ ::Ehbrs::Executables.wit.command
51
+ .append(change_path_and_type_args)
52
+ .system!
53
+ check_target
54
+ source.path.unlink
55
+ end
56
+
57
+ def change_path_and_type_args
58
+ r = %w[copy]
59
+ target_image_format.if_present { |v| r << v.option }
60
+ r + [source.path, target.path]
61
+ end
62
+
63
+ def change_type
64
+ ::Ehbrs::Executables.wit.command
65
+ .append(change_type_args)
66
+ .system!
67
+ end
68
+
69
+ def change_type_args
70
+ r = %w[convert]
71
+ target_image_format.if_present { |v| r << v.option }
72
+ r + [target.path]
73
+ end
74
+
75
+ def check_target
76
+ return if ::Ehbrs::Vg::Wii::GameFile.new(target.path).valid?
77
+
78
+ raise "Target \"#{target}\" is not a valid Wii game"
79
+ end
80
+
81
+ def target_image_format
82
+ return nil if target.type.blank?
83
+
84
+ ::Ehbrs::Vg::Wii::Wit::ImageFormat.by_name(target.type)
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end