1 // Copyright (C) 2002-2011 Nikolaus Gebhardt
\r
2 // This file is part of the "Irrlicht Engine".
\r
3 // For conditions of distribution and use, see copyright notice in irrlicht.h
\r
5 #include "IrrCompileConfig.h"
\r
7 #ifdef _IRR_COMPILE_ANDROID_ASSET_READER_
\r
9 #include "CAndroidAssetReader.h"
\r
11 #include "CReadFile.h"
\r
12 #include "coreutil.h"
\r
13 #include "CAndroidAssetFileArchive.h"
\r
14 #include "CIrrDeviceAndroid.h"
\r
15 #include "os.h" // for logging (just keep it in even when not needed right now as it's used all the time)
\r
17 #include <android_native_app_glue.h>
\r
18 #include <android/native_activity.h>
\r
19 #include <android/log.h>
\r
26 CAndroidAssetFileArchive::CAndroidAssetFileArchive(AAssetManager *assetManager, bool ignoreCase, bool ignorePaths)
\r
27 : CFileList("/asset", ignoreCase, ignorePaths), AssetManager(assetManager)
\r
32 CAndroidAssetFileArchive::~CAndroidAssetFileArchive()
\r
37 //! get the archive type
\r
38 E_FILE_ARCHIVE_TYPE CAndroidAssetFileArchive::getType() const
\r
40 return EFAT_ANDROID_ASSET;
\r
43 const IFileList* CAndroidAssetFileArchive::getFileList() const
\r
45 // The assert_manager can not read directory names, so
\r
46 // getFileList returns only files in folders which have been added.
\r
51 //! opens a file by file name
\r
52 IReadFile* CAndroidAssetFileArchive::createAndOpenFile(const io::path& filename)
\r
54 CAndroidAssetReader *reader = new CAndroidAssetReader(AssetManager, filename);
\r
56 if(reader->isOpen())
\r
63 //! opens a file by index
\r
64 IReadFile* CAndroidAssetFileArchive::createAndOpenFile(u32 index)
\r
66 const io::path& filename(getFullFileName(index));
\r
67 if ( filename.empty() )
\r
70 return createAndOpenFile(filename);
\r
73 void CAndroidAssetFileArchive::addDirectoryToFileList(const io::path &dirname_)
\r
75 io::path dirname(dirname_);
\r
76 fschar_t lastChar = dirname.lastChar();
\r
77 if ( lastChar == '/' || lastChar == '\\' )
\r
78 dirname.erase(dirname.size()-1);
\r
80 // os::Printer::log("addDirectoryToFileList:", dirname.c_str(), ELL_DEBUG);
\r
81 if (findFile(dirname, true) >= 0 )
\r
82 return; // was already added
\r
84 AAssetDir *dir = AAssetManager_openDir(AssetManager, core::stringc(dirname).c_str());
\r
88 // add directory itself
\r
89 addItem(dirname, 0, 0, /*isDir*/true, getFileCount());
\r
91 // add all files in folder.
\r
92 // Note: AAssetDir_getNextFileName does not return directory names (neither does any other NDK function)
\r
93 while(const char *filename = AAssetDir_getNextFileName(dir))
\r
95 core::stringc full_filename= dirname=="" ? filename
\r
96 : dirname+"/"+filename;
\r
98 // We can't get the size without opening the file - so for performance
\r
99 // reasons we set the file size to 0.
\r
100 // TODO: Does this really cost so much performance that it's worth losing this information? Dirs are usually just added once at startup...
\r
101 addItem(full_filename, /*offet*/0, /*size*/0, /*isDir*/false, getFileCount());
\r
102 // os::Printer::log("addItem:", full_filename.c_str(), ELL_DEBUG);
\r
104 AAssetDir_close(dir);
\r
107 } // end namespace io
\r
108 } // end namespace irr
\r
110 #endif // _IRR_COMPILE_ANDROID_ASSET_READER_
\r