-
Notifications
You must be signed in to change notification settings - Fork 0
/
pstools.py
132 lines (108 loc) · 3.62 KB
/
pstools.py
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
import logging
import os
import click
from format import PKG
from format import PSARC
from format import SFO
@click.group()
@click.option('-v', '--verbose', count=True)
def pstools(verbose: int):
if verbose == 1:
logging.basicConfig(level=logging.DEBUG, format='%(name)-32s: %(levelname)-8s %(message)s')
else:
logging.basicConfig(level=logging.INFO, format='%(name)-32s: %(levelname)-8s %(message)s')
"""
A comprehensive set of tools related to the Sony Playstation console files
"""
pass
@pstools.group()
def pkg():
"""
A set of tools to be used with the Sony Playstation 3 PKG file format
"""
pass
@pkg.command()
@click.argument('file', type=str)
@click.option('--verify/--no-verify', default=True)
def info(file: str, verify: bool):
"""
Info about Sony Playstation 3 PKG file contents
"""
PKG(file, verify)
@pkg.command()
@click.argument('file', type=str)
@click.option('--verify/--no-verify', default=True)
def extract(file: str, verify: bool):
"""
Extract Sony Playstation 3 PKG file contents
"""
pkg_file: PKG = PKG(file, verify)
for entry in pkg_file.files:
# TODO: Fix to use title_id but need to fix metadata for that
pkg_file.export(entry, f'{pkg_file.header.content_id}/', use_package_path=True)
@pstools.group()
def sfo():
"""
A set of tools to be used with the Sony Playstation SFO file format
"""
pass
@sfo.command()
@click.argument('file')
def info(file: str):
"""
Info about Sony Playstation SFO file contents
"""
SFO(file)
@sfo.command()
@click.argument('file', type=str)
@click.option('--out-file', '-o', default=None, type=str)
def edit(file: str, out_file: str):
"""
Edit Sony Playstation SFO file contents
"""
sfo_file: SFO = SFO(file)
while True:
#: Adding NULL Terminator because the keys contain the NULL Terminator in the file already
key: str = input('Enter pkg_internal_fs_key of the entry you would like to edit (q -> quit, w -> write and '
'quit): ') + '\0'
if key == 'q\0':
return
elif key == 'w\0':
sfo_file.write(out_file)
return
data: str = input('Enter entry data: ')
sfo_file.set_data(key, data)
sfo_file.print_key_data_map()
@pstools.group()
def psarc():
"""
A set of tools to be used with the Sony Playstation Archive (PSARC) file format
"""
pass
@psarc.command()
@click.argument('file')
def info(file: str):
"""
Info about Sony Playstation Archive (PSARC) file contents
"""
PSARC(file)
# noinspection PyShadowingBuiltins
@psarc.command()
@click.argument('file', type=str)
@click.option('--dir', default=None, type=str, help='target directory for extraction (default = archive name)')
@click.option('--use-package-path/--no-use-package-path', default=True, help='extract with directory structure')
@click.option('--create-directories/--no-create-directories', default=True, help='create needed directory structure')
@click.option('--overwrite/--no-overwrite', default=True, help='overwrite already extracted files')
def extract(file: str, dir: str, use_package_path: bool, create_directories: bool, overwrite: bool):
"""
Extract Sony Playstation Archive (PSARC) file contents
"""
psarc_file: PSARC = PSARC(file)
if dir is None:
dir = f'./{os.path.basename(file)}/'
for entry in psarc_file.entries[1:]:
psarc_file.save_entry(
entry, dir, use_package_path=use_package_path, create_directories=create_directories, overwrite=overwrite
)
if __name__ == '__main__':
pstools()