]> git.lizzy.rs Git - irrlicht.git/blob - source/Irrlicht/Android/CAndroidAssetFileArchive.cpp
Reduce IrrCompileConfig usage to files that actually need it
[irrlicht.git] / source / Irrlicht / Android / CAndroidAssetFileArchive.cpp
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
4 \r
5 \r
6 #ifdef   _IRR_COMPILE_ANDROID_ASSET_READER_\r
7 \r
8 #include "CAndroidAssetReader.h"\r
9 \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
15 \r
16 #include <android_native_app_glue.h>\r
17 #include <android/native_activity.h>\r
18 #include <android/log.h>\r
19 \r
20 namespace irr\r
21 {\r
22 namespace io\r
23 {\r
24 \r
25 CAndroidAssetFileArchive::CAndroidAssetFileArchive(AAssetManager *assetManager, bool ignoreCase, bool ignorePaths)\r
26   : CFileList("/asset", ignoreCase, ignorePaths), AssetManager(assetManager)\r
27 {\r
28 }\r
29 \r
30 \r
31 CAndroidAssetFileArchive::~CAndroidAssetFileArchive()\r
32 {\r
33 }\r
34 \r
35 \r
36 //! get the archive type\r
37 E_FILE_ARCHIVE_TYPE CAndroidAssetFileArchive::getType() const\r
38 {\r
39         return EFAT_ANDROID_ASSET;\r
40 }\r
41 \r
42 const IFileList* CAndroidAssetFileArchive::getFileList() const\r
43 {\r
44     // The assert_manager can not read directory names, so\r
45     // getFileList returns only files in folders which have been added.\r
46     return this;\r
47 }\r
48 \r
49 \r
50 //! opens a file by file name\r
51 IReadFile* CAndroidAssetFileArchive::createAndOpenFile(const io::path& filename)\r
52 {\r
53     CAndroidAssetReader *reader = new CAndroidAssetReader(AssetManager, filename);\r
54 \r
55     if(reader->isOpen())\r
56                 return reader;\r
57 \r
58         reader->drop();\r
59     return NULL;\r
60 }\r
61 \r
62 //! opens a file by index\r
63 IReadFile* CAndroidAssetFileArchive::createAndOpenFile(u32 index)\r
64 {\r
65         const io::path& filename(getFullFileName(index));\r
66         if ( filename.empty() )\r
67                 return 0;\r
68         \r
69     return createAndOpenFile(filename);\r
70 }\r
71 \r
72 void CAndroidAssetFileArchive::addDirectoryToFileList(const io::path &dirname_)\r
73 {\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
78         \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
82         \r
83         AAssetDir *dir = AAssetManager_openDir(AssetManager, core::stringc(dirname).c_str());\r
84         if(!dir)\r
85                 return;\r
86 \r
87         // add directory itself \r
88         addItem(dirname, 0, 0, /*isDir*/true, getFileCount());\r
89         \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
93         {\r
94                 core::stringc full_filename= dirname=="" ? filename\r
95                                              : dirname+"/"+filename;\r
96 \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
102         }\r
103         AAssetDir_close(dir);\r
104 }\r
105 \r
106 } // end namespace io\r
107 } // end namespace irr\r
108 \r
109 #endif //  _IRR_COMPILE_ANDROID_ASSET_READER_\r