SDL_storage.h 24 KB

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