2
0

ApkFilesystem.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. Copyright (c) 2013 Daniele Bartolini, Michele Rossi
  3. Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
  4. Permission is hereby granted, free of charge, to any person
  5. obtaining a copy of this software and associated documentation
  6. files (the "Software"), to deal in the Software without
  7. restriction, including without limitation the rights to use,
  8. copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the
  10. Software is furnished to do so, subject to the following
  11. conditions:
  12. The above copyright notice and this permission notice shall be
  13. included in all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  16. OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  17. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  19. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  21. OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. #include <android/asset_manager.h>
  24. #include "ApkFilesystem.h"
  25. #include "TempAllocator.h"
  26. #include "ApkFile.h"
  27. #include "OS.h"
  28. extern AAssetManager* get_android_asset_manager();
  29. namespace crown
  30. {
  31. //-----------------------------------------------------------------------------
  32. ApkFilesystem::ApkFilesystem()
  33. {
  34. }
  35. //-----------------------------------------------------------------------------
  36. File* ApkFilesystem::open(const char* path, FileOpenMode mode)
  37. {
  38. CE_ASSERT_NOT_NULL(path);
  39. CE_ASSERT(mode == FOM_READ, "Cannot open for writing in Android assets folder");
  40. return CE_NEW(default_allocator(), ApkFile)(path);
  41. }
  42. //-----------------------------------------------------------------------------
  43. void ApkFilesystem::close(File* file)
  44. {
  45. CE_ASSERT_NOT_NULL(file);
  46. CE_DELETE(default_allocator(), file);
  47. }
  48. //-----------------------------------------------------------------------------
  49. bool ApkFilesystem::is_directory(const char* path)
  50. {
  51. return true;
  52. }
  53. //-----------------------------------------------------------------------------
  54. bool ApkFilesystem::is_file(const char* path)
  55. {
  56. return true;
  57. }
  58. //-----------------------------------------------------------------------------
  59. void ApkFilesystem::create_directory(const char* /*path*/)
  60. {
  61. CE_ASSERT(false, "Attempt to create directory in Android assets folder");
  62. }
  63. //-----------------------------------------------------------------------------
  64. void ApkFilesystem::delete_directory(const char* /*path*/)
  65. {
  66. CE_ASSERT(false, "Attempt to delete directory in Android assets folder");
  67. }
  68. //-----------------------------------------------------------------------------
  69. void ApkFilesystem::create_file(const char* /*path*/)
  70. {
  71. CE_ASSERT(false, "Attempt to create file in Android assets folder");
  72. }
  73. //-----------------------------------------------------------------------------
  74. void ApkFilesystem::delete_file(const char* /*path*/)
  75. {
  76. CE_ASSERT(false, "Attempt to delete file in Android assets folder");
  77. }
  78. //-----------------------------------------------------------------------------
  79. void ApkFilesystem::list_files(const char* path, Vector<DynamicString>& files)
  80. {
  81. CE_ASSERT_NOT_NULL(path);
  82. AAssetDir* root_dir = AAssetManager_openDir(get_android_asset_manager(), path);
  83. CE_ASSERT(root_dir != NULL, "Failed to open Android assets folder");
  84. const char* filename = NULL;
  85. while ((filename = AAssetDir_getNextFileName(root_dir)) != NULL)
  86. {
  87. DynamicString name(default_allocator());
  88. name = filename;
  89. files.push_back(name);
  90. }
  91. AAssetDir_close(root_dir);
  92. }
  93. //-----------------------------------------------------------------------------
  94. void ApkFilesystem::get_absolute_path(const char* path, DynamicString& os_path)
  95. {
  96. os_path = path;
  97. }
  98. } // namespace crown