Auto-resolve extract directory name conflicts

If the output (extracted) folder for a given input file already exists, a new name is generated automatically (i.e. _2nd, _3rd, _4th etc)
This commit is contained in:
Plato Mavropoulos 2022-10-23 22:34:35 +03:00
parent 71cbfdaf8b
commit 65467da21c
2 changed files with 34 additions and 24 deletions

View file

@ -38,7 +38,7 @@ You can either Drag & Drop or manually enter AMI BIOS Guard (PFAT) image file(s)
* -v or --version : show utility name and version
* -i or --input-dir : extract from given input directory
* -o or --output-dir : extract in given output directory
* -e or --auto-exit : skip press enter to exit prompts
* -e or --auto-exit : skip all user action prompts
#### **Compatibility**
@ -70,7 +70,7 @@ You can either Drag & Drop or manually enter AMI UCP Update executable file(s).
* -v or --version : show utility name and version
* -i or --input-dir : extract from given input directory
* -o or --output-dir : extract in given output directory
* -e or --auto-exit : skip press enter to exit prompts
* -e or --auto-exit : skip all user action prompts
* -c or --checksum : verify AMI UCP Checksums (slow)
#### **Compatibility**
@ -108,7 +108,7 @@ You can either Drag & Drop or manually enter Apple EFI IM4P file(s). Optional ar
* -v or --version : show utility name and version
* -i or --input-dir : extract from given input directory
* -o or --output-dir : extract in given output directory
* -e or --auto-exit : skip press enter to exit prompts
* -e or --auto-exit : skip all user action prompts
#### **Compatibility**
@ -138,7 +138,7 @@ You can either Drag & Drop or manually enter Apple EFI image file(s). Optional a
* -v or --version : show utility name and version
* -i or --input-dir : extract from given input directory
* -o or --output-dir : extract in given output directory
* -e or --auto-exit : skip press enter to exit prompts
* -e or --auto-exit : skip all user action prompts
* -r or --rename : rename EFI image based on its tag
#### **Compatibility**
@ -172,7 +172,7 @@ You can either Drag & Drop or manually enter Apple EFI PKG package file(s). Opti
* -v or --version : show utility name and version
* -i or --input-dir : extract from given input directory
* -o or --output-dir : extract in given output directory
* -e or --auto-exit : skip press enter to exit prompts
* -e or --auto-exit : skip all user action prompts
#### **Compatibility**
@ -204,7 +204,7 @@ You can either Drag & Drop or manually enter Apple EFI PBZX image file(s). Optio
* -v or --version : show utility name and version
* -i or --input-dir : extract from given input directory
* -o or --output-dir : extract in given output directory
* -e or --auto-exit : skip press enter to exit prompts
* -e or --auto-exit : skip all user action prompts
#### **Compatibility**
@ -236,7 +236,7 @@ You can either Drag & Drop or manually enter Award BIOS image file(s). Optional
* -v or --version : show utility name and version
* -i or --input-dir : extract from given input directory
* -o or --output-dir : extract in given output directory
* -e or --auto-exit : skip press enter to exit prompts
* -e or --auto-exit : skip all user action prompts
#### **Compatibility**
@ -268,7 +268,7 @@ You can either Drag & Drop or manually enter Dell PFS Update images(s). Optional
* -v or --version : show utility name and version
* -i or --input-dir : extract from given input directory
* -o or --output-dir : extract in given output directory
* -e or --auto-exit : skip press enter to exit prompts
* -e or --auto-exit : skip all user action prompts
* -a or --advanced : extract signatures and metadata
* -s or --structure : show PFS structure information
@ -302,7 +302,7 @@ You can either Drag & Drop or manually enter Fujitsu SFX BIOS image file(s). Opt
* -v or --version : show utility name and version
* -i or --input-dir : extract from given input directory
* -o or --output-dir : extract in given output directory
* -e or --auto-exit : skip press enter to exit prompts
* -e or --auto-exit : skip all user action prompts
#### **Compatibility**
@ -334,7 +334,7 @@ You can either Drag & Drop or manually enter Fujitsu UPC BIOS image file(s). Opt
* -v or --version : show utility name and version
* -i or --input-dir : extract from given input directory
* -o or --output-dir : extract in given output directory
* -e or --auto-exit : skip press enter to exit prompts
* -e or --auto-exit : skip all user action prompts
#### **Compatibility**
@ -366,7 +366,7 @@ You can either Drag & Drop or manually enter Insyde iFlash/iFdPacker Update imag
* -v or --version : show utility name and version
* -i or --input-dir : extract from given input directory
* -o or --output-dir : extract in given output directory
* -e or --auto-exit : skip press enter to exit prompts
* -e or --auto-exit : skip all user action prompts
#### **Compatibility**
@ -396,7 +396,7 @@ You can either Drag & Drop or manually enter Panasonic BIOS Package executable f
* -v or --version : show utility name and version
* -i or --input-dir : extract from given input directory
* -o or --output-dir : extract in given output directory
* -e or --auto-exit : skip press enter to exit prompts
* -e or --auto-exit : skip all user action prompts
#### **Compatibility**
@ -433,7 +433,7 @@ You can either Drag & Drop or manually enter Phoenix Tools Development Kit (TDK)
* -v or --version : show utility name and version
* -i or --input-dir : extract from given input directory
* -o or --output-dir : extract in given output directory
* -e or --auto-exit : skip press enter to exit prompts
* -e or --auto-exit : skip all user action prompts
#### **Compatibility**
@ -465,7 +465,7 @@ You can either Drag & Drop or manually enter Portwell UEFI Unpacker EFI executab
* -v or --version : show utility name and version
* -i or --input-dir : extract from given input directory
* -o or --output-dir : extract in given output directory
* -e or --auto-exit : skip press enter to exit prompts
* -e or --auto-exit : skip all user action prompts
#### **Compatibility**
@ -503,7 +503,7 @@ You can either Drag & Drop or manually enter Toshiba BIOS COM image file(s). Opt
* -v or --version : show utility name and version
* -i or --input-dir : extract from given input directory
* -o or --output-dir : extract in given output directory
* -e or --auto-exit : skip press enter to exit prompts
* -e or --auto-exit : skip all user action prompts
#### **Compatibility**
@ -535,7 +535,7 @@ You can either Drag & Drop or manually enter VAIO Packaging Manager executable f
* -v or --version : show utility name and version
* -i or --input-dir : extract from given input directory
* -o or --output-dir : extract in given output directory
* -e or --auto-exit : skip press enter to exit prompts
* -e or --auto-exit : skip all user action prompts
#### **Compatibility**

