MCPcopy Create free account
hub / github.com/TurningWheel/Barony / readBooksIntoTemp

Method readBooksIntoTemp

src/book.cpp:304–350  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

302}
303
304void BookParser_t::readBooksIntoTemp()
305{
306 tempBookData.clear();
307
308 std::list<std::string> discoveredbooks = getListOfBooksAfterFiltering();
309
310 if ( !discoveredbooks.empty() )
311 {
312 printlog("[Books]: Read %d books into temporary storage...", discoveredbooks.size());
313 // read books
314 for ( const auto& filename : discoveredbooks )
315 {
316 //printlog("reading book: \"%s\"\n", filename.c_str());
317 std::string filenameNoExtension = filename;
318 auto findExtension = filename.find(".txt");
319 if ( findExtension != std::string::npos )
320 {
321 filenameNoExtension = filename.substr(0, findExtension);
322 }
323 tempBookData.insert(std::make_pair(filenameNoExtension, ""));
324 auto& entry = tempBookData[filenameNoExtension];
325
326 //Load in the text from a file.
327 std::string bookPath = "books/";
328 bookPath.append(filename);
329 if ( PHYSFS_getRealDir(bookPath.c_str()) != nullptr )
330 {
331 std::string path = PHYSFS_getRealDir(bookPath.c_str());
332 path.append(PHYSFS_getDirSeparator());
333 bookPath = path + bookPath;
334 }
335
336 char bookChar[PATH_MAX];
337 strncpy(bookChar, bookPath.c_str(), PATH_MAX - 1);
338 char* tmp = readFile(bookChar);
339 if ( tmp )
340 {
341 entry = tmp;
342 }
343 free(tmp);
344 }
345 }
346 else
347 {
348 printlog("[Books]: Warning - no books were discovered.");
349 }
350}
351
352void BookParser_t::createBooks(bool forceCacheRebuild)
353{

Callers

nothing calls this directly

Calls 7

printlogFunction · 0.85
readFileFunction · 0.85
appendMethod · 0.80
c_strMethod · 0.80
clearMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected