Files
ps5-pkg-manager/include/pkg_scanner.h
T
Mateusz Najdek 5efa45a655 Release v1.2.0 (#5)
* ws: direct-install streaming over WebSocket (RAM-only, no disk spool)

Browser pushes .pkg bytes over ws://:8846 while the PS5 installer pulls
ranges over :8845 concurrently through a demand-paged 1MB-segment ring
(64 slots, seg 0 pinned). Install can start at header_ready, mid-upload.

Backend (src/ws_stream.c, src/ws_upload.c):
- ws_live_* ring with waiter shielding, served-past / waited+acked /
  peak>0+acked LRU eviction, single store_seg_locked() truth shared by
  blocking write and non-blocking try_write (0/-1/-2 busy).
- Conn worker never blocks on storage (busy reply, browser retries);
  socket idle kill suppressed while readers are parked; stall
  diagnostics when a write parks.
- http_server.c: guarded /api/upload/* REST branch; multipart.c live:
  scheme adapter (frozen pull path untouched); installer_start_live.

Frontend: DirectInstallView + useDirectUpload pusher (FIFO seek queue
for parallel installer workers, busy requeue+retry, demand-paging
standby until install finalizes, silent-socket watchdog), wired into
the history router (#/direct-install, Circle-back closes it).

Parser: pkg_parser_parse_mem reuses in-file sub-parsers for live
header parsing (differential-tested).

Tests: ring unit (test_ws_stream), far-seek/pivot/busy/waiter unit
(test_ws_stream_far), transport (test_ws_upload, incl. socket
busy->retry), concurrent e2e incl. 90MB/64-slot parallel-pivot replay
of the production capture (test_direct_install_e2e), PS5 pull-replay
simulator (ps5_sim) + CLI tools.

Proven on console: 1GB PKG installs at status='playable' with zero
idle kills. Full host suite (13 binaries + CSS) green.

* perf(smb): pipeline reads for faster package streaming

Use a private SMB session per stream connection and keep up to eight credit-aware reads in flight, with requests up to 512 KiB. Reduce each request to the credits available in the current SMB2 window, including queued requests, so libsmb2 cannot silently shorten a request and leave a gap in the stream. Increase stream and socket buffers, and leave signing optional while still honoring servers that require it.

Add SMB timing and throughput logs plus negotiated session diagnostics to separate SMB read latency from HTTP streaming overhead. Include the SMB logger in PS5 and host builds and update the mock async API used by tests.

* fix(ws): harden direct install sessions and package preview

Tie uploads to a browser owner and one authenticated WebSocket. Resume from acknowledged segments so cache eviction does not lose progress.

Move Direct Install into media sources, show local PKG title and icon before installation, and warn before leaving an active transfer. Pass package metadata to the live installer and cover ownership and metadata parsing with tests.

* fix(smb): honor package install debug setting

Gate SMB debug file creation and per-read diagnostics behind pkg_install_debug, matching WebSocket stream logging behavior. Keep regular SMB package streaming unchanged.

* fix(ui): return direct install to drives route

Make the Direct Install Back to drives action replace the current route and restore the media source view directly. This prevents browsers that opened the page from leaving the app for an unrelated previous history entry.

* fix(ui): restore deep-linked pages on reload

Apply the initial hash route to the visible view during startup, including storage media and package details. Load package data for the linked drive so a direct package URL opens its detail page after a reload.

* fix(ui): accept package drops across the app

Handle package drops at the application level, open Direct Install, and pass the file through the existing package preview flow. Keep active uploads and installations protected from replacement.

* fix(direct): check package eligibility before install

Share the scanner's installed state and version rules with Direct Install. Check selected package metadata before enabling Install and again before starting a new transfer, while preserving resumed sessions. Show storage and active install blockers on the direct install page.

* fix(direct): share live install icon across browsers

Upload the parsed package icon once to the active direct install session and serve it from RAM through the existing icon API. Other browsers can resolve the live session path shown in installer status. Clear icon data when the session is canceled or replaced.

* fix(direct): cancel install when uploader closes

Use sendBeacon during browser teardown to call the authenticated Direct Install cancel endpoint for the sending session. Keep observer browsers unaffected and avoid duplicate cancellation requests.

* fix(direct): cancel when uploader socket closes

Treat an unexpected close of the authenticated uploader WebSocket before the final finish message as an install cancellation. Preserve normal completed sessions and reduce repetitive seek, eviction, and read-short logging in the main log.

* bump version to 1.1.1

* fix(ui): stop duplicate direct upload polling

Keep the observer watchdog stable across renders, disable it for the owning upload tab, and prevent overlapping status requests in both polling paths.

* Add PS4 and PS5 package badges

* feat: support platform-aware install storage

* fix: preserve catalog during provisional scans

* bump version to 1.2.0

* docs: add changelog for 1.2.0

* chore: remove stale refactor references

* feat: move streaming services to dedicated ports

* docs: update 1.2.0 documentation
2026-09-22 02:48:57 +02:00

156 lines
4.8 KiB
C

#ifndef PKG_SCANNER_H
#define PKG_SCANNER_H
#include <stddef.h>
#include "pkg_parser.h"
#define PKG_DEFAULT_DIR "/data/pkg"
#define PKG_DISC_DIR "/mnt/disc/pkg"
#ifdef __cplusplus
extern "C" {
#endif
/**
* Initializes the package scanner.
*/
void pkg_scanner_init(void);
/**
* Scans the package directories (/data/pkg and /mnt/disc/pkg) for .pkg files.
* Returns the number of valid packages found.
*/
int pkg_scanner_scan(void);
/**
* Returns the number of packages currently in the cache.
*/
size_t pkg_scanner_get_count(void);
/**
* Retrieves a copy of package details at index (0 <= index < count).
* Returns 0 on success, -1 if index is out of range.
*/
int pkg_scanner_get_at(size_t index, pkg_detail_t *out);
/**
* Finds a package by path.
* Returns 0 on success, -1 if not found.
*/
int pkg_scanner_find_by_path(const char *path, pkg_detail_t *out);
/* Evaluate a package against the console's current installed state. */
typedef struct {
int can_install;
const char *disabled_reason;
int is_installed;
char installed_version[32];
} pkg_install_eligibility_t;
void pkg_scanner_check_install_eligibility(const pkg_detail_t *pkg,
pkg_install_eligibility_t *out);
/**
* Updates the cached BlurHash placeholder for a package in memory.
* Returns 0 on success, -1 if not found.
*/
int pkg_scanner_set_blurhash(const char *path, const char *blurhash);
/**
* Searches scan directories for a specific part of a multi-part archive.
* Matches by package UUID (if provided) and/or PKG filename, and part_index.
* Returns 0 if found and writes path to out_path, -1 if not found.
*/
int pkg_scanner_find_part(const uint8_t *package_uuid, const char *pkg_filename,
uint32_t part_index, char *out_path, size_t out_max);
/**
* Extended search that also reports if a different part of the same package was detected.
*/
int pkg_scanner_find_part_ex(const uint8_t *package_uuid, const char *pkg_filename,
uint32_t part_index, char *out_path, size_t out_max,
uint32_t *out_detected_part);
typedef struct {
char id[32]; /* "usb0", "usb1", ..., "disc", "internal" */
char label[64]; /* "USB Drive 0", "Blu-ray Disc", "Internal Storage" */
char path[256]; /* "/mnt/usb0", "/mnt/disc", "/data/pkg" */
char type[16]; /* "usb", "disc", "internal" */
int mounted; /* 1 if mounted, 0 otherwise */
size_t pkg_count; /* Number of packages in root */
int clickable; /* 1 if pkg_count > 0, 0 otherwise */
} pkg_drive_t;
/**
* Returns number of detected drives.
*/
size_t pkg_scanner_get_drive_count(void);
/**
* Retrieves drive details at index (0 <= index < drive_count).
*/
int pkg_scanner_get_drive_at(size_t index, pkg_drive_t *out);
/**
* Serializes list of mounted drives into JSON array.
* Caller must free() the returned buffer.
*/
char *pkg_scanner_drives_to_json(void);
/**
* Serializes packages for a specific drive into JSON array, optionally resolving
* display titles using accept_language header.
* Caller must free() the returned buffer.
*/
char *pkg_scanner_packages_for_drive_to_json_ex(const char *drive_id_or_path, const char *accept_language);
/**
* Serializes packages for a specific drive (by id e.g. "usb0" or path e.g. "/mnt/usb0") into JSON array.
* If drive_id_or_path is NULL or empty, returns all packages.
* Caller must free() the returned buffer.
*/
char *pkg_scanner_packages_for_drive_to_json(const char *drive_id_or_path);
/**
* Serializes the list of scanned packages into a JSON array string.
* The returned buffer must be freed by caller using free().
*/
char *pkg_scanner_to_json(void);
/**
* Scan progress status for full-screen UI progress overlay.
*/
typedef struct {
int is_scanning;
size_t total_files;
size_t processed_files;
char current_drive[64];
char current_file[256];
} pkg_scan_status_t;
void pkg_scanner_get_status(pkg_scan_status_t *out);
char *pkg_scanner_status_to_json(void);
/**
* Performs a quick / light rescan of packages.
* If drive_id_or_path is non-NULL and non-empty (and not "__all__"), scans only that drive.
* Otherwise, scans all drives and enabled SMB shares.
* Unchanged sources (matching file list, size, mtime) are skipped with 0 parsing overhead.
* Only new/modified files are parsed. Removed files are purged.
* If out_changed is non-NULL, sets *out_changed to 1 if packages/drives changed, 0 otherwise.
* Returns total number of packages currently in catalog.
*/
int pkg_scanner_scan_quick(const char *drive_id_or_path, int *out_changed);
/**
* Checks if a persisted catalog manifest exists on disk.
* Returns 1 if manifest exists, 0 otherwise.
*/
int pkg_scanner_has_manifest(void);
#ifdef __cplusplus
}
#endif
#endif /* PKG_SCANNER_H */