Просмотр исходного кода

implement AndroidMountPoint, fix android build

mikymod 12 лет назад
Родитель
Сommit
b24d69446b

+ 4 - 0
engine/Android.mk

@@ -31,6 +31,9 @@ LOCAL_SRC_FILES :=\
 	core/filesystem/Filesystem.cpp\
 	core/filesystem/TextReader.cpp\
 	core/filesystem/TextWriter.cpp\
+	core/filesystem/DiskMountPoint.cpp\
+	core/filesystem/AndroidFile.cpp\
+	core/filesystem/AndroidMountPoint.cpp\
 \
 	core/json/JSONParser.cpp\
 \
@@ -70,6 +73,7 @@ LOCAL_SRC_FILES :=\
 	os/android/AndroidOS.cpp\
 	os/android/AndroidDevice.cpp\
 	os/android/OsWindow.cpp\
+	os/android/APKFile.cpp\
 	os/posix/OsFile.cpp\
 	os/posix/Thread.cpp\
 	os/posix/Mutex.cpp\

+ 19 - 17
engine/core/filesystem/AndroidFile.cpp

@@ -24,22 +24,23 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 */
 
-#include "AssetFile.h"
+#include "AndroidFile.h"
+#include "Log.h"
 
 namespace crown
 {
 
 //-----------------------------------------------------------------------------
-AssetFile::AssetFile(const char* path) :
+AndroidFile::AndroidFile(const char* path) :
 	File(FOM_READ),
 	m_file(path, FOM_READ),
 	m_last_was_read(true)
 {
-
+	Log::i("path: %s", path);
 }
 
 //-----------------------------------------------------------------------------
-void AssetFile::seek(size_t position)
+void AndroidFile::seek(size_t position)
 {
 	check_valid();
 
@@ -47,7 +48,7 @@ void AssetFile::seek(size_t position)
 }
 
 //-----------------------------------------------------------------------------
-void AssetFile::seek_to_end()
+void AndroidFile::seek_to_end()
 {
 	check_valid();
 
@@ -55,7 +56,7 @@ void AssetFile::seek_to_end()
 }
 
 //-----------------------------------------------------------------------------
-void AssetFile::skip(size_t bytes)
+void AndroidFile::skip(size_t bytes)
 {
 	check_valid();
 
@@ -63,7 +64,7 @@ void AssetFile::skip(size_t bytes)
 }
 
 //-----------------------------------------------------------------------------
-void AssetFile::read(void* buffer, size_t size)
+void AndroidFile::read(void* buffer, size_t size)
 {
 	check_valid();
 
@@ -78,37 +79,38 @@ void AssetFile::read(void* buffer, size_t size)
 }
 
 //-----------------------------------------------------------------------------
-void AssetFile::write(const void* buffer, size_t size)
+void AndroidFile::write(const void* /*buffer*/, size_t /*size*/)
 {
 	// Not needed
 }
 
 //-----------------------------------------------------------------------------
-bool AssetFile::copy_to(File& file, size_t size = 0)
+bool AndroidFile::copy_to(File& /*file*/, size_t /*size = 0*/)
 {
 	// Not needed
+	return false;
 }
 
 //-----------------------------------------------------------------------------
-void AssetFile::flush()
+void AndroidFile::flush()
 {
 	// Not needed
 }
 
 //-----------------------------------------------------------------------------
-bool AssetFile::is_valid() const
+bool AndroidFile::is_valid() const
 {
 	return m_file.is_open();
 }
 
 //-----------------------------------------------------------------------------
-bool AssetFile::end_of_file() const
+bool AndroidFile::end_of_file() const
 {
 	return position() == size();
 }
 
 //-----------------------------------------------------------------------------
-size_t AssetFile::size() const
+size_t AndroidFile::size() const
 {
 	check_valid();
 
@@ -116,7 +118,7 @@ size_t AssetFile::size() const
 }
 
 //-----------------------------------------------------------------------------
-size_t AssetFile::position() const
+size_t AndroidFile::position() const
 {
 	check_valid();
 
@@ -124,7 +126,7 @@ size_t AssetFile::position() const
 }
 
 //-----------------------------------------------------------------------------
-bool AssetFile::can_read() const
+bool AndroidFile::can_read() const
 {
 	check_valid();
 
@@ -132,7 +134,7 @@ bool AssetFile::can_read() const
 }
 
 //-----------------------------------------------------------------------------
-bool AssetFile::can_write() const
+bool AndroidFile::can_write() const
 {
 	check_valid();
 
@@ -140,7 +142,7 @@ bool AssetFile::can_write() const
 }
 
 //-----------------------------------------------------------------------------
-bool AssetFile::can_seek() const
+bool AndroidFile::can_seek() const
 {
 	check_valid();
 

+ 5 - 4
engine/core/filesystem/AndroidFile.h

@@ -27,15 +27,16 @@ OTHER DEALINGS IN THE SOFTWARE.
 #pragma once
 
 #include "APKFile.h"
+#include "Assert.h"
 
 namespace crown
 {
 
-class AssetFile : public File 
+class AndroidFile : public File 
 {
 public:
 
-				AssetFile(const char* path);
+				AndroidFile(const char* path);
 
 	void		seek(size_t position);
 
@@ -67,11 +68,11 @@ public:
 
 private:
 
-	APKFile*	m_file;
+	APKFile		m_file;
 
 	bool		m_last_was_read;
 
-private:
+protected:
 
 	inline void		check_valid() const
 	{

+ 139 - 0
engine/core/filesystem/AndroidMountPoint.cpp

@@ -0,0 +1,139 @@
+/*
+Copyright (c) 2013 Daniele Bartolini, Michele Rossi
+Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#include "AndroidMountPoint.h"
+#include "AndroidFile.h"
+#include "StringUtils.h"
+
+namespace crown
+{
+
+//-----------------------------------------------------------------------------
+AndroidMountPoint::AndroidMountPoint() :
+	MountPoint(ANDROID_TYPE)
+{
+}
+
+//-----------------------------------------------------------------------------
+File* AndroidMountPoint::open(const char* relative_path, FileOpenMode /*mode*/)
+{
+	CE_ASSERT(exists(relative_path), "File does not exist: %s", relative_path);
+	CE_ASSERT(is_file(relative_path), "File is not a regular file: %s", relative_path);
+
+	Log::i("path: %s", relative_path);
+
+	return CE_NEW(m_allocator, AndroidFile)(relative_path);
+}
+
+//-----------------------------------------------------------------------------
+void AndroidMountPoint::close(File* file)
+{
+	CE_DELETE(m_allocator, file);
+}
+
+//-----------------------------------------------------------------------------
+const char* AndroidMountPoint::root_path()
+{
+	return "Assets Folder";
+}
+
+//-----------------------------------------------------------------------------
+bool AndroidMountPoint::exists(const char* relative_path)
+{
+	// MountPointEntry info;
+
+	// return get_info(relative_path, info);
+
+	return true;
+}
+
+//-----------------------------------------------------------------------------
+bool AndroidMountPoint::get_info(const char* relative_path, MountPointEntry& info)
+{
+	// Entering OS-DEPENDENT-PATH-MODE (Android assets folder)
+
+	// const char* os_path = relative_path;
+
+	// string::strncpy(info.os_path, "", MAX_PATH_LENGTH);
+	// string::strncpy(info.relative_path, relative_path, MAX_PATH_LENGTH);
+
+	// AAssetDir* root = AAssetManager_openDir(g_android_asset_manager, "");
+
+	// char asset_name[512];
+
+	// string::strncpy(asset_name, AAssetDir_getNextFileName(root), 512);
+ // 	Log::i("AssetManager: %s", asset_name);
+
+ 	return true;
+
+	// while (asset_name != NULL)
+	// {
+	// 	Log::i("AssetManager: %s", asset_name);
+	// 	if (string::strcmp(asset_name, relative_path) == 0)
+	// 	{
+	// 		info.type = MountPointEntry::FILE;
+	// 		AAssetDir_rewind(root);
+	// 		return true;			
+	// 	}
+
+	// 	string::strncpy(asset_name, AAssetDir_getNextFileName(root), 512);
+	// }
+	
+	// info.type = MountPointEntry::UNKNOWN;
+
+	// return false;
+}
+
+//-----------------------------------------------------------------------------
+bool AndroidMountPoint::is_file(const char* relative_path)
+{
+	// MountPointEntry info;
+
+	// if (get_info(relative_path, info))
+	// {
+	// 	return info.type == MountPointEntry::FILE;
+	// }
+
+	// return false;
+
+	return true;
+}
+
+//-----------------------------------------------------------------------------
+bool AndroidMountPoint::is_dir(const char* relative_path)
+{
+	MountPointEntry info;
+
+	if (get_info(relative_path, info))
+	{
+		return info.type == MountPointEntry::DIRECTORY;
+	}
+
+	return false;
+}
+
+
+} // namespace crown

+ 59 - 0
engine/core/filesystem/AndroidMountPoint.h

@@ -0,0 +1,59 @@
+/*
+Copyright (c) 2013 Daniele Bartolini, Michele Rossi
+Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#pragma once
+
+#include "MountPoint.h"
+#include "HeapAllocator.h"
+
+namespace crown
+{
+
+class AndroidMountPoint : public MountPoint
+{
+public:
+						AndroidMountPoint();
+
+	File* 				open(const char* relative_path, FileOpenMode mode);
+
+	void				close(File* file);
+
+	const char*			root_path();
+
+	bool				exists(const char* relative_path);
+
+	bool				get_info(const char* relative_path, MountPointEntry& info);
+	
+	bool				is_file(const char* relative_path);
+
+	bool				is_dir(const char* relative_path);
+
+private:
+
+	HeapAllocator		m_allocator;
+};
+
+} // namespace crown

+ 5 - 3
engine/os/android/APKFile.cpp

@@ -26,14 +26,15 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #include <android/asset_manager_jni.h>
 
+#include "APKFile.h"
 #include "Assert.h"
 #include "OS.h"
-#include "APKFile.h"
-#include "AndroidOS.h"
 
 namespace crown
 {
 
+AAssetManager* get_android_asset_manager();
+
 static AAssetManager*	g_android_asset_manager = NULL;
 
 //-----------------------------------------------------------------------------
@@ -41,6 +42,7 @@ APKFile::APKFile(const char* path, FileOpenMode mode)
 {
 	// Android assets are always read-only
 	(void) mode;
+
 	m_mode = FOM_READ;
 	m_asset = AAssetManager_open(get_android_asset_manager(), path, AASSET_MODE_RANDOM);
 
@@ -90,7 +92,7 @@ size_t APKFile::read(void* data, size_t size)
 }
 
 //-----------------------------------------------------------------------------
-size_t APKFile::write(const void* data, size_t size)
+size_t APKFile::write(const void* data, size_t /*size*/)
 {
 	CE_ASSERT(data != NULL, "Data must be != NULL");
 

+ 1 - 1
engine/os/android/CrownActivity.java

@@ -70,7 +70,7 @@ public class CrownActivity extends Activity
 
 		// init AssetManager
 		mAssetManager = getAssets();
-		//CrownLib.initAssetManager(mAssetManager);
+		CrownLib.initAssetManager(mAssetManager);
 
 		// init Native Window
         mWindow = new CrownSurfaceView(this);