def _read_dat_files(self, args, prefix=''): path = get_content_ggpk_path() console(prefix + 'Reading "%s"...' % path) ggpk = get_content_ggpk(path) console(prefix + 'Reading .dat files') dat_files = {} ggpk_data = ggpk['Data'] lang = args.language or config.get_option('language') if lang != 'English': ggpk_data = ggpk_data[lang] remove = [] for name in tqdm(args.files): try: node = ggpk_data[name] except FileNotFoundError: console('Skipping "%s" (missing)' % name, msg=Msg.warning) remove.append(name) continue df = dat.DatFile(name) df.read(file_path_or_raw=node.record.extract(), use_dat_value=False) dat_files[name] = df for file_name in remove: args.files.remove(file_name) return dat_files
def test_runtime_rowsize_mismatch(self, rr_temp_dir): df = dat.DatFile('Main.dat') with pytest.raises(dat.SpecificationError) as e: dr = df.read( os.path.join(rr_temp_dir, 'Data', 'Main.dat'), specification=load(os.path.join( spec_dir, 'runtime_rowsize_mismatch.py' )), ) assert e.value.code == \ dat.SpecificationError.ERRORS.RUNTIME_ROWSIZE_MISMATCH
def getDatIterator(ggpkobj, datname): df = dat.DatFile(datname) try: node = ggpkobj['Data/' + datname] except FileNotFoundError: return opt = {'use_dat_value': False, } reader = df.read(node.record.extract(), **opt) rit = reader.row_iter() return rit
def test_definitions(dat_file_name, file_system, x64): opt = { 'use_dat_value': False, 'x64': x64 } if x64: dat_file_name += '64' # Will raise errors accordingly if it fails df = dat.DatFile(dat_file_name) try: df.read(file_system.get_file('Data/' + dat_file_name), **opt) # If a file is in the spec, but not in the dat file this is allright except FileNotFoundError: return
def test_definitions(dat_file_name, ggpkfile, x64): opt = { 'use_dat_value': False, 'x64': x64 } if x64: dat_file_name += '64' # Will raise errors accordingly if it fails df = dat.DatFile(dat_file_name) try: node = ggpkfile['Data/' + dat_file_name] df.read(node.record.extract(), **opt) # If a file is in the spec, but not in the dat file this is allright except FileNotFoundError: return
def test_dat_file(testspec_dat_file): spec = test_load() df = dat.DatFile('TestSpec.dat') dr = df.read(testspec_dat_file, specification=spec) for row in dr: for test in test_data: assert row[test[0]] == test[2], 'Value mismatch - int' assert row['ref|string'] == test_str, 'Value mismatch - string' l = row['ref|list|int'] assert l[0] == test_list[0], 'Value mismatch - list' assert l[1] == test_list[1], 'Value mismatch - list' # 0xFEFEFEFE is a magic key, so return -1 assert l[2] is None, 'Value mismatch - list, special value' assert row['ref|ref|ref|int'] == 0x1337, 'Value mismatch - nested pointers'
def _read_dat_files(self, args, prefix=''): path = get_content_path() console(prefix + 'Loading file system...') file_system = FileSystem(root_path=path) console(prefix + 'Reading .dat files') dat_files = {} lang = args.language or config.get_option('language') dir_path = "Data/" if lang != 'English': #ggpk_data = index.get_dir_record("Data/%s" % lang) dir_path = "Data/%s/" % lang remove = [] for name in tqdm(args.files): file_path = dir_path + name try: data = file_system.get_file(file_path) except FileNotFoundError: console('Skipping "%s" (missing)' % file_path, msg=Msg.warning) remove.append(name) continue df = dat.DatFile(name) try: df.read(file_path_or_raw=data, use_dat_value=False) except Exception: print(name, traceback.format_exc()) remove.append(name) dat_files[name] = df for file_name in remove: args.files.remove(file_name) return dat_files
def read_dat(file_name='GrantedEffects.dat'): d = dat.DatFile('GrantedEffects.dat') d.read(os.path.join(dir, 'Data', file_name)) return d
def test_runtime_missing_specification(self, testspec_dat_file): df = dat.DatFile('TestSpec.dat') with pytest.raises(dat.SpecificationError) as e: dr = df.read(testspec_dat_file) assert e.value.code == \ dat.SpecificationError.ERRORS.RUNTIME_MISSING_SPECIFICATION