-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add KeePass header check for testing remote download (#10910) #10915
base: develop
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
#include "DatabaseSettingsWidgetRemote.h" | ||
#include "ui_DatabaseSettingsWidgetRemote.h" | ||
|
||
#include "core/Database.h" | ||
#include "core/Global.h" | ||
#include "core/Metadata.h" | ||
|
||
|
@@ -191,10 +192,24 @@ void DatabaseSettingsWidgetRemote::testDownload() | |
} | ||
|
||
if (!QFile::exists(result.filePath)) { | ||
m_ui->messageWidget->showMessage(tr("Download finished, but file %1 could not be found.").arg(result.filePath), | ||
m_ui->messageWidget->showMessage(tr("Command finished, but downloaded file does not exist."), | ||
MessageWidget::Error); | ||
return; | ||
} | ||
|
||
if (!hasValidPublicHeaders(result.filePath)) { | ||
m_ui->messageWidget->showMessage(tr("Download finished, but file failed KeePass header check. File is not a " | ||
"KeePass file or it's an unsupported version"), | ||
MessageWidget::Error); | ||
return; | ||
} | ||
|
||
m_ui->messageWidget->showMessage(tr("Download successful."), MessageWidget::Positive); | ||
} | ||
|
||
bool DatabaseSettingsWidgetRemote::hasValidPublicHeaders(QString& filePath) { | ||
// Read public headers | ||
QString error; | ||
QScopedPointer<Database> db(new Database()); | ||
return db->open(filePath, nullptr, &error); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could inline this since you have only a single call for it and use the error string. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wasn't sure if I should use the error string, as it can be quite long and may not fit in the message box. I added the error anyway, as it is better to have it rather than leave the user in the dark. I did not inline the method though, as I prefer having a named method, rather than calling There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we are repeating this pattern we should introduce a |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use the actual error from database open here. "KeePass header check" is quite a technical error message as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have adapted the error message