SDL_storage.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. /**
  19. * # CategoryStorage
  20. *
  21. * The storage API is a high-level API designed to abstract away the
  22. * portability issues that come up when using something lower-level (in SDL's
  23. * case, this sits on top of the [Filesystem](CategoryFilesystem) and
  24. * [IOStream](CategoryIOStream) subsystems). It is significantly more
  25. * restrictive than a typical filesystem API, for a number of reasons:
  26. *
  27. * 1. **What to Access:** A common pitfall with existing filesystem APIs is
  28. * the assumption that all storage is monolithic. However, many other
  29. * platforms (game consoles in particular) are more strict about what _type_
  30. * of filesystem is being accessed; for example, game content and user data
  31. * are usually two separate storage devices with entirely different
  32. * characteristics (and possibly different low-level APIs altogether!).
  33. *
  34. * 2. **How to Access:** Another common mistake is applications assuming that
  35. * all storage is universally writeable - again, many platforms treat game
  36. * content and user data as two separate storage devices, and only user data
  37. * is writeable while game content is read-only.
  38. *
  39. * 3. **When to Access:** The most common portability issue with filesystem
  40. * access is _timing_ - you cannot always assume that the storage device is
  41. * always accessible all of the time, nor can you assume that there are no
  42. * limits to how long you have access to a particular device.
  43. *
  44. * Consider the following example:
  45. *
  46. * ```c
  47. * void ReadGameData(void)
  48. * {
  49. * extern char** fileNames;
  50. * extern size_t numFiles;
  51. * for (size_t i = 0; i < numFiles; i += 1) {
  52. * FILE *data = fopen(fileNames[i], "rwb");
  53. * if (data == NULL) {
  54. * // Something bad happened!
  55. * } else {
  56. * // A bunch of stuff happens here
  57. * fclose(data);
  58. * }
  59. * }
  60. * }
  61. *
  62. * void ReadSave(void)
  63. * {
  64. * FILE *save = fopen("saves/save0.sav", "rb");
  65. * if (save == NULL) {
  66. * // Something bad happened!
  67. * } else {
  68. * // A bunch of stuff happens here
  69. * fclose(save);
  70. * }
  71. * }
  72. *
  73. * void WriteSave(void)
  74. * {
  75. * FILE *save = fopen("saves/save0.sav", "wb");
  76. * if (save == NULL) {
  77. * // Something bad happened!
  78. * } else {
  79. * // A bunch of stuff happens here
  80. * fclose(save);
  81. * }
  82. * }
  83. * ```
  84. *
  85. * Going over the bullet points again:
  86. *
  87. * 1. **What to Access:** This code accesses a global filesystem; game data
  88. * and saves are all presumed to be in the current working directory (which
  89. * may or may not be the game's installation folder!).
  90. *
  91. * 2. **How to Access:** This code assumes that content paths are writeable,
  92. * and that save data is also writeable despite being in the same location as
  93. * the game data.
  94. *
  95. * 3. **When to Access:** This code assumes that they can be called at any
  96. * time, since the filesystem is always accessible and has no limits on how
  97. * long the filesystem is being accessed.
  98. *
  99. * Due to these assumptions, the filesystem code is not portable and will fail
  100. * under these common scenarios:
  101. *
  102. * - The game is installed on a device that is read-only, both content loading
  103. * and game saves will fail or crash outright
  104. * - Game/User storage is not implicitly mounted, so no files will be found
  105. * for either scenario when a platform requires explicitly mounting
  106. * filesystems
  107. * - Save data may not be safe since the I/O is not being flushed or
  108. * validated, so an error occurring elsewhere in the program may result in
  109. * missing/corrupted save data
  110. *
  111. * When using SDL_Storage, these types of problems are virtually impossible to
  112. * trip over:
  113. *
  114. * ```c
  115. * void ReadGameData(void)
  116. * {
  117. * extern char** fileNames;
  118. * extern size_t numFiles;
  119. *
  120. * SDL_Storage *title = SDL_OpenTitleStorage(NULL, 0);
  121. * if (title == NULL) {
  122. * // Something bad happened!
  123. * }
  124. * while (!SDL_StorageReady(title)) {
  125. * SDL_Delay(1);
  126. * }
  127. *
  128. * for (size_t i = 0; i < numFiles; i += 1) {
  129. * void* dst;
  130. * Uint64 dstLen = 0;
  131. *
  132. * if (SDL_GetStorageFileSize(title, fileNames[i], &dstLen) && dstLen > 0) {
  133. * dst = SDL_malloc(dstLen);
  134. * if (SDL_ReadStorageFile(title, fileNames[i], dst, dstLen)) {
  135. * // A bunch of stuff happens here
  136. * } else {
  137. * // Something bad happened!
  138. * }
  139. * SDL_free(dst);
  140. * } else {
  141. * // Something bad happened!
  142. * }
  143. * }
  144. *
  145. * SDL_CloseStorage(title);
  146. * }
  147. *
  148. * void ReadSave(void)
  149. * {
  150. * SDL_Storage *user = SDL_OpenUserStorage("libsdl", "Storage Example", 0);
  151. * if (user == NULL) {
  152. * // Something bad happened!
  153. * }
  154. * while (!SDL_StorageReady(user)) {
  155. * SDL_Delay(1);
  156. * }
  157. *
  158. * Uint64 saveLen = 0;
  159. * if (SDL_GetStorageFileSize(user, "save0.sav", &saveLen) && saveLen > 0) {
  160. * void* dst = SDL_malloc(saveLen);
  161. * if (SDL_ReadStorageFile(user, "save0.sav", dst, saveLen)) {
  162. * // A bunch of stuff happens here
  163. * } else {
  164. * // Something bad happened!
  165. * }
  166. * SDL_free(dst);
  167. * } else {
  168. * // Something bad happened!
  169. * }
  170. *
  171. * SDL_CloseStorage(user);
  172. * }
  173. *
  174. * void WriteSave(void)
  175. * {
  176. * SDL_Storage *user = SDL_OpenUserStorage("libsdl", "Storage Example", 0);
  177. * if (user == NULL) {
  178. * // Something bad happened!
  179. * }
  180. * while (!SDL_StorageReady(user)) {
  181. * SDL_Delay(1);
  182. * }
  183. *
  184. * extern void *saveData; // A bunch of stuff happened here...
  185. * extern Uint64 saveLen;
  186. * if (!SDL_WriteStorageFile(user, "save0.sav", saveData, saveLen)) {
  187. * // Something bad happened!
  188. * }
  189. *
  190. * SDL_CloseStorage(user);
  191. * }
  192. * ```
  193. *
  194. * Note the improvements that SDL_Storage makes:
  195. *
  196. * 1. **What to Access:** This code explicitly reads from a title or user
  197. * storage device based on the context of the function.
  198. *
  199. * 2. **How to Access:** This code explicitly uses either a read or write
  200. * function based on the context of the function.
  201. *
  202. * 3. **When to Access:** This code explicitly opens the device when it needs
  203. * to, and closes it when it is finished working with the filesystem.
  204. *
  205. * The result is an application that is significantly more robust against the
  206. * increasing demands of platforms and their filesystems!
  207. *
  208. * A publicly available example of an SDL_Storage backend is the
  209. * [Steam Cloud](https://partner.steamgames.com/doc/features/cloud)
  210. * backend - you can initialize Steamworks when starting the program, and then
  211. * SDL will recognize that Steamworks is initialized and automatically use
  212. * ISteamRemoteStorage when the application opens user storage. More
  213. * importantly, when you _open_ storage it knows to begin a "batch" of
  214. * filesystem operations, and when you _close_ storage it knows to end and
  215. * flush the batch. This is used by Steam to support
  216. * [Dynamic Cloud Sync](https://steamcommunity.com/groups/steamworks/announcements/detail/3142949576401813670)
  217. * ; users can save data on one PC, put the device to sleep, and then continue
  218. * playing on another PC (and vice versa) with the save data fully
  219. * synchronized across all devices, allowing for a seamless experience without
  220. * having to do full restarts of the program.
  221. *
  222. * ## Notes on valid paths
  223. *
  224. * All paths in the Storage API use Unix-style path separators ('/'). Using a
  225. * different path separator will not work, even if the underlying platform
  226. * would otherwise accept it. This is to keep code using the Storage API
  227. * portable between platforms and Storage implementations and simplify app
  228. * code.
  229. *
  230. * Paths with relative directories ("." and "..") are forbidden by the Storage
  231. * API.
  232. *
  233. * All valid UTF-8 strings (discounting the NULL terminator character and the
  234. * '/' path separator) are usable for filenames, however, an underlying
  235. * Storage implementation may not support particularly strange sequences and
  236. * refuse to create files with those names, etc.
  237. */
  238. #ifndef SDL_storage_h_
  239. #define SDL_storage_h_
  240. #include <SDL3/SDL_stdinc.h>
  241. #include <SDL3/SDL_error.h>
  242. #include <SDL3/SDL_filesystem.h>
  243. #include <SDL3/SDL_properties.h>
  244. #include <SDL3/SDL_begin_code.h>
  245. /* Set up for C function definitions, even when using C++ */
  246. #ifdef __cplusplus
  247. extern "C" {
  248. #endif
  249. /**
  250. * Function interface for SDL_Storage.
  251. *
  252. * Apps that want to supply a custom implementation of SDL_Storage will fill
  253. * in all the functions in this struct, and then pass it to SDL_OpenStorage to
  254. * create a custom SDL_Storage object.
  255. *
  256. * It is not usually necessary to do this; SDL provides standard
  257. * implementations for many things you might expect to do with an SDL_Storage.
  258. *
  259. * This structure should be initialized using SDL_INIT_INTERFACE()
  260. *
  261. * \since This struct is available since SDL 3.2.0.
  262. *
  263. * \sa SDL_INIT_INTERFACE
  264. */
  265. typedef struct SDL_StorageInterface
  266. {
  267. /* The version of this interface */
  268. Uint32 version;
  269. /* Called when the storage is closed */
  270. bool (SDLCALL *close)(void *userdata);
  271. /* Optional, returns whether the storage is currently ready for access */
  272. bool (SDLCALL *ready)(void *userdata);
  273. /* Enumerate a directory, optional for write-only storage */
  274. bool (SDLCALL *enumerate)(void *userdata, const char *path, SDL_EnumerateDirectoryCallback callback, void *callback_userdata);
  275. /* Get path information, optional for write-only storage */
  276. bool (SDLCALL *info)(void *userdata, const char *path, SDL_PathInfo *info);
  277. /* Read a file from storage, optional for write-only storage */
  278. bool (SDLCALL *read_file)(void *userdata, const char *path, void *destination, Uint64 length);
  279. /* Write a file to storage, optional for read-only storage */
  280. bool (SDLCALL *write_file)(void *userdata, const char *path, const void *source, Uint64 length);
  281. /* Create a directory, optional for read-only storage */
  282. bool (SDLCALL *mkdir)(void *userdata, const char *path);
  283. /* Remove a file or empty directory, optional for read-only storage */
  284. bool (SDLCALL *remove)(void *userdata, const char *path);
  285. /* Rename a path, optional for read-only storage */
  286. bool (SDLCALL *rename)(void *userdata, const char *oldpath, const char *newpath);
  287. /* Copy a file, optional for read-only storage */
  288. bool (SDLCALL *copy)(void *userdata, const char *oldpath, const char *newpath);
  289. /* Get the space remaining, optional for read-only storage */
  290. Uint64 (SDLCALL *space_remaining)(void *userdata);
  291. } SDL_StorageInterface;
  292. /* Check the size of SDL_StorageInterface
  293. *
  294. * If this assert fails, either the compiler is padding to an unexpected size,
  295. * or the interface has been updated and this should be updated to match and
  296. * the code using this interface should be updated to handle the old version.
  297. */
  298. SDL_COMPILE_TIME_ASSERT(SDL_StorageInterface_SIZE,
  299. (sizeof(void *) == 4 && sizeof(SDL_StorageInterface) == 48) ||
  300. (sizeof(void *) == 8 && sizeof(SDL_StorageInterface) == 96));
  301. /**
  302. * An abstract interface for filesystem access.
  303. *
  304. * This is an opaque datatype. One can create this object using standard SDL
  305. * functions like SDL_OpenTitleStorage or SDL_OpenUserStorage, etc, or create
  306. * an object with a custom implementation using SDL_OpenStorage.
  307. *
  308. * \since This struct is available since SDL 3.2.0.
  309. */
  310. typedef struct SDL_Storage SDL_Storage;
  311. /**
  312. * Opens up a read-only container for the application's filesystem.
  313. *
  314. * \param override a path to override the backend's default title root.
  315. * \param props a property list that may contain backend-specific information.
  316. * \returns a title storage container on success or NULL on failure; call
  317. * SDL_GetError() for more information.
  318. *
  319. * \since This function is available since SDL 3.2.0.
  320. *
  321. * \sa SDL_CloseStorage
  322. * \sa SDL_GetStorageFileSize
  323. * \sa SDL_OpenUserStorage
  324. * \sa SDL_ReadStorageFile
  325. */
  326. extern SDL_DECLSPEC SDL_Storage * SDLCALL SDL_OpenTitleStorage(const char *override, SDL_PropertiesID props);
  327. /**
  328. * Opens up a container for a user's unique read/write filesystem.
  329. *
  330. * While title storage can generally be kept open throughout runtime, user
  331. * storage should only be opened when the client is ready to read/write files.
  332. * This allows the backend to properly batch file operations and flush them
  333. * when the container has been closed; ensuring safe and optimal save I/O.
  334. *
  335. * \param org the name of your organization.
  336. * \param app the name of your application.
  337. * \param props a property list that may contain backend-specific information.
  338. * \returns a user storage container on success or NULL on failure; call
  339. * SDL_GetError() for more information.
  340. *
  341. * \since This function is available since SDL 3.2.0.
  342. *
  343. * \sa SDL_CloseStorage
  344. * \sa SDL_GetStorageFileSize
  345. * \sa SDL_GetStorageSpaceRemaining
  346. * \sa SDL_OpenTitleStorage
  347. * \sa SDL_ReadStorageFile
  348. * \sa SDL_StorageReady
  349. * \sa SDL_WriteStorageFile
  350. */
  351. extern SDL_DECLSPEC SDL_Storage * SDLCALL SDL_OpenUserStorage(const char *org, const char *app, SDL_PropertiesID props);
  352. /**
  353. * Opens up a container for local filesystem storage.
  354. *
  355. * This is provided for development and tools. Portable applications should
  356. * use SDL_OpenTitleStorage() for access to game data and
  357. * SDL_OpenUserStorage() for access to user data.
  358. *
  359. * \param path the base path prepended to all storage paths, or NULL for no
  360. * base path.
  361. * \returns a filesystem storage container on success or NULL on failure; call
  362. * SDL_GetError() for more information.
  363. *
  364. * \since This function is available since SDL 3.2.0.
  365. *
  366. * \sa SDL_CloseStorage
  367. * \sa SDL_GetStorageFileSize
  368. * \sa SDL_GetStorageSpaceRemaining
  369. * \sa SDL_OpenTitleStorage
  370. * \sa SDL_OpenUserStorage
  371. * \sa SDL_ReadStorageFile
  372. * \sa SDL_WriteStorageFile
  373. */
  374. extern SDL_DECLSPEC SDL_Storage * SDLCALL SDL_OpenFileStorage(const char *path);
  375. /**
  376. * Opens up a container using a client-provided storage interface.
  377. *
  378. * Applications do not need to use this function unless they are providing
  379. * their own SDL_Storage implementation. If you just need an SDL_Storage, you
  380. * should use the built-in implementations in SDL, like SDL_OpenTitleStorage()
  381. * or SDL_OpenUserStorage().
  382. *
  383. * This function makes a copy of `iface` and the caller does not need to keep
  384. * it around after this call.
  385. *
  386. * \param iface the interface that implements this storage, initialized using
  387. * SDL_INIT_INTERFACE().
  388. * \param userdata the pointer that will be passed to the interface functions.
  389. * \returns a storage container on success or NULL on failure; call
  390. * SDL_GetError() for more information.
  391. *
  392. * \since This function is available since SDL 3.2.0.
  393. *
  394. * \sa SDL_CloseStorage
  395. * \sa SDL_GetStorageFileSize
  396. * \sa SDL_GetStorageSpaceRemaining
  397. * \sa SDL_INIT_INTERFACE
  398. * \sa SDL_ReadStorageFile
  399. * \sa SDL_StorageReady
  400. * \sa SDL_WriteStorageFile
  401. */
  402. extern SDL_DECLSPEC SDL_Storage * SDLCALL SDL_OpenStorage(const SDL_StorageInterface *iface, void *userdata);
  403. /**
  404. * Closes and frees a storage container.
  405. *
  406. * \param storage a storage container to close.
  407. * \returns true if the container was freed with no errors, false otherwise;
  408. * call SDL_GetError() for more information. Even if the function
  409. * returns an error, the container data will be freed; the error is
  410. * only for informational purposes.
  411. *
  412. * \since This function is available since SDL 3.2.0.
  413. *
  414. * \sa SDL_OpenFileStorage
  415. * \sa SDL_OpenStorage
  416. * \sa SDL_OpenTitleStorage
  417. * \sa SDL_OpenUserStorage
  418. */
  419. extern SDL_DECLSPEC bool SDLCALL SDL_CloseStorage(SDL_Storage *storage);
  420. /**
  421. * Checks if the storage container is ready to use.
  422. *
  423. * This function should be called in regular intervals until it returns true -
  424. * however, it is not recommended to spinwait on this call, as the backend may
  425. * depend on a synchronous message loop. You might instead poll this in your
  426. * game's main loop while processing events and drawing a loading screen.
  427. *
  428. * \param storage a storage container to query.
  429. * \returns true if the container is ready, false otherwise.
  430. *
  431. * \since This function is available since SDL 3.2.0.
  432. */
  433. extern SDL_DECLSPEC bool SDLCALL SDL_StorageReady(SDL_Storage *storage);
  434. /**
  435. * Query the size of a file within a storage container.
  436. *
  437. * \param storage a storage container to query.
  438. * \param path the relative path of the file to query.
  439. * \param length a pointer to be filled with the file's length.
  440. * \returns true if the file could be queried or false on failure; call
  441. * SDL_GetError() for more information.
  442. *
  443. * \since This function is available since SDL 3.2.0.
  444. *
  445. * \sa SDL_ReadStorageFile
  446. * \sa SDL_StorageReady
  447. */
  448. extern SDL_DECLSPEC bool SDLCALL SDL_GetStorageFileSize(SDL_Storage *storage, const char *path, Uint64 *length);
  449. /**
  450. * Synchronously read a file from a storage container into a client-provided
  451. * buffer.
  452. *
  453. * The value of `length` must match the length of the file exactly; call
  454. * SDL_GetStorageFileSize() to get this value. This behavior may be relaxed in
  455. * a future release.
  456. *
  457. * \param storage a storage container to read from.
  458. * \param path the relative path of the file to read.
  459. * \param destination a client-provided buffer to read the file into.
  460. * \param length the length of the destination buffer.
  461. * \returns true if the file was read or false on failure; call SDL_GetError()
  462. * for more information.
  463. *
  464. * \since This function is available since SDL 3.2.0.
  465. *
  466. * \sa SDL_GetStorageFileSize
  467. * \sa SDL_StorageReady
  468. * \sa SDL_WriteStorageFile
  469. */
  470. extern SDL_DECLSPEC bool SDLCALL SDL_ReadStorageFile(SDL_Storage *storage, const char *path, void *destination, Uint64 length);
  471. /**
  472. * Synchronously write a file from client memory into a storage container.
  473. *
  474. * \param storage a storage container to write to.
  475. * \param path the relative path of the file to write.
  476. * \param source a client-provided buffer to write from.
  477. * \param length the length of the source buffer.
  478. * \returns true if the file was written or false on failure; call
  479. * SDL_GetError() for more information.
  480. *
  481. * \since This function is available since SDL 3.2.0.
  482. *
  483. * \sa SDL_GetStorageSpaceRemaining
  484. * \sa SDL_ReadStorageFile
  485. * \sa SDL_StorageReady
  486. */
  487. extern SDL_DECLSPEC bool SDLCALL SDL_WriteStorageFile(SDL_Storage *storage, const char *path, const void *source, Uint64 length);
  488. /**
  489. * Create a directory in a writable storage container.
  490. *
  491. * \param storage a storage container.
  492. * \param path the path of the directory to create.
  493. * \returns true on success or false on failure; call SDL_GetError() for more
  494. * information.
  495. *
  496. * \since This function is available since SDL 3.2.0.
  497. *
  498. * \sa SDL_StorageReady
  499. */
  500. extern SDL_DECLSPEC bool SDLCALL SDL_CreateStorageDirectory(SDL_Storage *storage, const char *path);
  501. /**
  502. * Enumerate a directory in a storage container through a callback function.
  503. *
  504. * This function provides every directory entry through an app-provided
  505. * callback, called once for each directory entry, until all results have been
  506. * provided or the callback returns either SDL_ENUM_SUCCESS or
  507. * SDL_ENUM_FAILURE.
  508. *
  509. * This will return false if there was a system problem in general, or if a
  510. * callback returns SDL_ENUM_FAILURE. A successful return means a callback
  511. * returned SDL_ENUM_SUCCESS to halt enumeration, or all directory entries
  512. * were enumerated.
  513. *
  514. * If `path` is NULL, this is treated as a request to enumerate the root of
  515. * the storage container's tree. An empty string also works for this.
  516. *
  517. * \param storage a storage container.
  518. * \param path the path of the directory to enumerate, or NULL for the root.
  519. * \param callback a function that is called for each entry in the directory.
  520. * \param userdata a pointer that is passed to `callback`.
  521. * \returns true on success or false on failure; call SDL_GetError() for more
  522. * information.
  523. *
  524. * \since This function is available since SDL 3.2.0.
  525. *
  526. * \sa SDL_StorageReady
  527. */
  528. extern SDL_DECLSPEC bool SDLCALL SDL_EnumerateStorageDirectory(SDL_Storage *storage, const char *path, SDL_EnumerateDirectoryCallback callback, void *userdata);
  529. /**
  530. * Remove a file or an empty directory in a writable storage container.
  531. *
  532. * \param storage a storage container.
  533. * \param path the path of the directory to enumerate.
  534. * \returns true on success or false on failure; call SDL_GetError() for more
  535. * information.
  536. *
  537. * \since This function is available since SDL 3.2.0.
  538. *
  539. * \sa SDL_StorageReady
  540. */
  541. extern SDL_DECLSPEC bool SDLCALL SDL_RemoveStoragePath(SDL_Storage *storage, const char *path);
  542. /**
  543. * Rename a file or directory in a writable storage container.
  544. *
  545. * \param storage a storage container.
  546. * \param oldpath the old path.
  547. * \param newpath the new path.
  548. * \returns true on success or false on failure; call SDL_GetError() for more
  549. * information.
  550. *
  551. * \since This function is available since SDL 3.2.0.
  552. *
  553. * \sa SDL_StorageReady
  554. */
  555. extern SDL_DECLSPEC bool SDLCALL SDL_RenameStoragePath(SDL_Storage *storage, const char *oldpath, const char *newpath);
  556. /**
  557. * Copy a file in a writable storage container.
  558. *
  559. * \param storage a storage container.
  560. * \param oldpath the old path.
  561. * \param newpath the new path.
  562. * \returns true on success or false on failure; call SDL_GetError() for more
  563. * information.
  564. *
  565. * \since This function is available since SDL 3.2.0.
  566. *
  567. * \sa SDL_StorageReady
  568. */
  569. extern SDL_DECLSPEC bool SDLCALL SDL_CopyStorageFile(SDL_Storage *storage, const char *oldpath, const char *newpath);
  570. /**
  571. * Get information about a filesystem path in a storage container.
  572. *
  573. * \param storage a storage container.
  574. * \param path the path to query.
  575. * \param info a pointer filled in with information about the path, or NULL to
  576. * check for the existence of a file.
  577. * \returns true on success or false if the file doesn't exist, or another
  578. * failure; call SDL_GetError() for more information.
  579. *
  580. * \since This function is available since SDL 3.2.0.
  581. *
  582. * \sa SDL_StorageReady
  583. */
  584. extern SDL_DECLSPEC bool SDLCALL SDL_GetStoragePathInfo(SDL_Storage *storage, const char *path, SDL_PathInfo *info);
  585. /**
  586. * Queries the remaining space in a storage container.
  587. *
  588. * \param storage a storage container to query.
  589. * \returns the amount of remaining space, in bytes.
  590. *
  591. * \since This function is available since SDL 3.2.0.
  592. *
  593. * \sa SDL_StorageReady
  594. * \sa SDL_WriteStorageFile
  595. */
  596. extern SDL_DECLSPEC Uint64 SDLCALL SDL_GetStorageSpaceRemaining(SDL_Storage *storage);
  597. /**
  598. * Enumerate a directory tree, filtered by pattern, and return a list.
  599. *
  600. * Files are filtered out if they don't match the string in `pattern`, which
  601. * may contain wildcard characters `*` (match everything) and `?` (match one
  602. * character). If pattern is NULL, no filtering is done and all results are
  603. * returned. Subdirectories are permitted, and are specified with a path
  604. * separator of '/'. Wildcard characters `*` and `?` never match a path
  605. * separator.
  606. *
  607. * `flags` may be set to SDL_GLOB_CASEINSENSITIVE to make the pattern matching
  608. * case-insensitive.
  609. *
  610. * The returned array is always NULL-terminated, for your iterating
  611. * convenience, but if `count` is non-NULL, on return it will contain the
  612. * number of items in the array, not counting the NULL terminator.
  613. *
  614. * If `path` is NULL, this is treated as a request to enumerate the root of
  615. * the storage container's tree. An empty string also works for this.
  616. *
  617. * \param storage a storage container.
  618. * \param path the path of the directory to enumerate, or NULL for the root.
  619. * \param pattern the pattern that files in the directory must match. Can be
  620. * NULL.
  621. * \param flags `SDL_GLOB_*` bitflags that affect this search.
  622. * \param count on return, will be set to the number of items in the returned
  623. * array. Can be NULL.
  624. * \returns an array of strings on success or NULL on failure; call
  625. * SDL_GetError() for more information. The caller should pass the
  626. * returned pointer to SDL_free when done with it. This is a single
  627. * allocation that should be freed with SDL_free() when it is no
  628. * longer needed.
  629. *
  630. * \threadsafety It is safe to call this function from any thread, assuming
  631. * the `storage` object is thread-safe.
  632. *
  633. * \since This function is available since SDL 3.2.0.
  634. */
  635. extern SDL_DECLSPEC char ** SDLCALL SDL_GlobStorageDirectory(SDL_Storage *storage, const char *path, const char *pattern, SDL_GlobFlags flags, int *count);
  636. /* Ends C function definitions when using C++ */
  637. #ifdef __cplusplus
  638. }
  639. #endif
  640. #include <SDL3/SDL_close_code.h>
  641. #endif /* SDL_storage_h_ */