six-arma-tools 0.1.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.
- data/LICENSE +3 -0
- data/README +8 -0
- data/Rakefile +45 -0
- data/lib/six/arma/tools.rb +61 -0
- data/lib/six/arma/tools/cfgconvert.rb +48 -0
- data/lib/six/arma/tools/pbodll.rb +223 -0
- metadata +61 -0
data/LICENSE
ADDED
data/README
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
#
|
2
|
+
# To change this template, choose Tools | Templates
|
3
|
+
# and open the template in the editor.
|
4
|
+
|
5
|
+
|
6
|
+
require 'rubygems'
|
7
|
+
require 'rake'
|
8
|
+
require 'rake/clean'
|
9
|
+
require 'rake/gempackagetask'
|
10
|
+
require 'rake/rdoctask'
|
11
|
+
require 'rake/testtask'
|
12
|
+
|
13
|
+
spec = Gem::Specification.new do |s|
|
14
|
+
s.name = 'six-arma-tools'
|
15
|
+
s.version = '0.1.0'
|
16
|
+
s.has_rdoc = true
|
17
|
+
s.extra_rdoc_files = ['README', 'LICENSE']
|
18
|
+
s.summary = 'Your summary here'
|
19
|
+
s.description = s.summary
|
20
|
+
s.author = ''
|
21
|
+
s.email = ''
|
22
|
+
# s.executables = ['your_executable_here']
|
23
|
+
s.files = %w(LICENSE README Rakefile) + Dir.glob("{bin,spec}/**/*") + Dir.glob("lib/six/**/*")
|
24
|
+
s.require_path = "lib"
|
25
|
+
s.bindir = "bin"
|
26
|
+
end
|
27
|
+
|
28
|
+
Rake::GemPackageTask.new(spec) do |p|
|
29
|
+
p.gem_spec = spec
|
30
|
+
p.need_tar = true
|
31
|
+
p.need_zip = true
|
32
|
+
end
|
33
|
+
|
34
|
+
Rake::RDocTask.new do |rdoc|
|
35
|
+
files =['README', 'LICENSE', 'lib/six/**/*.rb']
|
36
|
+
rdoc.rdoc_files.add(files)
|
37
|
+
rdoc.main = "README" # page to start on
|
38
|
+
rdoc.title = "six-arma-tools Docs"
|
39
|
+
rdoc.rdoc_dir = 'doc/rdoc' # rdoc output folder
|
40
|
+
rdoc.options << '--line-numbers'
|
41
|
+
end
|
42
|
+
|
43
|
+
Rake::TestTask.new do |t|
|
44
|
+
t.test_files = FileList['test/**/*.rb']
|
45
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
gem 'log4r'
|
3
|
+
require 'log4r'
|
4
|
+
|
5
|
+
module Six
|
6
|
+
module Arma
|
7
|
+
module Tools
|
8
|
+
if RUBY_VERSION[/[0-1]\.[0-8]\.[0-6]/]
|
9
|
+
puts "Please upgrade Ruby to at least 1.8.7"
|
10
|
+
Process.exit!
|
11
|
+
end
|
12
|
+
COMPONENT = 'six-arma-tools'
|
13
|
+
|
14
|
+
@@options = Hash.new unless defined?(@@options)
|
15
|
+
@@config = Hash.new
|
16
|
+
@@config[:paths] = Hash.new
|
17
|
+
@@config[:settings] = Hash.new
|
18
|
+
@@config[:settings][:prefix] = '$PBOPREFIX'
|
19
|
+
config = "#{COMPONENT}.yml"
|
20
|
+
if FileTest.exist?(config)
|
21
|
+
File.open(config) { |file| @@config.merge! YAML::load(file) }
|
22
|
+
else
|
23
|
+
puts "Warning: No config-file found, assuming default settings!"
|
24
|
+
end
|
25
|
+
|
26
|
+
module_function
|
27
|
+
def config
|
28
|
+
@@config
|
29
|
+
end
|
30
|
+
|
31
|
+
@@log = Log4r::Logger.new(COMPONENT)
|
32
|
+
format1 = Log4r::PatternFormatter.new(:pattern => "[%l] %d: %m", :date_pattern => '%H:%M:%S')
|
33
|
+
format2 = Log4r::PatternFormatter.new(:pattern => "[%l] %c %d: %m", :date_pattern => '%H:%M:%S')
|
34
|
+
|
35
|
+
# Create Outputters
|
36
|
+
if @@options[:verbose]
|
37
|
+
o_file = Log4r::FileOutputter.new "#{COMPONENT}-file",
|
38
|
+
'level' => 0, # All
|
39
|
+
:filename => "#{COMPONENT}.log",
|
40
|
+
'formatter' => format2
|
41
|
+
#:maxsize => 1024
|
42
|
+
@@log.outputters << o_file
|
43
|
+
end
|
44
|
+
|
45
|
+
o_out = Log4r::StdoutOutputter.new 'sixcore-stdout',
|
46
|
+
'level' => 2, # no DEBUG
|
47
|
+
'formatter' => format1
|
48
|
+
|
49
|
+
o_err = Log4r::StderrOutputter.new 'sixcore-stderr',
|
50
|
+
'level' => 4, # Error and Up
|
51
|
+
'formatter' => format1
|
52
|
+
|
53
|
+
@@log.outputters << o_out << o_err
|
54
|
+
def log
|
55
|
+
@@log
|
56
|
+
end
|
57
|
+
log.debug @@config
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Six
|
2
|
+
module Arma
|
3
|
+
module Tools
|
4
|
+
class CfgConvert
|
5
|
+
# TODO: Add to configuration file
|
6
|
+
TOOL = "CfgConvert.exe"
|
7
|
+
attr_reader(:source) # allows instance.attribute to be read (e.g convert.source)
|
8
|
+
attr_accessor(:destination) # allows instance.attribute to be read and written (e.g convert.destination)
|
9
|
+
|
10
|
+
# cfgConvert [-bin | -txt | -xml] {[-dst <destination>] <source>}
|
11
|
+
def initialize(source, destination = nil)
|
12
|
+
@source = source
|
13
|
+
@destination = destination
|
14
|
+
end
|
15
|
+
|
16
|
+
def bin
|
17
|
+
exec("bin")
|
18
|
+
end
|
19
|
+
|
20
|
+
def txt
|
21
|
+
exec("txt")
|
22
|
+
end
|
23
|
+
|
24
|
+
def xml
|
25
|
+
exec("xml")
|
26
|
+
end
|
27
|
+
|
28
|
+
def exec(cmd)
|
29
|
+
extension = "#{cmd}"
|
30
|
+
cmd += " -dst #{@destination}" if @destination
|
31
|
+
|
32
|
+
# TODO: Handle exceptions, maybe with FileTest
|
33
|
+
system "#{TOOL} -#{cmd} #{@source}"
|
34
|
+
"#{source[/\A.*\./]}#{extension}" # return the predicted output file
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
if $0 == __FILE__
|
42
|
+
File.glob(source, "**", file).each do |config|
|
43
|
+
convert = Six::Arma::Tools::CfgConvert.new(config, destination)
|
44
|
+
convert.txt # Convert to text file
|
45
|
+
convert.xml # Convert to xml file
|
46
|
+
# convert.bin # Convert to bin file
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,223 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'six/arma/tools'
|
3
|
+
module Six
|
4
|
+
module Arma
|
5
|
+
module Tools
|
6
|
+
class Pbo
|
7
|
+
include FileUtils
|
8
|
+
#BINARIZE, AUTOLINT, ATTACHTEXT, NONE = 'B', 'L', 'T', 'N'
|
9
|
+
#ARMA, CWC, ELITE, RESISTANCE = 'A', 'C', 'E', 'R'
|
10
|
+
|
11
|
+
FORMATS = {:arma => 'A', :cwc => 'C', :elite => 'E', :resistance => 'R'}
|
12
|
+
RAPIFY = {:binarize => 'B', :autolint => 'L', :attachtext => 'T', :none => 'N'}
|
13
|
+
|
14
|
+
attr_reader(:source) # allows instance.attribute to be read (e.g convert.source)
|
15
|
+
attr_accessor(:destination) # allows instance.attribute to be read and written (e.g convert.destination)
|
16
|
+
|
17
|
+
def initialize(source, destination = source)
|
18
|
+
@source = source
|
19
|
+
source[/(.*)\//]
|
20
|
+
if destination == $1
|
21
|
+
@same = true
|
22
|
+
end
|
23
|
+
@destination = destination
|
24
|
+
end
|
25
|
+
|
26
|
+
def log; Six::Arma::Tools::log; end
|
27
|
+
def config; Six::Arma::Tools::config; end
|
28
|
+
def settings; config[:settings]; end
|
29
|
+
def paths; config[:paths]; end
|
30
|
+
|
31
|
+
# Checks prefix, returns read from file prefix, empty prefix, or given prefix
|
32
|
+
# source:: Source folder to look for PREFIX_FILE file
|
33
|
+
# prefix:: String: Empty, '__AUTO__' or specific prefix can be given
|
34
|
+
def check_prefix(source, prefix)
|
35
|
+
return prefix unless prefix == '__AUTO__'
|
36
|
+
if FileTest.exist?("#{source}/#{settings[:prefix]}")
|
37
|
+
pf = File.open("#{source}/#{settings[:prefix]}") { |file| file.readlines.map { |line| line.chomp } }
|
38
|
+
if pf[0].empty?
|
39
|
+
return ''
|
40
|
+
else
|
41
|
+
return pf[0]
|
42
|
+
end
|
43
|
+
else
|
44
|
+
return ''
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# TODO: Calculate prefix from script_component's include? define PREFIX prefix
|
49
|
+
def auto_prefix
|
50
|
+
@source[/(.*)\/(.*)/]
|
51
|
+
folder, filename = $1, $2
|
52
|
+
tag = ''
|
53
|
+
log.info "AutoPrefix: #{@source}"
|
54
|
+
if FileTest.exist?(File.join(folder, filename, '$PBOPREFIX$'))
|
55
|
+
# TODO: .lines might be bugged in 1.8.6 windows
|
56
|
+
File.open(File.join(folder, filename, '$PBOPREFIX$'), 'r') { |file| file.lines.each { |line| tag = "#{$1}_" if line[/x\\(\w*)\\/] } }
|
57
|
+
end
|
58
|
+
unless tag == ''
|
59
|
+
mv(File.join(@destination, "#{filename}.pbo"), File.join(@destination,"#{tag}#{filename}.pbo"))
|
60
|
+
end
|
61
|
+
if FileTest.exist?(File.join(@destination, "#{filename}.log"))
|
62
|
+
dest = File.join(@destination, "#{tag}#{filename}.log")
|
63
|
+
# TODO: Move the log regardless of autoprefix!
|
64
|
+
dest = File.join(settings[:log], "#{tag}#{filename}.log") if settings[:log]
|
65
|
+
lf = File.join(@destination, "#{filename}.log")
|
66
|
+
mv(lf, dest) unless lf == dest
|
67
|
+
end
|
68
|
+
"#{tag}#{filename}.pbo"
|
69
|
+
end
|
70
|
+
|
71
|
+
# If path defined in the config, use it, if not defined, expect program to be in path
|
72
|
+
def tool(program)
|
73
|
+
program[/(.*)\./]
|
74
|
+
if paths[$1.to_sym]
|
75
|
+
File.join(paths[$1.to_sym], program)
|
76
|
+
else
|
77
|
+
program
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
DEFAULT_UNPACK = {:extract_to_prefix => false, :derapify => true, :prompt_overwrite => true, :silent => true, :list => false}
|
82
|
+
def unpack(params = {})
|
83
|
+
params = DEFAULT_UNPACK.merge params
|
84
|
+
cmd = []
|
85
|
+
cmd << 'n' unless params[:silent]
|
86
|
+
cmd << 'r' unless params[:derapify]
|
87
|
+
cmd << 'a' if params[:extract_to_prefix]
|
88
|
+
cmd << 'l' if params[:list]
|
89
|
+
cmd = " -#{cmd.join('')}" if cmd.size > 0
|
90
|
+
cmd << " -f \"#{params[:files_to_extract]}\"" if params[:files_to_extract]
|
91
|
+
cmd << " -w #{params[:output]}" if params[:output]
|
92
|
+
if @source[/\.pbo/]
|
93
|
+
@source[/(\w*)\.pbo/]
|
94
|
+
destination = File.join(@destination, $1)
|
95
|
+
|
96
|
+
log.info "Unpacking: #{@source} to #{destination}"
|
97
|
+
output = %x[#{tool('extractpbo.exe')}#{cmd.join('')} "#{@source}" "#{destination}"]
|
98
|
+
else
|
99
|
+
pbos = Dir.glob("#{source}/*.pbo")
|
100
|
+
pbos.each do |pbo|
|
101
|
+
puts pbo
|
102
|
+
obj = Pbo.new(pbo, @destination)
|
103
|
+
obj.unpack
|
104
|
+
end
|
105
|
+
end
|
106
|
+
log.debug output
|
107
|
+
output
|
108
|
+
end
|
109
|
+
|
110
|
+
DEFAULT_PACK = {:format => :arma, :rapify => :none, :autoprefix => true}
|
111
|
+
def pack(params = {})
|
112
|
+
params = DEFAULT_PACK.merge params
|
113
|
+
cli_params = [FORMATS[params[:format]], RAPIFY[params[:rapify]]]
|
114
|
+
cmd = "#{tool('makepbo.exe')} -#{cli_params.join('')} \"#{@source}\""
|
115
|
+
|
116
|
+
# TODO: Handle exceptions, maybe with FileTest
|
117
|
+
log.info "Packing: #{@source}"
|
118
|
+
exec = cmd
|
119
|
+
log.info exec
|
120
|
+
output = %x[#{exec}]
|
121
|
+
log.debug output
|
122
|
+
unless @same
|
123
|
+
# TODO: Better to have makepbo accept a destination.. Otherwise it overwrites/removes addons already present in source!
|
124
|
+
puts "#{@source} #{@destination}"
|
125
|
+
FileUtils::mv("#{@source}.pbo", @destination) if @destination
|
126
|
+
end
|
127
|
+
if params[:autoprefix]
|
128
|
+
auto_prefix
|
129
|
+
else
|
130
|
+
"#{source}.pbo"[/(.*)\/(.*)/]
|
131
|
+
$2
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
DEFAULT_RAPIFY = {:file => nil, :format => :arma, :rapify => :arma, :autoprefix => true}
|
136
|
+
def rapify(params = {})
|
137
|
+
params = DEFAULT_RAPIFY.merge params
|
138
|
+
cli_params = [FORMATS[params[:format]], RAPIFY[params[:rapify]]]
|
139
|
+
curdir = Dir.pwd
|
140
|
+
Dir.chdir(@source)
|
141
|
+
# TODO: Handle exceptions, maybe with FileTest
|
142
|
+
if params[:file]
|
143
|
+
log.info "Rapifying: #{@source}"
|
144
|
+
exec = "#{tool('rapify.exe')} -#{cli_params.join('')} \"#{params[:file]}\""
|
145
|
+
log.info exec
|
146
|
+
output = %x[#{exec}]
|
147
|
+
log.debug output
|
148
|
+
mv("#{params[:file]}.bin", "#{params[:file][/\w*\./]}bin") if FileTest.exist?("#{params[:file]}.bin")
|
149
|
+
else
|
150
|
+
# TODO: Handle 'Rapify all in @source and sub'
|
151
|
+
end
|
152
|
+
Dir.chdir(curdir)
|
153
|
+
output
|
154
|
+
end
|
155
|
+
|
156
|
+
# TODO: Define PROJECT elsewhere? (Config?)
|
157
|
+
def binpbo
|
158
|
+
params = "-BINARIZE -CLEAR -DEBUG"
|
159
|
+
params += " -TEMP \"#{settings[:temp]}\"" if settings[:temp]
|
160
|
+
params += " -INCLUDE \"#{settings[:include]}\"" if settings[:include]
|
161
|
+
params += " -PROJECT \"#{settings[:project]}\"" if settings[:project]
|
162
|
+
prefix = check_prefix(@source, '__AUTO__')
|
163
|
+
params += " -PREFIX #{prefix}" unless prefix.empty?
|
164
|
+
log.info "BinPBO: #{@source}"
|
165
|
+
exec = "#{tool('binpbo.exe')} \"#{@source}\" \"#{@destination}\" #{params}".gsub('/', '\\')
|
166
|
+
log.info exec
|
167
|
+
output = %x[#{exec}]
|
168
|
+
log.debug output
|
169
|
+
output
|
170
|
+
end
|
171
|
+
|
172
|
+
DEFAULT_BINARIZE = {:autoprefix => true}
|
173
|
+
def binarize(params = {})
|
174
|
+
# Rapify with Mikero tools
|
175
|
+
# Rename config.cpp to config.hpp
|
176
|
+
# Binarize with BinPBO - include file must include *.bin
|
177
|
+
# Pack with BinPBO
|
178
|
+
# Rename config.hpp to config.cpp
|
179
|
+
params = DEFAULT_BINARIZE.merge params
|
180
|
+
bla = false
|
181
|
+
log.info "Binarizing: #{@source}"
|
182
|
+
if FileTest.exist?(File.join(@source, 'config.cpp'))
|
183
|
+
bla = true
|
184
|
+
rapify(:file => 'config.cpp') # TODO: Rapify All - MakePBO does :O
|
185
|
+
mv(File.join(@source, 'config.cpp'), File.join(@source, 'config.hpp'))
|
186
|
+
end
|
187
|
+
binpbo
|
188
|
+
if bla
|
189
|
+
mv(File.join(@source, 'config.hpp'), File.join(@source, 'config.cpp'))
|
190
|
+
rm_f(File.join(@source, 'config.bin'))
|
191
|
+
end
|
192
|
+
if params[:autoprefix]
|
193
|
+
auto_prefix
|
194
|
+
else
|
195
|
+
"#{@source}.pbo"[/(.*)\/(.*)/]
|
196
|
+
$2
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
def sign(params = {})
|
201
|
+
# TODO: Prefix calculation.... use auto_prefix?
|
202
|
+
if params[:key]
|
203
|
+
params[:key].gsub!('/', '\\')
|
204
|
+
@source[/(.*)\/(.*)/]
|
205
|
+
path = $1
|
206
|
+
file = $2
|
207
|
+
file += ".pbo" unless file[/\.pbo\Z/]
|
208
|
+
# TODO: Export path to config
|
209
|
+
log.info "Signing"
|
210
|
+
Dir.chdir path
|
211
|
+
system "#{tool('dssignfile.exe')} #{params[:key]} #{file}"
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
if $0 == __FILE__
|
220
|
+
test = Six::Arma::Tools::Pbo.new(File.join('P:/', 'x', 'six', 'Addons', 'main'), File.join('C:/', '_Staging'))
|
221
|
+
#test.pack(:rapify => :none, :autoprefix => true)
|
222
|
+
test.binarize
|
223
|
+
end
|
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: six-arma-tools
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ""
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-12-16 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Your summary here
|
17
|
+
email: ""
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README
|
24
|
+
- LICENSE
|
25
|
+
files:
|
26
|
+
- LICENSE
|
27
|
+
- README
|
28
|
+
- Rakefile
|
29
|
+
- lib/six/arma/tools/cfgconvert.rb
|
30
|
+
- lib/six/arma/tools/pbodll.rb
|
31
|
+
- lib/six/arma/tools.rb
|
32
|
+
has_rdoc: true
|
33
|
+
homepage:
|
34
|
+
licenses: []
|
35
|
+
|
36
|
+
post_install_message:
|
37
|
+
rdoc_options: []
|
38
|
+
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
version:
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: "0"
|
52
|
+
version:
|
53
|
+
requirements: []
|
54
|
+
|
55
|
+
rubyforge_project:
|
56
|
+
rubygems_version: 1.3.5
|
57
|
+
signing_key:
|
58
|
+
specification_version: 3
|
59
|
+
summary: Your summary here
|
60
|
+
test_files: []
|
61
|
+
|