Files & storageSDL 3.2

SDL_OpenTitleStorage

Opens the game's own read-only files through SDL's storage API, which also works on consoles.

Signature

SDL_Storage * SDL_OpenTitleStorage(const char *override, SDL_PropertiesID props);

How it works

On a PC, reading assets with paths is fine. Consoles and some stores do not give you a normal file system: assets live in a package and saves in a managed container. SDL_Storage hides that difference. Open the container, wait until SDL_StorageReady says yes, read files with SDL_GetStorageFileSize and SDL_ReadStorageFile, then SDL_CloseStorage.

Parameters

overrideconst char *

NULL for the default (the base path on PC), or a folder to use instead.

propsSDL_PropertiesID

Backend-specific options, usually 0.

Return value

The storage container, or NULL on failure.

Example

example.cpp
1SDL_Storage* title = SDL_OpenTitleStorage(nullptr, 0);
2while (!SDL_StorageReady(title)) SDL_Delay(1);
3Uint64 size;
4SDL_GetStorageFileSize(title, "levels/1.json", &size);
5std::string text(size, '\0');
6SDL_ReadStorageFile(title, "levels/1.json", text.data(), size);
7SDL_CloseStorage(title);
Official SDL wiki