And even more...
This commit is contained in:
@@ -260,9 +260,10 @@ void XMLCALL ContentOpfParser::startElement(void* userData, const XML_Char* name
|
|||||||
if (strcmp(metaName, "cover") == 0) {
|
if (strcmp(metaName, "cover") == 0) {
|
||||||
self->coverItemId = metaContent;
|
self->coverItemId = metaContent;
|
||||||
} else if (strcmp(metaName, "calibre:series") == 0 && self->series.empty()) {
|
} else if (strcmp(metaName, "calibre:series") == 0 && self->series.empty()) {
|
||||||
self->series = trim(std::string(metaContent)).substr(0, MAX_DESCRIPTION_LENGTH);
|
self->series = trim(std::string(metaContent, std::min(strlen(metaContent), size_t{MAX_DESCRIPTION_LENGTH})));
|
||||||
} else if (strcmp(metaName, "calibre:series_index") == 0 && self->seriesIndex.empty()) {
|
} else if (strcmp(metaName, "calibre:series_index") == 0 && self->seriesIndex.empty()) {
|
||||||
self->seriesIndex = trim(std::string(metaContent)).substr(0, MAX_DESCRIPTION_LENGTH);
|
self->seriesIndex =
|
||||||
|
trim(std::string(metaContent, std::min(strlen(metaContent), size_t{MAX_DESCRIPTION_LENGTH})));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,7 +274,7 @@ void XMLCALL ContentOpfParser::startElement(void* userData, const XML_Char* name
|
|||||||
if (metaProperty) {
|
if (metaProperty) {
|
||||||
if (strcmp(metaProperty, "belongs-to-collection") == 0 && self->series.empty()) {
|
if (strcmp(metaProperty, "belongs-to-collection") == 0 && self->series.empty()) {
|
||||||
if (metaContent) {
|
if (metaContent) {
|
||||||
self->series = trim(std::string(metaContent)).substr(0, MAX_DESCRIPTION_LENGTH);
|
self->series = trim(std::string(metaContent, std::min(strlen(metaContent), size_t{MAX_DESCRIPTION_LENGTH})));
|
||||||
} else {
|
} else {
|
||||||
self->state = IN_BOOK_SERIES;
|
self->state = IN_BOOK_SERIES;
|
||||||
return;
|
return;
|
||||||
@@ -281,7 +282,8 @@ void XMLCALL ContentOpfParser::startElement(void* userData, const XML_Char* name
|
|||||||
}
|
}
|
||||||
if (strcmp(metaProperty, "group-position") == 0 && self->seriesIndex.empty()) {
|
if (strcmp(metaProperty, "group-position") == 0 && self->seriesIndex.empty()) {
|
||||||
if (metaContent) {
|
if (metaContent) {
|
||||||
self->seriesIndex = trim(std::string(metaContent)).substr(0, MAX_DESCRIPTION_LENGTH);
|
self->seriesIndex =
|
||||||
|
trim(std::string(metaContent, std::min(strlen(metaContent), size_t{MAX_DESCRIPTION_LENGTH})));
|
||||||
} else {
|
} else {
|
||||||
self->state = IN_BOOK_SERIES_INDEX;
|
self->state = IN_BOOK_SERIES_INDEX;
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -134,19 +134,26 @@ bool RecentBooksStore::loadFromBinaryFile() {
|
|||||||
|
|
||||||
// load book to get missing data
|
// load book to get missing data
|
||||||
RecentBook book = getDataFromBook(path);
|
RecentBook book = getDataFromBook(path);
|
||||||
if (book.title.empty() && book.author.empty() && version == 2) {
|
if (version == 2) {
|
||||||
// Fall back to loading what we can from the store
|
// v2 always stores title and author after path; consume them regardless
|
||||||
std::string title, author;
|
// of whether live metadata was found, to keep the stream aligned.
|
||||||
if (!serialization::readString(inputFile, title) || !serialization::readString(inputFile, author)) {
|
std::string storedTitle, storedAuthor;
|
||||||
|
if (!serialization::readString(inputFile, storedTitle) || !serialization::readString(inputFile, storedAuthor)) {
|
||||||
LOG_ERR("RBS", "Corrupt recent.bin: string too long at entry %u", i);
|
LOG_ERR("RBS", "Corrupt recent.bin: string too long at entry %u", i);
|
||||||
inputFile.close();
|
inputFile.close();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
// Prefer live metadata; fall back to stored when live is unavailable.
|
||||||
|
const std::string& title = !book.title.empty() ? book.title : storedTitle;
|
||||||
|
const std::string& author = !book.title.empty() ? book.author : storedAuthor;
|
||||||
if (!title.empty()) {
|
if (!title.empty()) {
|
||||||
tmpRecentBooks.push_back({path, title, author, "", ""});
|
tmpRecentBooks.push_back({path, title, author, "", ""});
|
||||||
}
|
}
|
||||||
} else if (!book.title.empty()) {
|
} else {
|
||||||
tmpRecentBooks.push_back(book);
|
// v1: no stored title/author bytes
|
||||||
|
if (!book.title.empty()) {
|
||||||
|
tmpRecentBooks.push_back(book);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
recentBooks = std::move(tmpRecentBooks);
|
recentBooks = std::move(tmpRecentBooks);
|
||||||
|
|||||||
Reference in New Issue
Block a user