Toolbox for analyzing and editing pkg application files for psp,ps3, ps4 and ps5, includes the most useful functions you might need.
| 1 | import os |
| 2 | from PyQt5.QtCore import QSize |
| 3 | |
| 4 | class FileUtils: |
| 5 | @staticmethod |
| 6 | def format_size(size): |
| 7 | """Format file size in human readable format""" |
| 8 | for unit in ['B', 'KB', 'MB', 'GB']: |
| 9 | if size < 1024: |
| 10 | return f"{size:.2f} {unit}" |
| 11 | size /= 1024 |
| 12 | return f"{size:.2f} TB" |
| 13 | |
| 14 | @staticmethod |
| 15 | def get_file_type(extension): |
| 16 | """Get file type based on extension""" |
| 17 | type_map = { |
| 18 | '.png': 'Image', |
| 19 | '.jpg': 'Image', |
| 20 | '.jpeg': 'Image', |
| 21 | '.bin': 'Binary', |
| 22 | '.self': 'Executable', |
| 23 | '.sprx': 'System Plugin', |
| 24 | '.rco': 'Resource', |
| 25 | '.sfo': 'System File', |
| 26 | '.ac3': 'Audio', |
| 27 | '.at3': 'Audio', |
| 28 | '.txt': 'Text', |
| 29 | '.xml': 'XML', |
| 30 | '.json': 'JSON', |
| 31 | '.pkg': 'Package' |
| 32 | } |
| 33 | return type_map.get(extension.lower(), 'Unknown') |
| 34 | |
| 35 | @staticmethod |
| 36 | def is_text_file(filename): |
| 37 | """Check if file is text based on extension""" |
| 38 | text_extensions = ['.txt', '.xml', '.json', '.cfg', '.ini', '.log'] |
| 39 | return any(filename.lower().endswith(ext) for ext in text_extensions) |
| 40 | |
| 41 | @staticmethod |
| 42 | def get_file_icon(file_type): |
| 43 | """Get appropriate icon for file type""" |
| 44 | from PyQt5.QtWidgets import QStyle, QApplication |
| 45 | style = QApplication.style() |
| 46 | |
| 47 | icon_map = { |
| 48 | 'Image': style.standardIcon(QStyle.SP_FileIcon), |
| 49 | 'Executable': style.standardIcon(QStyle.SP_FileLinkIcon), |
| 50 | 'Directory': style.standardIcon(QStyle.SP_DirIcon) |
| 51 | } |
| 52 | return icon_map.get(file_type, style.standardIcon(QStyle.SP_FileIcon)) |