mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 07:47:24 +00:00
Handle invalid appdata file.
This commit is contained in:
@@ -3,6 +3,7 @@ import 'dart:convert';
|
|||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
import 'package:venera/foundation/app.dart';
|
import 'package:venera/foundation/app.dart';
|
||||||
|
import 'package:venera/foundation/log.dart';
|
||||||
import 'package:venera/utils/data_sync.dart';
|
import 'package:venera/utils/data_sync.dart';
|
||||||
import 'package:venera/utils/init.dart';
|
import 'package:venera/utils/init.dart';
|
||||||
import 'package:venera/utils/io.dart';
|
import 'package:venera/utils/io.dart';
|
||||||
@@ -110,21 +111,31 @@ class Appdata with Init {
|
|||||||
if (!await file.exists()) {
|
if (!await file.exists()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var json = jsonDecode(await file.readAsString());
|
try {
|
||||||
for (var key in (json['settings'] as Map<String, dynamic>).keys) {
|
var json = jsonDecode(await file.readAsString());
|
||||||
if (json['settings'][key] != null) {
|
for (var key in (json['settings'] as Map<String, dynamic>).keys) {
|
||||||
settings[key] = json['settings'][key];
|
if (json['settings'][key] != null) {
|
||||||
|
settings[key] = json['settings'][key];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
searchHistory = List.from(json['searchHistory']);
|
||||||
}
|
}
|
||||||
searchHistory = List.from(json['searchHistory']);
|
catch(e) {
|
||||||
var implicitDataFile = File(FilePath.join(dataPath, 'implicitData.json'));
|
Log.error("Appdata", "Failed to load appdata", e);
|
||||||
if (await implicitDataFile.exists()) {
|
Log.info("Appdata", "Resetting appdata");
|
||||||
try {
|
file.deleteIgnoreError();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
var implicitDataFile = File(FilePath.join(dataPath, 'implicitData.json'));
|
||||||
|
if (await implicitDataFile.exists()) {
|
||||||
implicitData = jsonDecode(await implicitDataFile.readAsString());
|
implicitData = jsonDecode(await implicitDataFile.readAsString());
|
||||||
}
|
}
|
||||||
catch(_) {
|
}
|
||||||
// ignore
|
catch (e) {
|
||||||
}
|
Log.error("Appdata", "Failed to load implicit data", e);
|
||||||
|
Log.info("Appdata", "Resetting implicit data");
|
||||||
|
var implicitDataFile = File(FilePath.join(dataPath, 'implicitData.json'));
|
||||||
|
implicitDataFile.deleteIgnoreError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user