@@ -118,8 +118,7 @@ class DatabaseSettingsScreenState extends State<DatabaseSettingsScreen> {
118118 String ? targetPath;
119119
120120 if (Platform .isIOS) {
121- targetPath =
122- await DatabaseHelper .resolveCustomDatabasePath (pickedFolder);
121+ targetPath = await DatabaseHelper .resolveBookmarkPath (pickedFolder);
123122 if (targetPath == null ) {
124123 throw Exception ('Failed to resolve custom database bookmark on iOS.' );
125124 }
@@ -150,22 +149,21 @@ class DatabaseSettingsScreenState extends State<DatabaseSettingsScreen> {
150149 try {
151150 await _showLoadingDialog (
152151 AppLocalizations .of (context)! .movingDatabase);
153- final dbHelper = DatabaseHelper ();
154152 await dbHelper.closeDatabase ();
153+ final oldDbPath = await dbHelper.getDbPath ();
154+ final oldBaseDir = Directory (p.dirname (oldDbPath));
155155
156- final defaultAppDir = await getApplicationDocumentsDirectory ();
157- final oldDBPath = p.join (await getDatabasesPath (), 'wispar.db' );
158- final newDBPath = p.join (targetPath, 'wispar.db' );
156+ final newDbPath = p.join (targetPath, 'wispar.db' );
159157
160158 // Move database
161- final oldDBFile = File (oldDBPath );
159+ final oldDBFile = File (oldDbPath );
162160 if (await oldDBFile.exists ()) {
163- await oldDBFile.copy (newDBPath );
161+ await oldDBFile.copy (newDbPath );
164162 await oldDBFile.delete ();
165163 }
166164
167165 // Move PDFs
168- await for (final file in defaultAppDir .list ()) {
166+ await for (final file in oldBaseDir .list ()) {
169167 if (file is File && file.path.endsWith ('.pdf' )) {
170168 final newFile = File (p.join (targetPath, p.basename (file.path)));
171169 await file.copy (newFile.path);
@@ -175,7 +173,7 @@ class DatabaseSettingsScreenState extends State<DatabaseSettingsScreen> {
175173
176174 // Move graphical abstracts
177175 final oldGraphicalDir =
178- Directory (p.join (defaultAppDir .path, 'graphical_abstracts' ));
176+ Directory (p.join (oldBaseDir .path, 'graphical_abstracts' ));
179177 final newGraphicalDir =
180178 Directory (p.join (targetPath, 'graphical_abstracts' ));
181179
@@ -251,14 +249,24 @@ class DatabaseSettingsScreenState extends State<DatabaseSettingsScreen> {
251249 if (customPath == null ) {
252250 throw Exception ("Custom DB folder not accessible" );
253251 }
252+ String defaultDBPath;
253+ Directory defaultBaseDir;
254+
255+ if (Platform .isWindows) {
256+ final appDir = await getApplicationSupportDirectory ();
257+ defaultDBPath = p.join (appDir.path, 'wispar.db' );
258+ defaultBaseDir = appDir;
259+ } else {
260+ final defaultPath = await getDatabasesPath ();
261+ defaultDBPath = p.join (defaultPath, 'wispar.db' );
262+ defaultBaseDir = Directory (defaultPath);
263+ }
254264
255- final defaultDBPath = p.join (await getDatabasesPath (), 'wispar.db' );
256- final appDir = await getApplicationDocumentsDirectory ();
257265 final oldDBPath = p.join (customPath, 'wispar.db' );
258266 final oldGraphicalDir =
259267 Directory (p.join (customPath, 'graphical_abstracts' ));
260268 final newGraphicalDir =
261- Directory (p.join (appDir .path, 'graphical_abstracts' ));
269+ Directory (p.join (defaultBaseDir .path, 'graphical_abstracts' ));
262270
263271 // Move DB
264272 final oldDBFile = File (oldDBPath);
@@ -271,7 +279,8 @@ class DatabaseSettingsScreenState extends State<DatabaseSettingsScreen> {
271279 final customDir = Directory (customPath);
272280 await for (final file in customDir.list ()) {
273281 if (file is File && file.path.endsWith ('.pdf' )) {
274- final newFile = File (p.join (appDir.path, p.basename (file.path)));
282+ final newFile =
283+ File (p.join (defaultBaseDir.path, p.basename (file.path)));
275284 await file.copy (newFile.path);
276285 await file.delete ();
277286 }
@@ -372,22 +381,9 @@ class DatabaseSettingsScreenState extends State<DatabaseSettingsScreen> {
372381 final String outputFile =
373382 p.join (outputDirectory, 'wispar_backup_$timestamp .zip' );
374383
375- final customSourcePath = await _getUsableCustomPath ();
376- String sourceBasePath;
377- String dbDirectoryPath;
378-
379- if (customSourcePath != null ) {
380- sourceBasePath = customSourcePath;
381- dbDirectoryPath = customSourcePath;
382- } else {
383- // Use default paths
384- final defaultAppDir = await getApplicationDocumentsDirectory ();
385- sourceBasePath = defaultAppDir.path;
386- dbDirectoryPath = await getDatabasesPath ();
387- }
388-
389- String dbPath = p.join (dbDirectoryPath, "wispar.db" );
390- File dbFile = File (dbPath);
384+ final dbPath = await DatabaseHelper ().getDbPath ();
385+ final dbFile = File (dbPath);
386+ final sourceBasePath = p.dirname (dbPath);
391387
392388 final sourceDir = Directory (sourceBasePath);
393389
@@ -453,20 +449,18 @@ class DatabaseSettingsScreenState extends State<DatabaseSettingsScreen> {
453449 await dbHelper.closeDatabase ();
454450 File selectedFile = File (result.files.single.path! );
455451
452+ final dbPath = await dbHelper.getDbPath ();
453+ final dbDirectoryPath = p.dirname (dbPath);
454+
456455 final prefs = await SharedPreferences .getInstance ();
457456 final useCustomPath = prefs.getBool ('useCustomDatabasePath' ) ?? false ;
458457 final customPath = prefs.getString ('customDatabasePath' );
459-
460- String dbDestinationPath;
461- if (useCustomPath && customPath != null ) {
462- dbDestinationPath = customPath;
463- } else {
464- dbDestinationPath = await getDatabasesPath ();
465- }
466-
467458 String docsDestinationPath;
468459 if (useCustomPath && customPath != null ) {
469460 docsDestinationPath = customPath;
461+ } else if (Platform .isWindows) {
462+ final appDir = await getApplicationSupportDirectory ();
463+ docsDestinationPath = appDir.path;
470464 } else {
471465 final appDir = await getApplicationDocumentsDirectory ();
472466 docsDestinationPath = appDir.path;
@@ -478,7 +472,7 @@ class DatabaseSettingsScreenState extends State<DatabaseSettingsScreen> {
478472
479473 for (final file in archive) {
480474 final destinationBasePath =
481- file.name == 'wispar.db' ? dbDestinationPath : docsDestinationPath;
475+ file.name == 'wispar.db' ? dbDirectoryPath : docsDestinationPath;
482476
483477 final filePath = p.join (destinationBasePath, file.name);
484478 final outFile = File (filePath);
@@ -502,7 +496,7 @@ class DatabaseSettingsScreenState extends State<DatabaseSettingsScreen> {
502496 }
503497
504498 logger.info (
505- 'The database was successfully imported to $dbDestinationPath from ${selectedFile .path }' );
499+ 'The database was successfully imported to $dbDirectoryPath from ${selectedFile .path }' );
506500
507501 if (! mounted) return ;
508502 ScaffoldMessenger .of (context).showSnackBar (
0 commit comments