SDL3pp
A slim C++ wrapper for SDL3
Loading...
Searching...
No Matches
Classes | Typedefs | Functions

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). More...

Collaboration diagram for Storage Abstraction:

Classes

struct  SDL::StorageParam
 Safely wrap Storage for non owning parameters. More...
 
class  SDL::Storage
 An abstract interface for filesystem access. More...
 
struct  SDL::StorageRef
 Semi-safe reference for Storage. More...
 

Typedefs

using SDL::StorageRaw = SDL_Storage *
 Alias to raw representation for Storage.
 
using SDL::StorageInterface = SDL_StorageInterface
 Function interface for Storage. More...
 

Functions

Storage SDL::OpenTitleStorage (StringParam override, PropertiesParam props)
 Opens up a read-only container for the application's filesystem. More...
 
Storage SDL::OpenUserStorage (StringParam org, StringParam app, PropertiesParam props)
 Opens up a container for a user's unique read/write filesystem. More...
 
Storage SDL::OpenFileStorage (StringParam path)
 Opens up a container for local filesystem storage. More...
 
Storage SDL::OpenStorage (const StorageInterface &iface, void *userdata)
 Opens up a container using a client-provided storage interface. More...
 
bool SDL::CloseStorage (StorageRaw storage)
 Closes and frees a storage container. More...
 
bool SDL::StorageReady (StorageParam storage)
 Checks if the storage container is ready to use. More...
 
std::optional< Uint64SDL::GetStorageFileSize (StorageParam storage, StringParam path)
 Query the size of a file within a storage container. More...
 
bool SDL::ReadStorageFile (StorageParam storage, StringParam path, TargetBytes destination)
 Synchronously read a file from a storage container into a client-provided buffer. More...
 
std::string SDL::ReadStorageFile (StorageParam storage, StringParam path)
 Synchronously read a file from a storage container into a client-provided buffer. More...
 
template<class T >
std::vector< T > SDL::ReadStorageFileAs (StorageParam storage, StringParam path)
 Synchronously read a file from a storage container into a client-provided buffer. More...
 
void SDL::WriteStorageFile (StorageParam storage, StringParam path, SourceBytes source)
 Synchronously write a file from client memory into a storage container. More...
 
void SDL::CreateStorageDirectory (StorageParam storage, StringParam path)
 Create a directory in a writable storage container. More...
 
void SDL::EnumerateStorageDirectory (StorageParam storage, StringParam path, EnumerateDirectoryCallback callback, void *userdata)
 Enumerate a directory in a storage container through a callback function. More...
 
void SDL::EnumerateStorageDirectory (StorageParam storage, StringParam path, EnumerateDirectoryCB callback)
 Enumerate a directory in a storage container through a callback function. More...
 
std::vector< PathSDL::EnumerateStorageDirectory (StorageParam storage, StringParam path)
 Enumerate a directory in a storage container through a callback function. More...
 
void SDL::RemoveStoragePath (StorageParam storage, StringParam path)
 Remove a file or an empty directory in a writable storage container. More...
 
void SDL::RenameStoragePath (StorageParam storage, StringParam oldpath, StringParam newpath)
 Rename a file or directory in a writable storage container. More...
 
void SDL::CopyStorageFile (StorageParam storage, StringParam oldpath, StringParam newpath)
 Copy a file in a writable storage container. More...
 
PathInfo SDL::GetStoragePathInfo (StorageParam storage, StringParam path)
 Get information about a filesystem path in a storage container. More...
 
Uint64 SDL::GetStorageSpaceRemaining (StorageParam storage)
 Queries the remaining space in a storage container. More...
 
OwnArray< char * > SDL::GlobStorageDirectory (StorageParam storage, StringParam path, StringParam pattern, GlobFlags flags)
 Enumerate a directory tree, filtered by pattern, and return a list. More...
 
bool SDL::Storage::Close ()
 Closes and frees a storage container. More...
 
