Skip to content

Commit

Permalink
unify generation of cu2 files
Browse files Browse the repository at this point in the history
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
  • Loading branch information
sahlberg committed Sep 10, 2023
1 parent bbd5c69 commit 6ae0361
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 52 deletions.
25 changes: 3 additions & 22 deletions pop-fe-ps3.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def __init__(self, master=None):
self.pkgdir = None
self.data_track_only = 'off'
self.configs = []
self.subdir = 'pop-fe-ps3-work'
self.subdir = 'pop-fe-ps3-work/'

self.master = master
self.builder = builder = pygubu.Builder()
Expand Down Expand Up @@ -389,25 +389,6 @@ def on_path_changed(self, event):
img_file = self.subdir + mb + '.bin'
temp_files.append(img_file)

print('Generating cu2') if verbose else None
cu2_file = cue_file[:-4] + '.cu2'
try:
os.stat(cu2_file).st_size
print('Using existing CU2 file: %s' % cu2_file) if verbose else None
except:
cu2_file = self.subdir + 'CUE' + disc + '.cu2'
print('Creating temporary CU2 file %s from %s' % (cu2_file, cue_file)) if verbose else None
if os.name == 'posix':
subprocess.call(['python3', './cue2cu2.py', '-n', cu2_file, '--size', str(os.stat(img_file).st_size), cue_file])
else:
subprocess.call(['cue2cu2.exe', '-n', cu2_file, '--size', str(os.stat(img_file).st_size), cue_file])
temp_files.append(cu2_file)
try:
os.stat(cu2_file).st_size
except:
print('Failed to convert to cu2. The cue file is probably from a bad dump.')
raise Exception('Bad dump CUE, can not convert to CU2')

print('Scanning for Game ID') if verbose else None
tmp = self.subdir + 'TMP01.iso'
disc_id = get_disc_id(cue_file, tmp)
Expand All @@ -418,7 +399,6 @@ def on_path_changed(self, event):
self.disc_ids.append(disc_id)
self.real_disc_ids.append(disc_id)
self.cue_files.append(cue_file)
self.cu2_files.append(cu2_file)
self.configs.append(bytes())

try:
Expand Down Expand Up @@ -790,10 +770,11 @@ def on_create_pkg(self):

#
# Apply all PPF fixes we might need
# XXX should we re-generate cu2 to after this?
#
self.cue_files, self.img_files = popfe.apply_ppf_fixes(self.real_disc_ids, self.cue_files, self.img_files, self.subdir)

self.cu2_files = popfe.generate_cu2_files(self.cue_files, self.img_files, self.subdir)

popfe.create_ps3(pkg, disc_ids, title,
self.icon0 if self.icon0_disc=='off' else self.disc,
self.pic0 if self.pic0_disabled =='off' else None,
Expand Down
17 changes: 2 additions & 15 deletions pop-fe-psp.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -238,19 +238,6 @@ def on_path_changed(self, event):
img_file = self.subdir + mb + '.bin'
temp_files.append(img_file)

print('Generating cu2') if verbose else None
cu2_file = cue_file[:-4] + '.cu2'
try:
os.stat(cu2_file).st_size
print('Using existing CU2 file: %s' % cu2_file) if verbose else None
except:
cu2_file = self.subdir + 'CUE' + disc + '.cu2'
print('Creating temporary CU2 file %s from %s' % (cu2_file, cue_file)) if verbose else None
if os.name == 'posix':
subprocess.call(['python3', './cue2cu2.py', '-n', cu2_file, '--size', str(os.stat(img_file).st_size), cue_file])
else:
subprocess.call(['cue2cu2.exe', '-n', cu2_file, '--size', str(os.stat(img_file).st_size), cue_file])
temp_files.append(cu2_file)
print('Scanning for Game ID') if verbose else None
tmp = self.subdir + 'TMP01.iso'
disc_id = get_disc_id(cue_file, tmp)
Expand All @@ -263,7 +250,6 @@ def on_path_changed(self, event):
self.disc_ids.append(disc_id)
self.real_disc_ids.append(disc_id)
self.cue_files.append(cue_file)
self.cu2_files.append(cu2_file)

if disc == 'd1':
self.builder.get_object('discid1', self.master).config(state='normal')
Expand Down Expand Up @@ -524,10 +510,11 @@ def on_create_eboot(self):

#
# Apply all PPF fixes we might need
# XXX should we re-generate cu2 to after this?
#
self.cue_files, self.img_files = popfe.apply_ppf_fixes(self.real_disc_ids, self.cue_files, self.img_files, self.subdir)

self.cu2_files = popfe.generate_cu2_files(self.cue_files, self.img_files, self.subdir)

popfe.create_psp(ebootdir, self.disc_ids, title,
self.icon0,
self.pic0 if self.pic0_disabled =='off' else None,
Expand Down
40 changes: 25 additions & 15 deletions pop-fe.py
Original file line number Diff line number Diff line change
Expand Up @@ -1926,7 +1926,30 @@ def apply_ppf_fixes(real_disc_ids, cue_files, img_files, subdir):
ApplyPPF(img_files[i], ppf_fixes[disc_id]['ppf'])

return cue_files, img_files

def generate_cu2_files(cue_files, img_files, subdir):
cu2_files = []

for i in range(len(cue_files)):
cue_file = cue_files[i]
img_file = img_files[i]
cu2_file = cue_file[:-4] + '.cu2'
try:
os.stat(cu2_file).st_size
print('Using existing CU2 file: %s' % cu2_file) if verbose else None
except:
cu2_file = subdir + 'TMP%d.cu2' % (i)
print('Creating temporary CU2 file: %s' % cu2_file) if verbose else None
if os.name == 'posix':
subprocess.call(['python3', './cue2cu2.py', '-n', cu2_file, '--size', str(os.stat(img_file).st_size), cue_file])
else:
subprocess.call(['cue2cu2.exe', '-n', cu2_file, '--size', str(os.stat(img_file).st_size), cue_file])
temp_files.append(cu2_file)
cu2_files.append(cu2_file)

return cu2_files


# ICON0 is the game cover
# PIC0 is logo
# PIC1 is background image/poster
Expand Down Expand Up @@ -2149,22 +2172,8 @@ def apply_ppf_fixes(real_disc_ids, cue_files, img_files, subdir):
img_file = subdir + mb + '.bin'
temp_files.append(img_file)

cu2_file = cue_file[:-4] + '.cu2'
try:
os.stat(cu2_file).st_size
print('Using existing CU2 file: %s' % cu2_file) if verbose else None
except:
cu2_file = subdir + 'TMP%d.cu2' % (0 if not idx else idx[0])
print('Creating temporary CU2 file: %s' % cu2_file) if verbose else None
if os.name == 'posix':
subprocess.call(['python3', './cue2cu2.py', '-n', cu2_file, '--size', str(os.stat(img_file).st_size), cue_file])
else:
subprocess.call(['cue2cu2.exe', '-n', cu2_file, '--size', str(os.stat(img_file).st_size), cue_file])
temp_files.append(cu2_file)

img_files.append(img_file)
cue_files.append(cue_file)
cu2_files.append(cu2_file)

if args.psp_dir or args.ps3_pkg or args.retroarch_pbp_dir:
bc = bchunk()
Expand Down Expand Up @@ -2218,10 +2227,11 @@ def apply_ppf_fixes(real_disc_ids, cue_files, img_files, subdir):
ps3configs[i] = ps3configs[i] + f.read()
#
# Apply all PPF fixes we might need
# XXX should we generation of cu2 to after this?
#
cue_files, img_files = apply_ppf_fixes(real_disc_ids, cue_files, img_files, subdir)

cu2_files = generate_cu2_files(cue_files, img_files, subdir)

if args.game_id:
args.game_id = args.game_id.split(',')
if args.psp_install_memory_card:
Expand Down

0 comments on commit 6ae0361

Please sign in to comment.