Skip to content

Instantly share code, notes, and snippets.

@thurask
Created March 12, 2020 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thurask/6daa44fed3e4c061e6aaa7ad0ff4ac6c to your computer and use it in GitHub Desktop.
Save thurask/6daa44fed3e4c061e6aaa7ad0ff4ac6c to your computer and use it in GitHub Desktop.
import os
TS3HEADER = b'DBPF\x02\x00\x00\x00\x00'
TS4HEADER = b'DBPF\x02\x00\x00\x00\x01'
def collector(indir=None):
if indir is None:
indir = os.getcwd()
results = []
for root, _, files in os.walk(indir):
for filex in files:
if filex.endswith(".package"):
results.append(os.path.join(root, filex))
return results
def unified_opener(infile):
with open(infile, "rb") as afile:
data = afile.read()
return data
def bulk_check(infile):
indata = unified_opener(infile)
is_ts3 = ts3_check(indata)
is_posepack = posepack_check(indata)
return is_ts3, is_posepack
def ts3_check(indata):
header = indata[:9]
if header == TS3HEADER:
is_ts3 = True
elif header == TS4HEADER:
is_ts3 = False
else:
is_ts3 = None
return is_ts3
def posepack_check(indata):
is_posepack = True if b"STBL" in indata else False
return is_posepack
def dicter(infiles):
indict = {infi: bulk_check(infi) for infi in infiles}
return indict
def denker(indict):
all_ts3s = [key for key, val in indict.items() if val[0]]
all_replacers = [key for key, val in indict.items() if not val[0] and not val[1]]
return all_ts3s, all_replacers
def main():
infiles = collector()
indict = dicter(infiles)
all_ts3s, all_replacers = denker(indict)
if all_ts3s:
print("TS3 PACKAGE FILES:")
for _ in all_ts3s:
print(_)
if all_replacers:
print("POSSIBLE NON-POSE PACK FILES (CHECK S4PE):")
for _ in all_replacers:
print(_)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment