@@ -48,15 +48,45 @@ function restore_func() {
4848 cecho " Restoring applications."
4949 # We don't want a single app to break the whole script
5050 set +e
51- # There's a 15 minute timeout for app installs just in case there is a
52- # misbehaving app blocking the whole restore process.
53- # Please note that this doesn't forcibly kill adb, rather it sends a simple SIGTERM signal.
51+ # Apps containing their own directories may contain split APKs, which need to be installed using adb install-multiple.
52+ # Those without directories were created by past versions of this script and need to be imported the traditional way.
53+
54+ # Handle split APKs
55+ # Find directories in the Apps directory
56+ apk_dirs=$( find ./backup-tmp/Apps -mindepth 1 -maxdepth 1 -type d)
57+ for apk_dir in $apk_dirs ; do
58+ # Install all APKs in the directory
59+ # the APK files are sorted to ensure that base.apk is installed before split APKs
60+ apk_files=$( find " $apk_dir " -type f -name " *.apk" | sort | tr ' \n' ' ' )
61+ if [[ " $( uname -r | sed -n ' s/.*\( *Microsoft *\).*/\1/ip' ) " ]]; then
62+ cecho " Windows/WSL detected"
63+ # shellcheck disable=SC2086
64+ timeout 900 ./windows-dependencies/adb/adb.exe install-multiple $apk_files
65+ else
66+ cecho " macOS/Linux detected"
67+ # shellcheck disable=SC2086
68+ timeout 900 adb install-multiple $apk_files
69+ fi
70+ done
71+
72+ # Now all that's left is ensuring backwards compatibility with old backups
73+ # Look for APK files in the Apps directory
74+ apk_files=$( find ./backup-tmp/Apps -maxdepth 1 -type f -name " *.apk" | sort)
75+ # Notify if an old backup is being restored
76+ if [ -n " $apk_files " ]; then
77+ cecho " Old backup with no split APKs detected."
78+ fi
79+ # Install all APKs
5480 if [[ " $( uname -r | sed -n ' s/.*\( *Microsoft *\).*/\1/ip' ) " ]]; then
5581 cecho " Windows/WSL detected"
56- find ./backup-tmp/Apps -type f -name " *.apk" -exec timeout 900 ./windows-dependencies/adb/adb.exe install {} \;
82+ for apk_file in $apk_files ; do
83+ timeout 900 ./windows-dependencies/adb/adb.exe install " $apk_file "
84+ done
5785 else
5886 cecho " macOS/Linux detected"
59- find ./backup-tmp/Apps -type f -name " *.apk" -exec timeout 900 adb install {} \;
87+ for apk_file in $apk_files ; do
88+ timeout 900 adb install " $apk_file "
89+ done
6090 fi
6191 set -e
6292
0 commit comments