diff --git a/lib/app_sources/github.dart b/lib/app_sources/github.dart index c7aa120..d5165a2 100644 --- a/lib/app_sources/github.dart +++ b/lib/app_sources/github.dart @@ -273,10 +273,11 @@ class GitHub extends AppSource { List> getReleaseAssetUrls(dynamic release) => (release['assets'] as List?)?.map((e) { - return (e['name'] != null) && - ((e['url'] ?? e['browser_download_url']) != null) - ? MapEntry(e['name'] as String, - (e['url'] ?? e['browser_download_url']) as String) + var url = !e['name'].toString().toLowerCase().endsWith('.apk') + ? (e['browser_download_url'] ?? e['url']) + : (e['url'] ?? e['browser_download_url']); + return (e['name'] != null) && (url != null) + ? MapEntry(e['name'] as String, url as String) : const MapEntry('', ''); }).toList() ?? []; diff --git a/lib/providers/apps_provider.dart b/lib/providers/apps_provider.dart index f2c1531..5b39320 100644 --- a/lib/providers/apps_provider.dart +++ b/lib/providers/apps_provider.dart @@ -142,19 +142,20 @@ List> moveStrToEndMapEntryWithCount( return arr; } -Future downloadFileWithRetry( - String url, String fileNameNoExt, Function? onProgress, String destDir, +Future downloadFileWithRetry(String url, String fileName, + bool fileNameHasExt, Function? onProgress, String destDir, {bool useExisting = true, Map? headers, int retries = 3}) async { try { - return await downloadFile(url, fileNameNoExt, onProgress, destDir, + return await downloadFile( + url, fileName, fileNameHasExt, onProgress, destDir, useExisting: useExisting, headers: headers); } catch (e) { if (retries > 0 && e is ClientException) { await Future.delayed(const Duration(seconds: 5)); return await downloadFileWithRetry( - url, fileNameNoExt, onProgress, destDir, + url, fileName, fileNameHasExt, onProgress, destDir, useExisting: useExisting, headers: headers, retries: (retries - 1)); } else { rethrow; @@ -201,8 +202,8 @@ Future checkPartialDownloadHash(String url, int bytesToGrab, return hashListOfLists(bytes); } -Future downloadFile( - String url, String fileNameNoExt, Function? onProgress, String destDir, +Future downloadFile(String url, String fileName, bool fileNameHasExt, + Function? onProgress, String destDir, {bool useExisting = true, Map? headers}) async { // Send the initial request but cancel it as soon as you have the headers var reqHeaders = headers ?? {}; @@ -222,7 +223,11 @@ Future downloadFile( if (url.toLowerCase().endsWith('.apk') && ext != 'apk') { ext = 'apk'; } - File downloadedFile = File('$destDir/$fileNameNoExt.$ext'); + File downloadedFile = File('$destDir/$fileName.$ext'); + if (fileNameHasExt) { + // If the user says the filename already has an ext, ignore whatever you inferred from above + downloadedFile = File('$destDir/$fileName'); + } bool rangeFeatureEnabled = false; if (resHeaders['accept-ranges']?.isNotEmpty == true) { @@ -435,8 +440,8 @@ class AppsProvider with ChangeNotifier { var headers = await source.getRequestHeaders(app.additionalSettings, forAPKDownload: true); var downloadedFile = await downloadFileWithRetry( - downloadUrl, fileNameNoExt, - headers: headers, (double? progress) { + downloadUrl, fileNameNoExt, false, headers: headers, + (double? progress) { int? prog = progress?.ceil(); if (apps[app.id] != null) { apps[app.id]!.downloadProgress = progress; @@ -969,15 +974,8 @@ class AppsProvider with ChangeNotifier { if (!downloadsAccessible && exportDir != null) { downloadPath = exportDir.path; } - await downloadFile( - fileUrl.value, - fileUrl.key - .split('.') - .reversed - .toList() - .sublist(1) - .reversed - .join('.'), (double? progress) { + await downloadFile(fileUrl.value, fileUrl.key, true, + (double? progress) { notificationsProvider .notify(DownloadNotification(fileUrl.key, progress?.ceil() ?? 0)); }, downloadPath,