diff --git a/jni/NativeFormats/JavaNativeFormatPlugin.cpp b/jni/NativeFormats/JavaNativeFormatPlugin.cpp index 16645fbdc..02e718123 100644 --- a/jni/NativeFormats/JavaNativeFormatPlugin.cpp +++ b/jni/NativeFormats/JavaNativeFormatPlugin.cpp @@ -250,7 +250,10 @@ JNIEXPORT jboolean JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPl if (!plugin->readModel(*model)) { return JNI_FALSE; } - model->flush(); + if (!model->flush()) { + AndroidUtil::throwCachedCharStorageException("Cannot write file from native code"); + return JNI_FALSE; + } if (!initInternalHyperlinks(env, javaModel, *model) || !initTOC(env, javaModel, *model)) { return JNI_FALSE; diff --git a/jni/NativeFormats/fbreader/src/bookmodel/BookModel.cpp b/jni/NativeFormats/fbreader/src/bookmodel/BookModel.cpp index ec8b15329..272b721df 100644 --- a/jni/NativeFormats/fbreader/src/bookmodel/BookModel.cpp +++ b/jni/NativeFormats/fbreader/src/bookmodel/BookModel.cpp @@ -76,12 +76,19 @@ const shared_ptr BookModel::book() const { return myBook; } -void BookModel::flush() { +bool BookModel::flush() { myBookTextModel->flush(); + if (myBookTextModel->allocator().failed()) { + return false; + } myContentsModel->flush(); std::map >::const_iterator it = myFootnotes.begin(); for (; it != myFootnotes.end(); ++it) { it->second->flush(); + if (it->second->allocator().failed()) { + return false; + } } + return true; } diff --git a/jni/NativeFormats/fbreader/src/bookmodel/BookModel.h b/jni/NativeFormats/fbreader/src/bookmodel/BookModel.h index 5ce371ba8..b7027a451 100644 --- a/jni/NativeFormats/fbreader/src/bookmodel/BookModel.h +++ b/jni/NativeFormats/fbreader/src/bookmodel/BookModel.h @@ -75,7 +75,7 @@ public: const shared_ptr book() const; - void flush(); + bool flush(); private: const shared_ptr myBook; diff --git a/jni/NativeFormats/zlibrary/text/src/model/ZLCachedMemoryAllocator.cpp b/jni/NativeFormats/zlibrary/text/src/model/ZLCachedMemoryAllocator.cpp index c649c4203..605b9a47b 100644 --- a/jni/NativeFormats/zlibrary/text/src/model/ZLCachedMemoryAllocator.cpp +++ b/jni/NativeFormats/zlibrary/text/src/model/ZLCachedMemoryAllocator.cpp @@ -36,6 +36,7 @@ ZLCachedMemoryAllocator::ZLCachedMemoryAllocator(const size_t rowSize, myCurrentRowSize(0), myOffset(0), myHasChanges(false), + myFailed(false), myDirectoryName(directoryName), myFileExtension(fileExtension) { ZLFile(directoryName).directory(true); @@ -67,7 +68,7 @@ std::string ZLCachedMemoryAllocator::makeFileName(size_t index) { } void ZLCachedMemoryAllocator::writeCache(size_t blockLength) { - if (myPool.size() == 0) { + if (myFailed || myPool.size() == 0) { return; } const size_t index = myPool.size() - 1; @@ -75,7 +76,7 @@ void ZLCachedMemoryAllocator::writeCache(size_t blockLength) { ZLFile file(fileName); shared_ptr stream = file.outputStream(); if (stream.isNull() || !stream->open()) { - //AndroidUtil::throwCachedCharStorageException("Cannot create file " + fileName); + myFailed = true; return; } stream->write(myPool[index], blockLength); diff --git a/jni/NativeFormats/zlibrary/text/src/model/ZLCachedMemoryAllocator.h b/jni/NativeFormats/zlibrary/text/src/model/ZLCachedMemoryAllocator.h index 5ac314060..40815c0fa 100644 --- a/jni/NativeFormats/zlibrary/text/src/model/ZLCachedMemoryAllocator.h +++ b/jni/NativeFormats/zlibrary/text/src/model/ZLCachedMemoryAllocator.h @@ -46,6 +46,7 @@ public: const std::string &fileExtension() const; size_t blocksNumber() const; size_t currentBytesOffset() const; + bool failed() const; private: std::string makeFileName(size_t index); @@ -58,6 +59,7 @@ private: size_t myOffset; bool myHasChanges; + bool myFailed; const std::string myDirectoryName; const std::string myFileExtension; @@ -71,6 +73,7 @@ inline const std::string &ZLCachedMemoryAllocator::directoryName() const { retur inline const std::string &ZLCachedMemoryAllocator::fileExtension() const { return myFileExtension; } inline size_t ZLCachedMemoryAllocator::blocksNumber() const { return myPool.size(); } inline size_t ZLCachedMemoryAllocator::currentBytesOffset() const { return myOffset; } +inline bool ZLCachedMemoryAllocator::failed() const { return myFailed; } inline char *ZLCachedMemoryAllocator::writeUInt16(char *ptr, uint16_t value) { *ptr++ = value;