Performed project-wide code formatting

* Updated format CMake command to properly
ignore new directories and files
* Added output when command is run
* Resolves #2623
This commit is contained in:
Jonathan White 2019-01-20 09:50:20 -05:00
parent c74664097b
commit 7e1b16250c
68 changed files with 591 additions and 542 deletions

View file

@ -41,11 +41,10 @@ const QCommandLineOption Command::QuietOption =
<< "quiet",
QObject::tr("Silence password prompt and other secondary outputs."));
const QCommandLineOption Command::KeyFileOption =
QCommandLineOption(QStringList() << "k"
<< "key-file",
QObject::tr("Key file of the database."),
QObject::tr("path"));
const QCommandLineOption Command::KeyFileOption = QCommandLineOption(QStringList() << "k"
<< "key-file",
QObject::tr("Key file of the database."),
QObject::tr("path"));
QMap<QString, Command*> commands;

View file

@ -88,7 +88,7 @@ int Create::execute(const QStringList& arguments)
}
QSharedPointer<FileKey> fileKey;
if(parser.isSet(Command::KeyFileOption)) {
if (parser.isSet(Command::KeyFileOption)) {
if (!loadFileKey(parser.value(Command::KeyFileOption), fileKey)) {
err << QObject::tr("Loading the key file failed") << endl;
return EXIT_FAILURE;

View file

@ -83,9 +83,9 @@ int Extract::execute(const QStringList& arguments)
if (fileKey->type() != FileKey::Hashed) {
errorTextStream << QObject::tr("WARNING: You are using a legacy key file format which may become\n"
"unsupported in the future.\n\n"
"Please consider generating a new key file.")
<< endl;
"unsupported in the future.\n\n"
"Please consider generating a new key file.")
<< endl;
}
// LCOV_EXCL_STOP

View file

@ -47,14 +47,13 @@ namespace Utils
* DEVNULL file handle for the CLI.
*/
#ifdef Q_OS_WIN
FILE* DEVNULL = fopen("nul", "w");
FILE* DEVNULL = fopen("nul", "w");
#else
FILE* DEVNULL = fopen("/dev/null", "w");
FILE* DEVNULL = fopen("/dev/null", "w");
#endif
void setStdinEcho(bool enable = true)
{
void setStdinEcho(bool enable = true)
{
#ifdef Q_OS_WIN
HANDLE hIn = GetStdHandle(STD_INPUT_HANDLE);
DWORD mode;
@ -98,61 +97,61 @@ void setStdinEcho(bool enable = true)
}
} // namespace Test
QSharedPointer<Database> unlockDatabase(const QString& databaseFilename,
const QString& keyFilename,
FILE* outputDescriptor,
FILE* errorDescriptor)
{
auto compositeKey = QSharedPointer<CompositeKey>::create();
TextStream out(outputDescriptor);
TextStream err(errorDescriptor);
QSharedPointer<Database> unlockDatabase(const QString& databaseFilename,
const QString& keyFilename,
FILE* outputDescriptor,
FILE* errorDescriptor)
{
auto compositeKey = QSharedPointer<CompositeKey>::create();
TextStream out(outputDescriptor);
TextStream err(errorDescriptor);
out << QObject::tr("Insert password to unlock %1: ").arg(databaseFilename) << flush;
out << QObject::tr("Insert password to unlock %1: ").arg(databaseFilename) << flush;
QString line = Utils::getPassword(outputDescriptor);
auto passwordKey = QSharedPointer<PasswordKey>::create();
passwordKey->setPassword(line);
compositeKey->addKey(passwordKey);
QString line = Utils::getPassword(outputDescriptor);
auto passwordKey = QSharedPointer<PasswordKey>::create();
passwordKey->setPassword(line);
compositeKey->addKey(passwordKey);
if (!keyFilename.isEmpty()) {
auto fileKey = QSharedPointer<FileKey>::create();
QString errorMessage;
// LCOV_EXCL_START
if (!fileKey->load(keyFilename, &errorMessage)) {
err << QObject::tr("Failed to load key file %1: %2").arg(keyFilename, errorMessage) << endl;
return {};
if (!keyFilename.isEmpty()) {
auto fileKey = QSharedPointer<FileKey>::create();
QString errorMessage;
// LCOV_EXCL_START
if (!fileKey->load(keyFilename, &errorMessage)) {
err << QObject::tr("Failed to load key file %1: %2").arg(keyFilename, errorMessage) << endl;
return {};
}
if (fileKey->type() != FileKey::Hashed) {
err << QObject::tr("WARNING: You are using a legacy key file format which may become\n"
"unsupported in the future.\n\n"
"Please consider generating a new key file.")
<< endl;
}
// LCOV_EXCL_STOP
compositeKey->addKey(fileKey);
}
if (fileKey->type() != FileKey::Hashed) {
err << QObject::tr("WARNING: You are using a legacy key file format which may become\n"
"unsupported in the future.\n\n"
"Please consider generating a new key file.")
<< endl;
}
// LCOV_EXCL_STOP
compositeKey->addKey(fileKey);
}
auto db = QSharedPointer<Database>::create();
QString error;
auto db = QSharedPointer<Database>::create();
QString error;
if (db->open(databaseFilename, compositeKey, &error, false)) {
return db;
} else {
}else {
err << error << endl;
return {};
}
}
/**
* Read a user password from STDIN or return a password previously
* set by \link setNextPassword().
*
* @return the password
*/
QString getPassword(FILE* outputDescriptor)
{
TextStream out(outputDescriptor, QIODevice::WriteOnly);
/**
* Read a user password from STDIN or return a password previously
* set by \link setNextPassword().
*
* @return the password
*/
QString getPassword(FILE* outputDescriptor)
{
TextStream out(outputDescriptor, QIODevice::WriteOnly);
// return preset password if one is set
if (!Test::nextPasswords.isEmpty()) {

View file

@ -36,9 +36,9 @@ namespace Utils
QString getPassword(FILE* outputDescriptor = STDOUT);
int clipText(const QString& text);
QSharedPointer<Database> unlockDatabase(const QString& databaseFilename,
const QString& keyFilename = {},
FILE* outputDescriptor = STDOUT,
FILE* errorDescriptor = STDERR);
const QString& keyFilename = {},
FILE* outputDescriptor = STDOUT,
FILE* errorDescriptor = STDERR);
namespace Test
{