From 1424821ff5c8240f1cb47c2ccfc09b5a3b5aaad1 Mon Sep 17 00:00:00 2001 From: kelson42 Date: Tue, 1 Nov 2011 13:01:23 +0000 Subject: [PATCH] + improve kiwix-install --- src/installer/kiwix-install.cpp | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/installer/kiwix-install.cpp b/src/installer/kiwix-install.cpp index 7c4e942..9885eda 100644 --- a/src/installer/kiwix-install.cpp +++ b/src/installer/kiwix-install.cpp @@ -23,6 +23,7 @@ #include #include #include +#include enum supportedBackend { XAPIAN, CLUCENE }; enum supportedAction { NONE, ADDCONTENT }; @@ -116,6 +117,7 @@ int main(int argc, char **argv) { cerr << "The content available at '" << contentPath << "' is not a ZIM file." << endl; exit(1); } + string contentFilename = getLastPathElement(contentPath); /* Check if kiwixPath/kiwix/kiwix.exe exists */ string kiwixBinaryPath = computeAbsolutePath(kiwixPath, "kiwix/kiwix.exe"); @@ -149,12 +151,39 @@ int main(int argc, char **argv) { } /* Copy the file to the data/content directory */ - - /* Check if the library.xml exists */ + string newContentPath = computeAbsolutePath(dataContentPath, contentFilename); + copyFile(contentPath, newContentPath); /* Add the file to the library.xml */ + string libraryPath = computeAbsolutePath(dataLibraryPath, contentFilename + ".xml"); + kiwix::Manager libraryManager; + if (libraryManager.addBookFromPath(newContentPath, "../content/" + contentFilename, "", false)) { + libraryManager.writeFile(libraryPath); + } else { + cerr << "Unable to build or save library file '" << libraryPath << "'" << endl; + } /* Index the file if necessary */ + string indexPath = computeAbsolutePath(dataIndexPath, contentFilename + ".idx"); + kiwix::Indexer *indexer = NULL; + try { + if (backend == CLUCENE) { + indexer = new kiwix::CluceneIndexer(contentPath, indexPath); + } else { + indexer = new kiwix::XapianIndexer(contentPath, indexPath); + } + } catch (...) { + cerr << "Unable to index '" << contentPath << "'." << endl; + exit(1); + } + + if (indexer != NULL) { + while (indexer->indexNextPercent(verboseFlag)) {}; + delete indexer; + } else { + cerr << "Unable instanciate the Kiwix indexer." << endl; + exit(1); + } } exit(0);