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