View file

@ -11,11 +11,14 @@ import ctypes
import argparse
import traceback
from common.path_ops import runtime_root, is_path_absolute, safe_path, get_dequoted_path, get_path_files, path_parent, get_extract_path
from common.system import check_sys_py, check_sys_os, get_os_ver, printer, is_auto_exit
from common.num_ops import get_ordinal
from common.path_ops import get_dequoted_path, get_extract_path, get_path_files, is_path_absolute, path_parent, runtime_root, safe_path
from common.system import check_sys_os, check_sys_py, get_os_ver, is_auto_exit, printer
class BIOSUtility:
MAX_FAT32_ITEMS = 65535
def __init__(self, title, check, main, padding=0):
self._title = title
self._main = main
@ -27,7 +30,7 @@ class BIOSUtility:
self._argparser = argparse.ArgumentParser()
self._argparser.add_argument('files', type=argparse.FileType('r', encoding='utf-8'), nargs='*')
self._argparser.add_argument('-e', '--auto-exit', help='skip press enter to exit prompts', action='store_true')
self._argparser.add_argument('-e', '--auto-exit', help='skip all user action prompts', action='store_true')
self._argparser.add_argument('-v', '--version', help='show utility name and version', action='store_true')
self._argparser.add_argument('-o', '--output-dir', help='extract in given output directory')
self._argparser.add_argument('-i', '--input-dir', help='extract from given input directory')
@ -58,7 +61,7 @@ class BIOSUtility:
self._process_input_files()
# Count input files for exit code
self.exit_code = len(self._input_files)
self._exit_code = len(self._input_files)
def parse_argument(self, *args, **kwargs):
_dest = self._argparser.add_argument(*args, **kwargs).dest
@ -78,14 +81,21 @@ class BIOSUtility:
_extract_path = os.path.join(self._output_path, get_extract_path(_input_name))
if os.path.isdir(_extract_path):
for _suffix in range(2, self.MAX_FAT32_ITEMS):
_renamed_path = f'{os.path.normpath(_extract_path)}_{get_ordinal(_suffix)}'
if not os.path.isdir(_renamed_path):
_extract_path = _renamed_path
break # Extract path is now unique
if self._main(_input_file, _extract_path, self._padding + 4, **self._arguments_kw) in [0, None]:
self.exit_code -= 1
#print(self.exit_code)
self._exit_code -= 1
printer('Done!', pause=True)
sys.exit(self.exit_code)
sys.exit(self._exit_code)
# Process input files
def _process_input_files(self):