Skip to content

Commit 3eab9f4

Browse files
committed
fix(启动): 对游戏依赖库进行去重 & 增加日志记录
1 parent c34f476 commit 3eab9f4

1 file changed

Lines changed: 51 additions & 3 deletions

File tree

  • ZalithLauncher/src/main/java/com/movtery/zalithlauncher/game/launch

ZalithLauncher/src/main/java/com/movtery/zalithlauncher/game/launch/LaunchArgs.kt

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import com.movtery.zalithlauncher.utils.logging.Logger.lDebug
4545
import com.movtery.zalithlauncher.utils.logging.Logger.lInfo
4646
import com.movtery.zalithlauncher.utils.logging.Logger.lWarning
4747
import com.movtery.zalithlauncher.utils.network.ServerAddress
48+
import com.movtery.zalithlauncher.utils.string.compareVersion
4849
import com.movtery.zalithlauncher.utils.string.insertJSONValueList
4950
import com.movtery.zalithlauncher.utils.string.isEmptyOrBlank
5051
import com.movtery.zalithlauncher.utils.string.isLowerTo
@@ -299,15 +300,62 @@ class LaunchArgs(
299300
val libs = LinkedHashMap<GameManifest.Library, String>()
300301

301302
for (libItem in gameManifest.libraries) {
302-
if (!(GameManifest.Rule.checkRules(libItem.rules) && !libItem.isNative)) continue
303-
val path = libItem.progressLibrary() ?: continue
303+
if (!GameManifest.Rule.checkRules(libItem.rules)) {
304+
lDebug("Library ignored due to unmatched rules: ${libItem.name}")
305+
continue
306+
}
307+
if (libItem.isNative) {
308+
lDebug("Library ignored because it is a native library: ${libItem.name}")
309+
continue
310+
}
311+
val path = libItem.progressLibrary() ?: run {
312+
lDebug("Library ignored due to library filtering: ${libItem.name}")
313+
continue
314+
}
304315
with(libSortFix) {
305316
libs.insertLib(libItem, getLibrariesHome() + "/" + path)
306317
}
307318
}
308-
return libs.values.toTypedArray<String>()
319+
320+
//最后进行去重
321+
val deduplicated = LinkedHashMap<GameManifest.Library, String>()
322+
val bestVersionMap = mutableMapOf<String, Pair<GameManifest.Library, String>>()
323+
324+
for ((lib, path) in libs) {
325+
val nameParts = lib.name.split(":")
326+
if (nameParts.size < 3) {
327+
deduplicated[lib] = path
328+
continue
329+
}
330+
val groupArtifact = "${nameParts[0]}:${nameParts[1]}"
331+
val version = nameParts[2]
332+
333+
val existing = bestVersionMap[groupArtifact]
334+
if (existing == null) {
335+
bestVersionMap[groupArtifact] = lib to path
336+
deduplicated[lib] = path
337+
} else {
338+
val existingVersion = existing.first.name.split(":")[2]
339+
val cmp = version.compareVersion(existingVersion)
340+
if (cmp > 0) {
341+
//重复库,仅保留高版本
342+
lInfo("Duplicate library detected: $groupArtifact, replacing version $existingVersion with higher version $version")
343+
deduplicated.remove(existing.first)
344+
bestVersionMap[groupArtifact] = lib to path
345+
deduplicated[lib] = path
346+
} else if (cmp < 0) {
347+
lDebug("Duplicate library detected: $groupArtifact, ignoring lower version $version (keeping $existingVersion)")
348+
} else {
349+
//版本重复,仅保留一个
350+
lDebug("Duplicate library detected: $groupArtifact, ignoring duplicate version $version (keeping first occurrence)")
351+
}
352+
}
353+
}
354+
355+
return deduplicated.values.toTypedArray<String>()
309356
}
310357

358+
311359
/**
312360
* @return 库相对路径
313361
*/

0 commit comments

Comments
 (0)