Skip to content
This repository was archived by the owner on Jul 2, 2024. It is now read-only.

Commit dbb414e

Browse files
committed
Fix BaseModuleManagerImpl
1 parent b5e3cbb commit dbb414e

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

compat/src/main/kotlin/dev/sanmer/mrepo/compat/impl/BaseModuleManagerImpl.kt

+19-14
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,12 @@ internal abstract class BaseModuleManagerImpl(
3838
override fun getModules() = modulesDir.listFiles()
3939
.orEmpty()
4040
.mapNotNull { dir ->
41-
readProps(dir)
42-
?.toModule(
43-
state = readState(dir),
44-
lastUpdated = readLastUpdated(dir)
45-
)
41+
readProps(dir)?.toModule(dir)
4642
}
4743

4844
override fun getModuleById(id: String): LocalModule? {
4945
val dir = modulesDir.resolve(id)
50-
51-
return readProps(dir)
52-
?.toModule(
53-
state = readState(dir),
54-
lastUpdated = readLastUpdated(dir)
55-
)
46+
return readProps(dir)?.toModule(dir)
5647
}
5748

5849
override fun getModuleInfo(zipPath: String): LocalModule? {
@@ -113,20 +104,34 @@ internal abstract class BaseModuleManagerImpl(
113104
}
114105

115106
private fun Map<String, String>.toModule(
107+
dir: File
108+
) = toModule(
109+
path = dir.name,
110+
state = readState(dir),
111+
lastUpdated = readLastUpdated(dir)
112+
)
113+
114+
private fun Map<String, String>.toModule(
115+
path: String = "unknown",
116116
state: State = State.ENABLE,
117117
lastUpdated: Long = 0L
118118
) = LocalModule(
119-
id = getOrDefault("id", "unknown"),
120-
name = getOrDefault("name", "unknown"),
119+
id = getOrDefault("id", path),
120+
name = getOrDefault("name", path),
121121
version = getOrDefault("version", ""),
122-
versionCode = getOrDefault("versionCode", "-1").toInt(),
122+
versionCode = getOrDefault("versionCode", "-1").toIntOr(-1),
123123
author = getOrDefault("author", ""),
124124
description = getOrDefault("description", ""),
125125
updateJson = getOrDefault("updateJson", ""),
126126
state = state,
127127
lastUpdated = lastUpdated
128128
)
129129

130+
private fun String.toIntOr(defaultValue: Int) =
131+
runCatching {
132+
toInt()
133+
}.getOrDefault(defaultValue)
134+
130135
private fun String.exec() = ShellUtils.fastCmd(shell, this)
131136

132137
internal fun install(cmd: String, path: String, callback: IInstallCallback) {

0 commit comments

Comments
 (0)