Skip to content

Commit b5f83a3

Browse files
committed
use libVersion + logging lib
1 parent 5d36cb9 commit b5f83a3

14 files changed

Lines changed: 63 additions & 214 deletions

File tree

build.gradle.kts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
plugins {
2-
id("org.jetbrains.kotlin.jvm") version "1.5.31"
2+
id("org.jetbrains.kotlin.jvm") version "1.6.0"
33
id("com.github.johnrengelman.shadow") version "7.1.0"
44
}
55

@@ -12,22 +12,26 @@ repositories {
1212
}
1313

1414
dependencies {
15-
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.31")
16-
implementation("org.jetbrains.kotlin:kotlin-reflect:1.5.31")
15+
implementation(kotlin("stdlib-jdk8", "1.6.0"))
16+
implementation(kotlin("reflect", "1.6.0"))
1717

1818
implementation("com.google.code.gson:gson:2.8.9")
1919

20-
implementation("com.formdev:flatlaf:1.6.1")
20+
implementation("com.formdev:flatlaf:1.6.3")
2121

2222
implementation("io.ktor:ktor-client-gson:1.6.5")
2323
implementation("io.ktor:ktor-client-core:1.6.5")
2424
implementation("io.ktor:ktor-client-apache:1.6.5")
25+
26+
implementation("io.github.microutils:kotlin-logging-jvm:2.1.0")
27+
implementation("ch.qos.logback:logback-classic:1.2.7")
28+
29+
implementation("org.bundleproject:libversion:0.0.2")
2530
}
2631

