Skip rest of file if encoding of files in EPUB is broken.
Standard says UTF-8. I don't want to deal with weird Windows-encodings or whatever this is. Closes: #7
This commit is contained in:
parent
65b46ca846
commit
308e2d271f
14
src/zip.cpp
14
src/zip.cpp
|
@ -27,6 +27,7 @@
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
@ -45,7 +46,18 @@ std::vector<std::string> list(const fs::path &filepath)
|
||||||
std::vector<std::string> toc;
|
std::vector<std::string> toc;
|
||||||
while (archive_read_next_header(zipfile, &entry) == ARCHIVE_OK)
|
while (archive_read_next_header(zipfile, &entry) == ARCHIVE_OK)
|
||||||
{
|
{
|
||||||
toc.emplace_back(archive_entry_pathname_utf8(entry));
|
const auto *in_epub_filepath{archive_entry_pathname_utf8(entry)};
|
||||||
|
if (in_epub_filepath == nullptr)
|
||||||
|
{ // If the encoding is broken, we skip the file.
|
||||||
|
std::cerr << translate("WARNING: ")
|
||||||
|
<< format(translate("{0:s} is damaged. "
|
||||||
|
"Skipping rest of file.\n")
|
||||||
|
.str()
|
||||||
|
.data(),
|
||||||
|
filepath);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
toc.emplace_back(in_epub_filepath);
|
||||||
archive_read_data_skip(zipfile);
|
archive_read_data_skip(zipfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user