From e80690c340721c2dc511b8d76026ed24ffd2a7f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?lollipopkit=F0=9F=8F=B3=EF=B8=8F=E2=80=8D=E2=9A=A7?= =?UTF-8?q?=EF=B8=8F?= <10864310+lollipopkit@users.noreply.github.com> Date: Sun, 1 Sep 2024 21:03:13 +0800 Subject: [PATCH] opt.: backup backward compatiblility --- lib/data/model/app/backup.dart | 41 +++++++++++++++++--------------- lib/data/model/app/backup.g.dart | 2 +- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/lib/data/model/app/backup.dart b/lib/data/model/app/backup.dart index a70d0ef8a..0707b5b93 100644 --- a/lib/data/model/app/backup.dart +++ b/lib/data/model/app/backup.dart @@ -18,7 +18,7 @@ const backupFormatVersion = 1; final _logger = Logger('Backup'); @JsonSerializable() -class Backup extends Mergeable { +class Backup implements Mergeable { // backup format version final int version; final String date; @@ -28,9 +28,9 @@ class Backup extends Mergeable { final Map container; final Map history; final int? lastModTime; - final Map settings; + final Map? settings; - Backup({ + const Backup({ required this.version, required this.date, required this.spis, @@ -181,22 +181,25 @@ class Backup extends Mergeable { } // Settings - if (force) { - Stores.setting.box.putAll(settings); - } else { - final nowSettings = Stores.setting.box.keys.toSet(); - final bakSettings = settings.keys.toSet(); - final newSettings = bakSettings.difference(nowSettings); - final delSettings = nowSettings.difference(bakSettings); - final updateSettings = nowSettings.intersection(bakSettings); - for (final s in newSettings) { - Stores.setting.box.put(s, settings[s]); - } - for (final s in delSettings) { - Stores.setting.box.delete(s); - } - for (final s in updateSettings) { - Stores.setting.box.put(s, settings[s]); + final settings_ = settings; + if (settings_ != null) { + if (force) { + Stores.setting.box.putAll(settings_); + } else { + final nowSettings = Stores.setting.box.keys.toSet(); + final bakSettings = settings_.keys.toSet(); + final newSettings = bakSettings.difference(nowSettings); + final delSettings = nowSettings.difference(bakSettings); + final updateSettings = nowSettings.intersection(bakSettings); + for (final s in newSettings) { + Stores.setting.box.put(s, settings_[s]); + } + for (final s in delSettings) { + Stores.setting.box.delete(s); + } + for (final s in updateSettings) { + Stores.setting.box.put(s, settings_[s]); + } } } diff --git a/lib/data/model/app/backup.g.dart b/lib/data/model/app/backup.g.dart index 00b5717b4..9c5d53ccd 100644 --- a/lib/data/model/app/backup.g.dart +++ b/lib/data/model/app/backup.g.dart @@ -20,7 +20,7 @@ Backup _$BackupFromJson(Map json) => Backup( .toList(), container: json['container'] as Map, history: json['history'] as Map, - settings: json['settings'] as Map, + settings: json['settings'] as Map?, lastModTime: (json['lastModTime'] as num?)?.toInt(), );