From 69026487960e61aa951f55041b8cf730edc5e75b Mon Sep 17 00:00:00 2001 From: xpamych Date: Sun, 14 May 2023 12:30:46 +0300 Subject: [PATCH] 1 --- hlna.py | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 89 insertions(+), 7 deletions(-) diff --git a/hlna.py b/hlna.py index 87fffca..97e3acc 100755 --- a/hlna.py +++ b/hlna.py @@ -1,6 +1,10 @@ #!/usr/bin/env python3 import os +import re +import struct +import shutil import datetime +import subprocess import yaml import click @@ -356,18 +360,93 @@ WantedBy=default.target @click.option('-m', default='all', help="Название карты для запуска или all для запуска все карт") def modinstall(g, m): if g == "ark": - id_game = "346110" + id_game_workshop = "346110" if not os.path.isdir(dir_workshop_ark): create_dir(dir_workshop_ark) id_mods_ark = input("""Укажите id модов через запятую :""") os.environ.get('mod_branch', 'Windows') - os.system(f"steamcmd +login anonymous +workshop_download_item {id_game} {id_mods_ark} +quit") - os.system(f"mv {home_dir}/.local/share/Steam/steamapps/workshop/content/{id_game}/{id_mods_ark}/ {dir_server_ark}ShooterGame/Content/Mods/") + os.system(f"steamcmd +login anonymous +workshop_download_item {id_game_workshop} {id_mods_ark} +quit") + modextract(id_mods_ark, id_game_workshop) -@hlna.command() -@click.option("-m", required=True, help="Название Сервера") -@click.option("-e/-d", default=True, help="-e активировать карты, -d деактивировать") +def modextract(id_mods_ark, id_game_workshop): + mod_steam_workshop = "{}/content/{}/{}".format(dir_workshop_ark, id_game_workshop, id_mods_ark) + mod_ark_mods = "{}{}".format(dir_mods_ark, id_mods_ark) + modextractdir = mod_ark_mods + + if id_mods_ark == "111111111": + return + + if os.path.isfile("{}/WindowsNoEditor/mod.info".format(mod_steam_workshop)): + mod_steam_workshop = "{}/WindowsNoEditor".format(mod_steam_workshop) + + for dirpath, dirnames, filenames in os.walk(mod_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) + + 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))) + + 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): + shutil.copy2(srcfile, dstfile) + + modname = subprocess.check_output(['curl', '-s', 'http://steamcommunity.com/sharedfiles/filedetails/?id={}'.format(id_mods_ark)]).decode('utf-8') + modname = re.search(r'
(.+)
', modname) + mod_name = modname and modname.group(1) + + if os.path.isfile("{}/.mod".format(modextractdir)): + os.remove("{}/.mod".format(modextractdir)) + + modfile_bytes = b'' + with open(os.path.join(modextractdir, 'mod.info'), 'rb') as f: + data = f.read() + mapnamelen = struct.unpack_from('