aboutsummaryrefslogtreecommitdiff
path: root/source/Irrlicht/Android/CAndroidAssetReader.cpp
blob: 55383e28cd9cd02a458f589fc7c87da414642f4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// 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


#ifdef   _IRR_COMPILE_ANDROID_ASSET_READER_

#include "CAndroidAssetReader.h"

#include "CReadFile.h"
#include "coreutil.h"
#include "CAndroidAssetReader.h"
#include "CIrrDeviceAndroid.h"

#include <android_native_app_glue.h>
#include <android/native_activity.h>

namespace irr
{
namespace io
{

CAndroidAssetReader::CAndroidAssetReader(AAssetManager *assetManager, const io::path &filename)
	: AssetManager(assetManager), Filename(filename)
{
	Asset = AAssetManager_open(AssetManager, 
					core::stringc(filename).c_str(),
				    AASSET_MODE_RANDOM);

}

CAndroidAssetReader::~CAndroidAssetReader()
{
	if(Asset)
		AAsset_close(Asset);
}

size_t CAndroidAssetReader::read(void* buffer, size_t sizeToRead)
{
	int readBytes = AAsset_read(Asset, buffer, sizeToRead);
	if ( readBytes >= 0 )
		return size_t(readBytes);
	return 0;	// direct fd access is not possible (for example, if the asset is compressed). 
}
      
bool CAndroidAssetReader::seek(long finalPos, bool relativeMovement)
{
	off_t status =  AAsset_seek(Asset, finalPos, relativeMovement ? SEEK_CUR : SEEK_SET);

	return status+1;
}

long CAndroidAssetReader::getSize() const
{
	return AAsset_getLength(Asset);
}
      
long CAndroidAssetReader::getPos() const
{
	return AAsset_getLength(Asset) - AAsset_getRemainingLength(Asset);
}
      
const io::path& CAndroidAssetReader::getFileName() const
{
	return Filename;
}


} // end namespace io
} // end namespace irr

#endif //  _IRR_COMPILE_ANDROID_ASSET_READER_