Skip to content

Commit edbc805

Browse files
committed
Warn when trying to open file with newer version than app
For #168
1 parent 7b7c451 commit edbc805

File tree

3 files changed

+109
-29
lines changed

3 files changed

+109
-29
lines changed

src/db/db_upgrade.cpp

+58-15
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ bool DatabaseUpgrader::checkDatabaseVersionAndUpgrade(std::function<void ()> exe
7070
const QString currentDbVersion = determineCurrentDbVersion();
7171
const QString appVersion = getAppVersion();
7272

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+
}
7380
if (!isBelowVersion(currentDbVersion, appVersion)) {
7481
// No upgrade necessary
7582
executeAfterStructuralUpgrade();
@@ -79,11 +86,8 @@ bool DatabaseUpgrader::checkDatabaseVersionAndUpgrade(std::function<void ()> exe
7986
// Determine whether upgrading from the old version will definitely break compatibility
8087
bool upgradeBreakCompatibility = isBelowVersion(currentDbVersion, "1.2.0");
8188

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);
8791
if (abort) return false;
8892

8993

@@ -187,40 +191,78 @@ QString DatabaseUpgrader::determineCurrentDbVersion()
187191

188192

189193
/**
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.
191196
*
192197
* @param oldDbVersion The version of the database file before the upgrade.
193198
* @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.
195200
*/
196-
bool DatabaseUpgrader::promptUserAboutUpgrade(const QString& oldDbVersion, bool claimOlderVersionsIncompatible)
201+
bool DatabaseUpgrader::promptUserAboutUpgradeAndBackup(const QString& oldDbVersion, bool claimOlderVersionsIncompatible)
197202
{
198203
QString filepath = db->getCurrentFilepath();
199204
QString windowTitle = Database::tr("Database upgrade necessary");
200205
QString compatibilityStatement = claimOlderVersionsIncompatible
201206
? Database::tr("After the upgrade, previous versions of PAL will no longer be able to open the file.")
202207
: 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.");
203209
QString message = filepath + "\n\n"
204210
+ Database::tr("Opening this project requires upgrading its database from version %1 to version %2."
205211
"\n%3"
206212
"\n\nDo you want to perform the upgrade now?"
207-
"\n\nNote: 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);
209215
auto buttons = QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel;
210216
auto defaultButton = QMessageBox::Cancel;
211217

212218
auto response = QMessageBox::question(parent, windowTitle, message, buttons, defaultButton);
213219

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+
"\nOpening 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;
215256
}
216257

217258
/**
218259
* Creates a backup copy of the project file and asks the user whether to continue if the copy
219260
* fails.
220261
*
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.
222264
*/
223-
bool DatabaseUpgrader::createFileBackupCopy()
265+
bool DatabaseUpgrader::createFileBackupCopy(const QString& confirmationQuestion)
224266
{
225267
// Determine backup filename
226268
QString filepath = db->getCurrentFilepath();
@@ -237,8 +279,9 @@ bool DatabaseUpgrader::createFileBackupCopy()
237279
QString windowTitle = Database::tr("Error creating backup");
238280
QString message = filepath + "\n\n"
239281
+ Database::tr("An error occurred while trying to create a backup of the project file."
240-
"\nDo you want to perform the upgrade anyway?"
241-
"\n\nNote: You can still create a backup manually before proceeding.");
282+
"\n%1"
283+
"\n\nNote: You can still create a backup manually before proceeding.")
284+
.arg(confirmationQuestion);
242285
auto buttons = QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel;
243286
auto defaultButton = QMessageBox::Cancel;
244287

src/db/db_upgrade.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ class DatabaseUpgrader
4747

4848
private:
4949
QString determineCurrentDbVersion();
50-
bool promptUserAboutUpgrade(const QString& oldDbVersion, bool claimOlderVersionsIncompatible);
51-
bool createFileBackupCopy();
50+
bool promptUserAboutUpgradeAndBackup(const QString& oldDbVersion, bool claimOlderVersionsIncompatible);
51+
bool showOutdatedAppWarningAndBackup(const QString& dbVersion);
52+
bool createFileBackupCopy(const QString& confirmationQuestion);
5253
void showUpgradeSuccessMessage(const QString& previousVersion, const QString& newVersion);
5354

5455
// Version-specific functions

translation/de.ts

+48-12
Original file line numberDiff line numberDiff line change
@@ -1169,58 +1169,94 @@ Die Datei kann entfernt oder ersetzt werden. Alternativ können mit einem Werkze
11691169
<translation>Details:</translation>
11701170
</message>
11711171
<message>
1172-
<location filename="../src/db/db_upgrade.cpp" line="199"/>
1172+
<location filename="../src/db/db_upgrade.cpp" line="204"/>
11731173
<source>Database upgrade necessary</source>
11741174
<translation>Datenbank muss aktualisiert werden</translation>
11751175
</message>
11761176
<message>
1177-
<location filename="../src/db/db_upgrade.cpp" line="201"/>
1177+
<location filename="../src/db/db_upgrade.cpp" line="206"/>
11781178
<source>After the upgrade, previous versions of PAL will no longer be able to open the file.</source>
11791179
<translation>Nach der Aktualisierung werden ältere Versionen von PAL die Datei nicht mehr öffnen können.</translation>
11801180
</message>
11811181
<message>
1182-
<location filename="../src/db/db_upgrade.cpp" line="202"/>
1182+
<location filename="../src/db/db_upgrade.cpp" line="207"/>
11831183
<source>After the upgrade, previous versions of PAL might no longer be able to open the file.</source>
11841184
<translation>Nach der Aktualisierung werden ältere Versionen von PAL die Datei möglicherweise nicht mehr öffnen können.</translation>
11851185
</message>
11861186
<message>
1187-
<location filename="../src/db/db_upgrade.cpp" line="204"/>
1187+
<location filename="../src/db/db_upgrade.cpp" line="208"/>
1188+
<location filename="../src/db/db_upgrade.cpp" line="238"/>
1189+
<source>Note: A copy of the project file in its current state will be created as a backup.</source>
1190+
<translation>Hinweis: Eine Kopie der Projektdatei in ihrem aktuellen Zustand wird als Backup gespeichert.</translation>
1191+
</message>
1192+
<message>
1193+
<location filename="../src/db/db_upgrade.cpp" line="210"/>
11881194
<source>Opening this project requires upgrading its database from version %1 to version %2.
11891195
%3
11901196

11911197
Do you want to perform the upgrade now?
11921198

1193-
Note: A copy of the project file in its current state will be created as a backup.</source>
1199+
%4</source>
11941200
<translation>Um diese Projektdatei zu öffnen, muss die Datenbank von Version %1 zu Version %2 aktualisiert werden.
11951201
%3
11961202

11971203
Soll die Aktualisierung jetzt durchgeführt werden?
11981204

1199-
Hinweis: Eine Kopie der Projektdatei in ihrem aktuellen Zustand wird als Backup gespeichert.</translation>
1205+
%4</translation>
1206+
</message>
1207+
<message>
1208+
<location filename="../src/db/db_upgrade.cpp" line="223"/>
1209+
<source>Do you want to perform the upgrade anyway?</source>
1210+
<translation>Soll die Aktualisierung trotzdem durchgeführt werden?</translation>
12001211
</message>
12011212
<message>
12021213
<location filename="../src/db/db_upgrade.cpp" line="237"/>
1203-
<source>Error creating backup</source>
1204-
<translation>Fehler beim Erstellen des Backups</translation>
1214+
<source>App version outdated</source>
1215+
<translation>App-Version veraltet</translation>
12051216
</message>
12061217
<message>
12071218
<location filename="../src/db/db_upgrade.cpp" line="239"/>
1219+
<source>Do you want to open the file anyway?</source>
1220+
<translation>Soll die Datei trotzdem geöffnet werden?</translation>
1221+
</message>
1222+
<message>
1223+
<location filename="../src/db/db_upgrade.cpp" line="241"/>
1224+
<source>This project file has version %1, while the app has version %2.
1225+
Opening a file with an older version of PAL can lead to errors, crashes and data corruption.It is strongly recommended to only use PAL version %1 or newer to open this file.
1226+
1227+
%3
1228+
1229+
%4</source>
1230+
<translation>Diese Projektdatei hat Version %1, die App jedoch Version %2.
1231+
Eine Datei mit einer älteren Version von PAL zu öffnen, kann zu Fehlern, Abstürzen und Datenverlust führen. Es wird dringend empfohlen, nur PAL mit Version %1 oder neuer zu verwenden, um diese Datei zu öffnen.
1232+
1233+
%3
1234+
1235+
%4</translation>
1236+
</message>
1237+
<message>
1238+
<location filename="../src/db/db_upgrade.cpp" line="281"/>
12081239
<source>An error occurred while trying to create a backup of the project file.
1209-
Do you want to perform the upgrade anyway?
1240+
%1
12101241

12111242
Note: You can still create a backup manually before proceeding.</source>
12121243
<translation>Beim Kopieren der Projektdatei als Backup ist ein Fehler aufgetreten.
1213-
Soll die Aktualisierung trotzdem durchgeführt werden?
1244+
%1
12141245

12151246
Hinweis: Vor dem Bestätigen kann die Datei auch noch manuell gesichert werden.</translation>
12161247
</message>
12171248
<message>
1218-
<location filename="../src/db/db_upgrade.cpp" line="260"/>
1249+
<location filename="../src/db/db_upgrade.cpp" line="279"/>
1250+
<source>Error creating backup</source>
1251+
<translation>Fehler beim Erstellen des Backups</translation>
1252+
</message>
1253+
<message>
1254+
<location filename="../src/db/db_upgrade.cpp" line="303"/>
12191255
<source>Database upgrade successful</source>
12201256
<translation>Aktualisierung der Datenbank erfolgreich</translation>
12211257
</message>
12221258
<message>
1223-
<location filename="../src/db/db_upgrade.cpp" line="261"/>
1259+
<location filename="../src/db/db_upgrade.cpp" line="304"/>
12241260
<source>The database was successfully upgraded from version %1 to version %2.</source>
12251261
<translation>Die Datenbank wurde erfolgreich von Version %1 zu Version %2 aktualisiert.</translation>
12261262
</message>

0 commit comments

Comments
 (0)