libcryfs/src/cryfs-cli/main.cpp

48 lines
1.4 KiB
C++
Raw Normal View History

#include "Cli.h"
2016-02-11 16:39:42 +01:00
#include <cpp-utils/random/Random.h>
#include <cpp-utils/io/IOStreamConsole.h>
2019-01-26 08:38:34 +01:00
#include <cryfs/impl/CryfsException.h>
#if defined(_MSC_VER)
#include <cpp-utils/network/WinHttpClient.h>
2018-12-14 09:40:38 +01:00
#include <VersionHelpers.h>
#else
#include <cpp-utils/network/CurlHttpClient.h>
#endif
using namespace cryfs_cli;
using cpputils::Random;
using cpputils::SCrypt;
using cpputils::IOStreamConsole;
using cpputils::make_unique_ref;
using std::make_shared;
2016-09-24 09:51:29 +02:00
using std::cerr;
2015-09-28 13:41:23 +02:00
int main(int argc, const char *argv[]) {
2018-12-14 09:40:38 +01:00
#if defined(_MSC_VER)
2018-12-22 10:25:47 +01:00
if (!IsWindows7SP1OrGreater()) {
std::cerr << "CryFS is currently only supported on Windows 7 SP1 (or later)." << std::endl;
exit(1);
2018-12-14 09:40:38 +01:00
}
#endif
2016-09-24 09:51:29 +02:00
try {
auto &keyGenerator = Random::OSRandom();
#if defined(_MSC_VER)
2018-12-14 09:40:38 +01:00
auto httpClient = make_unique_ref<cpputils::WinHttpClient>();
#else
2018-12-14 09:40:38 +01:00
auto httpClient = make_unique_ref<cpputils::CurlHttpClient>();
#endif
return Cli(keyGenerator, SCrypt::DefaultSettings, make_shared<IOStreamConsole>())
.main(argc, argv, std::move(httpClient), []{});
} catch (const cryfs::CryfsException &e) {
if (e.what() != string()) {
std::cerr << "Error: " << e.what() << std::endl;
}
return exitCode(e.errorCode());
2016-09-24 09:51:29 +02:00
} catch (const std::exception &e) {
cerr << "Error: " << e.what();
return exitCode(cryfs::ErrorCode::UnspecifiedError);
2016-09-24 09:51:29 +02:00
}
2014-11-04 02:32:06 +01:00
}