Skip to content

Commit

Permalink
opt.: backup backward compatiblility
Browse files Browse the repository at this point in the history
  • Loading branch information
lollipopkit committed Sep 1, 2024
1 parent ec97661 commit e80690c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
41 changes: 22 additions & 19 deletions lib/data/model/app/backup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,9 +28,9 @@ class Backup extends Mergeable {
final Map<String, dynamic> container;
final Map<String, dynamic> history;
final int? lastModTime;
final Map<String, dynamic> settings;
final Map<String, dynamic>? settings;

Backup({
const Backup({
required this.version,
required this.date,
required this.spis,
Expand Down Expand Up @@ -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]);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/data/model/app/backup.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e80690c

Please sign in to comment.