xtminfo : Removed XtmHeader from xtminfo script.

This commit is contained in:
Glenn Y. Rolland 2010-11-08 14:06:42 +01:00
parent 90da6659c7
commit d9bc8a3555

View file

@ -1,64 +1,15 @@
#!/usr/bin/ruby -d #!/usr/bin/ruby
require 'optparse' require 'optparse'
require 'rubygems' require 'rubygems'
require 'bindata' require 'bindata'
class XtmHeader < BinData::Record require 'xtmfile/xtmheader'
# Offset Information Taille (octets)
# 0 Longueur du nom du programme 1
# 1 *Nom du programme 20
# 21 Longueur de la version 1
# 22 Version 4
# 26 Not used 10
# 36 Date 4
# 40 Longueur du nom du fichier original 1
# 41 Nom du fichier original 50
# 91 **Hash MD5 1
# 92 Nombre de fichiers 4
# 96 Taille du fichier original 8
endian :little
uint8 :progname_len, :value => lambda { progname_str.length } class XtmInfo
string :progname_str, :length => 20 class XtmInfoArgumentError < ArgumentError ; end
uint8 :version_len, :value => lambda { version_str.length }
string :version_str, :length => 4
string :unused, :length => 10
uint32le :date
uint8 :filename_len
stringz :filename_str, :length => 50
string :filename_str_pad, :length => lambda { 50 - filename_len - 1 }
uint8 :md5
uint32 :filecount
uint64 :filesize
def to_s
r = []
r << ( "Progname len : %s [%s]" % [self.progname_len, self.progname_len.offset] )
r << ( "Progname str : %s [%s]" % [self.progname_str, self.progname_str.offset] )
r << ( " Version len : %s [%s]" % [self.version_len, self.version_len.offset] )
r << ( " Version str : %s [%s]" % [self.version_str, self.version_str.offset] )
r << ( " Unused : %s [%s]" % [self.unused, self.unused.offset] )
r << ( " Date : %s [%s]" % [self.date, self.date.offset] )
r << ( "Filename len : %s [%s]" % [self.filename_len, self.filename_len.offset] )
r << ( "Filename str : %s [%s]" % [self.filename_str, self.filename_str.offset] )
r << ( " md5 : %s [%s]" % [self.md5, self.md5.offset] )
r << ( " Filecount : %d [%s]" % [self.filecount, self.filecount.offset] )
r << ( " Filesize : %s [%s]" % [self.filesize, self.filesize.offset] )
return r.join("\n")
end
end
class XtmJoin
class XtmJoinArgumentError < ArgumentError ; end
attr_reader :opts attr_reader :opts
@ -72,10 +23,10 @@ class XtmJoin
def parse_command_line args def parse_command_line args
@args = args.clone @args = args.clone
@opts = OptionParser.new do |opts| @opts = OptionParser.new do |opts|
opts.banner = "Usage: #{File.basename $0} [action] [options]\n" opts.banner = "Usage: #{File.basename $0} [options]\n"
opts.separator "" opts.separator ""
opts.separator "Actions:" opts.separator "Mandatory options"
opts.on("-i", "--input FILE", "Input XTM file") do |r| opts.on("-i", "--input FILE", "Input XTM file") do |r|
@input_xtm = r @input_xtm = r
@ -90,13 +41,14 @@ class XtmJoin
opts.on("-v", "--verbose", "Show warnings too") do |v| opts.on("-v", "--verbose", "Show warnings too") do |v|
@verbose = v @verbose = v
end end
opts.separator ""
end end
end end
def validate! def validate!
@opts.parse! @opts.parse!
raise XtmJoinArgumentError, "No input XTM file specified!" if @input_xtm.nil? raise XtmInfoArgumentError, "No input XTM file specified!" if @input_xtm.nil?
end end
@ -112,10 +64,10 @@ class XtmJoin
def self.main args def self.main args
xj = nil xj = nil
begin begin
xj = XtmJoin.new args xj = XtmInfo.new args
xj.run xj.run
exit 0 exit 0
rescue XtmJoinArgumentError => e rescue XtmInfoArgumentError => e
STDERR.puts "%s" % xj.opts STDERR.puts "%s" % xj.opts
STDERR.puts "error: %s" % e.message STDERR.puts "error: %s" % e.message
@ -129,4 +81,4 @@ class XtmJoin
end end
end end
XtmJoin.main ARGV XtmInfo.main ARGV