mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 07:47:24 +00:00
handle invalid local path
This commit is contained in:
@@ -175,6 +175,27 @@ class LocalManager with ChangeNotifier {
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<String> findDefaultPath() async {
|
||||
if (App.isAndroid) {
|
||||
var external = await getExternalStorageDirectories();
|
||||
if (external != null && external.isNotEmpty) {
|
||||
return FilePath.join(external.first.path, 'local');
|
||||
} else {
|
||||
return FilePath.join(App.dataPath, 'local');
|
||||
}
|
||||
} else if (App.isIOS) {
|
||||
var oldPath = FilePath.join(App.dataPath, 'local');
|
||||
if (Directory(oldPath).existsSync() && Directory(oldPath).listSync().isNotEmpty) {
|
||||
return oldPath;
|
||||
} else {
|
||||
var directory = await getApplicationDocumentsDirectory();
|
||||
return FilePath.join(directory.path, 'local');
|
||||
}
|
||||
} else {
|
||||
return FilePath.join(App.dataPath, 'local');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> init() async {
|
||||
_db = sqlite3.open(
|
||||
'${App.dataPath}/local.db',
|
||||
@@ -196,28 +217,19 @@ class LocalManager with ChangeNotifier {
|
||||
''');
|
||||
if (File(FilePath.join(App.dataPath, 'local_path')).existsSync()) {
|
||||
path = File(FilePath.join(App.dataPath, 'local_path')).readAsStringSync();
|
||||
if (!Directory(path).existsSync()) {
|
||||
path = await findDefaultPath();
|
||||
}
|
||||
} else {
|
||||
if (App.isAndroid) {
|
||||
var external = await getExternalStorageDirectories();
|
||||
if (external != null && external.isNotEmpty) {
|
||||
path = FilePath.join(external.first.path, 'local');
|
||||
} else {
|
||||
path = FilePath.join(App.dataPath, 'local');
|
||||
}
|
||||
} else if (App.isIOS) {
|
||||
var oldPath = FilePath.join(App.dataPath, 'local');
|
||||
if (Directory(oldPath).existsSync() && Directory(oldPath).listSync().isNotEmpty) {
|
||||
path = oldPath;
|
||||
} else {
|
||||
var directory = await getApplicationDocumentsDirectory();
|
||||
path = FilePath.join(directory.path, 'local');
|
||||
}
|
||||
} else {
|
||||
path = FilePath.join(App.dataPath, 'local');
|
||||
path = await findDefaultPath();
|
||||
}
|
||||
try {
|
||||
if (!Directory(path).existsSync()) {
|
||||
await Directory(path).create();
|
||||
}
|
||||
}
|
||||
if (!Directory(path).existsSync()) {
|
||||
await Directory(path).create();
|
||||
catch(e, s) {
|
||||
Log.error("IO", "Failed to create local folder: $e", s);
|
||||
}
|
||||
restoreDownloadingTasks();
|
||||
}
|
||||
|
@@ -32,11 +32,11 @@ class Log {
|
||||
static const String? logFile = null;
|
||||
|
||||
static void printWarning(String text) {
|
||||
print('\x1B[33m$text\x1B[0m');
|
||||
debugPrint('\x1B[33m$text\x1B[0m');
|
||||
}
|
||||
|
||||
static void printError(String text) {
|
||||
print('\x1B[31m$text\x1B[0m');
|
||||
debugPrint('\x1B[31m$text\x1B[0m');
|
||||
}
|
||||
|
||||
static void addLog(LogLevel level, String title, String content) {
|
||||
@@ -44,15 +44,15 @@ class Log {
|
||||
content = "${content.substring(0, maxLogLength)}...";
|
||||
}
|
||||
|
||||
if (kDebugMode) {
|
||||
switch (level) {
|
||||
case LogLevel.error:
|
||||
printError(content);
|
||||
case LogLevel.warning:
|
||||
printWarning(content);
|
||||
case LogLevel.info:
|
||||
print(content);
|
||||
}
|
||||
switch (level) {
|
||||
case LogLevel.error:
|
||||
printError(content);
|
||||
case LogLevel.warning:
|
||||
printWarning(content);
|
||||
case LogLevel.info:
|
||||
if(kDebugMode) {
|
||||
debugPrint(content);
|
||||
}
|
||||
}
|
||||
|
||||
var newLog = LogItem(level, title, content);
|
||||
|
Reference in New Issue
Block a user