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

Commit

Permalink
Fix BaseModuleManagerImpl
Browse files Browse the repository at this point in the history
  • Loading branch information
SanmerDev committed May 24, 2024
1 parent b5e3cbb commit dbb414e
Showing 1 changed file with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,12 @@ internal abstract class BaseModuleManagerImpl(
override fun getModules() = modulesDir.listFiles()
.orEmpty()
.mapNotNull { dir ->
readProps(dir)
?.toModule(
state = readState(dir),
lastUpdated = readLastUpdated(dir)
)
readProps(dir)?.toModule(dir)
}

override fun getModuleById(id: String): LocalModule? {
val dir = modulesDir.resolve(id)

return readProps(dir)
?.toModule(
state = readState(dir),
lastUpdated = readLastUpdated(dir)
)
return readProps(dir)?.toModule(dir)
}

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

private fun Map<String, String>.toModule(
dir: File
) = toModule(
path = dir.name,
state = readState(dir),
lastUpdated = readLastUpdated(dir)
)

private fun Map<String, String>.toModule(
path: String = "unknown",
state: State = State.ENABLE,
lastUpdated: Long = 0L
) = LocalModule(
id = getOrDefault("id", "unknown"),
name = getOrDefault("name", "unknown"),
id = getOrDefault("id", path),
name = getOrDefault("name", path),
version = getOrDefault("version", ""),
versionCode = getOrDefault("versionCode", "-1").toInt(),
versionCode = getOrDefault("versionCode", "-1").toIntOr(-1),
author = getOrDefault("author", ""),
description = getOrDefault("description", ""),
updateJson = getOrDefault("updateJson", ""),
state = state,
lastUpdated = lastUpdated
)

private fun String.toIntOr(defaultValue: Int) =
runCatching {
toInt()
}.getOrDefault(defaultValue)

private fun String.exec() = ShellUtils.fastCmd(shell, this)

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

0 comments on commit dbb414e

Please sign in to comment.