aboutsummaryrefslogtreecommitdiff
path: root/source/Irrlicht/Android/CAndroidAssetFileArchive.cpp
diff options
context:
space:
mode:
authorcutealien <cutealien@dfc29bdd-3216-0410-991c-e03cc46cb475>2020-01-03 19:05:16 +0000
committercutealien <cutealien@dfc29bdd-3216-0410-991c-e03cc46cb475>2020-01-03 19:05:16 +0000
commit2ae2a551a6290f46734307bbfdafea4b1a2cf2ba (patch)
treeba2f0b468640e44899fed3df2d4cc58795f4a003 /source/Irrlicht/Android/CAndroidAssetFileArchive.cpp
downloadirrlicht-2ae2a551a6290f46734307bbfdafea4b1a2cf2ba.tar.xz
Merging r5975 through r6036 from trunk to ogl-es branch.
GLES drivers adapted, but only did make compile-tests. git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/branches/ogl-es@6038 dfc29bdd-3216-0410-991c-e03cc46cb475
Diffstat (limited to 'source/Irrlicht/Android/CAndroidAssetFileArchive.cpp')
-rw-r--r--source/Irrlicht/Android/CAndroidAssetFileArchive.cpp110
1 files changed, 110 insertions, 0 deletions
diff --git a/source/Irrlicht/Android/CAndroidAssetFileArchive.cpp b/source/Irrlicht/Android/CAndroidAssetFileArchive.cpp
new file mode 100644
index 0000000..53d06f8
--- /dev/null
+++ b/source/Irrlicht/Android/CAndroidAssetFileArchive.cpp
@@ -0,0 +1,110 @@
+// Copyright (C) 2002-2011 Nikolaus Gebhardt
+// This file is part of the "Irrlicht Engine".
+// For conditions of distribution and use, see copyright notice in irrlicht.h
+
+#include "IrrCompileConfig.h"
+
+#ifdef _IRR_COMPILE_ANDROID_ASSET_READER_
+
+#include "CAndroidAssetReader.h"
+
+#include "CReadFile.h"
+#include "coreutil.h"
+#include "CAndroidAssetFileArchive.h"
+#include "CIrrDeviceAndroid.h"
+#include "os.h" // for logging (just keep it in even when not needed right now as it's used all the time)
+
+#include <android_native_app_glue.h>
+#include <android/native_activity.h>
+#include <android/log.h>
+
+namespace irr
+{
+namespace io
+{
+
+CAndroidAssetFileArchive::CAndroidAssetFileArchive(AAssetManager *assetManager, bool ignoreCase, bool ignorePaths)
+ : CFileList("/asset", ignoreCase, ignorePaths), AssetManager(assetManager)
+{
+}
+
+
+CAndroidAssetFileArchive::~CAndroidAssetFileArchive()
+{
+}
+
+
+//! get the archive type
+E_FILE_ARCHIVE_TYPE CAndroidAssetFileArchive::getType() const
+{
+ return EFAT_ANDROID_ASSET;
+}
+
+const IFileList* CAndroidAssetFileArchive::getFileList() const
+{
+ // The assert_manager can not read directory names, so
+ // getFileList returns only files in folders which have been added.
+ return this;
+}
+
+
+//! opens a file by file name
+IReadFile* CAndroidAssetFileArchive::createAndOpenFile(const io::path& filename)
+{
+ CAndroidAssetReader *reader = new CAndroidAssetReader(AssetManager, filename);
+
+ if(reader->isOpen())
+ return reader;
+
+ reader->drop();
+ return NULL;
+}
+
+//! opens a file by index
+IReadFile* CAndroidAssetFileArchive::createAndOpenFile(u32 index)
+{
+ const io::path& filename(getFullFileName(index));
+ if ( filename.empty() )
+ return 0;
+
+ return createAndOpenFile(filename);
+}
+
+void CAndroidAssetFileArchive::addDirectoryToFileList(const io::path &dirname_)
+{
+ io::path dirname(dirname_);
+ fschar_t lastChar = dirname.lastChar();
+ if ( lastChar == '/' || lastChar == '\\' )
+ dirname.erase(dirname.size()-1);
+
+ // os::Printer::log("addDirectoryToFileList:", dirname.c_str(), ELL_DEBUG);
+ if (findFile(dirname, true) >= 0 )
+ return; // was already added
+
+ AAssetDir *dir = AAssetManager_openDir(AssetManager, core::stringc(dirname).c_str());
+ if(!dir)
+ return;
+
+ // add directory itself
+ addItem(dirname, 0, 0, /*isDir*/true, getFileCount());
+
+ // add all files in folder.
+ // Note: AAssetDir_getNextFileName does not return directory names (neither does any other NDK function)
+ while(const char *filename = AAssetDir_getNextFileName(dir))
+ {
+ core::stringc full_filename= dirname=="" ? filename
+ : dirname+"/"+filename;
+
+ // We can't get the size without opening the file - so for performance
+ // reasons we set the file size to 0.
+ // TODO: Does this really cost so much performance that it's worth losing this information? Dirs are usually just added once at startup...
+ addItem(full_filename, /*offet*/0, /*size*/0, /*isDir*/false, getFileCount());
+ // os::Printer::log("addItem:", full_filename.c_str(), ELL_DEBUG);
+ }
+ AAssetDir_close(dir);
+}
+
+} // end namespace io
+} // end namespace irr
+
+#endif // _IRR_COMPILE_ANDROID_ASSET_READER_