@@ -197,8 +197,29 @@ class AppDatabase extends _$AppDatabase {
|
||||
|
||||
LazyDatabase _openConnection() {
|
||||
return LazyDatabase(() async {
|
||||
final dbFolder = await getApplicationDocumentsDirectory();
|
||||
final Directory dbFolder;
|
||||
if (Platform.isAndroid || Platform.isIOS) {
|
||||
dbFolder = await getApplicationDocumentsDirectory();
|
||||
} else {
|
||||
dbFolder = await getApplicationSupportDirectory();
|
||||
}
|
||||
|
||||
final file = File(p.join(dbFolder.path, 'plezy_downloads.db'));
|
||||
|
||||
// Ensure directory exists
|
||||
if (!await file.parent.exists()) {
|
||||
await file.parent.create(recursive: true);
|
||||
}
|
||||
|
||||
// Migrate from old location on desktop (was in Documents subfolder)
|
||||
if (!Platform.isAndroid && !Platform.isIOS && !await file.exists()) {
|
||||
final oldFolder = await getApplicationDocumentsDirectory();
|
||||
final oldFile = File(p.join(oldFolder.path, 'plezy_downloads.db'));
|
||||
if (await oldFile.exists()) {
|
||||
await oldFile.rename(file.path);
|
||||
}
|
||||
}
|
||||
|
||||
return NativeDatabase(file);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user