From 5c9ec9cf3b209d39e2c862cbfa56507be6889b21 Mon Sep 17 00:00:00 2001 From: kelson42 Date: Mon, 12 Nov 2012 10:17:23 +0000 Subject: [PATCH] + fixed buggy kiwix-manage remove feature --- src/manager/kiwix-manage.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/manager/kiwix-manage.cpp b/src/manager/kiwix-manage.cpp index 7a25401..0b0fb9e 100644 --- a/src/manager/kiwix-manage.cpp +++ b/src/manager/kiwix-manage.cpp @@ -174,15 +174,20 @@ int main(int argc, char **argv) { } else if (action == REMOVE) { unsigned int bookIndex = 0; + const unsigned int totalBookCount = libraryManager.getBookCount(true, true); if (argc>3) { bookIndex = atoi(argv[3]); } - if (bookIndex > 0) { - libraryManager.removeBookByIndex(bookIndex); + if (bookIndex > 0 && bookIndex <= totalBookCount) { + libraryManager.removeBookByIndex(bookIndex - 1); } else { - std::cerr << "Invalid book index number" << std::endl; + if (totalBookCount > 0) { + std::cerr << "Invalid book index number. Please give a number between 1 and " << totalBookCount << std::endl; + } else { + std::cerr << "Invalid book index number. Library is empty, no book to delete." << std::endl; + } } }