Skip to content

Commit

Permalink
Attempt at more resilient XAPK installs (#682)
Browse files Browse the repository at this point in the history
  • Loading branch information
Imran Remtulla committed Jul 16, 2023
1 parent 53dba06 commit 579bc94
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lib/providers/apps_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -341,20 +341,33 @@ class AppsProvider with ChangeNotifier {

Future<void> installXApkDir(DownloadedXApkDir dir,
{bool silent = false}) async {
// We don't know which APKs in an XAPK are supported by the user's device
// So we try installing all of them and assume success if at least one installed
// If 0 APKs installed, throw the first install error encountered
try {
var somethingInstalled = false;
var firstError = null;
for (var file in dir.extracted
.listSync(recursive: true, followLinks: false)
.whereType<File>()) {
if (file.path.toLowerCase().endsWith('.apk')) {
somethingInstalled = somethingInstalled ||
await installApk(DownloadedApk(dir.appId, file), silent: silent);
try {
somethingInstalled = somethingInstalled ||
await installApk(DownloadedApk(dir.appId, file),
silent: silent);
} catch (e) {
logs.add(
'Could not install APK from XAPK \'${file.path}\': ${e.toString()}');
firstError ??= e;
}
} else if (file.path.toLowerCase().endsWith('.obb')) {
await moveObbFile(file, dir.appId);
}
}
if (somethingInstalled) {
dir.file.delete(recursive: true);
} else if (firstError) {
throw firstError;
}
} finally {
dir.extracted.delete(recursive: true);
Expand Down

0 comments on commit 579bc94

Please sign in to comment.