From 8a5e9f2ebc12a440cdd8e16f4b342b93b1db1ff4 Mon Sep 17 00:00:00 2001 From: Navv Date: Tue, 22 Apr 2014 23:30:45 +0300 Subject: [PATCH] Command line interface changes, code replication removal. --- casc_extract/casc.py | 33 ++++++++++++++++++++++++++------- casc_extract/casc_extract.py | 36 +++++------------------------------- 2 files changed, 31 insertions(+), 38 deletions(-) diff --git a/casc_extract/casc.py b/casc_extract/casc.py index 615f2de031c..5eb490c0a8e 100644 --- a/casc_extract/casc.py +++ b/casc_extract/casc.py @@ -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) @@ -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: @@ -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): diff --git a/casc_extract/casc_extract.py b/casc_extract/casc_extract.py index 4c1d31e49f2..d4d12a284f2 100644 --- a/casc_extract/casc_extract.py +++ b/casc_extract/casc_extract.py @@ -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]" ) @@ -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) @@ -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) @@ -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) \ No newline at end of file