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
6 #ifdef _IRR_COMPILE_ANDROID_ASSET_READER_
\r
8 #include "CAndroidAssetReader.h"
\r
10 #include "CReadFile.h"
\r
11 #include "coreutil.h"
\r
12 #include "CAndroidAssetFileArchive.h"
\r
13 #include "CIrrDeviceAndroid.h"
\r
14 #include "os.h" // for logging (just keep it in even when not needed right now as it's used all the time)
\r
16 #include <android_native_app_glue.h>
\r
17 #include <android/native_activity.h>
\r
18 #include <android/log.h>
\r
25 CAndroidAssetFileArchive::CAndroidAssetFileArchive(AAssetManager *assetManager, bool ignoreCase, bool ignorePaths)
\r
26 : CFileList("/asset", ignoreCase, ignorePaths), AssetManager(assetManager)
\r
31 CAndroidAssetFileArchive::~CAndroidAssetFileArchive()
\r
36 //! get the archive type
\r
37 E_FILE_ARCHIVE_TYPE CAndroidAssetFileArchive::getType() const
\r
39 return EFAT_ANDROID_ASSET;
\r
42 const IFileList* CAndroidAssetFileArchive::getFileList() const
\r
44 // The assert_manager can not read directory names, so
\r
45 // getFileList returns only files in folders which have been added.
\r
50 //! opens a file by file name
\r
51 IReadFile* CAndroidAssetFileArchive::createAndOpenFile(const io::path& filename)
\r
53 CAndroidAssetReader *reader = new CAndroidAssetReader(AssetManager, filename);
\r
55 if(reader->isOpen())
\r
62 //! opens a file by index
\r
63 IReadFile* CAndroidAssetFileArchive::createAndOpenFile(u32 index)
\r
65 const io::path& filename(getFullFileName(index));
\r
66 if ( filename.empty() )
\r
69 return createAndOpenFile(filename);
\r
72 void CAndroidAssetFileArchive::addDirectoryToFileList(const io::path &dirname_)
\r
74 io::path dirname(dirname_);
\r
75 fschar_t lastChar = dirname.lastChar();
\r
76 if ( lastChar == '/' || lastChar == '\\' )
\r
77 dirname.erase(dirname.size()-1);
\r
79 // os::Printer::log("addDirectoryToFileList:", dirname.c_str(), ELL_DEBUG);
\r
80 if (findFile(dirname, true) >= 0 )
\r
81 return; // was already added
\r
83 AAssetDir *dir = AAssetManager_openDir(AssetManager, core::stringc(dirname).c_str());
\r
87 // add directory itself
\r
88 addItem(dirname, 0, 0, /*isDir*/true, getFileCount());
\r
90 // add all files in folder.
\r
91 // Note: AAssetDir_getNextFileName does not return directory names (neither does any other NDK function)
\r
92 while(const char *filename = AAssetDir_getNextFileName(dir))
\r
94 core::stringc full_filename= dirname=="" ? filename
\r
95 : dirname+"/"+filename;
\r
97 // We can't get the size without opening the file - so for performance
\r
98 // reasons we set the file size to 0.
\r
99 // TODO: Does this really cost so much performance that it's worth losing this information? Dirs are usually just added once at startup...
\r
100 addItem(full_filename, /*offet*/0, /*size*/0, /*isDir*/false, getFileCount());
\r
101 // os::Printer::log("addItem:", full_filename.c_str(), ELL_DEBUG);
\r
103 AAssetDir_close(dir);
\r
106 } // end namespace io
\r
107 } // end namespace irr
\r
109 #endif // _IRR_COMPILE_ANDROID_ASSET_READER_
\r