From c3a89f589eb8ba68f5df166fcd38ccceb9d30b8b Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Thu, 25 Jul 2019 01:54:42 -0700 Subject: [PATCH] Download to proper filename --- .../main/java/com/topjohnwu/magisk/model/entity/Repo.java | 3 ++- .../magisk/model/entity/internal/DownloadSubject.kt | 2 +- app/src/main/java/com/topjohnwu/magisk/utils/Utils.kt | 6 ------ app/src/main/java/com/topjohnwu/magisk/utils/XString.kt | 6 +++++- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/model/entity/Repo.java b/app/src/main/java/com/topjohnwu/magisk/model/entity/Repo.java index 853d013f3..abd44c9e8 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/entity/Repo.java +++ b/app/src/main/java/com/topjohnwu/magisk/model/entity/Repo.java @@ -7,6 +7,7 @@ import android.os.Parcelable; import com.topjohnwu.magisk.Const; import com.topjohnwu.magisk.utils.Utils; +import com.topjohnwu.magisk.utils.XStringKt; import java.text.DateFormat; import java.util.Date; @@ -103,7 +104,7 @@ public class Repo extends BaseModule { } public String getDownloadFilename() { - return Utils.INSTANCE.getLegalFilename(getName() + "-" + getVersion() + ".zip"); + return XStringKt.legalFilename(getName() + "-" + getVersion() + ".zip"); } public class IllegalRepoException extends Exception { diff --git a/app/src/main/java/com/topjohnwu/magisk/model/entity/internal/DownloadSubject.kt b/app/src/main/java/com/topjohnwu/magisk/model/entity/internal/DownloadSubject.kt index 54278371f..1a72f6672 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/entity/internal/DownloadSubject.kt +++ b/app/src/main/java/com/topjohnwu/magisk/model/entity/internal/DownloadSubject.kt @@ -27,7 +27,7 @@ sealed class DownloadSubject : Parcelable { @IgnoredOnParcel override val file by lazy { - File(Config.downloadDirectory, "${module.name}-v${module.version}(${module.versionCode}).zip") + File(Config.downloadDirectory, module.downloadFilename) } } diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/Utils.kt b/app/src/main/java/com/topjohnwu/magisk/utils/Utils.kt index 19be391cc..fa5cdb435 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/Utils.kt +++ b/app/src/main/java/com/topjohnwu/magisk/utils/Utils.kt @@ -70,12 +70,6 @@ object Utils { return info.loadLabel(pm).toString() } - fun getLegalFilename(filename: CharSequence): String { - return filename.toString().replace(" ", "_").replace("'", "").replace("\"", "") - .replace("$", "").replace("`", "").replace("*", "").replace("/", "_") - .replace("#", "").replace("@", "").replace("\\", "_") - } - @WorkerThread fun loadModulesLeanback(): Map { val moduleMap = ValueSortedMap() diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/XString.kt b/app/src/main/java/com/topjohnwu/magisk/utils/XString.kt index cd1a1bc64..3cebc9792 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/XString.kt +++ b/app/src/main/java/com/topjohnwu/magisk/utils/XString.kt @@ -20,4 +20,8 @@ fun Int.res(vararg args: Any): String { return resources.getString(this, *args) } -fun String.trimEmptyToNull(): String? = if (isBlank()) null else this \ No newline at end of file +fun String.trimEmptyToNull(): String? = if (isBlank()) null else this + +fun String.legalFilename() = replace(" ", "_").replace("'", "").replace("\"", "") + .replace("$", "").replace("`", "").replace("*", "").replace("/", "_") + .replace("#", "").replace("@", "").replace("\\", "_")