mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2026-11-27 20:36:49 -08:00
Allow specifing database backup paths. (#7035)
- Default backupFilePath is '{DB_FILENAME}.old.kdbx' to conform to existing standards
- Implement backupPathPattern tests.
- Show tooltip on how to format database backup location text field.
This commit is contained in:
1 parent
8d7e491810
commit
84ff6a13f9
25 files changed
+368
-81
No files matched your search
@@ -22,7 +22,10 @@
|
||||
#include "config-keepassx.h"
|
||||
#include "git-info.h"
|
||||
|
||||
#include "core/Clock.h"
|
||||
|
||||
#include <QElapsedTimer>
|
||||
#include <QFileInfo>
|
||||
#include <QImageReader>
|
||||
#include <QLocale>
|
||||
#include <QMetaProperty>
|
||||
@@ -376,4 +379,37 @@ namespace Tools
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
QString substituteBackupFilePath(QString pattern, const QString& databasePath)
|
||||
{
|
||||
// Fail if substitution fails
|
||||
if (databasePath.isEmpty()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
// Replace backup pattern
|
||||
QFileInfo dbFileInfo(databasePath);
|
||||
QString baseName = dbFileInfo.completeBaseName();
|
||||
|
||||
pattern.replace(QString("{DB_FILENAME}"), baseName);
|
||||
|
||||
auto re = QRegularExpression(R"(\{TIME(?::([^\\]*))?\})");
|
||||
auto match = re.match(pattern);
|
||||
while (match.hasMatch()) {
|
||||
// Extract time format specifier
|
||||
auto formatSpecifier = QString("dd_MM_yyyy_hh-mm-ss");
|
||||
if (!match.captured(1).isEmpty()) {
|
||||
formatSpecifier = match.captured(1);
|
||||
}
|
||||
auto replacement = Clock::currentDateTime().toString(formatSpecifier);
|
||||
pattern.replace(match.capturedStart(), match.capturedLength(), replacement);
|
||||
match = re.match(pattern);
|
||||
}
|
||||
|
||||
// Replace escaped braces
|
||||
pattern.replace("\\{", "{");
|
||||
pattern.replace("\\}", "}");
|
||||
|
||||
return pattern;
|
||||
}
|
||||
} // namespace Tools
|
||||
Reference in new issue
Block a user