diff options
Diffstat (limited to 'platform/android/file_access_android.cpp')
-rw-r--r-- | platform/android/file_access_android.cpp | 100 |
1 files changed, 40 insertions, 60 deletions
diff --git a/platform/android/file_access_android.cpp b/platform/android/file_access_android.cpp index 2828d3c074..4426af4dad 100644 --- a/platform/android/file_access_android.cpp +++ b/platform/android/file_access_android.cpp @@ -29,40 +29,34 @@ #include "file_access_android.h" #include "print_string.h" - - - -AAssetManager *FileAccessAndroid::asset_manager=NULL; - +AAssetManager *FileAccessAndroid::asset_manager = NULL; /*void FileAccessAndroid::make_default() { create_func=create_android; }*/ -FileAccess* FileAccessAndroid::create_android() { +FileAccess *FileAccessAndroid::create_android() { return memnew(FileAccessAndroid); } +Error FileAccessAndroid::_open(const String &p_path, int p_mode_flags) { -Error FileAccessAndroid::_open(const String& p_path, int p_mode_flags) { - - String path=fix_path(p_path).simplify_path(); + String path = fix_path(p_path).simplify_path(); if (path.begins_with("/")) - path=path.substr(1,path.length()); + path = path.substr(1, path.length()); else if (path.begins_with("res://")) - path=path.substr(6,path.length()); + path = path.substr(6, path.length()); - - ERR_FAIL_COND_V(p_mode_flags&FileAccess::WRITE,ERR_UNAVAILABLE); //can't write on android.. - a=AAssetManager_open(asset_manager,path.utf8().get_data(),AASSET_MODE_STREAMING); + ERR_FAIL_COND_V(p_mode_flags & FileAccess::WRITE, ERR_UNAVAILABLE); //can't write on android.. + a = AAssetManager_open(asset_manager, path.utf8().get_data(), AASSET_MODE_STREAMING); if (!a) return ERR_CANT_OPEN; //ERR_FAIL_COND_V(!a,ERR_FILE_NOT_FOUND); - len=AAsset_getLength(a); - pos=0; - eof=false; + len = AAsset_getLength(a); + pos = 0; + eof = false; return OK; } @@ -72,34 +66,32 @@ void FileAccessAndroid::close() { if (!a) return; AAsset_close(a); - a=NULL; + a = NULL; } bool FileAccessAndroid::is_open() const { - return a!=NULL; + return a != NULL; } void FileAccessAndroid::seek(size_t p_position) { ERR_FAIL_COND(!a); - AAsset_seek(a,p_position,SEEK_SET); - pos=p_position; - if (pos>len) { - pos=len; - eof=true; + AAsset_seek(a, p_position, SEEK_SET); + pos = p_position; + if (pos > len) { + pos = len; + eof = true; } else { - eof=false; + eof = false; } - } void FileAccessAndroid::seek_end(int64_t p_position) { ERR_FAIL_COND(!a); - AAsset_seek(a,p_position,SEEK_END); - pos=len+p_position; - + AAsset_seek(a, p_position, SEEK_END); + pos = len + p_position; } size_t FileAccessAndroid::get_pos() const { @@ -119,79 +111,67 @@ bool FileAccessAndroid::eof_reached() const { uint8_t FileAccessAndroid::get_8() const { - - if (pos>=len) { - eof=true; + if (pos >= len) { + eof = true; return 0; } - uint8_t byte; - AAsset_read(a,&byte,1); + AAsset_read(a, &byte, 1); pos++; return byte; - } int FileAccessAndroid::get_buffer(uint8_t *p_dst, int p_length) const { + off_t r = AAsset_read(a, p_dst, p_length); - off_t r = AAsset_read(a,p_dst,p_length); - - if (pos+p_length >len ) { - eof=true; + if (pos + p_length > len) { + eof = true; } - if (r>=0) { + if (r >= 0) { - pos+=r; - if (pos>len) { - pos=len; + pos += r; + if (pos > len) { + pos = len; } - } return r; - } Error FileAccessAndroid::get_error() const { - return eof?ERR_FILE_EOF:OK; //not sure what else it may happen + return eof ? ERR_FILE_EOF : OK; //not sure what else it may happen } void FileAccessAndroid::store_8(uint8_t p_dest) { ERR_FAIL(); - } -bool FileAccessAndroid::file_exists(const String& p_path) { +bool FileAccessAndroid::file_exists(const String &p_path) { - String path=fix_path(p_path).simplify_path(); + String path = fix_path(p_path).simplify_path(); if (path.begins_with("/")) - path=path.substr(1,path.length()); + path = path.substr(1, path.length()); else if (path.begins_with("res://")) - path=path.substr(6,path.length()); + path = path.substr(6, path.length()); - AAsset *at=AAssetManager_open(asset_manager,path.utf8().get_data(),AASSET_MODE_STREAMING); + AAsset *at = AAssetManager_open(asset_manager, path.utf8().get_data(), AASSET_MODE_STREAMING); if (!at) return false; AAsset_close(at); return true; - } - FileAccessAndroid::FileAccessAndroid() { - a=NULL; - eof=false; + a = NULL; + eof = false; } - -FileAccessAndroid::~FileAccessAndroid() -{ +FileAccessAndroid::~FileAccessAndroid() { close(); } - |