diff --git a/app/src/main/java/cc/ioctl/dialog/RikkaBaseApkFormatDialog.java b/app/src/main/java/cc/ioctl/dialog/RikkaBaseApkFormatDialog.java index 756f3ce3e8..72ff50a885 100644 --- a/app/src/main/java/cc/ioctl/dialog/RikkaBaseApkFormatDialog.java +++ b/app/src/main/java/cc/ioctl/dialog/RikkaBaseApkFormatDialog.java @@ -33,8 +33,9 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; -import cc.ioctl.util.HostInfo; +import cc.hicore.QApp.QAppUtils; import cc.ioctl.hook.file.BaseApk; +import cc.ioctl.util.HostInfo; import io.github.qauxv.BuildConfig; import io.github.qauxv.R; import io.github.qauxv.config.ConfigManager; @@ -44,12 +45,13 @@ public class RikkaBaseApkFormatDialog { - private static final String DEFAULT_BASE_APK_REGEX = ".*\\.apk"; + private static final String DEFAULT_BASE_APK_REGEX = "base(\\([0-9]+\\))?\\.apk"; private static final String DEFAULT_BASE_APK_FORMAT = "%n_%v.APK"; private static final String rq_base_apk_regex = "rq_base_apk_regex"; private static final String rq_base_apk_format = "rq_base_apk_format"; private static final String rq_base_apk_enabled = "rq_base_apk_enabled"; + private static final String rq_base_apk_always_APK = "rq_base_apk_always_APK"; @Nullable private AlertDialog dialog; @@ -59,11 +61,16 @@ public class RikkaBaseApkFormatDialog { private String currentRegex; private String currentFormat; private boolean enableBaseApk; + private boolean alwaysAPK; public static boolean IsEnabled() { return ConfigManager.getDefaultConfig().getBooleanOrFalse(rq_base_apk_enabled); } + public static boolean IsAlwaysAPKEnabled() { + return ConfigManager.getDefaultConfig().getBooleanOrFalse(rq_base_apk_always_APK); + } + @Nullable public static String getCurrentBaseApkRegex() { ConfigManager cfg = ConfigManager.getDefaultConfig(); @@ -103,9 +110,16 @@ public void showDialog(@NonNull Context context) { final TextView regex = vg.findViewById(R.id.editTextBaseApkRegex); final TextView format = vg.findViewById(R.id.editTextBaseApkFormat); final CheckBox enable = vg.findViewById(R.id.checkBoxEnableBaseApk); + final CheckBox always = vg.findViewById(R.id.checkBoxAlwaysAPK); final LinearLayout panel = vg.findViewById(R.id.layoutBaseApkPanel); enableBaseApk = ConfigManager.getDefaultConfig().getBooleanOrFalse(rq_base_apk_enabled); enable.setChecked(enableBaseApk); + if (!QAppUtils.isQQnt()) { + always.setVisibility(View.GONE); + } else { + alwaysAPK = ConfigManager.getDefaultConfig().getBooleanOrFalse(rq_base_apk_always_APK); + always.setChecked(alwaysAPK); + } panel.setVisibility(enableBaseApk ? View.VISIBLE : View.GONE); currentRegex = ConfigManager.getDefaultConfig().getString(rq_base_apk_regex); if (currentRegex == null) { @@ -159,6 +173,9 @@ public void afterTextChanged(Editable s) { enableBaseApk = isChecked; panel.setVisibility(enableBaseApk ? View.VISIBLE : View.GONE); }); + always.setOnCheckedChangeListener((buttonView, isChecked) -> { + alwaysAPK = isChecked; + }); dialog.setView(vg); dialog.show(); dialog.getButton(AlertDialog.BUTTON_POSITIVE) @@ -170,9 +187,10 @@ public void afterTextChanged(Editable s) { done = true; } else { if (currentFormat != null && !currentFormat.isEmpty() && - currentRegex != null && !currentRegex.isEmpty() &&( + currentRegex != null && !currentRegex.isEmpty() && ( currentFormat.contains("%n") || currentFormat.contains("%p"))) { cfg.putBoolean(rq_base_apk_enabled, true); + cfg.putBoolean(rq_base_apk_always_APK, alwaysAPK); cfg.putString(rq_base_apk_regex, currentRegex); cfg.putString(rq_base_apk_format, currentFormat); done = true; diff --git a/app/src/main/java/cc/ioctl/hook/file/BaseApk.java b/app/src/main/java/cc/ioctl/hook/file/BaseApk.java index effbe5f210..8d44e042ca 100644 --- a/app/src/main/java/cc/ioctl/hook/file/BaseApk.java +++ b/app/src/main/java/cc/ioctl/hook/file/BaseApk.java @@ -35,8 +35,6 @@ import cc.ioctl.dialog.RikkaBaseApkFormatDialog; import cc.ioctl.util.HookUtils; import cc.ioctl.util.HostInfo; -import io.github.qauxv.util.xpcompat.XC_MethodHook; -import io.github.qauxv.util.xpcompat.XposedHelpers; import io.github.qauxv.base.IUiItemAgent; import io.github.qauxv.base.annotation.FunctionHookEntry; import io.github.qauxv.base.annotation.UiItemAgentEntry; @@ -46,12 +44,13 @@ import io.github.qauxv.util.dexkit.DexKit; import io.github.qauxv.util.dexkit.DexKitTarget; import io.github.qauxv.util.dexkit.TroopSendFile_QQNT; +import io.github.qauxv.util.xpcompat.XC_MethodHook; +import io.github.qauxv.util.xpcompat.XposedHelpers; import java.io.File; import java.io.FileNotFoundException; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Modifier; -import java.util.Objects; import kotlin.Unit; import kotlin.jvm.functions.Function3; import kotlinx.coroutines.flow.MutableStateFlow; @@ -117,6 +116,11 @@ public boolean initOnce() throws Exception { throw new FileNotFoundException("file not found: path='" + localFile + "'"); } fileName.set(item, getFormattedFileNameByPath(localFile)); + } else if (RikkaBaseApkFormatDialog.IsAlwaysAPKEnabled()) { + String fn = (String) fileName.get(item); + if (fn.endsWith(".apk")) { + fileName.set(item, replaceLast(fn, ".apk", ".APK")); + } } }); } else if (HostInfo.requireMinQQVersion(QQ_8_6_0)) { @@ -199,8 +203,14 @@ private String getFormattedFileNameByPath(String path) { .replace("%p", applicationInfo.packageName) .replace("%v", packageArchiveInfo.versionName) .replace("%c", String.valueOf(packageArchiveInfo.versionCode)); - } else + } else { throw new RuntimeException("format is null"); + } return result; } + + public static String replaceLast(String str, String target, String replacement) { + // 使用正则表达式匹配最后一个目标子字符串,并替换为新字符串 + return str.replaceFirst("(?s)(.*)" + target, "$1" + replacement); + } } diff --git a/app/src/main/res/layout/rikka_base_apk_dialog.xml b/app/src/main/res/layout/rikka_base_apk_dialog.xml index 226be680d7..e904d9539d 100644 --- a/app/src/main/res/layout/rikka_base_apk_dialog.xml +++ b/app/src/main/res/layout/rikka_base_apk_dialog.xml @@ -1,8 +1,8 @@ @@ -13,12 +13,19 @@ android:layout_height="wrap_content" android:text="启用重命名 APK" /> + + +