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:
tastytea 2021-05-28 13:55:11 +02:00
parent 65b46ca846
commit 308e2d271f
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
1 changed files with 13 additions and 1 deletions

View File

@ -27,6 +27,7 @@
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <stdexcept>
#include <string>
#include <vector>
@ -45,7 +46,18 @@ std::vector<std::string> list(const fs::path &filepath)
std::vector<std::string> toc;
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);
}