parent
26678812c9
commit
c94d9de0db
30
src/main.cpp
30
src/main.cpp
|
@ -32,12 +32,14 @@
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
|
#include <fstream>
|
||||||
#include <future>
|
#include <future>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <locale>
|
#include <locale>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
#include <system_error>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
@ -70,8 +72,8 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
catch (std::exception &e)
|
catch (std::exception &e)
|
||||||
{ // Exceptions we can't recover from or ones we don't know.
|
{ // Exceptions we can't recover from or ones we don't know.
|
||||||
cerr << translate("ERROR: ") << e.what() << '\n';
|
cerr << translate("ERROR: ") << e.what();
|
||||||
cerr << translate("Error while parsing options.") << '\n';
|
cerr << translate(" (while parsing options)") << '\n';
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,17 +152,33 @@ int main(int argc, char *argv[])
|
||||||
catch (const zip::exception &e)
|
catch (const zip::exception &e)
|
||||||
{
|
{
|
||||||
if (opts.ignore_archive_errors && e.code == 1)
|
if (opts.ignore_archive_errors && e.code == 1)
|
||||||
{
|
{ // File is probably not an EPUB.
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
cerr << translate("ERROR: ") << e.what() << '\n';
|
cerr << translate("ERROR: ") << e.what();
|
||||||
cerr << format(translate("Error while searching {0:s}.")
|
cerr << format(translate(" (while searching {0:s})").str(),
|
||||||
.str(),
|
|
||||||
filepath)
|
filepath)
|
||||||
<< '\n';
|
<< '\n';
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
catch (const std::ifstream::failure &e)
|
||||||
|
{
|
||||||
|
cerr << translate("ERROR: ");
|
||||||
|
if (e.code() == std::errc::permission_denied)
|
||||||
|
{
|
||||||
|
cerr << translate("Permission denied.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{ // std::ifstream seems to always return a generic error?
|
||||||
|
cerr << translate("Probably permission denied.") << " ("
|
||||||
|
<< e.what() << ')';
|
||||||
|
}
|
||||||
|
|
||||||
|
cerr << format(translate(" (while opening {0:s})").str(),
|
||||||
|
filepath)
|
||||||
|
<< '\n';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
|
14
src/zip.cpp
14
src/zip.cpp
|
@ -106,16 +106,10 @@ std::string read_file(const fs::path &filepath, std::string_view entry_path)
|
||||||
|
|
||||||
struct archive *open_file(const fs::path &filepath)
|
struct archive *open_file(const fs::path &filepath)
|
||||||
{
|
{
|
||||||
std::ifstream file{filepath};
|
// Throw exception if we can't open the file.
|
||||||
if (!file.good())
|
std::ifstream file;
|
||||||
{
|
file.exceptions(std::ios::failbit);
|
||||||
exception e{format(translate("Could not open {0:s}: "
|
file.open(filepath);
|
||||||
"Permission denied.")
|
|
||||||
.str(),
|
|
||||||
filepath.string())};
|
|
||||||
e.code = 2;
|
|
||||||
throw exception{e};
|
|
||||||
}
|
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
auto *zipfile{archive_read_new()};
|
auto *zipfile{archive_read_new()};
|
||||||
|
|
Loading…
Reference in New Issue