6.2.0 - Fix2 - 修复版本检查问题

This commit is contained in:
SuperMonster003
2023-01-22 00:26:30 +08:00
parent 270ca6430c
commit 1db767fa2f

View File

@@ -1,128 +1,106 @@
package org.autojs.autojs.network.entity; package org.autojs.autojs.network.entity
import static org.autojs.autojs.util.StringUtils.str; import org.autojs.autojs.util.StringUtils.str
import org.autojs.autojs.util.UpdateUtils.isVersionIgnored
import androidx.annotation.NonNull; import org.autojs.autojs6.BuildConfig
import org.autojs.autojs6.R
import org.autojs.autojs.util.UpdateUtils;
import org.autojs.autojs6.BuildConfig;
import org.autojs.autojs6.R;
import java.text.MessageFormat;
/** /**
* Created by Stardust on 2017/9/20. * Created by Stardust on 2017/9/20.
* Modified by SuperMonster003 as of May 29, 2022. * Modified by SuperMonster003 as of May 29, 2022.
*/ */
public class VersionInfo implements ExtendedVersionInfo { class VersionInfo : ExtendedVersionInfo {
var versionName: String? = null
private set
var versionCode = 0
private set
private var mSize: Long = -1
private var mDownloadUrl: String? = null
private var mAbi: String? = null
private var mFileName: String? = null
private String mVersionName; constructor(propertiesFileRawString: String) {
private int mVersionCode; val regexVersionName = "VERSION_NAME=.+".toRegex()
val regexVersionCode = "VERSION_BUILD=.+".toRegex()
private long mSize = -1; for (string in propertiesFileRawString.split("\n".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()) {
private String mDownloadUrl;
private String mAbi;
private String mFileName;
public VersionInfo(@NonNull String propertiesFileRawString) {
String regexVersionName = "VERSION_NAME=.+";
String regexVersionCode = "VERSION_BUILD=.+";
for (String string : propertiesFileRawString.split("\n")) {
if (string.matches(regexVersionName)) { if (string.matches(regexVersionName)) {
mVersionName = string.split("=")[1]; versionName = string.split("=".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()[1]
} else if (string.matches(regexVersionCode)) { } else if (string.matches(regexVersionCode)) {
mVersionCode = Integer.parseInt(string.split("=")[1]); versionCode = string.split("=".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()[1].toInt()
} }
if (mVersionName != null && mVersionCode > 0) { if (versionName != null && versionCode > 0) {
break; break
} }
} }
} }
public VersionInfo(@NonNull String versionName, int versionCode) { constructor(versionName: String, versionCode: Int) {
mVersionName = versionName; this.versionName = versionName
mVersionCode = versionCode; this.versionCode = versionCode
} }
public boolean isNewer() { val isNewer: Boolean
return mVersionCode > BuildConfig.VERSION_CODE; get() = versionCode > BuildConfig.VERSION_CODE
val isNotIgnored: Boolean
get() = !isVersionIgnored(this)
override fun toString(): String {
return if (mAbi == null) {
"${str(R.string.text_version)}: $versionName ($versionCode)"
} else "${str(R.string.text_version)}: $versionName ($versionCode) [$mAbi]"
} }
public boolean isNotIgnored() { fun toSummary(): String {
return !UpdateUtils.isVersionIgnored(this); return "$versionName ($versionCode)"
} }
@NonNull fun setFileName(fileName: String?) {
@Override mFileName = fileName
public String toString() {
if (mAbi == null) {
return MessageFormat.format("{0}: {1} ({2})", str(R.string.text_version), mVersionName, mVersionCode);
}
return MessageFormat.format("{0}: {1} ({2}) [{3}]", str(R.string.text_version), mVersionName, mVersionCode, mAbi);
} }
public String toSummary() { fun setSize(size: Long) {
return MessageFormat.format("{0} ({1})", mVersionName, mVersionCode); mSize = size
} }
public static SimpleVersionInfo parseSummary(CharSequence summary) { fun setDownloadUrl(downloadUrl: String?) {
int indexForVersionName = 0; mDownloadUrl = downloadUrl
int indexForVersionCode = 1; }
String versionName = null; override fun getFileName(): String {
int versionCode = -1; return mFileName!!
}
String[] split = summary.toString().split(" "); fun setAbi(abi: String?) {
mAbi = abi
}
for (int i = 0; i < split.length; i++) { override fun getSize(): Long {
if (i == indexForVersionName) { return mSize
versionName = split[i]; }
} else if (i == indexForVersionCode) {
versionCode = Integer.parseInt(split[i].replaceAll("[()]", "")); override fun getDownloadUrl(): String {
return mDownloadUrl!!
}
override fun getAbi(): String {
return mAbi!!
}
companion object {
fun parseSummary(summary: CharSequence): SimpleVersionInfo {
val indexForVersionName = 0
val indexForVersionCode = 1
var versionName: String? = null
var versionCode = -1
val split = summary.toString().split(" ".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
for (i in split.indices) {
if (i == indexForVersionName) {
versionName = split[i]
} else if (i == indexForVersionCode) {
versionCode = split[i].replace("[()]".toRegex(), "").toInt()
}
} }
return SimpleVersionInfo(versionName, versionCode)
} }
return new SimpleVersionInfo(versionName, versionCode);
} }
public String getVersionName() {
return mVersionName;
}
public int getVersionCode() {
return mVersionCode;
}
public void setFileName(String fileName) {
this.mFileName = fileName;
}
public void setSize(long size) {
mSize = size;
}
public void setDownloadUrl(String downloadUrl) {
mDownloadUrl = downloadUrl;
}
public String getFileName() {
return mFileName;
}
public void setAbi(String abi) {
mAbi = abi;
}
public long getSize() {
return mSize;
}
public String getDownloadUrl() {
return mDownloadUrl;
}
@Override
public String getAbi() {
return mAbi;
}
} }