2732
tasks {
2833
shadowJar {
2934
archiveClassifier.set("")
30-
3135
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
3236

3337
relocate("com.google.code.gson", "org.bundleproject.lib.gson")
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-all.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

src/main/kotlin/org/bundleproject/bundle/Bundle.kt

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,16 @@ import com.google.gson.JsonParser
55
import kotlinx.coroutines.async
66
import kotlinx.coroutines.awaitAll
77
import kotlinx.coroutines.coroutineScope
8-
import kotlinx.coroutines.runBlocking
98
import org.bundleproject.bundle.entities.Mod
109
import org.bundleproject.bundle.api.data.Platform
1110
import org.bundleproject.bundle.api.requests.BulkModRequest
1211
import org.bundleproject.bundle.gui.LoadingGui
13-
import org.bundleproject.bundle.gui.UpdateOverviewGui
1412
import org.bundleproject.bundle.utils.*
13+
import org.bundleproject.libversion.Version
1514
import java.io.File
1615
import java.io.InputStreamReader
17-
import java.net.URL
18-
import java.nio.file.Files
19-
import java.util.concurrent.locks.ReentrantLock
2016
import java.util.jar.JarFile
2117
import javax.swing.*
22-
import kotlin.concurrent.withLock
2318

2419
/**
2520
* The Bundle object holds the code to start the version checking
@@ -30,24 +25,22 @@ import kotlin.concurrent.withLock
3025
*
3126
* @since 0.0.1
3227
*/
33-
class Bundle(private val gameDir: File, private val version: Version?, modFolderName: String) {
28+
class Bundle(gameDir: File, private val version: Version?, modFolderName: String) {
3429
private val modsDir = File(gameDir, modFolderName)
3530

36-
constructor(gameDir: File, version: String?, modFolderName: String) : this(gameDir, version?.let(Version::of), modFolderName)
37-
3831
suspend fun start() {
3932
try {
40-
info("Starting Bundle...")
33+
logger.info("Starting Bundle...")
4134
println()
4235

4336
try { UIManager.setLookAndFeel(FlatLightLaf()) }
44-
catch (e: Throwable) { e.printStackTrace() }
37+
catch (e: Throwable) { logger.error(e) { "Couldn't set look and feel...." } }
4538

4639
val outdated = getOutdatedMods()
4740

4841
// return if outdated is empty
4942
if (outdated.isEmpty()) {
50-
info("No outdated mods found.")
43+
logger.info("No outdated mods found.")
5144
return
5245
}
5346

@@ -63,7 +56,7 @@ class Bundle(private val gameDir: File, private val version: Version?, modFolder
6356
updateMods(outdated)
6457

6558
} catch (e: Throwable) {
66-
e.printStackTrace()
59+
logger.error(e) { "Error while updating mods! Bundle exited!" }
6760
}
6861
}
6962

@@ -78,7 +71,7 @@ class Bundle(private val gameDir: File, private val version: Version?, modFolder
7871
* @since 0.0.1
7972
*/
8073
private suspend fun getOutdatedMods(): MutableList<ModPair> {
81-
info("Getting outdated mods...")
74+
logger.info("Getting outdated mods...")
8275

8376
val localMods = mutableListOf<Mod>()
8477
for (mod in modsDir.walkTopDown()) {
@@ -87,8 +80,8 @@ class Bundle(private val gameDir: File, private val version: Version?, modFolder
8780
val localMod = try {
8881
getModInfo(mod)
8982
} catch (e: Exception) {
90-
if (e is Version.VersionParseException) err("Failed to parse version for ${mod.name}")
91-
else e.printStackTrace()
83+
if (e is Version.VersionParseException) logger.error(e) { "Failed to parse version for ${mod.name}" }
84+
else logger.error(e) { "Failed to get mod info for ${mod.name}" }
9285

9386
null
9487
} ?: continue
@@ -97,14 +90,14 @@ class Bundle(private val gameDir: File, private val version: Version?, modFolder
9790

9891
localMods.add(localMod)
9992
}
100-
info("Found: ${localMods.map { it.id }.toFormattedString()}")
93+
logger.info("Found: ${localMods.map { it.id }.toFormattedString()}")
10194
println()
10295

103-
info("Making bulk request to API.")
96+
logger.info("Making bulk request to API.")
10497
val request = BulkModRequest(localMods.map { it.makeRequest() })
10598
val response = request.request()
10699

107-
info("Comparing local to remote mod versions.")
100+
logger.info("Comparing local to remote mod versions.")
108101
val outdated = mutableListOf<ModPair>()
109102
for (i in localMods.indices) {
110103
val local = localMods[i]
@@ -113,8 +106,8 @@ class Bundle(private val gameDir: File, private val version: Version?, modFolder
113106
if (remote > local)
114107
outdated.add(ModPair(local, remote))
115108
}
116-
info("${outdated.size}/${localMods.size} mods need an update.")
117-
info("Outdated: ${outdated.map { it.remote.id }.toFormattedString()}")
109+
logger.info("${outdated.size}/${localMods.size} mods need an update.")
110+
logger.info("Outdated: ${outdated.map { it.remote.id }.toFormattedString()}")
118111
println()
119112

120113
return outdated
@@ -126,10 +119,10 @@ class Bundle(private val gameDir: File, private val version: Version?, modFolder
126119
* @since 0.0.1
127120
*/
128121
private fun getModInfo(modFile: File): Mod? {
129-
info("Getting mod info using method: ", false)
122+
logger.info("Getting mod info using method...")
130123
JarFile(modFile).use { jar ->
131124
jar.getJarEntry("bundle.project.json")?.let getJarEntry@{ modInfo ->
132-
info("Bundle Info File")
125+
logger.info("Bundle Info File")
133126

134127
InputStreamReader(jar.getInputStream(modInfo)).use {
135128
val json = JsonParser.parseReader(it).asJsonObject
@@ -148,7 +141,7 @@ class Bundle(private val gameDir: File, private val version: Version?, modFolder
148141
}
149142

150143
jar.getJarEntry("fabric.mod.json")?.let { modInfo ->
151-
info("Fabric Info File")
144+
logger.info("Fabric Info File")
152145

153146
InputStreamReader(jar.getInputStream(modInfo)).use {
154147
val json = JsonParser.parseReader(it).asJsonObject
@@ -164,7 +157,7 @@ class Bundle(private val gameDir: File, private val version: Version?, modFolder
164157
}
165158

166159
jar.getJarEntry("mcmod.info")?.let { modInfo ->
167-
info("Forge Info File")
160+
logger.info("Forge Info File")
168161

169162
InputStreamReader(jar.getInputStream(modInfo)).use {
170163
val json = JsonParser.parseReader(it).asJsonArray[0].asJsonObject
@@ -180,7 +173,7 @@ class Bundle(private val gameDir: File, private val version: Version?, modFolder
180173
}
181174
}
182175

183-
err("None")
176+
logger.error("None")
184177
return null
185178
}
186179

@@ -192,7 +185,7 @@ class Bundle(private val gameDir: File, private val version: Version?, modFolder
192185
* @since 0.0.2
193186
*/
194187
suspend fun updateMods(mods: List<ModPair>) {
195-
info("Updating Mods...")
188+
logger.info("Updating Mods...")
196189

197190
coroutineScope {
198191
val loading = LoadingGui(mods.size)
@@ -202,9 +195,9 @@ class Bundle(private val gameDir: File, private val version: Version?, modFolder
202195
val current = File(modsDir, local.fileName)
203196
val new = File(modsDir, remote.fileName)
204197

205-
info("Downloading: ${new.name}")
198+
logger.info("Downloading: ${new.name}")
206199
if (http.downloadFile(new, remote.downloadEndpoint)) {
207-
info("Deleting: ${current.name}")
200+
logger.info("Deleting: ${current.name}")
208201
current.delete()
209202
} else {
210203
error("Failed to download! Skipping!")

src/main/kotlin/org/bundleproject/bundle/api/data/ModData.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.bundleproject.bundle.api.data
22

3-
import org.bundleproject.bundle.utils.Version
3+
import org.bundleproject.libversion.Version
44

55
data class ModData(
66
val url: String,

src/main/kotlin/org/bundleproject/bundle/entities/Mod.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package org.bundleproject.bundle.entities
33
import org.bundleproject.bundle.api.data.ModData
44
import org.bundleproject.bundle.api.data.Platform
55
import org.bundleproject.bundle.api.requests.ModRequest
6-
import org.bundleproject.bundle.utils.Version
76
import org.bundleproject.bundle.utils.getFileNameFromUrl
7+
import org.bundleproject.libversion.Version
88

99
open class Mod(
1010
@Transient var enabled: Boolean = true,

src/main/kotlin/org/bundleproject/bundle/entities/RemoteMod.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package org.bundleproject.bundle.entities
22

33
import org.bundleproject.bundle.api.data.Platform
4-
import org.bundleproject.bundle.utils.Version
4+
import org.bundleproject.libversion.Version
55

66
class RemoteMod(
77
enabled: Boolean = true,

src/main/kotlin/org/bundleproject/bundle/gui/LoadingGui.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import javax.swing.WindowConstants
1313
* @since 0.0.4
1414
*/
1515
class LoadingGui(private val updateCount: Int) : JFrame("Updating Mods") {
16-
1716
private val progressBar: JProgressBar
1817

1918
init {
@@ -43,5 +42,4 @@ class LoadingGui(private val updateCount: Int) : JFrame("Updating Mods") {
4342
progressBar.value += 1
4443
}
4544
}
46-
4745
}

src/main/kotlin/org/bundleproject/bundle/gui/UpdateOverviewGui.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import javax.swing.*
2020
* @since 0.0.2
2121
*/
2222
class UpdateOverviewGui(private val bundle: Bundle, mods: MutableList<ModPair>, condition: Condition? = null) : JFrame("Bundle") {
23-
2423
init {
2524
iconImage = getResourceImage("/bundle.png")
2625
defaultCloseOperation = WindowConstants.DISPOSE_ON_CLOSE
@@ -75,5 +74,4 @@ class UpdateOverviewGui(private val bundle: Bundle, mods: MutableList<ModPair>,
7574

7675
pack()
7776
}
78-
7977
}

src/main/kotlin/org/bundleproject/bundle/main/Main.kt

Lines changed: 0 additions & 68 deletions
This file was deleted.

src/main/kotlin/org/bundleproject/bundle/utils/Logger.kt

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)