mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-05 17:43:23 -08:00
[Client] Extract at-risk data warning out of MainWindow
This commit is contained in:
parent
d72db0f5b0
commit
202c0d6561
5 changed files with 436 additions and 382 deletions
55
cockatrice/src/interface/at_risk_data_warning.h
Normal file
55
cockatrice/src/interface/at_risk_data_warning.h
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
#ifndef AT_RISK_DATA_WARNING_H
|
||||
#define AT_RISK_DATA_WARNING_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QtGlobal>
|
||||
|
||||
class QWidget;
|
||||
|
||||
/**
|
||||
* @brief Warns when user data lives inside the program directory and backs it up first.
|
||||
*
|
||||
* The uninstallers shipped in Cockatrice 3.1.0/3.1.1 delete the whole install
|
||||
* tree, so data paths configured inside the program directory (and portable
|
||||
* installs, whose data lives there by design) get a safety backup outside the
|
||||
* install directory before the warning is shown.
|
||||
*/
|
||||
class AtRiskDataWarning : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
struct AtRiskBackupOutcome
|
||||
{
|
||||
QStringList locations; ///< backup targets created for this check
|
||||
QString sessionDir; ///< session directory holding the backup
|
||||
bool complete = true; ///< false when only a partial/fallback backup exists
|
||||
bool reused = false; ///< true when a recent session was reused instead of copying
|
||||
bool skippedDueToSize = false; ///< true when the automatic copy was skipped for size
|
||||
qint64 bytes = 0; ///< estimated bytes, only set when a fresh copy was attempted
|
||||
};
|
||||
struct AtRiskPaths
|
||||
{
|
||||
QStringList sourcesToBackUp; ///< existing paths that need a safety copy
|
||||
QStringList offendersForDisplay; ///< paths listed in the warning (empty for portable)
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Backs up at-risk data paths and warns about them.
|
||||
* @param parent Parent widget for the warning dialog
|
||||
*/
|
||||
static void warnAboutDataPathsInProgramDir(QWidget *parent);
|
||||
|
||||
private:
|
||||
static AtRiskPaths collectPortableAtRiskPaths(const QString &appDir);
|
||||
static QStringList collectInstalledAtRiskPaths(const QString &appDir);
|
||||
static AtRiskBackupOutcome backUpAtRiskPaths(const QStringList &sources, const QString &appDir);
|
||||
static QString buildPortableAtRiskMessage(const AtRiskBackupOutcome &outcome, bool emptySources);
|
||||
static QString buildInstalledAtRiskMessage(const QStringList &offenders,
|
||||
const QStringList &sources,
|
||||
const AtRiskBackupOutcome &outcome);
|
||||
static void showAtRiskDataWarning(QWidget *parent, const QString &title, const QString &message);
|
||||
};
|
||||
|
||||
#endif // AT_RISK_DATA_WARNING_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue