@@ -29,10 +29,10 @@ using namespace std;
29
29
30
30
enum supportedAction { NONE, ADD, SHOW, REMOVE };
31
31
32
- void show (kiwix::Library* library, const std::string& bookId)
32
+ void show (const kiwix::Library& library, const std::string& bookId)
33
33
{
34
34
try {
35
- auto & book = library-> getBookById (bookId);
35
+ auto & book = library. getBookById (bookId);
36
36
std::cout << " id:\t\t " << book.getId () << std::endl
37
37
<< " path:\t\t " << book.getPath () << std::endl
38
38
<< " url:\t\t " << book.getUrl () << std::endl
@@ -96,7 +96,7 @@ void usage()
96
96
<< std::endl;
97
97
}
98
98
99
- int handle_show (kiwix::Library* library, const std::string& libraryPath,
99
+ int handle_show (const kiwix::Library& library, const std::string& libraryPath,
100
100
int argc, char * argv[])
101
101
{
102
102
if (argc > 3 ) {
@@ -105,15 +105,15 @@ int handle_show(kiwix::Library* library, const std::string& libraryPath,
105
105
show (library, bookId);
106
106
}
107
107
} else {
108
- auto booksIds = library-> getBooksIds ();
108
+ auto booksIds = library. getBooksIds ();
109
109
for (auto & bookId: booksIds) {
110
110
show (library, bookId);
111
111
}
112
112
}
113
113
return (0 );
114
114
}
115
115
116
- int handle_add (kiwix::Library* library, const std::string& libraryPath,
116
+ int handle_add (kiwix::LibraryPtr library, const std::string& libraryPath,
117
117
int argc, char * argv[])
118
118
{
119
119
string zimPath;
@@ -182,11 +182,11 @@ int handle_add(kiwix::Library* library, const std::string& libraryPath,
182
182
return (resultCode);
183
183
}
184
184
185
- int handle_remove (kiwix::Library* library, const std::string& libraryPath,
185
+ int handle_remove (kiwix::Library& library, const std::string& libraryPath,
186
186
int argc, char * argv[])
187
187
{
188
188
std::string bookId;
189
- const unsigned int totalBookCount = library-> getBookCount (true , true );
189
+ const unsigned int totalBookCount = library. getBookCount (true , true );
190
190
int exitCode = 0 ;
191
191
192
192
if (argc <= 3 ) {
@@ -203,7 +203,7 @@ int handle_remove(kiwix::Library* library, const std::string& libraryPath,
203
203
for (int i = 3 ; i<argc; i++) {
204
204
bookId = argv[i];
205
205
206
- if (!library-> removeBookById (bookId)) {
206
+ if (!library. removeBookById (bookId)) {
207
207
std::cerr << " Invalid book id '" << bookId << " '." << std::endl;
208
208
exitCode = 1 ;
209
209
}
@@ -216,7 +216,7 @@ int main(int argc, char** argv)
216
216
{
217
217
string libraryPath = " " ;
218
218
supportedAction action = NONE;
219
- kiwix::Library library ;
219
+ auto library = kiwix::Library::create () ;
220
220
221
221
/* General argument parsing */
222
222
static struct option long_options[] = {
@@ -261,7 +261,7 @@ int main(int argc, char** argv)
261
261
libraryPath = kiwix::isRelativePath (libraryPath)
262
262
? kiwix::computeAbsolutePath (kiwix::getCurrentDirectory (), libraryPath)
263
263
: libraryPath;
264
- kiwix::Manager manager (& library);
264
+ kiwix::Manager manager (library);
265
265
if (!manager.readFile (libraryPath, false )) {
266
266
if (kiwix::fileExists (libraryPath) || action!=ADD) {
267
267
std::cerr << " Cannot read the library " << libraryPath << std::endl;
@@ -273,13 +273,13 @@ int main(int argc, char** argv)
273
273
int exitCode = 0 ;
274
274
switch (action) {
275
275
case SHOW:
276
- exitCode = handle_show (& library, libraryPath, argc, argv);
276
+ exitCode = handle_show (* library, libraryPath, argc, argv);
277
277
break ;
278
278
case ADD:
279
- exitCode = handle_add (& library, libraryPath, argc, argv);
279
+ exitCode = handle_add (library, libraryPath, argc, argv);
280
280
break ;
281
281
case REMOVE:
282
- exitCode = handle_remove (& library, libraryPath, argc, argv);
282
+ exitCode = handle_remove (* library, libraryPath, argc, argv);
283
283
break ;
284
284
case NONE:
285
285
break ;
@@ -292,7 +292,7 @@ int main(int argc, char** argv)
292
292
/* Rewrite the library file */
293
293
if (action == REMOVE || action == ADD) {
294
294
// writeToFile return true (1) if everything is ok => exitCode is 0
295
- if (!library. writeToFile (libraryPath)) {
295
+ if (!library-> writeToFile (libraryPath)) {
296
296
std::cerr << " Cannot write the library " << libraryPath << std::endl;
297
297
return 1 ;
298
298
}
0 commit comments