physfs_platform_emscripten.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Emscripten support routines for PhysicsFS.
  3. *
  4. * Please see the file LICENSE.txt in the source's root directory.
  5. *
  6. * This file written by Ryan C. Gordon.
  7. */
  8. #define __PHYSICSFS_INTERNAL__
  9. #include "physfs_platforms.h"
  10. #ifdef PHYSFS_PLATFORM_EMSCRIPTEN
  11. #include "physfs_internal.h"
  12. int __PHYSFS_platformInit(const char *argv0)
  13. {
  14. return 1; /* always succeed. */
  15. } /* __PHYSFS_platformInit */
  16. void __PHYSFS_platformDeinit(void)
  17. {
  18. /* no-op */
  19. } /* __PHYSFS_platformDeinit */
  20. void __PHYSFS_platformDetectAvailableCDs(PHYSFS_StringCallback cb, void *data)
  21. {
  22. /* never CD-ROMs on Emscripten. */
  23. } /* __PHYSFS_platformDetectAvailableCDs */
  24. char *__PHYSFS_platformCalcBaseDir(const char *argv0)
  25. {
  26. return __PHYSFS_strdup("/");
  27. } /* __PHYSFS_platformCalcBaseDir */
  28. char *__PHYSFS_platformCalcPrefDir(const char *org, const char *app)
  29. {
  30. #ifndef PHYSFS_EMSCRIPTEN_STORAGE_PATH
  31. /* historically, this is where Emscripten chose by default, since it was
  32. using the Unix codepath, so we'll keep it. */
  33. #define PHYSFS_EMSCRIPTEN_STORAGE_PATH "/home/web_user/.local/share"
  34. #endif
  35. const char *deflt = PHYSFS_EMSCRIPTEN_STORAGE_PATH;
  36. const char *envr = getenv("XDG_DATA_HOME"); /* check this just in case the app overrode it when we used the Unix code... */
  37. const char *base = envr ? envr : deflt;
  38. const size_t len = strlen(base) + strlen(app) + 3;
  39. char *retval = (char *) allocator.Malloc(len);
  40. BAIL_IF(!retval, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
  41. snprintf(retval, len, "%s/%s/", base, app);
  42. return retval;
  43. } /* __PHYSFS_platformCalcPrefDir */
  44. #endif /* PHYSFS_PLATFORM_EMSCRIPTEN */
  45. /* end of physfs_platform_emscripten.c ... */