diff --git a/lib/app_sources/html.dart b/lib/app_sources/html.dart index 51f6143..6ebee0a 100644 --- a/lib/app_sources/html.dart +++ b/lib/app_sources/html.dart @@ -244,16 +244,17 @@ class HTML extends AppSource { true) { var reg = RegExp(additionalSettings['customLinkFilterRegex']); links = allLinks - .where((element) => - reg.hasMatch(filterLinkByText ? element.value : element.key)) + .where((element) => reg.hasMatch( + filterLinkByText ? element.value : Uri.decodeFull(element.key))) .toList(); } else { links = allLinks - .where((element) => - Uri.parse(filterLinkByText ? element.value : element.key) - .path - .toLowerCase() - .endsWith('.apk')) + .where((element) => Uri.parse(filterLinkByText + ? element.value + : Uri.decodeFull(element.key)) + .path + .toLowerCase() + .endsWith('.apk')) .toList(); } if (!skipSort) { @@ -315,7 +316,7 @@ class HTML extends AppSource { additionalSettings['matchGroupToUse'] as String?, additionalSettings['versionExtractWholePage'] == true ? versionExtractionWholePageString - : rel); + : Uri.decodeFull(rel)); version ??= additionalSettings['defaultPseudoVersioningMethod'] == 'APKLinkHash' ? rel.hashCode.toString() diff --git a/lib/providers/apps_provider.dart b/lib/providers/apps_provider.dart index 6015434..6620006 100644 --- a/lib/providers/apps_provider.dart +++ b/lib/providers/apps_provider.dart @@ -235,8 +235,9 @@ Future downloadFile( var fullContentLength = response.contentLength; if (useExisting && downloadedFile.existsSync()) { var length = downloadedFile.lengthSync(); - if (fullContentLength == null) { - // Assume full + if (fullContentLength == null || !rangeFeatureEnabled) { + // If there is no content length reported, assume it the existing file is fully downloaded + // Also if the range feature is not supported, don't trust the content length if any (#1542) client.close(); return downloadedFile; } else { @@ -291,14 +292,11 @@ Future downloadFile( return s; }).pipe(sink); await sink.close(); - bool likelyCorruptFile = (progress ?? 0) > 101; progress = null; if (onProgress != null) { onProgress(progress); } - if (response.statusCode < 200 || - response.statusCode > 299 || - likelyCorruptFile) { + if (response.statusCode < 200 || response.statusCode > 299) { tempDownloadedFile.deleteSync(recursive: true); throw response.reasonPhrase ?? tr('unexpectedError'); } @@ -392,30 +390,26 @@ class AppsProvider with ChangeNotifier { }(); } - Future handleAPKIDChange(App app, PackageInfo? newInfo, + Future handleAPKIDChange(App app, PackageInfo newInfo, File downloadedFile, String downloadUrl) async { // If the APK package ID is different from the App ID, it is either new (using a placeholder ID) or the ID has changed // The former case should be handled (give the App its real ID), the latter is a security issue var isTempIdBool = isTempId(app); - if (newInfo != null) { - if (app.id != newInfo.packageName) { - if (apps[app.id] != null && !isTempIdBool && !app.allowIdChange) { - throw IDChangedError(newInfo.packageName!); - } - var idChangeWasAllowed = app.allowIdChange; - app.allowIdChange = false; - var originalAppId = app.id; - app.id = newInfo.packageName!; - downloadedFile = downloadedFile.renameSync( - '${downloadedFile.parent.path}/${app.id}-${downloadUrl.hashCode}.${downloadedFile.path.split('.').last}'); - if (apps[originalAppId] != null) { - await removeApps([originalAppId]); - await saveApps([app], - onlyIfExists: !isTempIdBool && !idChangeWasAllowed); - } + if (app.id != newInfo.packageName) { + if (apps[app.id] != null && !isTempIdBool && !app.allowIdChange) { + throw IDChangedError(newInfo.packageName!); + } + var idChangeWasAllowed = app.allowIdChange; + app.allowIdChange = false; + var originalAppId = app.id; + app.id = newInfo.packageName!; + downloadedFile = downloadedFile.renameSync( + '${downloadedFile.parent.path}/${app.id}-${downloadUrl.hashCode}.${downloadedFile.path.split('.').last}'); + if (apps[originalAppId] != null) { + await removeApps([originalAppId]); + await saveApps([app], + onlyIfExists: !isTempIdBool && !idChangeWasAllowed); } - } else if (isTempIdBool) { - throw ObtainiumError('Could not get ID from APK'); } return downloadedFile; } @@ -479,6 +473,10 @@ class AppsProvider with ChangeNotifier { newInfo = await pm.getPackageArchiveInfo(archiveFilePath: apks.first.path); } + if (newInfo == null) { + downloadedFile.delete(); + throw ObtainiumError('Could not get ID from APK'); + } downloadedFile = await handleAPKIDChange(app, newInfo, downloadedFile, downloadUrl); // Delete older versions of the file if any diff --git a/pubspec.lock b/pubspec.lock index 2bea883..349b896 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -275,10 +275,10 @@ packages: dependency: "direct main" description: name: flutter_archive - sha256: "004132780d382df5171589ab793e2efc9c3eef570fe72d78b4ccfbfbe52762ae" + sha256: "5ca235f304c12bf468979235f400f79846d204169d715939e39197106f5fc970" url: "https://pub.dev" source: hosted - version: "6.0.0" + version: "6.0.3" flutter_fgbg: dependency: "direct main" description: @@ -336,10 +336,10 @@ packages: dependency: "direct main" description: name: flutter_markdown - sha256: "31c12de79262b5431c5492e9c89948aa789158435f707d3519a7fdef6af28af7" + sha256: "04c4722cc36ec5af38acc38ece70d22d3c2123c61305d555750a091517bbe504" url: "https://pub.dev" source: hosted - version: "0.6.22+1" + version: "0.6.23" flutter_plugin_android_lifecycle: dependency: transitive description: @@ -362,10 +362,10 @@ packages: dependency: "direct main" description: name: fluttertoast - sha256: dfdde255317af381bfc1c486ed968d5a43a2ded9c931e87cbecd88767d6a71c1 + sha256: "81b68579e23fcbcada2db3d50302813d2371664afe6165bc78148050ab94bf66" url: "https://pub.dev" source: hosted - version: "8.2.4" + version: "8.2.5" gtk: dependency: transitive description: @@ -903,10 +903,10 @@ packages: dependency: transitive description: name: url_launcher_web - sha256: "3692a459204a33e04bc94f5fb91158faf4f2c8903281ddd82915adecdb1a901d" + sha256: "8d9e750d8c9338601e709cd0885f95825086bd8b642547f26bda435aade95d8a" url: "https://pub.dev" source: hosted - version: "2.3.0" + version: "2.3.1" url_launcher_windows: dependency: transitive description: @@ -991,10 +991,10 @@ packages: dependency: transitive description: name: win32_registry - sha256: "41fd8a189940d8696b1b810efb9abcf60827b6cbfab90b0c43e8439e3a39d85a" + sha256: "10589e0d7f4e053f2c61023a31c9ce01146656a70b7b7f0828c0b46d7da2a9bb" url: "https://pub.dev" source: hosted - version: "1.1.2" + version: "1.1.3" xdg_directories: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 8e2e1ce..a3f2daf 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -17,7 +17,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 1.1.3+2260 +version: 1.1.4+2261 environment: sdk: '>=3.0.0 <4.0.0'