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"
303 bool Ready()
const {
return SDL_StorageReady(
get()); }
319 if (Uint64 length; SDL_GetStorageFileSize(
get(), path, &length)) {
346 if (!sz || *sz == 0)
return {};
347 std::string buffer(*sz, 0);
348 if (
ReadFile(std::move(path), buffer))
return buffer;
373 return SDL_ReadStorageFile(
399 if (!sz || *sz == 0)
return {};
400 std::vector<T> buffer(*sz /
sizeof(T) + (*sz %
sizeof(T) ? 1 : 0), 0);
401 if (
ReadFile(std::move(path), {buffer.data(), *sz}))
return buffer;
450 r.emplace_back(fname);
485 [](
void* userdata,
const char* dirname,
const char* fname) {
487 return cb(dirname, fname);
522 CheckError(SDL_EnumerateStorageDirectory(
get(), path, callback, userdata));
585 if (
PathInfo info; SDL_GetStoragePathInfo(
get(), path, &info)) {
603 return SDL_GetStorageSpaceRemaining(
get());
645 CheckError(SDL_GlobStorageDirectory(
get(), path, pattern, flags, &count));
662 static void reset(SDL_Storage* resource)
Base class for SDL memory allocated array wrap.
Definition SDL3pp_ownPtr.h:43
RESOURCE release()
Returns reference and reset this.
Definition SDL3pp_resource.h:178
Implement shared ownership for a resource.
Definition SDL3pp_resource.h:283
Implement unique ownership for a resource.
Definition SDL3pp_resource.h:226
constexpr ResourceUnique(std::nullptr_t=nullptr)
Default constructor.
Definition SDL3pp_resource.h:231
void reset()
Resets the value, destroying the resource if not nullptr.
Definition SDL3pp_resource.h:265
A dumb pointer to resource.
Definition SDL3pp_resource.h:197
constexpr ResourceUnsafe()=default
Default constructor.
Implement weak ownership for a resource.
Definition SDL3pp_resource.h:328
A SDL managed resource.
Definition SDL3pp_resource.h:29
constexpr Resource(T resource={})
Constructs from the underlying resource.
Definition SDL3pp_resource.h:37
constexpr SDL_Storage * get() const
Return contained resource;.
Definition SDL3pp_resource.h:76
Helpers to use C++ strings parameters.
Definition SDL3pp_strings.h:43
constexpr const char * c_str() const
Converts to a null terminated C string.
Definition SDL3pp_strings.h:124
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition SDL3pp_error.h:206
std::function< EnumerationResult(const char *dirname, const char *fname)> EnumerateDirectoryCB
Callback for directory enumeration.
Definition SDL3pp_filesystem.h:476
constexpr EnumerationResult ENUM_CONTINUE
Value that requests that enumeration continue.
Definition SDL3pp_filesystem.h:412
SDL_EnumerateDirectoryCallback EnumerateDirectoryCallback
Callback for directory enumeration.
Definition SDL3pp_filesystem.h:449
Uint32 GlobFlags
Flags for path matching.
Definition SDL3pp_filesystem.h:380
SDL_StorageInterface StorageInterface
Function interface for Storage.
Definition SDL3pp_storage.h:272
ResourceShared< Storage > StorageShared
Handle to a shared storage.
Definition SDL3pp_storage.h:244
StorageShared share()
Move this storage into a StorageShared.
Definition SDL3pp_storage.h:808
the main namespace where all SDL3pp public functions and types live
Definition SDL3pp_assert.h:7
Information about a path on the filesystem.
Definition SDL3pp_filesystem.h:346
SDL properties ID.
Definition SDL3pp_properties.h:209
Source byte stream.
Definition SDL3pp_strings.h:239
size_t size_bytes
The size in bytes.
Definition SDL3pp_strings.h:241
const void * data
The data copied from.
Definition SDL3pp_strings.h:240
An abstract interface for filesystem access.
Definition SDL3pp_storage.h:288
std::vector< Path > EnumerateDirectory(StringParam path)
Enumerate a directory.
Definition SDL3pp_storage.h:446
void EnumerateDirectory(StringParam path, EnumerateDirectoryCB callback)
Enumerate a directory in a storage container through a callback function.
Definition SDL3pp_storage.h:481
static void reset(SDL_Storage *resource)
Closes and frees a storage container.
Definition SDL3pp_storage.h:662
bool Ready() const
Checks if the storage container is ready to use.
Definition SDL3pp_storage.h:303
void RemovePath(StringParam path)
Remove a file or an empty directory in a writable storage container.
Definition SDL3pp_storage.h:535
PathInfo GetPathInfo(StringParam path) const
Get information about a filesystem path in a storage container.
Definition SDL3pp_storage.h:583
OwnArray< char * > GlobDirectory(StringParam path, StringParam pattern, GlobFlags flags)
Enumerate a directory tree, filtered by pattern, and return a list.
Definition SDL3pp_storage.h:639
std::string ReadFile(StringParam path) const
Synchronously read a file from a storage container into a client-provided buffer.
Definition SDL3pp_storage.h:343
bool ReadFile(StringParam path, TargetBytes destination) const
Synchronously read a file from a storage container into a client-provided buffer.
Definition SDL3pp_storage.h:371
std::optional< Uint64 > GetFileSize(StringParam path) const
Query the size of a file within a storage container.
Definition SDL3pp_storage.h:317
Uint64 GetSpaceRemaining() const
Queries the remaining space in a storage container.
Definition SDL3pp_storage.h:601
void CopyFile(StringParam oldpath, StringParam newpath)
Copy a file in a writable storage container.
Definition SDL3pp_storage.h:567
void EnumerateDirectory(StringParam path, EnumerateDirectoryCallback callback, void *userdata)
Enumerate a directory in a storage container through a callback function.
Definition SDL3pp_storage.h:518
void WriteFile(StringParam path, SourceBytes source)
Synchronously write a file from client memory into a storage container.
Definition SDL3pp_storage.h:418
void CreateDirectory(StringParam path)
Create a directory in a writable storage container.
Definition SDL3pp_storage.h:433
void RenamePath(StringParam oldpath, StringParam newpath)
Rename a file or directory in a writable storage container.
Definition SDL3pp_storage.h:551
std::vector< T > ReadFileAs(StringParam path) const
Synchronously read a file from a storage container into a client-provided buffer.
Definition SDL3pp_storage.h:396
Unsafe Handle to storage.
Definition SDL3pp_storage.h:823
constexpr StorageUnsafe(Storage &&other)
Constructs StorageUnsafe from Storage.
Definition SDL3pp_storage.h:829
Handle to an owned storage.
Definition SDL3pp_storage.h:676
static Storage Open(const StorageInterface &iface, void *userdata)
Opens up a container using a client-provided storage interface.
Definition SDL3pp_storage.h:782
static Storage OpenUser(StringParam org, StringParam app, PropertiesRef props)
Opens up a container for a user's unique read/write filesystem.
Definition SDL3pp_storage.h:723
void Close()
Closes and frees a storage container.
Definition SDL3pp_storage.h:799
static Storage OpenFile(StringParam path)
Opens up a container for local filesystem storage.
Definition SDL3pp_storage.h:750
static Storage OpenTitle(StringParam override, PropertiesRef props)
Opens up a read-only container for the application's filesystem.
Definition SDL3pp_storage.h:694
Target byte stream.
Definition SDL3pp_strings.h:305
size_t size_bytes
The size in bytes.
Definition SDL3pp_strings.h:307
void * data
The address to have data copied to it.
Definition SDL3pp_strings.h:306