-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathmain.py
More file actions
203 lines (176 loc) · 6.87 KB
/
Copy pathmain.py
File metadata and controls
203 lines (176 loc) · 6.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
import struct
import sys
import os
import logging
import ctypes
import argparse
import io
import json
from contextlib import redirect_stdout
# Aggiungi la directory root al path di Python
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
# Import dei moduli
from GraphicUserInterface.main_window import MainWindow
from packages import PackagePS4, PackagePS5, PackagePS3
from Utilities.Trophy import Archiver, TrophyFile, TRPCreator, TRPReader
from file_operations import extract_file, inject_file, modify_file_header
from Utilities import Logger, SettingsManager
from tools.repack import Repack
from tools.PS5_Game_Info import PS5GameInfo
from PySide6.QtWidgets import QApplication
from qt_material import apply_stylesheet
# Configure logging
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
def check_settings_file_presence():
"""Check and create necessary directories and settings file"""
temp_directory = os.path.join(os.path.dirname(os.path.abspath(__file__)), "PS4PKGToolTemp")
if not os.path.exists(temp_directory):
os.makedirs(temp_directory)
Logger.log_information("Creating PS4PKGToolTemp directory...")
settings_file_path = os.path.join(temp_directory, "settings.json")
if not os.path.exists(settings_file_path) or os.path.getsize(settings_file_path) == 0:
create_default_settings(settings_file_path)
return temp_directory, settings_file_path
def create_default_settings(settings_file_path):
"""Create default settings file"""
default_settings = {
"theme": "Light",
"night_mode": False,
"font": "Arial",
"font_size": 12,
"bg_color": "#ffffff",
"text_color": "#000000",
"accent_color": "#3498db",
"auto_expand": True,
"show_hidden": False,
"confirm_exit": True,
"output_path": "",
"temp_path": "",
"pkg_directories": [],
"scan_recursive": False,
"play_bgm": False,
"show_directory_settings_at_startup": True,
"auto_sort_row": False,
"local_server_ip": "",
"ps4_ip": "",
"nodejs_installed": False,
"http_server_installed": False,
"official_update_download_directory": "",
"pkg_color_label": False,
"game_pkg_forecolor": 0xDDDDDD,
"patch_pkg_forecolor": 0xDDDDDD,
"addon_pkg_forecolor": 0xDDDDDD,
"app_pkg_forecolor": 0xDDDDDD,
"game_pkg_backcolor": 0x333333,
"patch_pkg_backcolor": 0x333333,
"addon_pkg_backcolor": 0x333333,
"app_pkg_backcolor": 0x333333,
"rename_custom_format": "",
"ps5bc_json_download_date": "",
"psvr_neo_ps5bc_check": False,
"pkg_titleId_column": True,
"pkg_contentId_column": True,
"pkg_region_column": True,
"pkg_minimum_firmware_column": True,
"pkg_version_column": True,
"pkg_type_column": True,
"pkg_category_column": True,
"pkg_size_column": True,
"pkg_location_column": True,
"pkg_backport_column": True
}
with open(settings_file_path, 'w') as f:
json.dump(default_settings, f, indent=4)
Logger.log_information("Default settings created.")
def execute_command(cmd, pkg, file, out, update_callback_info):
"""Execute PKG related commands"""
logging.debug(f"execute_command called with cmd={cmd}, pkg={pkg}, file={file}, out={out}")
if not cmd or not pkg:
raise ValueError("The 'Command' and 'PKG' fields are required.")
try:
# Determine package type and create appropriate instance
with open(pkg, "rb") as fp:
magic = struct.unpack(">I", fp.read(4))[0]
if magic == PackagePS4.MAGIC_PS4:
target = PackagePS4(pkg)
elif magic == PackagePS5.MAGIC_PS5:
target = PackagePS5(pkg)
elif magic == PackagePS3.MAGIC_PS3:
target = PackagePS3(pkg)
else:
raise ValueError(f"Unknown PKG format: {magic:08X}")
# Execute requested command
if cmd == "info":
return get_pkg_info(target, update_callback_info)
elif cmd == "extract":
return extract_pkg_file(target, file, out, update_callback_info)
elif cmd == "dump":
return dump_pkg(target, out, update_callback_info)
elif cmd == "inject":
return inject_pkg_file(target, file, out)
elif cmd == "modify":
return modify_pkg_header(target, file, out)
else:
raise ValueError(f"Unknown command: {cmd}")
except Exception as e:
logging.error(f"Error executing command: {str(e)}")
raise
def get_pkg_info(package, callback):
"""Get PKG information"""
f = io.StringIO()
with redirect_stdout(f):
package.info()
info_output = f.getvalue()
if not info_output:
raise ValueError("No information found in the PKG file.")
info_dict = {}
for line in info_output.split('\n'):
if ':' in line:
key, value = line.split(':', 1)
info_dict[key.strip()] = value.strip()
callback(info_dict)
return info_output
def extract_pkg_file(package, file_path, output_path, callback):
"""Extract file from PKG"""
file_info = package.get_file_info(file_path)
extract_file(package.original_file, file_info, output_path, callback)
return f"File extracted: {file_path}"
def dump_pkg(package, output_path, callback):
"""Dump PKG contents"""
try:
result = package.dump(output_path, callback)
return result
except Exception as e:
raise ValueError(f"Error during dump: {str(e)}")
def inject_pkg_file(package, file_path, input_path):
"""Inject file into PKG"""
file_info = package.get_file_info(file_path)
injected_size = inject_file(package.original_file, file_info, input_path)
return f"Injected {injected_size} bytes"
def modify_pkg_header(package, offset, new_data):
"""Modify PKG header"""
modified_size = modify_file_header(package.original_file, int(offset, 16), new_data.encode())
return f"Modified {modified_size} bytes"
def is_admin():
"""Check if running with admin privileges"""
try:
return ctypes.windll.shell32.IsUserAnAdmin()
except:
return False
def main():
"""Main application entry point"""
# Initialize application
app = QApplication(sys.argv)
app.setStyle('Fusion')
# Setup directories and settings
temp_directory, settings_file_path = check_settings_file_presence()
# Apply Material Design theme (qt-material)
# Choose 'light_blue.xml' as default - looks modern and professional
apply_stylesheet(app, theme='light_blue.xml')
# Create and show main window
window = MainWindow(temp_directory)
window.show()
# Start application
sys.exit(app.exec())
if __name__ == "__main__":
main()