SDL 3.0
|
#include <SDL_storage.h>
Data Fields | |
Uint32 | version |
bool(* | close )(void *userdata) |
bool(* | ready )(void *userdata) |
bool(* | enumerate )(void *userdata, const char *path, SDL_EnumerateDirectoryCallback callback, void *callback_userdata) |
bool(* | info )(void *userdata, const char *path, SDL_PathInfo *info) |
bool(* | read_file )(void *userdata, const char *path, void *destination, Uint64 length) |
bool(* | write_file )(void *userdata, const char *path, const void *source, Uint64 length) |
bool(* | mkdir )(void *userdata, const char *path) |
bool(* | remove )(void *userdata, const char *path) |
bool(* | rename )(void *userdata, const char *oldpath, const char *newpath) |
bool(* | copy )(void *userdata, const char *oldpath, const char *newpath) |
Uint64(* | space_remaining )(void *userdata) |
The storage API is a high-level API designed to abstract away the portability issues that come up when using something lower-level (in SDL's case, this sits on top of the [Filesystem](CategoryFilesystem) and [IOStream](CategoryIOStream) subsystems). It is significantly more restrictive than a typical filesystem API, for a number of reasons:
Consider the following example:
Going over the bullet points again:
Due to these assumptions, the filesystem code is not portable and will fail under these common scenarios:
When using SDL_Storage, these types of problems are virtually impossible to trip over:
Note the improvements that SDL_Storage makes:
The result is an application that is significantly more robust against the increasing demands of platforms and their filesystems!
A publicly available example of an SDL_Storage backend is the Steam Cloud backend - you can initialize Steamworks when starting the program, and then SDL will recognize that Steamworks is initialized and automatically use ISteamRemoteStorage when the application opens user storage. More importantly, when you open storage it knows to begin a "batch" of filesystem operations, and when you close storage it knows to end and flush the batch. This is used by Steam to support Dynamic Cloud Sync ; users can save data on one PC, put the device to sleep, and then continue playing on another PC (and vice versa) with the save data fully synchronized across all devices, allowing for a seamless experience without having to do full restarts of the program.
All paths in the Storage API use Unix-style path separators ('/'). Using a different path separator will not work, even if the underlying platform would otherwise accept it. This is to keep code using the Storage API portable between platforms and Storage implementations and simplify app code.
Paths with relative directories ("." and "..") are forbidden by the Storage API.
All valid UTF-8 strings (discounting the NULL terminator character and the '/' path separator) are usable for filenames, however, an underlying Storage implementation may not support particularly strange sequences and refuse to create files with those names, etc. Function interface for SDL_Storage.
Apps that want to supply a custom implementation of SDL_Storage will fill in all the functions in this struct, and then pass it to SDL_OpenStorage to create a custom SDL_Storage object.
It is not usually necessary to do this; SDL provides standard implementations for many things you might expect to do with an SDL_Storage.
This structure should be initialized using SDL_INIT_INTERFACE()
Definition at line 274 of file SDL_storage.h.
bool(* SDL_StorageInterface::close) (void *userdata) |
Definition at line 280 of file SDL_storage.h.
bool(* SDL_StorageInterface::copy) (void *userdata, const char *oldpath, const char *newpath) |
Definition at line 307 of file SDL_storage.h.
bool(* SDL_StorageInterface::enumerate) (void *userdata, const char *path, SDL_EnumerateDirectoryCallback callback, void *callback_userdata) |
Definition at line 286 of file SDL_storage.h.
bool(* SDL_StorageInterface::info) (void *userdata, const char *path, SDL_PathInfo *info) |
Definition at line 289 of file SDL_storage.h.
bool(* SDL_StorageInterface::mkdir) (void *userdata, const char *path) |
Definition at line 298 of file SDL_storage.h.
bool(* SDL_StorageInterface::read_file) (void *userdata, const char *path, void *destination, Uint64 length) |
Definition at line 292 of file SDL_storage.h.
bool(* SDL_StorageInterface::ready) (void *userdata) |
Definition at line 283 of file SDL_storage.h.
bool(* SDL_StorageInterface::remove) (void *userdata, const char *path) |
Definition at line 301 of file SDL_storage.h.
bool(* SDL_StorageInterface::rename) (void *userdata, const char *oldpath, const char *newpath) |
Definition at line 304 of file SDL_storage.h.
Uint64(* SDL_StorageInterface::space_remaining) (void *userdata) |
Definition at line 310 of file SDL_storage.h.
Uint32 SDL_StorageInterface::version |
Definition at line 277 of file SDL_storage.h.
bool(* SDL_StorageInterface::write_file) (void *userdata, const char *path, const void *source, Uint64 length) |
Definition at line 295 of file SDL_storage.h.