-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
124 additions
and
4 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
NMSLCore/src/main/kotlin/com/github/purofle/nmsl/download/fabric/FabricDownloader.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.github.purofle.nmsl.download.fabric | ||
|
||
import com.github.purofle.nmsl.download.DownloadProvider | ||
import com.github.purofle.nmsl.download.MCBBSDownloadProvider | ||
import com.github.purofle.nmsl.game.GameJson | ||
import com.github.purofle.nmsl.utils.io.HttpRequest | ||
import com.github.purofle.nmsl.utils.io.HttpRequest.downloadFile | ||
import com.github.purofle.nmsl.utils.os.OS | ||
import org.apache.log4j.LogManager | ||
import org.apache.log4j.Logger | ||
import kotlin.io.path.createDirectories | ||
import kotlin.io.path.div | ||
|
||
class FabricDownloader( | ||
private val provider: DownloadProvider = MCBBSDownloadProvider(), | ||
private val version: GameJson, | ||
) { | ||
|
||
private val versionDir = OS.minecraftWorkingDirectory() / "versions" / version.id | ||
private val librariesDir = OS.minecraftWorkingDirectory() / "libraries" | ||
|
||
private val gameJsonFile = versionDir / "${version.id}.json" | ||
|
||
private val logger: Logger = LogManager.getLogger(this::class.java) | ||
|
||
suspend fun downloadFabric() { | ||
val fabricVersion = FabricVersion.getFabricVersion() | ||
val fabricMeta = getFabricMeta(fabricVersion.first { it.gameVersion == version.id }.metaUrl) | ||
|
||
fabricMeta.loader.download() | ||
fabricMeta.intermediary.download() | ||
|
||
val libraries = fabricMeta.launcherMeta.libraries.common.map { | ||
val file = librariesDir.resolve(getPath(it.name)) | ||
file.parent.createDirectories() | ||
HttpRequest.DownloadInfo(getLibraryUrl(maven = it.name), file.toFile(), it.sha1) | ||
} | ||
|
||
HttpRequest.downloadFiles(libraries, onDownloadComplete = {}) | ||
logger.info("Downloaded libraries") | ||
} | ||
|
||
suspend fun editGameJson() { | ||
} | ||
|
||
suspend fun Maven.download() { | ||
val path = librariesDir.resolve(getPath(maven)) | ||
path.parent.createDirectories() | ||
|
||
val url = getLibraryUrl(maven = maven) | ||
downloadFile { | ||
this.url = url | ||
saveFile = path.toFile() | ||
} | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
NMSLCore/src/main/kotlin/com/github/purofle/nmsl/download/fabric/FabricMeta.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.github.purofle.nmsl.download.fabric | ||
|
||
import com.github.purofle.nmsl.utils.io.HttpRequest | ||
import kotlinx.serialization.Serializable | ||
|
||
suspend fun getFabricMeta(url: String): FabricMeta { | ||
return HttpRequest.getJson(url) | ||
} | ||
|
||
@Serializable | ||
data class FabricMeta( | ||
val loader: Maven, | ||
val intermediary: Maven, | ||
val launcherMeta: LauncherMeta | ||
) | ||
|
||
@Serializable | ||
data class Maven( | ||
val maven: String, | ||
val version: String | ||
) | ||
|
||
@Serializable | ||
data class LauncherMeta( | ||
val libraries: Libraries, | ||
val mainClass: Map<String, String> | ||
) | ||
|
||
@Serializable | ||
data class Libraries( | ||
val common: List<FabricLibrary>, | ||
) | ||
|
||
@Serializable | ||
data class FabricLibrary( | ||
val name: String, | ||
val url: String, | ||
val sha1: String, | ||
val size: Int, | ||
) | ||
|
||
fun getLibraryUrl(url: String = "https://maven.fabricmc.net/", maven: String): String = "${url}${getPath(maven)}" | ||
|
||
fun getPath(maven: String): String { | ||
val (group, artifact, version) = maven.split(":") | ||
return "${group.replace(".", "/")}/${artifact}/$version/${artifact}-$version.jar" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import com.github.purofle.nmsl.download.MCBBSDownloadProvider | ||
import com.github.purofle.nmsl.download.fabric.FabricDownloader | ||
import com.github.purofle.nmsl.game.GameManager | ||
|
||
suspend fun main() { | ||
val provider = MCBBSDownloadProvider() | ||
val versions = GameManager.getVersionJson(GameManager.versions.first()) | ||
FabricDownloader(provider, versions).apply { | ||
downloadFabric() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters