@@ -38,21 +38,12 @@ internal abstract class BaseModuleManagerImpl(
38
38
override fun getModules () = modulesDir.listFiles()
39
39
.orEmpty()
40
40
.mapNotNull { dir ->
41
- readProps(dir)
42
- ?.toModule(
43
- state = readState(dir),
44
- lastUpdated = readLastUpdated(dir)
45
- )
41
+ readProps(dir)?.toModule(dir)
46
42
}
47
43
48
44
override fun getModuleById (id : String ): LocalModule ? {
49
45
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)
56
47
}
57
48
58
49
override fun getModuleInfo (zipPath : String ): LocalModule ? {
@@ -113,20 +104,34 @@ internal abstract class BaseModuleManagerImpl(
113
104
}
114
105
115
106
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",
116
116
state : State = State .ENABLE ,
117
117
lastUpdated : Long = 0L
118
118
) = LocalModule (
119
- id = getOrDefault(" id" , " unknown " ),
120
- name = getOrDefault(" name" , " unknown " ),
119
+ id = getOrDefault(" id" , path ),
120
+ name = getOrDefault(" name" , path ),
121
121
version = getOrDefault(" version" , " " ),
122
- versionCode = getOrDefault(" versionCode" , " -1" ).toInt( ),
122
+ versionCode = getOrDefault(" versionCode" , " -1" ).toIntOr( - 1 ),
123
123
author = getOrDefault(" author" , " " ),
124
124
description = getOrDefault(" description" , " " ),
125
125
updateJson = getOrDefault(" updateJson" , " " ),
126
126
state = state,
127
127
lastUpdated = lastUpdated
128
128
)
129
129
130
+ private fun String.toIntOr (defaultValue : Int ) =
131
+ runCatching {
132
+ toInt()
133
+ }.getOrDefault(defaultValue)
134
+
130
135
private fun String.exec () = ShellUtils .fastCmd(shell, this )
131
136
132
137
internal fun install (cmd : String , path : String , callback : IInstallCallback ) {
0 commit comments