1
0
mirror of https://github.com/Swordfish90/cool-retro-term.git synced 2025-01-31 10:11:20 +00:00

Handle database and profile upgrade for new versions.

This commit is contained in:
Filippo Scognamiglio 2018-11-21 18:11:01 +01:00
parent 04a64e1312
commit cc7c13e17f
3 changed files with 12 additions and 4 deletions

View File

@ -24,7 +24,9 @@ import QtQuick.Controls 1.0
import "utils.js" as Utils import "utils.js" as Utils
QtObject{ QtObject{
property string version: "1.0.1" readonly property string version: "1.0.1"
readonly property int profileVersion: 2
// STATIC CONSTANTS //////////////////////////////////////////////////////// // STATIC CONSTANTS ////////////////////////////////////////////////////////

View File

@ -107,12 +107,15 @@ Tab{
if (!name) if (!name)
throw "Profile doesn't have a name"; throw "Profile doesn't have a name";
var version = profileObject.version !== undefined ? profileObject.version : 1;
if (version !== appSettings.profileVersion)
throw "This profile is not supported on this version of CRT.";
delete profileObject.name; delete profileObject.name;
appSettings.appendCustomProfile(name, JSON.stringify(profileObject)); appSettings.appendCustomProfile(name, JSON.stringify(profileObject));
} catch (err) { } catch (err) {
console.log(err); messageDialog.text = qsTr(err)
messageDialog.text = qsTr("There has been an error reading the file.")
messageDialog.open(); messageDialog.open();
} }
} }
@ -144,6 +147,7 @@ Tab{
var profileObject = appSettings.profilesList.get(currentIndex); var profileObject = appSettings.profilesList.get(currentIndex);
var profileSettings = JSON.parse(profileObject.obj_string); var profileSettings = JSON.parse(profileObject.obj_string);
profileSettings["name"] = profileObject.text; profileSettings["name"] = profileObject.text;
profileSettings["version"] = appSettings.profileVersion;
var result = fileIO.write(url, JSON.stringify(profileSettings, undefined, 2)); var result = fileIO.write(url, JSON.stringify(profileSettings, undefined, 2));
if (!result) if (!result)

View File

@ -22,10 +22,12 @@ import QtQuick 2.2
import QtQuick.LocalStorage 2.0 import QtQuick.LocalStorage 2.0
QtObject { QtObject {
readonly property string dbMajorVersion: "1"
readonly property string dbMinorVersion: "1.0"
property bool initialized: false property bool initialized: false
function getDatabase() { function getDatabase() {
return LocalStorage.openDatabaseSync("coolretroterm", "1.0", "StorageDatabase", 100000); return LocalStorage.openDatabaseSync("coolretroterm" + dbMajorVersion, dbMinorVersion, "StorageDatabase", 100000);
} }
function initialize() { function initialize() {