1#ifndef SDL3PP_STORAGE_H_
2#define SDL3PP_STORAGE_H_
4#include <SDL3/SDL_storage.h>
5#include "SDL3pp_filesystem.h"
6#include "SDL3pp_properties.h"
7#include "SDL3pp_stdinc.h"
747 return Storage(std::move(
override), props);
798 return Storage(std::move(org), std::move(app), props);
825 return Storage(std::move(path));
857 return Storage(iface, userdata);
878 return SDL_CloseStorage(storage);
898 return SDL_StorageReady(storage);
919 if (
Uint64 length; SDL_GetStorageFileSize(storage, path, &length)) {
954 return SDL_ReadStorageFile(
976 if (!sz || *sz == 0)
return {};
977 std::string buffer(*sz, 0);
1011 if (!sz || *sz == 0)
return {};
1012 std::vector<T> buffer(*sz /
sizeof(T) + (*sz %
sizeof(T) ? 1 : 0), 0);
1013 CheckError(ReadFile(std::move(path), {buffer.data(), *sz}));
1042 SDL_WriteStorageFile(storage, path, source.
data(), source.
size_bytes()));
1063 CheckError(SDL_CreateStorageDirectory(storage, path));
1100 CheckError(SDL_EnumerateStorageDirectory(storage, path, callback, userdata));
1133 [](
void* userdata,
const char* dirname,
const char* fname) {
1135 return cb(dirname, fname);
1166 std::vector<Path> r;
1168 storage, std::move(path), [&](
const char*,
const char* fname) {
1169 r.emplace_back(fname);
1206 CheckError(SDL_RemoveStoragePath(storage, path));
1230 CheckError(SDL_RenameStoragePath(storage, oldpath, newpath));
1254 CheckError(SDL_CopyStorageFile(storage, oldpath, newpath));
1276 if (
PathInfo info; SDL_GetStoragePathInfo(storage, path, &info)) {
1300 return SDL_GetStorageSpaceRemaining(storage);
1348 CheckError(SDL_GlobStorageDirectory(storage, path, pattern, flags, &count));
1357 get(), std::move(path), std::move(pattern), flags);
Base class for SDL memory allocated array wrap.
Definition SDL3pp_ownPtr.h:44
constexpr RawPointer get() const noexcept
Definition SDL3pp_resource.h:53
constexpr RawPointer release() noexcept
Definition SDL3pp_resource.h:56
constexpr ResourceBase(RawPointer resource)
Constructs from resource pointer.
Definition SDL3pp_resource.h:29
Source byte stream.
Definition SDL3pp_strings.h:237
constexpr size_t size_bytes() const
Retrieves contained size in bytes.
Definition SDL3pp_strings.h:301
constexpr const char * data() const
Retrieves contained data.
Definition SDL3pp_strings.h:304
Helpers to use C++ strings parameters.
Definition SDL3pp_strings.h:43
const char * c_str() const
Converts to a null terminated C string.
Definition SDL3pp_strings.h:118
Target byte stream.
Definition SDL3pp_strings.h:323
constexpr char * data() const
Retrieves contained data.
Definition SDL3pp_strings.h:409
constexpr size_t size_bytes() const
Retrieves contained size in bytes.
Definition SDL3pp_strings.h:406
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition SDL3pp_error.h:199
constexpr EnumerationResult ENUM_CONTINUE
Value that requests that enumeration continue.
Definition SDL3pp_filesystem.h:426
Uint32 GlobFlags
Flags for path matching.
Definition SDL3pp_filesystem.h:392
EnumerationResult( SDLCALL *)(void *userdata, const char *dirname, const char *fname) EnumerateDirectoryCallback
Callback for directory enumeration.
Definition SDL3pp_filesystem.h:459
std::function< EnumerationResult(const char *dirname, const char *fname)> EnumerateDirectoryCB
Callback for directory enumeration.
Definition SDL3pp_filesystem.h:487
ResourceRef< Properties > PropertiesRef
Reference for Properties.
Definition SDL3pp_properties.h:54
::Uint64 Uint64
An unsigned 64-bit integer type.
Definition SDL3pp_stdinc.h:320
Uint64 GetStorageSpaceRemaining(StorageRef storage)
Queries the remaining space in a storage container.
Definition SDL3pp_storage.h:1298
void CreateDirectory(StringParam path)
Create a directory in a writable storage container.
Definition SDL3pp_storage.h:1066
bool ReadStorageFile(StorageRef storage, StringParam path, TargetBytes destination)
Synchronously read a file from a storage container into a client-provided buffer.
Definition SDL3pp_storage.h:950
std::vector< T > ReadStorageFileAs(StorageRef storage, StringParam path)
Synchronously read a file from a storage container into a client-provided buffer.
Definition SDL3pp_storage.h:1008
PathInfo GetStoragePathInfo(StorageRef storage, StringParam path)
Get information about a filesystem path in a storage container.
Definition SDL3pp_storage.h:1274
PathInfo GetPathInfo(StringParam path)
Get information about a filesystem path in a storage container.
Definition SDL3pp_storage.h:1282
Storage OpenTitleStorage(StringParam override, PropertiesRef props)
Opens up a read-only container for the application's filesystem.
Definition SDL3pp_storage.h:745
Storage OpenStorage(const StorageInterface &iface, void *userdata)
Opens up a container using a client-provided storage interface.
Definition SDL3pp_storage.h:855
void WriteFile(StringParam path, SourceBytes source)
Synchronously write a file from client memory into a storage container.
Definition SDL3pp_storage.h:1045
Uint64 GetSpaceRemaining()
Queries the remaining space in a storage container.
Definition SDL3pp_storage.h:1303
OwnArray< char * > GlobDirectory(StringParam path, StringParam pattern, GlobFlags flags)
Enumerate a directory tree, filtered by pattern, and return a list.
Definition SDL3pp_storage.h:1352
Storage OpenUserStorage(StringParam org, StringParam app, PropertiesRef props)
Opens up a container for a user's unique read/write filesystem.
Definition SDL3pp_storage.h:794
std::vector< T > ReadFileAs(StringParam path)
Synchronously read a file from a storage container into a client-provided buffer.
Definition SDL3pp_storage.h:1018
bool ReadFile(StringParam path, TargetBytes destination)
Synchronously read a file from a storage container into a client-provided buffer.
Definition SDL3pp_storage.h:982
std::optional< Uint64 > GetFileSize(StringParam path)
Query the size of a file within a storage container.
Definition SDL3pp_storage.h:925
bool Close()
Closes and frees a storage container.
Definition SDL3pp_storage.h:881
void RemovePath(StringParam path)
Remove a file or an empty directory in a writable storage container.
Definition SDL3pp_storage.h:1209
void RemoveStoragePath(StorageRef storage, StringParam path)
Remove a file or an empty directory in a writable storage container.
Definition SDL3pp_storage.h:1204
SDL_Storage * StorageRaw
Alias to raw representation for Storage.
Definition SDL3pp_storage.h:230
void CopyStorageFile(StorageRef storage, StringParam oldpath, StringParam newpath)
Copy a file in a writable storage container.
Definition SDL3pp_storage.h:1250
std::optional< Uint64 > GetStorageFileSize(StorageRef storage, StringParam path)
Query the size of a file within a storage container.
Definition SDL3pp_storage.h:916
bool Ready()
Checks if the storage container is ready to use.
Definition SDL3pp_storage.h:901
SDL_StorageInterface StorageInterface
Function interface for Storage.
Definition SDL3pp_storage.h:255
void RenamePath(StringParam oldpath, StringParam newpath)
Rename a file or directory in a writable storage container.
Definition SDL3pp_storage.h:1233
bool StorageReady(StorageRef storage)
Checks if the storage container is ready to use.
Definition SDL3pp_storage.h:896
Storage OpenFileStorage(StringParam path)
Opens up a container for local filesystem storage.
Definition SDL3pp_storage.h:823
void CreateStorageDirectory(StorageRef storage, StringParam path)
Create a directory in a writable storage container.
Definition SDL3pp_storage.h:1061
void CopyFile(StringParam oldpath, StringParam newpath)
Copy a file in a writable storage container.
Definition SDL3pp_storage.h:1257
bool CloseStorage(StorageRaw storage)
Closes and frees a storage container.
Definition SDL3pp_storage.h:876
void WriteStorageFile(StorageRef storage, StringParam path, SourceBytes source)
Synchronously write a file from client memory into a storage container.
Definition SDL3pp_storage.h:1037
void EnumerateDirectory(StringParam path, EnumerateDirectoryCallback callback, void *userdata)
Enumerate a directory in a storage container through a callback function.
Definition SDL3pp_storage.h:1175
void RenameStoragePath(StorageRef storage, StringParam oldpath, StringParam newpath)
Rename a file or directory in a writable storage container.
Definition SDL3pp_storage.h:1226
OwnArray< char * > GlobStorageDirectory(StorageRef storage, StringParam path, StringParam pattern, GlobFlags flags)
Enumerate a directory tree, filtered by pattern, and return a list.
Definition SDL3pp_storage.h:1341
ResourceRef< Storage > StorageRef
Reference for Storage.
Definition SDL3pp_storage.h:237
void EnumerateStorageDirectory(StorageRef storage, StringParam path, EnumerateDirectoryCallback callback, void *userdata)
Enumerate a directory in a storage container through a callback function.
Definition SDL3pp_storage.h:1095
Main include header for the SDL3pp library.
Information about a path on the filesystem.
Definition SDL3pp_filesystem.h:352
A non-owning reference wrapper for a given resource.
Definition SDL3pp_resource.h:156
An abstract interface for filesystem access.
Definition SDL3pp_storage.h:269
constexpr Storage(const Storage &other)=delete
Copy constructor.
constexpr ResourceBase(RawPointer resource)
Constructs from resource pointer.
Definition SDL3pp_resource.h:29
Storage & operator=(const Storage &other)=delete
Assignment operator.
~Storage()
Destructor.
Definition SDL3pp_storage.h:398
constexpr Storage(Storage &&other) noexcept
Move constructor.
Definition SDL3pp_storage.h:288
constexpr Storage(StorageRaw resource) noexcept
Constructs from raw Storage.
Definition SDL3pp_storage.h:279
constexpr Storage & operator=(Storage &&other) noexcept
Assignment operator.
Definition SDL3pp_storage.h:401