virtualFileMountAndroidAsset.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /**
  2. * PANDA 3D SOFTWARE
  3. * Copyright (c) Carnegie Mellon University. All rights reserved.
  4. *
  5. * All use of this software is subject to the terms of the revised BSD
  6. * license. You should have received a copy of this license along
  7. * with this source code in a file named "LICENSE."
  8. *
  9. * @file virtualFileMountAndroidAsset.h
  10. * @author rdb
  11. * @date 2013-01-21
  12. */
  13. #ifndef VIRTUALFILEMOUNTANDROIDASSET_H
  14. #define VIRTUALFILEMOUNTANDROIDASSET_H
  15. #ifdef ANDROID
  16. #include "pandabase.h"
  17. #include "virtualFileMount.h"
  18. #include "multifile.h"
  19. #include "pointerTo.h"
  20. #include <android/asset_manager.h>
  21. /**
  22. * Maps a Multifile's contents into the VirtualFileSystem.
  23. */
  24. class EXPCL_PANDA_EXPRESS VirtualFileMountAndroidAsset : public VirtualFileMount {
  25. PUBLISHED:
  26. INLINE VirtualFileMountAndroidAsset(AAssetManager *mgr, const std::string &apk_path);
  27. virtual ~VirtualFileMountAndroidAsset();
  28. public:
  29. int get_fd(const Filename &file, off_t *start, off_t *end) const;
  30. virtual bool has_file(const Filename &file) const;
  31. virtual bool is_directory(const Filename &file) const;
  32. virtual bool is_regular_file(const Filename &file) const;
  33. virtual bool read_file(const Filename &file, bool do_uncompress,
  34. vector_uchar &result) const;
  35. virtual std::istream *open_read_file(const Filename &file) const;
  36. virtual std::streamsize get_file_size(const Filename &file, std::istream *stream) const;
  37. virtual std::streamsize get_file_size(const Filename &file) const;
  38. virtual time_t get_timestamp(const Filename &file) const;
  39. virtual bool get_system_info(const Filename &file, SubfileInfo &info);
  40. virtual bool scan_directory(vector_string &contents,
  41. const Filename &dir) const;
  42. private:
  43. AAssetManager *_asset_mgr;
  44. std::string _apk_path;
  45. class AssetStream : public std::istream {
  46. public:
  47. INLINE AssetStream(AAsset *asset);
  48. virtual ~AssetStream();
  49. };
  50. class AssetStreamBuf : public std::streambuf {
  51. public:
  52. AssetStreamBuf(AAsset *asset);
  53. virtual ~AssetStreamBuf();
  54. virtual std::streampos seekoff(std::streamoff off, ios_seekdir dir, ios_openmode which);
  55. virtual std::streampos seekpos(std::streampos pos, ios_openmode which);
  56. protected:
  57. virtual int underflow();
  58. private:
  59. AAsset *_asset;
  60. friend class VirtualFileMountAndroidAsset;
  61. };
  62. public:
  63. virtual TypeHandle get_type() const {
  64. return get_class_type();
  65. }
  66. virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
  67. static TypeHandle get_class_type() {
  68. return _type_handle;
  69. }
  70. static void init_type() {
  71. VirtualFileMount::init_type();
  72. register_type(_type_handle, "VirtualFileMountAndroidAsset",
  73. VirtualFileMount::get_class_type());
  74. }
  75. private:
  76. static TypeHandle _type_handle;
  77. };
  78. #include "virtualFileMountAndroidAsset.I"
  79. #endif // ANDROID
  80. #endif