mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-05 09:33:25 -08:00
[Client] Warn when data paths point inside the program directory (#7473)
Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
f83a61979f
commit
57a6a0d9cb
10 changed files with 247 additions and 1 deletions
|
|
@ -0,0 +1,34 @@
|
|||
#include "path_safety_warning.h"
|
||||
|
||||
#include "../../client/settings/cache_settings.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QMessageBox>
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <libcockatrice/settings/paths_settings.h>
|
||||
|
||||
class QWidget;
|
||||
|
||||
bool PathSafetyWarning::confirmOutsideProgramDir(QWidget *parent, const QString &path)
|
||||
{
|
||||
if (SettingsCache::instance().getIsPortableBuild()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!PathsSettings::isInsideDir(path, QCoreApplication::applicationDirPath())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
QMessageBox box(QMessageBox::Warning, QObject::tr("Path inside the program directory"),
|
||||
QObject::tr("'%1' is inside the Cockatrice program directory.\n\n"
|
||||
"Files stored there can be deleted by an update or by uninstalling "
|
||||
"Cockatrice, so this change was not applied. Choose a location outside "
|
||||
"the program directory.")
|
||||
.arg(path),
|
||||
QMessageBox::Ok, parent);
|
||||
box.setTextFormat(Qt::PlainText);
|
||||
box.exec();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
#ifndef COCKATRICE_PATH_SAFETY_WARNING_H
|
||||
#define COCKATRICE_PATH_SAFETY_WARNING_H
|
||||
|
||||
class QString;
|
||||
class QWidget;
|
||||
|
||||
namespace PathSafetyWarning
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief Warns when the user tries to configure a data path inside the program directory.
|
||||
*
|
||||
* Shows a message box explaining that files kept there can be deleted by an
|
||||
* update or by uninstalling Cockatrice. Portable builds are always exempt:
|
||||
* their data lives beside the executables by design.
|
||||
*
|
||||
* @param parent The parent widget
|
||||
* @param path The path the user is trying to configure
|
||||
* @return true when the path is outside the program directory and safe to apply
|
||||
*/
|
||||
bool confirmOutsideProgramDir(QWidget *parent, const QString &path);
|
||||
|
||||
} // namespace PathSafetyWarning
|
||||
|
||||
#endif // COCKATRICE_PATH_SAFETY_WARNING_H
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "../../../client/settings/cache_settings.h"
|
||||
#include "../../pixel_map_generator.h"
|
||||
#include "../dialogs/path_safety_warning.h"
|
||||
#include "update/card_spoiler/spoiler_background_updater.h"
|
||||
|
||||
#include <QAbstractItemModel>
|
||||
|
|
@ -363,6 +364,9 @@ void DeckEditorSettingsPage::spoilerPathButtonClicked()
|
|||
if (lsPath.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (!PathSafetyWarning::confirmOutsideProgramDir(this, lsPath + "/spoiler.xml")) {
|
||||
return;
|
||||
}
|
||||
|
||||
mpSpoilerSavePathLineEdit->setText(lsPath + "/spoiler.xml");
|
||||
SettingsCache::instance().paths().setSpoilerDatabasePath(lsPath + "/spoiler.xml");
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#include "general_settings_page.h"
|
||||
|
||||
#include "../../../client/settings/cache_settings.h"
|
||||
#include "../dialogs/path_safety_warning.h"
|
||||
#include "../interface/card_picture_loader/card_picture_loader.h"
|
||||
#include "../main.h"
|
||||
#include "../server/user/user_info_connection.h"
|
||||
|
|
@ -378,6 +379,9 @@ void GeneralSettingsPage::deckPathButtonClicked()
|
|||
if (path.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (!PathSafetyWarning::confirmOutsideProgramDir(this, path)) {
|
||||
return;
|
||||
}
|
||||
|
||||
deckPathEdit->setText(path);
|
||||
SettingsCache::instance().paths().setDeckPath(path);
|
||||
|
|
@ -389,6 +393,9 @@ void GeneralSettingsPage::filtersPathButtonClicked()
|
|||
if (path.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (!PathSafetyWarning::confirmOutsideProgramDir(this, path)) {
|
||||
return;
|
||||
}
|
||||
|
||||
filtersPathEdit->setText(path);
|
||||
SettingsCache::instance().paths().setFiltersPath(path);
|
||||
|
|
@ -400,6 +407,9 @@ void GeneralSettingsPage::replaysPathButtonClicked()
|
|||
if (path.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (!PathSafetyWarning::confirmOutsideProgramDir(this, path)) {
|
||||
return;
|
||||
}
|
||||
|
||||
replaysPathEdit->setText(path);
|
||||
SettingsCache::instance().paths().setReplaysPath(path);
|
||||
|
|
@ -411,6 +421,9 @@ void GeneralSettingsPage::picsPathButtonClicked()
|
|||
if (path.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (!PathSafetyWarning::confirmOutsideProgramDir(this, path)) {
|
||||
return;
|
||||
}
|
||||
|
||||
picsPathEdit->setText(path);
|
||||
SettingsCache::instance().paths().setPicsPath(path);
|
||||
|
|
@ -422,6 +435,9 @@ void GeneralSettingsPage::cardDatabasePathButtonClicked()
|
|||
if (path.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (!PathSafetyWarning::confirmOutsideProgramDir(this, path)) {
|
||||
return;
|
||||
}
|
||||
|
||||
cardDatabasePathEdit->setText(path);
|
||||
SettingsCache::instance().paths().setCardDatabasePath(path);
|
||||
|
|
@ -433,6 +449,9 @@ void GeneralSettingsPage::customCardDatabaseButtonClicked()
|
|||
if (path.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (!PathSafetyWarning::confirmOutsideProgramDir(this, path)) {
|
||||
return;
|
||||
}
|
||||
|
||||
customCardDatabasePathEdit->setText(path);
|
||||
SettingsCache::instance().paths().setCustomCardDatabasePath(path);
|
||||
|
|
@ -444,6 +463,9 @@ void GeneralSettingsPage::tokenDatabasePathButtonClicked()
|
|||
if (path.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (!PathSafetyWarning::confirmOutsideProgramDir(this, path)) {
|
||||
return;
|
||||
}
|
||||
|
||||
tokenDatabasePathEdit->setText(path);
|
||||
SettingsCache::instance().paths().setTokenDatabasePath(path);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue