diff --git a/lib/pages/database_download/database_download_page.dart b/lib/pages/database_download/database_download_page.dart index c4c492bb8..51803fa82 100644 --- a/lib/pages/database_download/database_download_page.dart +++ b/lib/pages/database_download/database_download_page.dart @@ -85,6 +85,21 @@ class DataBaseDownloadPageState extends State { } Future downloadFileAndroid() async { + try { + await downloadFileAndroidWith('latest'); + } catch(e){ + await downloadFileAndroidWith('safe'); + } + } + Future downloadFileIOS() async { + try { + await downloadFileIOSWith('latest'); + } catch(e){ + await downloadFileIOSWith('safe'); + } + } + + Future downloadFileAndroidWith(String target) async { Dio dio = Dio(); int oneMega = 1024 * 1024; int nu = 0; @@ -105,7 +120,18 @@ class DataBaseDownloadPageState extends State { tlatest = tnu; tnu = 0; })); - await SyncManager.checkSync(); + switch(target){ + case 'latest': await SyncManager.checkSyncLatest(); break; + case 'safe': await SyncManager.checkSync(); break; + default: { + try { + await downloadFileAndroidWith('latest'); + } catch(e){ + await downloadFileAndroidWith('safe'); + } + return; + } + } await dio.download( SyncManager.getLatestDB().getDBDownloadUrl(widget.dbType!), '${dir.path}/db.sql.7z', onReceiveProgress: (rec, total) { @@ -162,10 +188,26 @@ class DataBaseDownloadPageState extends State { await DataBaseManager.reloadInstance(); - if (Settings.useOptimizeDatabase) { - await deleteUnused(); - + try { + if (Settings.useOptimizeDatabase) { + await deleteUnused(); + await indexing(); + } + } catch(e1,st1){ + Logger.error('[Sync-check] E: $e1\n' + '$st1'); + } + try { + if (Settings.useOptimizeDatabase) await deleteUnused(); + } catch(e1,st1){ + Logger.error('[deleteUnused] E: $e1\n' + '$st1'); + } + try { await indexing(); + } catch(e1,st1){ + Logger.error('[indexing] E: $e1\n' + '$st1'); } if (widget.isSync == true) { @@ -181,6 +223,7 @@ class DataBaseDownloadPageState extends State { } catch (e, st) { Logger.error('[DBDownload] E: $e\n' '$st'); + if(target == 'latest') throw e; } setState(() { @@ -189,7 +232,7 @@ class DataBaseDownloadPageState extends State { }); } - Future downloadFileIOS() async { + Future downloadFileIOSWith(String target) async { Dio dio = Dio(); int oneMega = 1024 * 1024; int nu = 0; @@ -210,7 +253,18 @@ class DataBaseDownloadPageState extends State { tlatest = tnu; tnu = 0; })); - await SyncManager.checkSync(); + switch(target){ + case 'latest': await SyncManager.checkSyncLatest(); break; + case 'safe': await SyncManager.checkSync(); break; + default: { + try { + await downloadFileIOSWith('latest'); + } catch(e){ + await downloadFileIOSWith('safe'); + } + return; + } + } await dio.download( SyncManager.getLatestDB().getDBDownloadUrliOS(widget.dbType!), '$dir/data.db', onReceiveProgress: (rec, total) { @@ -246,9 +300,18 @@ class DataBaseDownloadPageState extends State { await DataBaseManager.reloadInstance(); - if (Settings.useOptimizeDatabase) await deleteUnused(); - - await indexing(); + try { + if (Settings.useOptimizeDatabase) await deleteUnused(); + } catch(e1,st1){ + Logger.error('[deleteUnused] E: $e1\n' + '$st1'); + } + try { + await indexing(); + } catch(e1,st1){ + Logger.error('[indexing] E: $e1\n' + '$st1'); + } if (widget.isSync == true) { Navigator.pop(context); @@ -263,6 +326,7 @@ class DataBaseDownloadPageState extends State { } catch (e, st) { Logger.error('[DBDownload] E: $e\n' '$st'); + if(target == 'latest') throw e; } setState(() { @@ -275,7 +339,7 @@ class DataBaseDownloadPageState extends State { var sql = HitomiManager.translate2query( '${Settings.includeTags} ${Settings.excludeTags.where((e) => e.trim().isNotEmpty).map((e) => '-$e').join(' ')}') .replaceAll(' AND ExistOnHitomi=1', ''); - + await (await DataBaseManager.getInstance()).delete('HitomiColumnModel', 'NOT (${sql.substring(sql.indexOf('WHERE') + 6)})', []); } diff --git a/lib/version/sync.dart b/lib/version/sync.dart index 081f4e9fc..c79f31e46 100644 --- a/lib/version/sync.dart +++ b/lib/version/sync.dart @@ -125,12 +125,13 @@ class SyncManager { } catch (e, st) { Logger.error('[Sync-check] E: $e\n' '$st'); + throw e; } } static Future checkSync() async { - for(int i = 0;i < 100;i++){ + // for(int i = 0;i < 100;i++){ try { var ls = const LineSplitter(); var infoRaw = (await http.get(syncInfoURL('d2bd5ae068efb26eb4689e5d6281a590e59fc4e2'))).body; @@ -201,11 +202,11 @@ class SyncManager { if (requestSize > ignoreUserAcceptThreshold) syncRequire = true; if (_rows!.any((element) => element.type == 'chunk')) chunkRequire = true; } catch (e, st) { - continue; + // continue; Logger.error('[Sync-check] E: $e\n' '$st'); } - } + // } } static SyncInfoRecord getLatestDB() {