diff --git a/source/menus/book/BookReader.cpp b/source/menus/book/BookReader.cpp index 68029e0..6093eb3 100644 --- a/source/menus/book/BookReader.cpp +++ b/source/menus/book/BookReader.cpp @@ -47,9 +47,9 @@ static void save_last_page(const char *book_name, int current_page) { } } -BookReader::BookReader(const char *path) { +BookReader::BookReader(const char *path, int* result) { if (ctx == NULL) { - ctx = fz_new_context(NULL, NULL, 128 << 10); + ctx = fz_new_context(NULL, NULL, FZ_STORE_UNLIMITED); fz_register_document_handlers(ctx); } @@ -62,15 +62,32 @@ BookReader::BookReader(const char *path) { book_name.erase(std::remove(book_name.begin(), book_name.end(), c), book_name.end()); } - std::cout << "fz_open_document" << std::endl; - doc = fz_open_document(ctx, path); - - int current_page = load_last_page(book_name.c_str()); - //int current_page = 0; - switch_current_page_layout(_currentPageLayout, current_page); - - if (current_page > 0) { - show_status_bar(); + fz_try(ctx) { + std::cout << "fz_open_document" << std::endl; + doc = fz_open_document(ctx, path); + + if (!doc) + { + std::cout << "Error opening file!" << std::endl; + *result = -1; + return; + } + + int current_page = load_last_page(book_name.c_str()); + //int current_page = 0; + + std::cout << "current_page = " << current_page << std::endl; + + switch_current_page_layout(_currentPageLayout, current_page); + + if (current_page > 0) { + show_status_bar(); + } + } + fz_catch(ctx){ + std::cout << "fz_catch reached, closing gracefully" << std::endl; + *result = -2; + return; } } diff --git a/source/menus/book/BookReader.hpp b/source/menus/book/BookReader.hpp index 69508ed..1ed11e9 100644 --- a/source/menus/book/BookReader.hpp +++ b/source/menus/book/BookReader.hpp @@ -14,7 +14,7 @@ typedef enum { class BookReader { public: - BookReader(const char *path); + BookReader(const char *path, int *result); ~BookReader(); bool permStatusBar = false; diff --git a/source/menus/book/menu_book_reader.cpp b/source/menus/book/menu_book_reader.cpp index 1692b81..6f2a9bf 100644 --- a/source/menus/book/menu_book_reader.cpp +++ b/source/menus/book/menu_book_reader.cpp @@ -10,14 +10,21 @@ extern "C" { #include "BookReader.hpp" void Menu_OpenBook(char *path) { - BookReader *reader = new BookReader(path); + BookReader *reader = NULL; + int result = 0; + + reader = new BookReader(path, &result); + + if(result < 0){ + std::cout << "Menu_OpenBook: document not loaded" << std::endl; + } /*TouchInfo touchInfo; Touch_Init(&touchInfo);*/ bool helpMenu = false; - while(appletMainLoop()) { + while(result >= 0 && appletMainLoop()) { reader->draw(helpMenu); hidScanInput();