Added Award BIOS Module Extractor v2.0_a3

Improved 7-Zip exit code handling
This commit is contained in:
platomav 2022-06-26 19:09:01 +03:00
parent fc73921967
commit 82cd4336bd
7 changed files with 184 additions and 13 deletions

View file

@ -18,10 +18,17 @@ def get_szip_path():
return safe_path(project_root(), ['external',exec_name])
# Check 7-Zip bad exit codes (0 OK, 1 Warning)
def check_bad_exit_code(exit_code):
if exit_code not in (0,1):
raise Exception(f'BAD_EXIT_CODE_{exit_code}')
# Check if file is 7-Zip supported
def is_szip_supported(in_path, padding=0, silent=False):
def is_szip_supported(in_path, padding=0, check=False, silent=False):
try:
subprocess.run([get_szip_path(), 't', in_path, '-bso0', '-bse0', '-bsp0'], check=True)
szip_t = subprocess.run([get_szip_path(), 't', in_path, '-bso0', '-bse0', '-bsp0'], check=False)
if check: check_bad_exit_code(szip_t.returncode)
except:
if not silent:
printer(f'Error: 7-Zip could not check support for file {in_path}!', padding)
@ -31,11 +38,13 @@ def is_szip_supported(in_path, padding=0, silent=False):
return True
# Archive decompression via 7-Zip
def szip_decompress(in_path, out_path, in_name, padding=0, silent=False):
def szip_decompress(in_path, out_path, in_name, padding=0, check=False, silent=False):
if not in_name: in_name = 'archive'
try:
subprocess.run([get_szip_path(), 'x', '-aou', '-bso0', '-bse0', '-bsp0', '-o' + out_path, in_path], check=True)
szip_x = subprocess.run([get_szip_path(), 'x', '-aou', '-bso0', '-bse0', '-bsp0', '-o' + out_path, in_path], check=False)
if check: check_bad_exit_code(szip_x.returncode)
if not os.path.isdir(out_path): raise Exception('EXTRACT_DIR_MISSING')
except: