Skip to content

Commit

Permalink
Command line interface changes, code replication removal.
Browse files Browse the repository at this point in the history
  • Loading branch information
navv1234 committed Jul 7, 2014
1 parent 815c848 commit 8a5e9f2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 38 deletions.
33 changes: 26 additions & 7 deletions casc_extract/casc.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,29 @@ def close(self):
if self.fdesc:
self.fdesc.close()

def __extract_data(self):
if self.fd.read(4) != _BLTE_MAGIC:
self.options.parser.error('Invalid BLTE magic in file')

file = BLTEFile(self)
if not file.extract():
return None

def extract(self, file_name):
pass
if not self.open(file_name):
return False

if not os.access(self.options.output, os.W_OK):
self.options.parser.error('Output file %s is not writeable' % self.options.output)
return False

file = self.__extract_data()
if not file:
return False

self.close()

return True

def extract_file(self, file_key, file_md5sum, file_output, data_file_number, data_file_offset, blte_file_size):
path = os.path.join(self.options.data_dir, 'Data', 'data', 'data.%03u' % data_file_number)
Expand All @@ -190,12 +211,8 @@ def extract_file(self, file_key, file_md5sum, file_output, data_file_number, dat

# Skip 10 bytes of unknown data
self.fd.seek(10, os.SEEK_CUR)
if self.fd.read(4) != _BLTE_MAGIC:
self.options.parser.error('Invalid BLTE magic in file')

file = BLTEFile(self)
if not file.extract():
return False

file = self.__extract_data()

file_md5 = md5.new(file.output_data).digest()
if file_md5sum != file_md5:
Expand All @@ -204,6 +221,8 @@ def extract_file(self, file_key, file_md5sum, file_output, data_file_number, dat
with open(output_path, 'wb') as output_file:
output_file.write(file.output_data)

self.close()

return True

def extract_file_by_md5(self, file_md5s):
Expand Down
36 changes: 5 additions & 31 deletions casc_extract/casc_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import build_cfg, casc, jenkins

parser = optparse.OptionParser( usage = 'Usage: %prog -d wow_install_dir [options] file_path ...')
parser.add_option( '-m', '--mode', dest = 'mode', choices = [ 'meta', 'dbc', 'unpack', 'extract' ],
parser.add_option( '-m', '--mode', dest = 'mode', choices = [ 'dbc', 'unpack', 'extract' ],
help = 'Extraction mode: "root" for root/encoding file extraction, "dbc" for DBC file extraction' )
parser.add_option( '-b', '--dbfile', dest = 'dbfile', type = 'string', default = 'dbfile',
help = "A textual file containing a list of file paths to extract [default dbfile]" )
Expand Down Expand Up @@ -47,14 +47,10 @@

blte = casc.BLTEExtract(opts)


for file_hash, file_name in fname_db.iteritems():
extract_data = []

file_md5s = root.GetFileHashMD5(file_hash)
if len(file_md5s) == 0:
continue

file_keys = []
for md5s in file_md5s:
file_keys = encoding.GetFileKeys(md5s)
Expand All @@ -69,22 +65,19 @@
continue

if len(extract_data) > 1:
print extract_data
parser.error('File %s has multiple extraction locations' % file_name)

print 'Extracting %s ...' % file_name

if not blte.extract_file(*extract_data[0]):
sys.exit(1)

blte.close()

elif opts.mode == 'unpack':
blte = casc.BLTEExtract(opts)
if not blte.open(args[0]):
sys.exit(1)

blte.extract_file_by_md5('b4fd319c94658281cfb9b6f9ec7d49de')
for file in args:
print 'Extracting %s ...'
if not blte.extract(file):
sys.exit(1)

elif opts.mode == 'extract':
build = build_cfg.BuildCfg(opts)
Expand Down Expand Up @@ -118,22 +111,3 @@

if not blte.extract_file(keys[0], args[0].decode('hex'), *file_location):
sys.exit(1)

elif opts.mode == 'meta':
encoding = casc.CASCEncodingFile(opts, build.encoding_file())
encoding.open()

root = casc.CASCRootFile(opts, encoding, build.root_file())
root.open()

index = casc.CASCDataIndex(opts)
index.open()

md5ss = root.GetFileMD5('DBFilesClient\\SpellClassOptions.db2')

for md5s in md5ss:
keys = encoding.GetFileKeys(md5s)
print md5s.encode('hex'), keys[0].encode('hex')
print index.GetIndexData(keys[0])

#time.sleep(1000000)

0 comments on commit 8a5e9f2

Please sign in to comment.