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 | import json |
| 3 | from datetime import datetime |
| 4 | from PyQt5.QtWidgets import QMessageBox |
| 5 | from PyQt5.QtGui import QPixmap |
| 6 | from PyQt5.QtCore import QByteArray, Qt |
| 7 | |
| 8 | class Helper: |
| 9 | first_launch = True |
| 10 | finalize_pkg_process = True |
| 11 | ps4pkg_tool_temp_directory = "path/to/temp/directory" |
| 12 | orbis_pub_cmd = os.path.join(ps4pkg_tool_temp_directory, "orbis-pub-cmd.exe") |
| 13 | ps5_bc_json_file = os.path.join(ps4pkg_tool_temp_directory, "ps5bc.json") |
| 14 | ps4pkg_tool_log_file = os.path.join(ps4pkg_tool_temp_directory, "PS4PKGToolLog.txt") |
| 15 | |
| 16 | @staticmethod |
| 17 | def round_bytes(num): |
| 18 | if num < 1024: |
| 19 | return f"{num} bytes" |
| 20 | elif num < 1048576: |
| 21 | return f"{round(num / 1024, 2)} KB" |
| 22 | elif num < 1073741824: |
| 23 | return f"{round(num / 1048576, 2)} MB" |
| 24 | elif num < 1099511627776: |
| 25 | return f"{round(num / 1073741824, 2)} GB" |
| 26 | else: |
| 27 | return f"{round(num / 1099511627776, 2)} TB" |
| 28 | |
| 29 | @staticmethod |
| 30 | def extract_resources(): |
| 31 | pass |
| 32 | |
| 33 | @classmethod |
| 34 | def get_backport_info_file(cls): |
| 35 | return os.path.join(cls.ps4pkg_tool_temp_directory, "backport.json") |
| 36 | |
| 37 | class Backport: |
| 38 | backport_info_file = None |
| 39 | pkg_file_list = [] |
| 40 | |
| 41 | @staticmethod |
| 42 | def check_pkg_backported(pkg_file): |
| 43 | if Backport.backport_info_file is None: |
| 44 | Backport.backport_info_file = Helper.get_backport_info_file() |
| 45 | with open(Backport.backport_info_file, 'r') as f: |
| 46 | Backport.pkg_file_list = json.load(f) |
| 47 | matching_file = next((file for file in Backport.pkg_file_list if file["FilePath"].lower() == pkg_file.lower()), None) |
| 48 | return matching_file["Backported"] if matching_file else None |
| 49 | |
| 50 | @staticmethod |
| 51 | def save_data(data_grid_view): |
| 52 | updated_pkg_file_list = [] |
| 53 | for row in data_grid_view: |
| 54 | file_path = os.path.join(row[12], row[0]) |
| 55 | backported = "No" if row[13] == "No" else row[13] |
| 56 | updated_pkg_file_list.append({"FilePath": file_path, "Backported": backported}) |
| 57 | with open(Backport.backport_info_file, 'w') as f: |
| 58 | json.dump(updated_pkg_file_list, f, indent=4) |
| 59 | |
| 60 | class Bitmap: |
| 61 | pic0 = None |
| 62 | pic1 = None |
| 63 | fail_extract_image_list = "" |
| 64 | |
| 65 | @staticmethod |
| 66 | def bytes_to_bitmap(img_bytes): |
| 67 | pixmap = QPixmap() |
| 68 | pixmap.loadFromData(QByteArray(img_bytes)) |
| 69 | return pixmap |
| 70 | |
| 71 | @staticmethod |
| 72 | def resize_image(image, width, height): |
| 73 | return image.scaled(width, height, aspectRatioMode=Qt.KeepAspectRatio, transformMode=Qt.SmoothTransformation) |
| 74 | |
| 75 | class Trophy: |
| 76 | trophy = None |
| 77 | id_entry_list = [] |
| 78 | name_entry_list = [] |
| 79 | image_to_extract_list = [] |
| 80 | trophy_filename_to_extract_list = [] |
| 81 | trophy_temp_folder = os.path.join(Helper.ps4pkg_tool_temp_directory, "TrophyFile") |
| 82 | out_path = "" |
| 83 | |
| 84 | @staticmethod |
| 85 | def resize_image(image, width, height): |
| 86 | return image.scaled(width, height, aspectRatioMode=Qt.KeepAspectRatio, transformMode=Qt.SmoothTransformation) |