diff --git a/app/qml/ApplicationSettings.qml b/app/qml/ApplicationSettings.qml index 1742d89..6df3653 100644 --- a/app/qml/ApplicationSettings.qml +++ b/app/qml/ApplicationSettings.qml @@ -24,7 +24,9 @@ import QtQuick.Controls 1.0 import "utils.js" as Utils QtObject{ - property string version: "1.0.1" + readonly property string version: "1.0.1" + readonly property int profileVersion: 2 + // STATIC CONSTANTS //////////////////////////////////////////////////////// @@ -109,6 +111,8 @@ QtObject{ signal initializedSettings() + signal showErrorMessage(string message) + property Loader fontManager: Loader{ states: [ State { when: rasterization == no_rasterization @@ -331,6 +335,17 @@ QtObject{ burnInQuality = settings.burnInQuality !== undefined ? settings.burnInQuality : burnInQuality; } + function userLoadProfileString(profileString) { + var profile = JSON.parse(profileString); + var version = profile.version !== undefined ? profile.version : 1; + + if (version === profileVersion) { + loadProfileString(profileString); + } else { + showErrorMessage("This profile is not supported on this version of CRT.") + } + } + function loadProfileString(profileString){ var settings = JSON.parse(profileString); diff --git a/app/qml/Storage.qml b/app/qml/Storage.qml index a95dd02..fff7183 100644 --- a/app/qml/Storage.qml +++ b/app/qml/Storage.qml @@ -23,9 +23,20 @@ import QtQuick.LocalStorage 2.0 QtObject { property bool initialized: false + property string dbVersion: "1.1" function getDatabase() { - return LocalStorage.openDatabaseSync("coolretroterm", "1.0", "StorageDatabase", 100000); + try { + return _getDatabase(dbVersion); + } catch (error) { + console.log("Error while reading from settings database:", error); + updateAndResetDatabase(_getDatabase("")); + return _getDatabase(dbVersion); + } + } + + function _getDatabase(version) { + return LocalStorage.openDatabaseSync("coolretroterm", version, "StorageDatabase", 100000); } function initialize() { @@ -74,9 +85,22 @@ QtObject { function dropSettings(){ var db = getDatabase(); + dropSettingsFromDB(db); + } + + function updateAndResetDatabase(db) { + console.log("Updating and resetting database."); + db.changeVersion(db.version, dbVersion); + + try { + dropSettingsFromDB(db); + } catch (error) {} + } + + function dropSettingsFromDB(db) { db.transaction( function(tx) { tx.executeSql('DROP TABLE settings'); - }); + }); } }