@@ -41,6 +41,7 @@ import xyz.deathsgun.modmanager.api.provider.IModUpdateProvider
41
41
import xyz.deathsgun.modmanager.api.provider.Sorting
42
42
import xyz.deathsgun.modmanager.models.FabricMetadata
43
43
import xyz.deathsgun.modmanager.state.ModState
44
+ import java.io.File
44
45
import java.math.BigInteger
45
46
import java.net.URI
46
47
import java.net.http.HttpClient
@@ -325,11 +326,7 @@ class UpdateManager {
325
326
FileUtils .listFiles(FabricLoader .getInstance().gameDir.resolve(" mods" ).toFile(), arrayOf(" jar" ), true )
326
327
return try {
327
328
for (jar in jars) {
328
- val jarFile = ZipFile (jar)
329
- val fabricEntry = jarFile.getEntry(" fabric.mod.json" )
330
- val data = jarFile.getInputStream(fabricEntry).bufferedReader().use { it.readText() }
331
- val meta = json.decodeFromString<FabricMetadata >(data)
332
- jarFile.close()
329
+ val meta = openFabricMeta(jar)
333
330
if (meta.id == container.id) {
334
331
return jar.toPath()
335
332
}
@@ -340,17 +337,12 @@ class UpdateManager {
340
337
}
341
338
}
342
339
343
- @OptIn(ExperimentalSerializationApi ::class )
344
- fun findJarByMod (mod : Mod ): Path ? {
340
+ private fun findJarByMod (mod : Mod ): Path ? {
345
341
val jars =
346
342
FileUtils .listFiles(FabricLoader .getInstance().gameDir.resolve(" mods" ).toFile(), arrayOf(" jar" ), true )
347
343
return try {
348
344
for (jar in jars) {
349
- val jarFile = ZipFile (jar)
350
- val fabricEntry = jarFile.getEntry(" fabric.mod.json" )
351
- val data = jarFile.getInputStream(fabricEntry).bufferedReader().use { it.readText() }
352
- val meta = json.decodeFromString<FabricMetadata >(data)
353
- jarFile.close()
345
+ val meta = openFabricMeta(jar)
354
346
if (meta.id == mod.id || meta.id == mod.slug || meta.id == mod.slug.replace(" -" , " " ) ||
355
347
meta.custom.modmanager[ModManager .modManager.config.defaultProvider] == mod.id ||
356
348
meta.id.replace(" _" , " -" ) == mod.id ||
@@ -365,6 +357,16 @@ class UpdateManager {
365
357
}
366
358
}
367
359
360
+ @OptIn(ExperimentalSerializationApi ::class )
361
+ private fun openFabricMeta (file : File ): FabricMetadata {
362
+ val jarFile = ZipFile (file)
363
+ val fabricEntry = jarFile.getEntry(" fabric.mod.json" )
364
+ val data = jarFile.getInputStream(fabricEntry).bufferedReader().use { it.readText() }
365
+ val meta = json.decodeFromString<FabricMetadata >(data)
366
+ jarFile.close()
367
+ return meta
368
+ }
369
+
368
370
private fun getIdBy (metadata : ModMetadata ): Map <String , String >? {
369
371
if (! metadata.containsCustomValue(" modmanager" )) {
370
372
return null
@@ -382,7 +384,7 @@ class UpdateManager {
382
384
if (deletableMods.isEmpty()) {
383
385
return
384
386
}
385
- logger.info(" Deleting {} mods on the next start. " , deletableMods.size)
387
+ logger.info(" Deleting {} mods on the next start" , deletableMods.size)
386
388
val configFile = FabricLoader .getInstance().configDir.resolve(" .modmanager.delete.json" )
387
389
val data = json.encodeToString(deletableMods)
388
390
Files .writeString(configFile, data, Charsets .UTF_8 )
0 commit comments