Only cache magisk zips
This commit is contained in:
parent
ee39616a8b
commit
ff828116bc
@ -47,7 +47,6 @@ object Config : PreferenceModel, DBConfig {
|
|||||||
const val DARK_THEME = "dark_theme"
|
const val DARK_THEME = "dark_theme"
|
||||||
const val REPO_ORDER = "repo_order"
|
const val REPO_ORDER = "repo_order"
|
||||||
const val SHOW_SYSTEM_APP = "show_system"
|
const val SHOW_SYSTEM_APP = "show_system"
|
||||||
const val DOWNLOAD_CACHE = "download_cache"
|
|
||||||
const val DOWNLOAD_PATH = "download_path"
|
const val DOWNLOAD_PATH = "download_path"
|
||||||
|
|
||||||
// system state
|
// system state
|
||||||
@ -101,7 +100,6 @@ object Config : PreferenceModel, DBConfig {
|
|||||||
if (Utils.isCanary) Value.CANARY_DEBUG_CHANNEL
|
if (Utils.isCanary) Value.CANARY_DEBUG_CHANNEL
|
||||||
else Value.DEFAULT_CHANNEL
|
else Value.DEFAULT_CHANNEL
|
||||||
|
|
||||||
var isDownloadCacheEnabled by preference(Key.DOWNLOAD_CACHE, true)
|
|
||||||
var downloadPath by preference(Key.DOWNLOAD_PATH, Environment.DIRECTORY_DOWNLOADS)
|
var downloadPath by preference(Key.DOWNLOAD_PATH, Environment.DIRECTORY_DOWNLOADS)
|
||||||
var repoOrder by preference(Key.REPO_ORDER, Value.ORDER_DATE)
|
var repoOrder by preference(Key.REPO_ORDER, Value.ORDER_DATE)
|
||||||
|
|
||||||
|
@ -4,11 +4,9 @@ import android.app.Activity
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import androidx.core.app.NotificationCompat
|
import androidx.core.app.NotificationCompat
|
||||||
import com.skoumal.teanity.extensions.subscribeK
|
import com.skoumal.teanity.extensions.subscribeK
|
||||||
import com.topjohnwu.magisk.Config
|
|
||||||
import com.topjohnwu.magisk.R
|
import com.topjohnwu.magisk.R
|
||||||
import com.topjohnwu.magisk.data.network.GithubRawServices
|
import com.topjohnwu.magisk.data.network.GithubRawServices
|
||||||
import com.topjohnwu.magisk.di.NullActivity
|
import com.topjohnwu.magisk.di.NullActivity
|
||||||
import com.topjohnwu.magisk.extensions.firstMap
|
|
||||||
import com.topjohnwu.magisk.extensions.get
|
import com.topjohnwu.magisk.extensions.get
|
||||||
import com.topjohnwu.magisk.extensions.writeTo
|
import com.topjohnwu.magisk.extensions.writeTo
|
||||||
import com.topjohnwu.magisk.model.entity.internal.DownloadSubject
|
import com.topjohnwu.magisk.model.entity.internal.DownloadSubject
|
||||||
@ -20,19 +18,12 @@ import io.reactivex.Completable
|
|||||||
import okhttp3.ResponseBody
|
import okhttp3.ResponseBody
|
||||||
import org.koin.android.ext.android.inject
|
import org.koin.android.ext.android.inject
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.io.File
|
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
|
|
||||||
abstract class RemoteFileService : NotificationService() {
|
abstract class RemoteFileService : NotificationService() {
|
||||||
|
|
||||||
private val service: GithubRawServices by inject()
|
private val service: GithubRawServices by inject()
|
||||||
|
|
||||||
private val supportedFolders
|
|
||||||
get() = listOf(
|
|
||||||
cacheDir,
|
|
||||||
Config.downloadDirectory
|
|
||||||
)
|
|
||||||
|
|
||||||
override val defaultNotification: NotificationCompat.Builder
|
override val defaultNotification: NotificationCompat.Builder
|
||||||
get() = Notifications.progress(this, "")
|
get() = Notifications.progress(this, "")
|
||||||
|
|
||||||
@ -43,7 +34,7 @@ abstract class RemoteFileService : NotificationService() {
|
|||||||
|
|
||||||
// ---
|
// ---
|
||||||
|
|
||||||
private fun start(subject: DownloadSubject) = search(subject)
|
private fun start(subject: DownloadSubject) = checkExisting(subject)
|
||||||
.onErrorResumeNext { download(subject) }
|
.onErrorResumeNext { download(subject) }
|
||||||
.doOnSubscribe { update(subject.hashCode()) { it.setContentTitle(subject.title) } }
|
.doOnSubscribe { update(subject.hashCode()) { it.setContentTitle(subject.title) } }
|
||||||
.subscribeK(onError = {
|
.subscribeK(onError = {
|
||||||
@ -60,16 +51,12 @@ abstract class RemoteFileService : NotificationService() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun search(subject: DownloadSubject) = Completable.fromAction {
|
private fun checkExisting(subject: DownloadSubject) = Completable.fromAction {
|
||||||
if (!Config.isDownloadCacheEnabled || subject is Manager) {
|
check(subject is Magisk) { "Download cache is disabled" }
|
||||||
throw IllegalStateException("The download cache is disabled")
|
|
||||||
}
|
|
||||||
|
|
||||||
supportedFolders.firstMap { it.find(subject.file.name) }.also {
|
subject.file.also {
|
||||||
if (subject is Magisk) {
|
check(it.exists() && ShellUtils.checkSum("MD5", it, subject.magisk.md5)) {
|
||||||
if (!ShellUtils.checkSum("MD5", it, subject.magisk.md5)) {
|
"The given file does not match checksum"
|
||||||
throw IllegalStateException("The given file doesn't match the md5")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -88,12 +75,6 @@ abstract class RemoteFileService : NotificationService() {
|
|||||||
handleAPK(subject)
|
handleAPK(subject)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---
|
|
||||||
|
|
||||||
private fun File.find(name: String) = list()
|
|
||||||
?.firstOrNull { it == name }
|
|
||||||
?.let { File(this, it) }
|
|
||||||
|
|
||||||
private fun ResponseBody.toStream(id: Int): InputStream {
|
private fun ResponseBody.toStream(id: Int): InputStream {
|
||||||
val maxRaw = contentLength()
|
val maxRaw = contentLength()
|
||||||
val max = maxRaw / 1_000_000f
|
val max = maxRaw / 1_000_000f
|
||||||
|
@ -29,18 +29,6 @@
|
|||||||
android:summary="@string/settings_restore_manager_summary"
|
android:summary="@string/settings_restore_manager_summary"
|
||||||
android:title="@string/settings_restore_manager_title" />
|
android:title="@string/settings_restore_manager_title" />
|
||||||
|
|
||||||
</PreferenceCategory>
|
|
||||||
|
|
||||||
<PreferenceCategory
|
|
||||||
android:key="downloads"
|
|
||||||
android:title="@string/settings_downloads_category">
|
|
||||||
|
|
||||||
<SwitchPreferenceCompat
|
|
||||||
android:defaultValue="true"
|
|
||||||
android:key="download_cache"
|
|
||||||
android:summary="@string/settings_download_cache_summary"
|
|
||||||
android:title="@string/settings_download_cache_title" />
|
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:key="download_path"
|
android:key="download_path"
|
||||||
android:title="@string/settings_download_path_title" />
|
android:title="@string/settings_download_path_title" />
|
||||||
|
Loading…
Reference in New Issue
Block a user