mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 15:24:35 +01:00
fix: manual restore
This commit is contained in:
@@ -90,83 +90,109 @@ class Backup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Snippets
|
// Snippets
|
||||||
final nowSnippets = Stores.snippet.box.keys.toSet();
|
if (force) {
|
||||||
final bakSnippets = snippets.map((e) => e.name).toSet();
|
for (final s in snippets) {
|
||||||
final newSnippets = bakSnippets.difference(nowSnippets);
|
Stores.snippet.box.put(s.name, s);
|
||||||
final delSnippets = nowSnippets.difference(bakSnippets);
|
}
|
||||||
final updateSnippets = nowSnippets.intersection(bakSnippets);
|
} else {
|
||||||
for (final s in newSnippets) {
|
final nowSnippets = Stores.snippet.box.keys.toSet();
|
||||||
Stores.snippet.box.put(s, snippets.firstWhere((e) => e.name == s));
|
final bakSnippets = snippets.map((e) => e.name).toSet();
|
||||||
}
|
final newSnippets = bakSnippets.difference(nowSnippets);
|
||||||
for (final s in delSnippets) {
|
final delSnippets = nowSnippets.difference(bakSnippets);
|
||||||
Stores.snippet.box.delete(s);
|
final updateSnippets = nowSnippets.intersection(bakSnippets);
|
||||||
}
|
for (final s in newSnippets) {
|
||||||
for (final s in updateSnippets) {
|
Stores.snippet.box.put(s, snippets.firstWhere((e) => e.name == s));
|
||||||
Stores.snippet.box.put(s, snippets.firstWhere((e) => e.name == s));
|
}
|
||||||
|
for (final s in delSnippets) {
|
||||||
|
Stores.snippet.box.delete(s);
|
||||||
|
}
|
||||||
|
for (final s in updateSnippets) {
|
||||||
|
Stores.snippet.box.put(s, snippets.firstWhere((e) => e.name == s));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServerPrivateInfo
|
// ServerPrivateInfo
|
||||||
final nowSpis = Stores.server.box.keys.toSet();
|
if (force) {
|
||||||
final bakSpis = spis.map((e) => e.id).toSet();
|
for (final s in spis) {
|
||||||
final newSpis = bakSpis.difference(nowSpis);
|
Stores.server.box.put(s.id, s);
|
||||||
final delSpis = nowSpis.difference(bakSpis);
|
}
|
||||||
final updateSpis = nowSpis.intersection(bakSpis);
|
} else {
|
||||||
for (final s in newSpis) {
|
final nowSpis = Stores.server.box.keys.toSet();
|
||||||
Stores.server.box.put(s, spis.firstWhere((e) => e.id == s));
|
final bakSpis = spis.map((e) => e.id).toSet();
|
||||||
}
|
final newSpis = bakSpis.difference(nowSpis);
|
||||||
for (final s in delSpis) {
|
final delSpis = nowSpis.difference(bakSpis);
|
||||||
Stores.server.box.delete(s);
|
final updateSpis = nowSpis.intersection(bakSpis);
|
||||||
}
|
for (final s in newSpis) {
|
||||||
for (final s in updateSpis) {
|
Stores.server.box.put(s, spis.firstWhere((e) => e.id == s));
|
||||||
Stores.server.box.put(s, spis.firstWhere((e) => e.id == s));
|
}
|
||||||
|
for (final s in delSpis) {
|
||||||
|
Stores.server.box.delete(s);
|
||||||
|
}
|
||||||
|
for (final s in updateSpis) {
|
||||||
|
Stores.server.box.put(s, spis.firstWhere((e) => e.id == s));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// PrivateKeyInfo
|
// PrivateKeyInfo
|
||||||
final nowKeys = Stores.key.box.keys.toSet();
|
if (force) {
|
||||||
final bakKeys = keys.map((e) => e.id).toSet();
|
for (final s in keys) {
|
||||||
final newKeys = bakKeys.difference(nowKeys);
|
Stores.key.box.put(s.id, s);
|
||||||
final delKeys = nowKeys.difference(bakKeys);
|
}
|
||||||
final updateKeys = nowKeys.intersection(bakKeys);
|
} else {
|
||||||
for (final s in newKeys) {
|
final nowKeys = Stores.key.box.keys.toSet();
|
||||||
Stores.key.box.put(s, keys.firstWhere((e) => e.id == s));
|
final bakKeys = keys.map((e) => e.id).toSet();
|
||||||
}
|
final newKeys = bakKeys.difference(nowKeys);
|
||||||
for (final s in delKeys) {
|
final delKeys = nowKeys.difference(bakKeys);
|
||||||
Stores.key.box.delete(s);
|
final updateKeys = nowKeys.intersection(bakKeys);
|
||||||
}
|
for (final s in newKeys) {
|
||||||
for (final s in updateKeys) {
|
Stores.key.box.put(s, keys.firstWhere((e) => e.id == s));
|
||||||
Stores.key.box.put(s, keys.firstWhere((e) => e.id == s));
|
}
|
||||||
|
for (final s in delKeys) {
|
||||||
|
Stores.key.box.delete(s);
|
||||||
|
}
|
||||||
|
for (final s in updateKeys) {
|
||||||
|
Stores.key.box.put(s, keys.firstWhere((e) => e.id == s));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// History
|
// History
|
||||||
final nowHistory = Stores.history.box.keys.toSet();
|
if (force) {
|
||||||
final bakHistory = history.keys.toSet();
|
Stores.history.box.putAll(history);
|
||||||
final newHistory = bakHistory.difference(nowHistory);
|
} else {
|
||||||
final delHistory = nowHistory.difference(bakHistory);
|
final nowHistory = Stores.history.box.keys.toSet();
|
||||||
final updateHistory = nowHistory.intersection(bakHistory);
|
final bakHistory = history.keys.toSet();
|
||||||
for (final s in newHistory) {
|
final newHistory = bakHistory.difference(nowHistory);
|
||||||
Stores.history.box.put(s, history[s]);
|
final delHistory = nowHistory.difference(bakHistory);
|
||||||
}
|
final updateHistory = nowHistory.intersection(bakHistory);
|
||||||
for (final s in delHistory) {
|
for (final s in newHistory) {
|
||||||
Stores.history.box.delete(s);
|
Stores.history.box.put(s, history[s]);
|
||||||
}
|
}
|
||||||
for (final s in updateHistory) {
|
for (final s in delHistory) {
|
||||||
Stores.history.box.put(s, history[s]);
|
Stores.history.box.delete(s);
|
||||||
|
}
|
||||||
|
for (final s in updateHistory) {
|
||||||
|
Stores.history.box.put(s, history[s]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Container
|
// Container
|
||||||
final nowContainer = Stores.container.box.keys.toSet();
|
if (force) {
|
||||||
final bakContainer = container.keys.toSet();
|
Stores.container.box.putAll(container);
|
||||||
final newContainer = bakContainer.difference(nowContainer);
|
} else {
|
||||||
final delContainer = nowContainer.difference(bakContainer);
|
final nowContainer = Stores.container.box.keys.toSet();
|
||||||
final updateContainer = nowContainer.intersection(bakContainer);
|
final bakContainer = container.keys.toSet();
|
||||||
for (final s in newContainer) {
|
final newContainer = bakContainer.difference(nowContainer);
|
||||||
Stores.container.box.put(s, container[s]);
|
final delContainer = nowContainer.difference(bakContainer);
|
||||||
}
|
final updateContainer = nowContainer.intersection(bakContainer);
|
||||||
for (final s in delContainer) {
|
for (final s in newContainer) {
|
||||||
Stores.container.box.delete(s);
|
Stores.container.box.put(s, container[s]);
|
||||||
}
|
}
|
||||||
for (final s in updateContainer) {
|
for (final s in delContainer) {
|
||||||
Stores.container.box.put(s, container[s]);
|
Stores.container.box.delete(s);
|
||||||
|
}
|
||||||
|
for (final s in updateContainer) {
|
||||||
|
Stores.container.box.put(s, container[s]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Pros.reload();
|
Pros.reload();
|
||||||
|
|||||||
Reference in New Issue
Block a user