bool SDL::Storage::Ready ()
 Checks if the storage container is ready to use. More...
 
std::optional< Uint64SDL::Storage::GetFileSize (StringParam path)
 Query the size of a file within a storage container. More...
 
bool SDL::Storage::ReadFile (StringParam path, TargetBytes destination)
 Synchronously read a file from a storage container into a client-provided buffer. More...
 
std::string SDL::Storage::ReadFile (StringParam path)
 Synchronously read a file from a storage container into a client-provided buffer. More...
 
template<class T >
std::vector< T > SDL::Storage::ReadFileAs (StringParam path)
 Synchronously read a file from a storage container into a client-provided buffer. More...
 
void SDL::Storage::WriteFile (StringParam path, SourceBytes source)
 Synchronously write a file from client memory into a storage container. More...
 
void SDL::Storage::CreateDirectory (StringParam path)
 Create a directory in a writable storage container. More...
 
void SDL::Storage::EnumerateDirectory (StringParam path, EnumerateDirectoryCallback callback, void *userdata)
 Enumerate a directory in a storage container through a callback function. More...
 
std::vector< PathSDL::Storage::EnumerateDirectory (StringParam path)
 Enumerate a directory in a storage container through a callback function. More...
 
void SDL::Storage::EnumerateDirectory (StringParam path, EnumerateDirectoryCB callback)
 Enumerate a directory in a storage container through a callback function. More...
 
void SDL::Storage::RemovePath (StringParam path)
 Remove a file or an empty directory in a writable storage container. More...
 
void SDL::Storage::RenamePath (StringParam oldpath, StringParam newpath)
 Rename a file or directory in a writable storage container. More...
 
void SDL::Storage::CopyFile (StringParam oldpath, StringParam newpath)
 Copy a file in a writable storage container. More...
 
PathInfo SDL::Storage::GetPathInfo (StringParam path)
 Get information about a filesystem path in a storage container. More...
 
Uint64 SDL::Storage::GetSpaceRemaining ()
 Queries the remaining space in a storage container. More...
 
OwnArray< char * > SDL::Storage::GlobDirectory (StringParam path, StringParam pattern, GlobFlags flags)
 Enumerate a directory tree, filtered by pattern, and return a list. More...
 

Detailed Description

It is significantly more restrictive than a typical filesystem API, for a number of reasons:

  1. What to Access: A common pitfall with existing filesystem APIs is the assumption that all storage is monolithic. However, many other platforms (game consoles in particular) are more strict about what type of filesystem is being accessed; for example, game content and user data are usually two separate storage devices with entirely different characteristics (and possibly different low-level APIs altogether!).
  2. How to Access: Another common mistake is applications assuming that all storage is universally writeable - again, many platforms treat game content and user data as two separate storage devices, and only user data is writeable while game content is read-only.
  3. When to Access: The most common portability issue with filesystem access is timing - you cannot always assume that the storage device is always accessible all of the time, nor can you assume that there are no limits to how long you have access to a particular device.

Consider the following example:

void ReadGameData(void)
{
extern char** fileNames;
extern size_t numFiles;
for (size_t i = 0; i < numFiles; i += 1) {
FILE *data = fopen(fileNames[i], "rwb");
if (data == nullptr) {
// Something bad happened!
} else {
// A bunch of stuff happens here
fclose(data);
}
}
}
void ReadSave(void)
{
FILE *save = fopen("saves/save0.sav", "rb");
if (save == nullptr) {
// Something bad happened!
} else {
// A bunch of stuff happens here
fclose(save);
}
}
void WriteSave(void)
{
FILE *save = fopen("saves/save0.sav", "wb");
if (save == nullptr) {
// Something bad happened!
} else {
// A bunch of stuff happens here
fclose(save);
}
}

