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