apk_filesystem.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright (c) 2012-2014 Daniele Bartolini and individual contributors.
  3. * License: https://github.com/taylor001/crown/blob/master/LICENSE
  4. */
  5. #include "config.h"
  6. #if CROWN_PLATFORM_ANDROID
  7. #include "apk_filesystem.h"
  8. #include "temp_allocator.h"
  9. #include "apk_file.h"
  10. #include "os.h"
  11. #include <sys/types.h>
  12. #include <android/asset_manager.h>
  13. namespace crown
  14. {
  15. ApkFilesystem::ApkFilesystem(AAssetManager* asset_manager)
  16. : _asset_manager(asset_manager)
  17. {
  18. }
  19. File* ApkFilesystem::open(const char* path, FileOpenMode mode)
  20. {
  21. CE_ASSERT_NOT_NULL(path);
  22. CE_ASSERT(mode == FOM_READ, "Cannot open for writing in Android assets folder");
  23. return CE_NEW(default_allocator(), ApkFile)(_asset_manager, path);
  24. }
  25. void ApkFilesystem::close(File* file)
  26. {
  27. CE_ASSERT_NOT_NULL(file);
  28. CE_DELETE(default_allocator(), file);
  29. }
  30. bool ApkFilesystem::exists(const char* path)
  31. {
  32. return false;
  33. }
  34. bool ApkFilesystem::is_directory(const char* path)
  35. {
  36. return true;
  37. }
  38. bool ApkFilesystem::is_file(const char* path)
  39. {
  40. return true;
  41. }
  42. void ApkFilesystem::create_directory(const char* /*path*/)
  43. {
  44. CE_ASSERT(false, "Attempt to create directory in Android assets folder");
  45. }
  46. void ApkFilesystem::delete_directory(const char* /*path*/)
  47. {
  48. CE_ASSERT(false, "Attempt to delete directory in Android assets folder");
  49. }
  50. void ApkFilesystem::create_file(const char* /*path*/)
  51. {
  52. CE_ASSERT(false, "Attempt to create file in Android assets folder");
  53. }
  54. void ApkFilesystem::delete_file(const char* /*path*/)
  55. {
  56. CE_ASSERT(false, "Attempt to delete file in Android assets folder");
  57. }
  58. void ApkFilesystem::list_files(const char* path, Vector<DynamicString>& files)
  59. {
  60. CE_ASSERT_NOT_NULL(path);
  61. AAssetDir* root_dir = AAssetManager_openDir(_asset_manager, path);
  62. CE_ASSERT(root_dir != NULL, "Failed to open Android assets folder");
  63. const char* filename = NULL;
  64. while ((filename = AAssetDir_getNextFileName(root_dir)) != NULL)
  65. {
  66. DynamicString name(default_allocator());
  67. name = filename;
  68. vector::push_back(files, name);
  69. }
  70. AAssetDir_close(root_dir);
  71. }
  72. void ApkFilesystem::get_absolute_path(const char* path, DynamicString& os_path)
  73. {
  74. os_path = path;
  75. }
  76. } // namespace crown
  77. #endif // CROWN_PLATFORM_ANDROID