@@ -70,6 +70,13 @@ bool DatabaseUpgrader::checkDatabaseVersionAndUpgrade(std::function<void ()> exe
70
70
const QString currentDbVersion = determineCurrentDbVersion ();
71
71
const QString appVersion = getAppVersion ();
72
72
73
+ if (isBelowVersion (appVersion, currentDbVersion)) {
74
+ // App is older than database version, show warning
75
+ bool abort = !showOutdatedAppWarningAndBackup (currentDbVersion);
76
+ if (abort ) return false ;
77
+ executeAfterStructuralUpgrade ();
78
+ return true ;
79
+ }
73
80
if (!isBelowVersion (currentDbVersion, appVersion)) {
74
81
// No upgrade necessary
75
82
executeAfterStructuralUpgrade ();
@@ -79,11 +86,8 @@ bool DatabaseUpgrader::checkDatabaseVersionAndUpgrade(std::function<void ()> exe
79
86
// Determine whether upgrading from the old version will definitely break compatibility
80
87
bool upgradeBreakCompatibility = isBelowVersion (currentDbVersion, " 1.2.0" );
81
88
82
- // Ask user to confirm upgrade
83
- bool abort = !promptUserAboutUpgrade (currentDbVersion, upgradeBreakCompatibility);
84
- if (abort ) return false ;
85
- // Create backup copy of project file
86
- abort = !createFileBackupCopy ();
89
+ // Ask user to confirm upgrade and create backup
90
+ bool abort = !promptUserAboutUpgradeAndBackup (currentDbVersion, upgradeBreakCompatibility);
87
91
if (abort ) return false ;
88
92
89
93
@@ -187,40 +191,78 @@ QString DatabaseUpgrader::determineCurrentDbVersion()
187
191
188
192
189
193
/* *
190
- * Shows a message box informing the user about the upgrade and asking them to confirm it.
194
+ * Shows a message box informing the user about the upgrade, asking them to confirm it, and creates
195
+ * a backup copy of the project file if so.
191
196
*
192
197
* @param oldDbVersion The version of the database file before the upgrade.
193
198
* @param claimOlderVersionsIncompatible Whether to claim that older versions of the app will be incompatible with the upgraded database.
194
- * @return True if the user confirmed the upgrade , false otherwise.
199
+ * @return True if the user wants to continue , false otherwise.
195
200
*/
196
- bool DatabaseUpgrader::promptUserAboutUpgrade (const QString& oldDbVersion, bool claimOlderVersionsIncompatible)
201
+ bool DatabaseUpgrader::promptUserAboutUpgradeAndBackup (const QString& oldDbVersion, bool claimOlderVersionsIncompatible)
197
202
{
198
203
QString filepath = db->getCurrentFilepath ();
199
204
QString windowTitle = Database::tr (" Database upgrade necessary" );
200
205
QString compatibilityStatement = claimOlderVersionsIncompatible
201
206
? Database::tr (" After the upgrade, previous versions of PAL will no longer be able to open the file." )
202
207
: Database::tr (" After the upgrade, previous versions of PAL might no longer be able to open the file." );
208
+ QString backupNote = Database::tr (" Note: A copy of the project file in its current state will be created as a backup." );
203
209
QString message = filepath + " \n\n "
204
210
+ Database::tr (" Opening this project requires upgrading its database from version %1 to version %2."
205
211
" \n %3"
206
212
" \n\n Do you want to perform the upgrade now?"
207
- " \n\n Note: A copy of the project file in its current state will be created as a backup. " )
208
- .arg (oldDbVersion, getAppVersion (), compatibilityStatement);
213
+ " \n\n %4 " )
214
+ .arg (oldDbVersion, getAppVersion (), compatibilityStatement, backupNote );
209
215
auto buttons = QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel;
210
216
auto defaultButton = QMessageBox::Cancel;
211
217
212
218
auto response = QMessageBox::question (parent, windowTitle, message, buttons, defaultButton);
213
219
214
- return response == QMessageBox::Yes;
220
+ bool abort = response != QMessageBox::Yes;
221
+ if (abort ) return false ;
222
+
223
+ QString confirmationQuestion = Database::tr (" Do you want to perform the upgrade anyway?" );
224
+ abort = !createFileBackupCopy (confirmationQuestion);
225
+ return !abort ;
226
+ }
227
+
228
+ /* *
229
+ * Shows a message box informing the user about the outdated app version, asking them to confirm
230
+ * opening the file anyway, and creates a backup copy of the project file if so.
231
+ *
232
+ * @param dbVersion The version of the database file before the upgrade.
233
+ * @return True if the user wants to continue, false otherwise.
234
+ */
235
+ bool DatabaseUpgrader::showOutdatedAppWarningAndBackup (const QString& dbVersion)
236
+ {
237
+ QString windowTitle = Database::tr (" App version outdated" );
238
+ QString backupNote = Database::tr (" Note: A copy of the project file in its current state will be created as a backup." );
239
+ QString confirmationQuestion = Database::tr (" Do you want to open the file anyway?" );
240
+ QString message = db->getCurrentFilepath () + " \n\n "
241
+ + Database::tr (" This project file has version %1, while the app has version %2."
242
+ " \n Opening a file with an older version of PAL can lead to errors, crashes and data corruption."
243
+ " It is strongly recommended to only use PAL version %1 or newer to open this file."
244
+ " \n\n %3"
245
+ " \n\n %4" )
246
+ .arg (dbVersion, getAppVersion (), confirmationQuestion, backupNote);
247
+ auto buttons = QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel;
248
+ auto defaultButton = QMessageBox::Cancel;
249
+
250
+ auto response = QMessageBox::warning (parent, windowTitle, message, buttons, defaultButton);
251
+ bool abort = response != QMessageBox::Yes;
252
+ if (abort ) return false ;
253
+
254
+ abort = !createFileBackupCopy (confirmationQuestion);
255
+ return !abort ;
215
256
}
216
257
217
258
/* *
218
259
* Creates a backup copy of the project file and asks the user whether to continue if the copy
219
260
* fails.
220
261
*
221
- * @return True if the backup was created successfully or the user wants to continue anyway, false otherwise.
262
+ * @param confirmationQuestion Translated string to insert into the message, asking the user whether to continue if the backup failed.
263
+ * @return True if the backup was created successfully or the user wants to continue anyway, false otherwise.
222
264
*/
223
- bool DatabaseUpgrader::createFileBackupCopy ()
265
+ bool DatabaseUpgrader::createFileBackupCopy (const QString& confirmationQuestion )
224
266
{
225
267
// Determine backup filename
226
268
QString filepath = db->getCurrentFilepath ();
@@ -237,8 +279,9 @@ bool DatabaseUpgrader::createFileBackupCopy()
237
279
QString windowTitle = Database::tr (" Error creating backup" );
238
280
QString message = filepath + " \n\n "
239
281
+ Database::tr (" An error occurred while trying to create a backup of the project file."
240
- " \n Do you want to perform the upgrade anyway?"
241
- " \n\n Note: You can still create a backup manually before proceeding." );
282
+ " \n %1"
283
+ " \n\n Note: You can still create a backup manually before proceeding." )
284
+ .arg (confirmationQuestion);
242
285
auto buttons = QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel;
243
286
auto defaultButton = QMessageBox::Cancel;
244
287
0 commit comments