mirror of
https://github.com/SirHumza/orbisRPC.git
synced 2026-10-12 21:01:14 +02:00
increased WS_RBUF_MAX to 32MB and new drain fix, also added notification for invalid tokens
55 lines
2.2 KiB
Python
55 lines
2.2 KiB
Python
#!/usr/bin/env python3
|
|
"""Generate orbisrpc/icon_embedded.h from a PNG, for the notification icon.
|
|
|
|
python3 scripts/gen_icon_header.py [png] [out]
|
|
|
|
sceKernelSendNotificationRequest's icon_uri points at a file on disk, not at
|
|
payload memory, so the bytes have to be written out at runtime. That makes an
|
|
embedded copy the only way to show a custom icon without shipping the PNG
|
|
separately.
|
|
|
|
The PNG is embedded exactly as given -- no resizing here. Notification icons
|
|
are capped around 512x512 and the service silently falls back to the default
|
|
icon when given something larger, so this only warns. Use scripts/fit_icon.py
|
|
to prepare a source icon.
|
|
"""
|
|
import sys, os, struct
|
|
|
|
SRC = sys.argv[1] if len(sys.argv) > 1 else 'config/images/icons/logo.notify.png'
|
|
OUT = sys.argv[2] if len(sys.argv) > 2 else 'orbisrpc/icon_embedded.h'
|
|
|
|
MAX_ICON = 512
|
|
|
|
data = open(SRC, 'rb').read()
|
|
if data[:8] != b'\x89PNG\r\n\x1a\n':
|
|
sys.exit('%s is not a PNG (bad magic)' % SRC)
|
|
|
|
w, h = struct.unpack('>II', data[16:24])
|
|
if w > MAX_ICON or h > MAX_ICON:
|
|
print('WARNING: %s is %dx%d; notifications reject anything over %d '
|
|
'and will show the default icon.' % (SRC, w, h, MAX_ICON))
|
|
print(' Run scripts/fit_icon.py %s to produce a fitted copy.'
|
|
% os.path.basename(SRC))
|
|
else:
|
|
print('%s is %dx%d (within the %d limit)' % (SRC, w, h, MAX_ICON))
|
|
|
|
L = []
|
|
L.append('/* icon_embedded.h - GENERATED by scripts/gen_icon_header.py. Do not edit.\n'
|
|
' *\n'
|
|
' * Source: %s (%d bytes)\n'
|
|
' *\n'
|
|
' * Embedded so the payload can drop the notification icon on disk at\n'
|
|
' * first boot; sceKernelSendNotificationRequest takes a path, not a\n'
|
|
' * memory blob.\n'
|
|
' */\n' % (SRC, len(data)))
|
|
L.append('#ifndef ORBISRPC_ICON_EMBEDDED_H\n#define ORBISRPC_ICON_EMBEDDED_H\n')
|
|
L.append('#include <stddef.h>\n')
|
|
L.append('static const unsigned char orbisrpc_notify_icon_png[] = {\n')
|
|
for i in range(0, len(data), 16):
|
|
L.append(' ' + ''.join('0x%02x,' % b for b in data[i:i+16]) + '\n')
|
|
L.append('};\n')
|
|
L.append('#define ORBISRPC_NOTIFY_ICON_SIZE %d\n' % len(data))
|
|
L.append('#endif /* ORBISRPC_ICON_EMBEDDED_H */\n')
|
|
|
|
open(OUT, 'w').write(''.join(L))
|
|
print('%s -> %s (%d bytes of PNG)' % (SRC, OUT, len(data))) |