mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2024-12-23 20:36:53 +01:00
Ported: Fix issue preventing the Android Editor from displaying the project content
The issue was causing by a bug within the logic for `FileAccessFilesystemJAndroid#eof_reached()` causing that value to remain false after the eof was reached.
This in turn caused an infinite loop in the file scanner preventing the project's content from showing up.
-m4gr3d
30479543b0
This commit is contained in:
parent
33a2d5e20b
commit
54c49a25a0
@ -45,6 +45,7 @@ jmethodID FileAccessFilesystemJAndroid::_file_seek_end = nullptr;
|
||||
jmethodID FileAccessFilesystemJAndroid::_file_read = nullptr;
|
||||
jmethodID FileAccessFilesystemJAndroid::_file_tell = nullptr;
|
||||
jmethodID FileAccessFilesystemJAndroid::_file_eof = nullptr;
|
||||
jmethodID FileAccessFilesystemJAndroid::_file_set_eof = nullptr;
|
||||
jmethodID FileAccessFilesystemJAndroid::_file_close = nullptr;
|
||||
jmethodID FileAccessFilesystemJAndroid::_file_write = nullptr;
|
||||
jmethodID FileAccessFilesystemJAndroid::_file_flush = nullptr;
|
||||
@ -161,6 +162,16 @@ bool FileAccessFilesystemJAndroid::eof_reached() const {
|
||||
}
|
||||
}
|
||||
|
||||
void FileAccessFilesystemJAndroid::_set_eof(bool eof) {
|
||||
if (_file_set_eof) {
|
||||
ERR_FAIL_COND_MSG(!is_open(), "File must be opened before use.");
|
||||
|
||||
JNIEnv *env = get_jni_env();
|
||||
ERR_FAIL_COND(env == nullptr);
|
||||
env->CallVoidMethod(file_access_handler, _file_set_eof, id, eof);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t FileAccessFilesystemJAndroid::get_8() const {
|
||||
ERR_FAIL_COND_V_MSG(!is_open(), 0, "File must be opened before use.");
|
||||
uint8_t byte;
|
||||
@ -183,6 +194,7 @@ String FileAccessFilesystemJAndroid::get_line() const {
|
||||
while (true) {
|
||||
size_t line_buffer_size = MIN(buffer_size_limit, file_size - get_position());
|
||||
if (line_buffer_size <= 0) {
|
||||
const_cast<FileAccessFilesystemJAndroid *>(this)->_set_eof(true);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -309,6 +321,7 @@ void FileAccessFilesystemJAndroid::setup(jobject p_file_access_handler) {
|
||||
_file_get_size = env->GetMethodID(cls, "fileGetSize", "(I)J");
|
||||
_file_tell = env->GetMethodID(cls, "fileGetPosition", "(I)J");
|
||||
_file_eof = env->GetMethodID(cls, "isFileEof", "(I)Z");
|
||||
_file_set_eof = env->GetMethodID(cls, "setFileEof", "(IZ)V");
|
||||
_file_seek = env->GetMethodID(cls, "fileSeek", "(IJ)V");
|
||||
_file_seek_end = env->GetMethodID(cls, "fileSeekFromEnd", "(IJ)V");
|
||||
_file_read = env->GetMethodID(cls, "fileRead", "(ILjava/nio/ByteBuffer;)I");
|
||||
|
@ -44,6 +44,7 @@ class FileAccessFilesystemJAndroid : public FileAccess {
|
||||
static jmethodID _file_seek_end;
|
||||
static jmethodID _file_tell;
|
||||
static jmethodID _file_eof;
|
||||
static jmethodID _file_set_eof;
|
||||
static jmethodID _file_read;
|
||||
static jmethodID _file_write;
|
||||
static jmethodID _file_flush;
|
||||
@ -55,6 +56,8 @@ class FileAccessFilesystemJAndroid : public FileAccess {
|
||||
String absolute_path;
|
||||
String path_src;
|
||||
|
||||
void _set_eof(bool eof);
|
||||
|
||||
public:
|
||||
virtual Error _open(const String &p_path, int p_mode_flags); ///< open a file
|
||||
virtual void close(); ///< close a file
|
||||
|
@ -104,7 +104,6 @@ internal abstract class DataAccess(private val filePath: String) {
|
||||
|
||||
protected abstract val fileChannel: FileChannel
|
||||
internal var endOfFile = false
|
||||
private set
|
||||
|
||||
fun close() {
|
||||
try {
|
||||
@ -125,9 +124,7 @@ internal abstract class DataAccess(private val filePath: String) {
|
||||
fun seek(position: Long) {
|
||||
try {
|
||||
fileChannel.position(position)
|
||||
if (position <= size()) {
|
||||
endOfFile = false
|
||||
}
|
||||
endOfFile = position >= fileChannel.size()
|
||||
} catch (e: Exception) {
|
||||
Log.w(TAG, "Exception when seeking file $filePath.", e)
|
||||
}
|
||||
@ -161,8 +158,7 @@ internal abstract class DataAccess(private val filePath: String) {
|
||||
fun read(buffer: ByteBuffer): Int {
|
||||
return try {
|
||||
val readBytes = fileChannel.read(buffer)
|
||||
endOfFile = readBytes == -1
|
||||
|| (fileChannel.position() >= fileChannel.size() && fileChannel.size() > 0)
|
||||
endOfFile = readBytes == -1 || (fileChannel.position() >= fileChannel.size())
|
||||
if (readBytes == -1) {
|
||||
0
|
||||
} else {
|
||||
|
@ -194,6 +194,11 @@ class FileAccessHandler(val context: Context) {
|
||||
return files[fileId].endOfFile
|
||||
}
|
||||
|
||||
fun setFileEof(fileId: Int, eof: Boolean) {
|
||||
val file = files[fileId] ?: return
|
||||
file.endOfFile = eof
|
||||
}
|
||||
|
||||
fun fileClose(fileId: Int) {
|
||||
if (hasFileId(fileId)) {
|
||||
files[fileId].close()
|
||||
|
Loading…
Reference in New Issue
Block a user