From fdabffb1e2106d729944963bf28658c9c80f65ab Mon Sep 17 00:00:00 2001 From: xpamych Date: Sun, 14 May 2023 15:32:06 +0300 Subject: [PATCH] 1 --- hlna.py | 81 ++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 54 insertions(+), 27 deletions(-) diff --git a/hlna.py b/hlna.py index f521a9c..09b82a4 100755 --- a/hlna.py +++ b/hlna.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 import os import re +import zlib import struct import shutil import datetime @@ -371,44 +372,70 @@ def modinstall(g, m): def modextract(id_mod, id_game_workshop): - mod_steam_workshop = f"{dir_workshop_ark}/content/{id_game_workshop}/{id_mod}/WindowsNoEditor/" - mod_ark_mods = f"{dir_mods_ark}{id_mod}" - modextractdir = mod_ark_mods + dir_steam_workshop = f"{dir_workshop_ark}/content/{id_game_workshop}/{id_mod}/WindowsNoEditor/" + dir_ark_mods = f"{dir_mods_ark}{id_mod}" + dir_extract = dir_ark_mods if id_mod == "111111111": return - for dirpath, dirnames, filenames in os.walk(mod_steam_workshop): + for dirpath, dirnames, filenames in os.walk(dir_steam_workshop): for dname in dirnames: - os.makedirs(os.path.join(modextractdir, os.path.relpath(os.path.join(dirpath, dname), mod_steam_workshop)), exist_ok=True) + os.makedirs(os.path.join(dir_extract, os.path.relpath(os.path.join(dirpath, dname), dir_steam_workshop)), exist_ok=True) # for fname in filenames: # if not os.path.isfile(os.path.join(mod_steam_workshop, fname)) and not os.path.isfile(os.path.join(mod_steam_workshop, fname + ".z")): # os.unlink(os.path.join(modextractdir, fname)) for dname in dirnames: - if not os.path.isdir(os.path.join(mod_steam_workshop, dname)): - shutil.rmtree(os.path.join(modextractdir, os.path.relpath(os.path.join(dirpath, dname), mod_steam_workshop))) + if not os.path.isdir(os.path.join(dir_steam_workshop, dname)): + shutil.rmtree(os.path.join(dir_extract, os.path.relpath(os.path.join(dirpath, dname), dir_steam_workshop))) - for root, dirs, files in os.walk(mod_steam_workshop): - print_line(files) - for name in files: - if not (name.endswith(".z") or name.endswith(".z.uncompressed_size")): - srcfile = os.path.join(root, name) - dstfile = os.path.join(modextractdir, os.path.relpath(srcfile, mod_steam_workshop)) - if not os.path.isfile(dstfile) or os.path.getmtime(srcfile) > os.path.getmtime(dstfile): - print_line(dstfile) - shutil.copy2(srcfile, dstfile) + # for root, dirs, files in os.walk(mod_steam_workshop): + # for name in files: + # if not (name.endswith(".z") or name.endswith(".z.uncompressed_size")): + # srcfile = os.path.join(root, name) + # dstfile = os.path.join(modextractdir, os.path.relpath(srcfile, mod_steam_workshop)) + # if not os.path.isfile(dstfile) or os.path.getmtime(srcfile) > os.path.getmtime(dstfile): + # print_line(dstfile) + # shutil.copy2(srcfile, dstfile) + for root, dirs, files in os.walk(dir_steam_workshop): + for file in files: + if file.endswith('.z'): + filepath = os.path.join(root, file) + extract_path = os.path.join(dir_extract, os.path.splitext(file)[0]) + + if not os.path.isfile(extract_path) or os.path.getmtime(filepath) > os.path.getmtime(extract_path): + print(f"{os.path.getsize(filepath):<10} {file:<20} ", end="") + with open(filepath, "rb") as zfile: + data = zfile.read() + if data[0:8] != b"\xC1\x83\x2A\x9E\x00\x00\x00\x00": + raise ValueError("Bad file magic") + chunk_size, compressed_size, uncompressed_size = struct.unpack("(.+)', modname) modname = modname and modname.group(1) - if os.path.isfile("{}/.mod".format(modextractdir)): - os.remove("{}/.mod".format(modextractdir)) + if os.path.isfile("{}/.mod".format(dir_extract)): + os.remove("{}/.mod".format(dir_extract)) modfile_bytes = b'' - with open(os.path.join(modextractdir, 'mod.info'), 'rb') as f: + with open(os.path.join(dir_extract, 'mod.info'), 'rb') as f: data = f.read() mapnamelen = struct.unpack_from('