diff --git a/cli/src/translate.cpp b/cli/src/translate.cpp index 24a80102..dc027844 100644 --- a/cli/src/translate.cpp +++ b/cli/src/translate.cpp @@ -16,25 +16,25 @@ int main(int argc, char **argv) { password = argv[3]; } - File file{input}; + DecodedFile decoded_file{input}; - HtmlConfig config; - config.editable = true; - - PasswordCallback password_callback = [&]() { - if (!password) { + if (decoded_file.is_document_file()) { + DocumentFile document_file = decoded_file.document_file(); + if (document_file.password_encrypted() && !password) { std::cerr << "document encrypted but no password given" << std::endl; - std::exit(2); + return 2; + } + if (document_file.password_encrypted() && + !document_file.decrypt(*password)) { + std::cerr << "wrong password" << std::endl; + return 1; } - return *password; - }; - - try { - html::translate(file, output, config, password_callback); - } catch (const WrongPassword &e) { - std::cerr << "wrong password" << std::endl; - return 1; } + HtmlConfig config; + config.editable = true; + + html::translate(decoded_file, output, config); + return 0; }