Move OPF file path detection into own function.
This commit is contained in:
parent
d2aff45018
commit
fca719634a
40
src/book.cpp
40
src/book.cpp
|
@ -189,28 +189,28 @@ string page(const document &doc, const size_t pos)
|
|||
return string(last);
|
||||
}
|
||||
|
||||
fs::path get_opf_file_path(const fs::path &zipfile)
|
||||
{
|
||||
pugi::xml_document xml;
|
||||
const std::string container{
|
||||
zip::read_file(zipfile, "META-INF/container.xml")};
|
||||
const auto result{xml.load_buffer(&container[0], container.size())};
|
||||
if (result)
|
||||
{
|
||||
return fs::path{xml.child("container")
|
||||
.child("rootfiles")
|
||||
.first_child()
|
||||
.attribute("full-path")
|
||||
.value()};
|
||||
}
|
||||
LOG(log::sev::error) << result.description() << '\n';
|
||||
|
||||
return fs::path{};
|
||||
};
|
||||
|
||||
std::vector<string> list_spine(const fs::path &filepath)
|
||||
{
|
||||
const auto opf_file_path{
|
||||
[&filepath]
|
||||
{
|
||||
pugi::xml_document xml;
|
||||
const std::string container{
|
||||
zip::read_file(filepath, "META-INF/container.xml")};
|
||||
const auto result{xml.load_buffer(&container[0], container.size())};
|
||||
if (result)
|
||||
{
|
||||
return fs::path{xml.child("container")
|
||||
.child("rootfiles")
|
||||
.first_child()
|
||||
.attribute("full-path")
|
||||
.value()};
|
||||
}
|
||||
LOG(log::sev::error) << result.description() << '\n';
|
||||
|
||||
return fs::path{};
|
||||
}()};
|
||||
|
||||
auto opf_file_path{get_opf_file_path(filepath)};
|
||||
std::vector<std::string> spine_filepaths;
|
||||
if (!opf_file_path.empty())
|
||||
{
|
||||
|
|
|
@ -62,6 +62,9 @@ struct book
|
|||
//! Return current page if possible.
|
||||
[[nodiscard]] std::string page(const document &doc, size_t pos);
|
||||
|
||||
//! Returns the file path of the OPF file in the EPUB.
|
||||
[[nodiscard]] fs::path get_opf_file_path(const fs::path &zipfile);
|
||||
|
||||
//! Returns the files in the EPUB “spine” (all pages that are actually text).
|
||||
[[nodiscard]] std::vector<string> list_spine(const fs::path &filepath);
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user