Adding saveToFile function.

This commit is contained in:
Louis-Bertrand Varin 2017-06-14 19:50:19 -04:00
parent 139658b5c3
commit f3f6f6a493
4 changed files with 41 additions and 28 deletions

View file

@ -19,6 +19,7 @@
#include "Database.h"
#include <QFile>
#include <QSaveFile>
#include <QTextStream>
#include <QTimer>
#include <QXmlStreamReader>
@ -28,6 +29,7 @@
#include "crypto/Random.h"
#include "format/KeePass2.h"
#include "format/KeePass2Reader.h"
#include "format/KeePass2Writer.h"
QHash<Uuid, Database*> Database::m_uuidMap;
@ -412,3 +414,28 @@ Database* Database::unlockFromStdin(QString databaseFilename)
return Database::openDatabaseFile(databaseFilename, key);
}
QString Database::saveToFile(QString filePath)
{
KeePass2Writer writer;
QSaveFile saveFile(filePath);
if (saveFile.open(QIODevice::WriteOnly)) {
// write the database to the file
writer.writeDatabase(&saveFile, this);
if (writer.hasError()) {
return writer.errorString();
}
if (saveFile.commit()) {
// successfully saved database file
return QString();
} else {
return saveFile.errorString();
}
} else {
return saveFile.errorString();
}
}