mod: 修改版本检查规则

This commit is contained in:
guozhigq
2023-10-15 20:05:16 +08:00
parent 424bdd9fff
commit f25dab2eb8

View File

@ -187,15 +187,21 @@ class Utils {
} }
// 版本对比 // 版本对比
static bool needUpdate(localVersion, remoteVersion) { static bool needUpdate(String currentVersion, String remoteVersion) {
List<String> localVersionList = localVersion.split('.'); List<int> current = currentVersion.split('.').map(int.parse).toList();
List<String> remoteVersionList = remoteVersion.split('v')[1].split('.'); List<int> remote =
for (int i = 0; i < localVersionList.length; i++) { remoteVersion.split('v')[1].split('.').map(int.parse).toList();
int localVersion = int.parse(localVersionList[i]);
int remoteVersion = int.parse(remoteVersionList[i]); int maxLength =
if (remoteVersion > localVersion) { current.length > remote.length ? current.length : remote.length;
for (int i = 0; i < maxLength; i++) {
int currentValue = i < current.length ? current[i] : 0;
int remoteValue = i < remote.length ? remote[i] : 0;
if (currentValue < remoteValue) {
return true; return true;
} else if (remoteVersion < localVersion) { } else if (currentValue > remoteValue) {
return false; return false;
} }
} }