Going over the bullet points again:

  1. What to Access: This code accesses a global filesystem; game data and saves are all presumed to be in the current working directory (which may or may not be the game's installation folder!).
  2. How to Access: This code assumes that content paths are writeable, and that save data is also writeable despite being in the same location as the game data.
  3. When to Access: This code assumes that they can be called at any time, since the filesystem is always accessible and has no limits on how long the filesystem is being accessed.

Due to these assumptions, the filesystem code is not portable and will fail under these common scenarios:

When using Storage, these types of problems are virtually impossible to trip over:

void ReadGameData(void)
{
extern char** fileNames;
extern size_t numFiles;
Storage title(nullptr, 0);
if (title == nullptr) {
// Something bad happened!
}
while (!title.Ready()) {
Delay(1);
}
for (size_t i = 0; i < numFiles; i += 1) {
void* dst;
Uint64 dstLen = title.GetSize(fileNames[i]);
if (dstLen > 0) {
dst = malloc(dstLen);
if (title.ReadFile(fileNames[i], dst, dstLen)) {
// A bunch of stuff happens here
} else {
// Something bad happened!
}
free(dst);
} else {
// Something bad happened!
}
}
}
void ReadSave(void)
{
Storage user("libsdl", "Storage Example", 0);
if (user == nullptr) {
// Something bad happened!
}
while (!user.Ready()) {
Delay(1);
}
Uint64 saveLen = user.GetFileSize();
if (saveLen > 0) {
void* dst = malloc(saveLen);
if (user.ReadFile("save0.sav", dst, saveLen)) {
// A bunch of stuff happens here
} else {
// Something bad happened!
}
free(dst);
} else {
// Something bad happened!
}
}
void WriteSave(void)
{
Storage user("libsdl", "Storage Example", 0);
if (user == nullptr) {
// Something bad happened!
}
while (!user.Ready()) {
Delay(1);
}
extern void *saveData; // A bunch of stuff happened here...
extern Uint64 saveLen;
if (!user.WriteFile("save0.sav", saveData, saveLen)) {
// Something bad happened!
}
}
void * malloc(size_t size)
Allocate uninitialized memory.
Definition: SDL3pp_stdinc.h:646
::Uint64 Uint64
An unsigned 64-bit integer type.
Definition: SDL3pp_stdinc.h:373
void free(void *mem)
Free allocated memory.
Definition: SDL3pp_stdinc.h:734
void Delay(std::chrono::nanoseconds duration)
Wait a specified duration before returning.
Definition: SDL3pp_timer.h:102

Note the improvements that Storage makes:

  1. What to Access: This code explicitly reads from a title or user storage device based on the context of the function.
  2. How to Access: This code explicitly uses either a read or write function based on the context of the function.
  3. When to Access: This code explicitly opens the device when it needs to, and closes it when it is finished working with the filesystem.

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 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.

Notes on valid paths

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 nullptr 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.

Typedef Documentation

◆ StorageInterface

using SDL::StorageInterface = typedef SDL_StorageInterface

Apps that want to supply a custom implementation of Storage will fill in all the functions in this struct, and then pass it to Storage.Storage to create a custom Storage object.

It is not usually necessary to do this; SDL provides standard implementations for many things you might expect to do with an Storage.

This structure should be initialized using InitInterface()

Since
This struct is available since SDL 3.2.0.
See also
InitInterface

Function Documentation

◆ Close()

bool SDL::Storage::Close ( )
inline
Returns
true if the container was freed with no errors, false otherwise; call GetError() for more information. Even if the function returns an error, the container data will be freed; the error is only for informational purposes.
Since
This function is available since SDL 3.2.0.
See also
Storage.Storage

◆ CloseStorage()

bool SDL::CloseStorage ( StorageRaw  storage)
inline
Parameters
storagea storage container to close.
Returns
true if the container was freed with no errors, false otherwise; call GetError() for more information. Even if the function returns an error, the container data will be freed; the error is only for informational purposes.
Since
This function is available since SDL 3.2.0.
See also
Storage.Storage
Storage.Storage
Storage.Storage
Storage.Storage

◆ CopyFile()

void SDL::Storage::CopyFile ( StringParam  oldpath,
StringParam  newpath 
)
inline
Parameters
oldpaththe old path.
newpaththe new path.
Exceptions
Erroron failure.
Since
This function is available since SDL 3.2.0.
See also
Storage.Ready

◆ CopyStorageFile()

void SDL::CopyStorageFile ( StorageParam  storage,
StringParam  oldpath,
StringParam  newpath 
)
inline
Parameters
storagea storage container.
oldpaththe old path.
newpaththe new path.
Exceptions
Erroron failure.
Since
This function is available since SDL 3.2.0.
See also
Storage.Ready

◆ CreateDirectory()

void SDL::Storage::CreateDirectory ( StringParam  path)
inline
Parameters
paththe path of the directory to create.
Exceptions
Erroron failure.
Since
This function is available since SDL 3.2.0.
See also
Storage.Ready

◆ CreateStorageDirectory()

void SDL::CreateStorageDirectory ( StorageParam  storage,
StringParam  path 
)
inline
Parameters
storagea storage container.
paththe path of the directory to create.
Exceptions
Erroron failure.
Since
This function is available since SDL 3.2.0.
See also
Storage.Ready

◆ EnumerateDirectory() [1/3]

std::vector< Path > SDL::Storage::EnumerateDirectory ( StringParam  path)
inline

This function provides every directory entry through an app-provided callback, called once for each directory entry, until all results have been provided or the callback returns either ENUM_SUCCESS or ENUM_FAILURE.

This will return false if there was a system problem in general, or if a callback returns ENUM_FAILURE. A successful return means a callback returned ENUM_SUCCESS to halt enumeration, or all directory entries were enumerated.

If path is nullptr, this is treated as a request to enumerate the root of the storage container's tree. An empty string also works for this.

Parameters
paththe path of the directory to enumerate, or nullptr for the root.
Returns
all the directory contents.
Exceptions
Erroron failure.
Since
This function is available since SDL 3.2.0.
See also
Storage.Ready

◆ EnumerateDirectory() [2/3]

void SDL::Storage::EnumerateDirectory ( StringParam  path,
EnumerateDirectoryCallback  callback,
void *  userdata 
)
inline

This function provides every directory entry through an app-provided callback, called once for each directory entry, until all results have been provided or the callback returns either ENUM_SUCCESS or ENUM_FAILURE.

This will return false if there was a system problem in general, or if a callback returns ENUM_FAILURE. A successful return means a callback returned ENUM_SUCCESS to halt enumeration, or all directory entries were enumerated.

If path is nullptr, this is treated as a request to enumerate the root of the storage container's tree. An empty string also works for this.

Parameters
paththe path of the directory to enumerate, or nullptr for the root.
callbacka function that is called for each entry in the directory.
userdataa pointer that is passed to callback.
Exceptions
Erroron failure.
Since
This function is available since SDL 3.2.0.
See also
Storage.Ready

◆ EnumerateDirectory() [3/3]

void SDL::Storage::EnumerateDirectory ( StringParam  path,
EnumerateDirectoryCB  callback 
)
inline

This function provides every directory entry through an app-provided callback, called once for each directory entry, until all results have been provided or the callback returns either ENUM_SUCCESS or ENUM_FAILURE.

This will return false if there was a system problem in general, or if a callback returns ENUM_FAILURE. A successful return means a callback returned ENUM_SUCCESS to halt enumeration, or all directory entries were enumerated.

If path is nullptr, this is treated as a request to enumerate the root of the storage container's tree. An empty string also works for this.

Parameters
paththe path of the directory to enumerate, or nullptr for the root.
callbacka function that is called for each entry in the directory.
Exceptions
Erroron failure.
Since
This function is available since SDL 3.2.0.
See also
Storage.Ready

◆ EnumerateStorageDirectory() [1/3]

std::vector< Path > SDL::EnumerateStorageDirectory ( StorageParam  storage,
StringParam  path 
)
inline

This function provides every directory entry through an app-provided callback, called once for each directory entry, until all results have been provided or the callback returns either ENUM_SUCCESS or ENUM_FAILURE.

This will return false if there was a system problem in general, or if a callback returns ENUM_FAILURE. A successful return means a callback returned ENUM_SUCCESS to halt enumeration, or all directory entries were enumerated.

If path is nullptr, this is treated as a request to enumerate the root of the storage container's tree. An empty string also works for this.

Parameters
storagea storage container.
paththe path of the directory to enumerate, or nullptr for the root.
Returns
all the directory contents.
Exceptions
Erroron failure.
Since
This function is available since SDL 3.2.0.
See also
Storage.Ready

◆ EnumerateStorageDirectory() [2/3]

void SDL::EnumerateStorageDirectory ( StorageParam  storage,
StringParam  path,
EnumerateDirectoryCallback  callback,
void *  userdata 
)
inline

This function provides every directory entry through an app-provided callback, called once for each directory entry, until all results have been provided or the callback returns either ENUM_SUCCESS or ENUM_FAILURE.

This will return false if there was a system problem in general, or if a callback returns ENUM_FAILURE. A successful return means a callback returned ENUM_SUCCESS to halt enumeration, or all directory entries were enumerated.

If path is nullptr, this is treated as a request to enumerate the root of the storage container's tree. An empty string also works for this.

Parameters
storagea storage container.
paththe path of the directory to enumerate, or nullptr for the root.
callbacka function that is called for each entry in the directory.
userdataa pointer that is passed to callback.
Exceptions
Erroron failure.
Since
This function is available since SDL 3.2.0.
See also
Storage.Ready

◆ EnumerateStorageDirectory() [3/3]

void SDL::EnumerateStorageDirectory ( StorageParam  storage,
StringParam  path,
EnumerateDirectoryCB  callback 
)
inline

This function provides every directory entry through an app-provided callback, called once for each directory entry, until all results have been provided or the callback returns either ENUM_SUCCESS or ENUM_FAILURE.

This will return false if there was a system problem in general, or if a callback returns ENUM_FAILURE. A successful return means a callback returned ENUM_SUCCESS to halt enumeration, or all directory entries were enumerated.

If path is nullptr, this is treated as a request to enumerate the root of the storage container's tree. An empty string also works for this.

Parameters
storagea storage container.
paththe path of the directory to enumerate, or nullptr for the root.
callbacka function that is called for each entry in the directory.
Exceptions
Erroron failure.
Since
This function is available since SDL 3.2.0.
See also
Storage.Ready

◆ GetFileSize()

std::optional< Uint64 > SDL::Storage::GetFileSize ( StringParam  path)
inline
Parameters
paththe relative path of the file to query.
Returns
the file's length on success or 0 on failure; call GetError() for more information.
Since
This function is available since SDL 3.2.0.
See also
Storage.ReadFile
Storage.Ready

◆ GetPathInfo()

PathInfo SDL::Storage::GetPathInfo ( StringParam  path)
inline
Parameters
paththe path to query.
Returns
the info on success or false if the file doesn't exist, or another failure; call GetError() for more information.
Since
This function is available since SDL 3.2.0.
See also
Storage.Ready

◆ GetSpaceRemaining()

Uint64 SDL::Storage::GetSpaceRemaining ( )
inline
Returns
the amount of remaining space, in bytes.
Since
This function is available since SDL 3.2.0.
See also
Storage.Ready
Storage.WriteFile

◆ GetStorageFileSize()

std::optional< Uint64 > SDL::GetStorageFileSize ( StorageParam  storage,
StringParam  path 
)
inline
Parameters
storagea storage container to query.
paththe relative path of the file to query.
Returns
the file's length on success or std::nullopt on failure; call GetError() for more information.
Since
This function is available since SDL 3.2.0.
See also
Storage.ReadFile
Storage.Ready

◆ GetStoragePathInfo()

PathInfo SDL::GetStoragePathInfo ( StorageParam  storage,
StringParam  path 
)
inline
Parameters
storagea storage container.
paththe path to query.
Returns
the info on success or false if the file doesn't exist, or another failure; call GetError() for more information.
Since
This function is available since SDL 3.2.0.
See also
Storage.Ready

◆ GetStorageSpaceRemaining()

Uint64 SDL::GetStorageSpaceRemaining ( StorageParam  storage)
inline
Parameters
storagea storage container to query.
Returns
the amount of remaining space, in bytes.
Since
This function is available since SDL 3.2.0.
See also
Storage.Ready
Storage.WriteFile

◆ GlobDirectory()

OwnArray< char * > SDL::Storage::GlobDirectory ( StringParam  path,
StringParam  pattern,
GlobFlags  flags 
)
inline

Files are filtered out if they don't match the string in pattern, which may contain wildcard characters * (match everything) and ? (match one character). If pattern is nullptr, no filtering is done and all results are returned. Subdirectories are permitted, and are specified with a path separator of '/'. Wildcard characters * and ? never match a path separator.

flags may be set to GLOB_CASEINSENSITIVE to make the pattern matching case-insensitive.

The returned array is always nullptr-terminated, for your iterating convenience, but if count is non-nullptr, on return it will contain the number of items in the array, not counting the nullptr terminator.

If path is nullptr, this is treated as a request to enumerate the root of the storage container's tree. An empty string also works for this.

Parameters
paththe path of the directory to enumerate, or nullptr for the root.
patternthe pattern that files in the directory must match. Can be nullptr.
flagsSDL_GLOB_* bitflags that affect this search.
Returns
an array of strings on success.
Exceptions
Erroron failure.
Thread safety:
It is safe to call this function from any thread, assuming the storage object is thread-safe.
Since
This function is available since SDL 3.2.0.

◆ GlobStorageDirectory()

OwnArray< char * > SDL::GlobStorageDirectory ( StorageParam  storage,
StringParam  path,
StringParam  pattern,
GlobFlags  flags 
)
inline

Files are filtered out if they don't match the string in pattern, which may contain wildcard characters * (match everything) and ? (match one character). If pattern is nullptr, no filtering is done and all results are returned. Subdirectories are permitted, and are specified with a path separator of '/'. Wildcard characters * and ? never match a path separator.

flags may be set to GLOB_CASEINSENSITIVE to make the pattern matching case-insensitive.

The returned array is always nullptr-terminated, for your iterating convenience, but if count is non-nullptr, on return it will contain the number of items in the array, not counting the nullptr terminator.

If path is nullptr, this is treated as a request to enumerate the root of the storage container's tree. An empty string also works for this.

Parameters
storagea storage container.
paththe path of the directory to enumerate, or nullptr for the root.
patternthe pattern that files in the directory must match. Can be nullptr.
flagsSDL_GLOB_* bitflags that affect this search.
Returns
an array of strings on success.
Exceptions
Erroron failure.
Thread safety:
It is safe to call this function from any thread, assuming the storage object is thread-safe.
Since
This function is available since SDL 3.2.0.

◆ OpenFileStorage()

Storage SDL::OpenFileStorage ( StringParam  path)
inline

This is provided for development and tools. Portable applications should use Storage.Storage() for access to game data and Storage.Storage() for access to user data.

Parameters
paththe base path prepended to all storage paths, or nullptr for no base path.
Returns
a filesystem storage container on success.
Exceptions
Erroron failure.
Since
This function is available since SDL 3.2.0.
See also
Storage.Close
Storage.GetFileSize
Storage.GetSpaceRemaining
Storage.Storage
Storage.Storage
Storage.ReadFile
Storage.WriteFile

◆ OpenStorage()

Storage SDL::OpenStorage ( const StorageInterface iface,
void *  userdata 
)
inline

Applications do not need to use this function unless they are providing their own Storage implementation. If you just need an Storage, you should use the built-in implementations in SDL, like Storage.Storage() or Storage.Storage().

This function makes a copy of iface and the caller does not need to keep it around after this call.

Parameters
ifacethe interface that implements this storage, initialized using InitInterface().
userdatathe pointer that will be passed to the interface functions.
Returns
a storage container on success.
Exceptions
Erroron failure.
Since
This function is available since SDL 3.2.0.
See also
Storage.Close
Storage.GetFileSize
Storage.GetSpaceRemaining
InitInterface
Storage.ReadFile
Storage.Ready
Storage.WriteFile

◆ OpenTitleStorage()

Storage SDL::OpenTitleStorage ( StringParam  override,
PropertiesParam  props 
)
inline
Parameters
overridea path to override the backend's default title root.
propsa property list that may contain backend-specific information.
Returns
a title storage container on success.
Exceptions
Erroron failure.
Since
This function is available since SDL 3.2.0.
See also
Storage.Close
Storage.GetFileSize
Storage.Storage
Storage.ReadFile

◆ OpenUserStorage()

Storage SDL::OpenUserStorage ( StringParam  org,
StringParam  app,
PropertiesParam  props 
)
inline

While title storage can generally be kept open throughout runtime, user storage should only be opened when the client is ready to read/write files. This allows the backend to properly batch file operations and flush them when the container has been closed; ensuring safe and optimal save I/O.

Parameters
orgthe name of your organization.
appthe name of your application.
propsa property list that may contain backend-specific information.
Returns
a user storage container on success.
Exceptions
Erroron failure.
Since
This function is available since SDL 3.2.0.
See also
Storage.Close
Storage.GetFileSize
Storage.GetSpaceRemaining
Storage.Storage
Storage.ReadFile
Storage.Ready
Storage.WriteFile

◆ ReadFile() [1/2]

std::string SDL::Storage::ReadFile ( StringParam  path)
inline

The value of length must match the length of the file exactly; call Storage.GetFileSize() to get this value. This behavior may be relaxed in a future release.

Parameters
paththe relative path of the file to read.
Returns
true if the file was read or false on failure; call GetError() for more information.
Since
This function is available since SDL 3.2.0.
See also
Storage.GetFileSize
Storage.Ready
Storage.WriteFile

◆ ReadFile() [2/2]

bool SDL::Storage::ReadFile ( StringParam  path,
TargetBytes  destination 
)
inline

The value of length must match the length of the file exactly; call Storage.GetFileSize() to get this value. This behavior may be relaxed in a future release.

Parameters
paththe relative path of the file to read.
destinationa client-provided buffer to read the file into.
Returns
true if the file was read or false on failure; call GetError() for more information.
Since
This function is available since SDL 3.2.0.
See also
Storage.GetFileSize
Storage.Ready
Storage.WriteFile

◆ ReadFileAs()

template<class T >
std::vector< T > SDL::Storage::ReadFileAs ( StringParam  path)
inline

The value of length must match the length of the file exactly; call Storage.GetFileSize() to get this value. This behavior may be relaxed in a future release.

Parameters
paththe relative path of the file to read.
Returns
the content if the file was read or empty string on failure; call GetError() for more information.
Since
This function is available since SDL 3.2.0.
See also
Storage.GetFileSize
Storage.Ready
Storage.WriteFile

◆ ReadStorageFile() [1/2]

std::string SDL::ReadStorageFile ( StorageParam  storage,
StringParam  path 
)
inline
Parameters
storagea storage container to read from.
paththe relative path of the file to read.
Returns
the content if the file was read.
Exceptions
Erroron failure.
Since
This function is available since SDL 3.2.0.
See also
Storage.GetFileSize
Storage.Ready
Storage.WriteFile

◆ ReadStorageFile() [2/2]

bool SDL::ReadStorageFile ( StorageParam  storage,
StringParam  path,
TargetBytes  destination 
)
inline
Parameters
storagea storage container to read from.
paththe relative path of the file to read.
destinationa client-provided buffer to read the file into.
Returns
true if the file was read or false on failure; call GetError() for more information.
Since
This function is available since SDL 3.2.0.
See also
Storage.GetFileSize
Storage.Ready
Storage.WriteFile

◆ ReadStorageFileAs()

template<class T >
std::vector< T > SDL::ReadStorageFileAs ( StorageParam  storage,
StringParam  path 
)
inline
Parameters
storagea storage container to read from.
paththe relative path of the file to read.
Returns
the content if the file was read.
Exceptions
Erroron failure.
Since
This function is available since SDL 3.2.0.
See also
Storage.GetFileSize
Storage.Ready
Storage.WriteFile

◆ Ready()

bool SDL::Storage::Ready ( )
inline

This function should be called in regular intervals until it returns true - however, it is not recommended to spinwait on this call, as the backend may depend on a synchronous message loop. You might instead poll this in your game's main loop while processing events and drawing a loading screen.

Returns
true if the container is ready, false otherwise.
Since
This function is available since SDL 3.2.0.

◆ RemovePath()

void SDL::Storage::RemovePath ( StringParam  path)
inline
Parameters
paththe path of the directory to enumerate.
Exceptions
Erroron failure.
Since
This function is available since SDL 3.2.0.
See also
Storage.Ready

◆ RemoveStoragePath()

void SDL::RemoveStoragePath ( StorageParam  storage,
StringParam  path 
)
inline
Parameters
storagea storage container.
paththe path of the directory to enumerate.
Exceptions
Erroron failure.
Since
This function is available since SDL 3.2.0.
See also
Storage.Ready

◆ RenamePath()

void SDL::Storage::RenamePath ( StringParam  oldpath,
StringParam  newpath 
)
inline
Parameters
oldpaththe old path.
newpaththe new path.
Exceptions
Erroron failure.
Since
This function is available since SDL 3.2.0.
See also
Storage.Ready

◆ RenameStoragePath()

void SDL::RenameStoragePath ( StorageParam  storage,
StringParam  oldpath,
StringParam  newpath 
)
inline
Parameters
storagea storage container.
oldpaththe old path.
newpaththe new path.
Exceptions
Erroron failure.
Since
This function is available since SDL 3.2.0.
See also
Storage.Ready

◆ StorageReady()

bool SDL::StorageReady ( StorageParam  storage)
inline

This function should be called in regular intervals until it returns true - however, it is not recommended to spinwait on this call, as the backend may depend on a synchronous message loop. You might instead poll this in your game's main loop while processing events and drawing a loading screen.

Parameters
storagea storage container to query.
Returns
true if the container is ready, false otherwise.
Since
This function is available since SDL 3.2.0.

◆ WriteFile()

void SDL::Storage::WriteFile ( StringParam  path,
SourceBytes  source 
)
inline
Parameters
paththe relative path of the file to write.
sourcea client-provided buffer to write from.
Exceptions
Erroron failure.
Since
This function is available since SDL 3.2.0.
See also
Storage.GetSpaceRemaining
Storage.ReadFile
Storage.Ready

◆ WriteStorageFile()

void SDL::WriteStorageFile ( StorageParam  storage,
StringParam  path,
SourceBytes  source 
)
inline
Parameters
storagea storage container to write to.
paththe relative path of the file to write.
sourcea client-provided buffer to write from.
Exceptions
Erroron failure.
Since
This function is available since SDL 3.2.0.
See also
Storage.GetSpaceRemaining
Storage.ReadFile
Storage.Ready