mirror of
https://github.com/itsPLK/ps5-pkg-manager.git
synced 2026-10-22 20:03:00 -05:00
- Resolve PS5 param.json titles by client/browser language preference instead of blindly picking the first entry (e.g. Arabic) - If a package defines a global title outside localizedParameters or in PS4 param.sfo TITLE, use that directly - Extract localized titles map and defaultLanguage in pkg_parser and persist them in manifest/cache - Forward Accept-Language header in HTTP server GET /api/packages endpoint - Dynamically resolve title in frontend UI via navigator.languages and allow searching against all localized titles - Add unit tests for synthetic multi-language packages
94 lines
3.7 KiB
C
94 lines
3.7 KiB
C
#ifndef PKG_PARSER_H
|
|
#define PKG_PARSER_H
|
|
|
|
#include <stdint.h>
|
|
#include <stddef.h>
|
|
|
|
#define PKG_TITLE_ID_LEN 32
|
|
#define PKG_TITLE_NAME_LEN 256
|
|
#define PKG_LOCALIZED_TITLES_LEN 2048
|
|
#define PKG_DEFAULT_LANG_LEN 32
|
|
#define PKG_CONTENT_ID_LEN 64
|
|
#define PKG_PATH_LEN 512
|
|
|
|
typedef enum {
|
|
PKG_TYPE_UNKNOWN = 0,
|
|
PKG_TYPE_BASE, /* Base application / package */
|
|
PKG_TYPE_UPDATE, /* Application update / patch */
|
|
PKG_TYPE_DLC /* Additional content / DLC */
|
|
} pkg_type_t;
|
|
|
|
typedef struct {
|
|
char path[PKG_PATH_LEN];
|
|
char filename[256];
|
|
char title_id[PKG_TITLE_ID_LEN];
|
|
char title_name[PKG_TITLE_NAME_LEN];
|
|
char localized_titles[PKG_LOCALIZED_TITLES_LEN]; /* JSON object string: {"ar-AE":"...","en-US":"..."} */
|
|
char default_language[PKG_DEFAULT_LANG_LEN]; /* e.g. "en-US" */
|
|
char content_id[PKG_CONTENT_ID_LEN];
|
|
char app_version[32];
|
|
uint64_t file_size;
|
|
uint64_t total_pkg_size;
|
|
uint64_t icon_offset;
|
|
uint32_t icon_size;
|
|
int has_icon;
|
|
int is_valid;
|
|
int is_multipart;
|
|
uint32_t part_index;
|
|
uint32_t total_parts;
|
|
pkg_type_t pkg_type;
|
|
char pkg_type_str[16]; /* "base", "update", "dlc", "unknown" */
|
|
char category[16]; /* e.g. "gd", "gp", "ac", etc. */
|
|
uint64_t mtime; /* File modification timestamp */
|
|
char blurhash[64]; /* BlurHash placeholder for icon0.png ("" if none) */
|
|
} pkg_detail_t;
|
|
|
|
/**
|
|
* Resolves the best-matching title from a localized_titles JSON object given
|
|
* an Accept-Language header string (or comma-separated list of languages).
|
|
* Falls back to default_lang, English, or the first localized title.
|
|
* Returns 0 on success and populates out, or negative on failure.
|
|
*/
|
|
int pkg_parser_resolve_localized_title(const char *loc_json, const char *default_lang,
|
|
const char *accept_lang, char *out, size_t out_max);
|
|
|
|
/**
|
|
* Parses PS5 param.json buffer to extract titleId, category, version,
|
|
* localized titles map, default language, and best default title.
|
|
*/
|
|
void pkg_parser_parse_param_json(const char *json_buf, size_t data_sz,
|
|
char *out_title_id, size_t tid_max,
|
|
char *out_title_name, size_t tname_max,
|
|
char *out_category, size_t cat_max,
|
|
char *out_version, size_t ver_max,
|
|
char *out_localized_titles, size_t loc_max,
|
|
char *out_default_lang, size_t def_lang_max);
|
|
|
|
/**
|
|
* Parses PS4 param.sfo buffer to extract titleId, category, version,
|
|
* localized titles map, default language, and default title.
|
|
*/
|
|
void pkg_parser_parse_param_sfo(const uint8_t *sfo, size_t sfo_len, char *out_title, size_t title_max,
|
|
char *out_title_id, size_t title_id_max,
|
|
char *out_version, size_t version_max,
|
|
char *out_category, size_t category_max,
|
|
char *out_localized_titles, size_t loc_max,
|
|
char *out_default_lang, size_t def_lang_max);
|
|
|
|
/**
|
|
* Parses a PKG file (PS5 FIH or PS4 CNT format) and extracts metadata:
|
|
* title_id, title_name, content_id, and icon0.png offset/size.
|
|
* Returns 0 on success, negative value on error.
|
|
*/
|
|
int pkg_parser_parse(const char *file_path, pkg_detail_t *out);
|
|
|
|
/**
|
|
* Extracts raw icon bytes from the PKG file.
|
|
* Allocates *out_data with malloc, which caller must free().
|
|
* Returns 0 on success, negative on error.
|
|
*/
|
|
int pkg_parser_get_icon(const char *file_path, uint64_t offset, uint32_t size,
|
|
uint8_t **out_data, size_t *out_size);
|
|
|
|
#endif /* PKG_PARSER_H */
|