Skip to content

Commit

Permalink
fixed Url mod download
Browse files Browse the repository at this point in the history
  • Loading branch information
liplum committed Dec 20, 2023
1 parent faadc21 commit 87ad7b8
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 15 deletions.
7 changes: 3 additions & 4 deletions main/src/dsl/FileSystem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,10 @@ fun Task.createSymbolicLinkOrCopy(
if (!overwrite && link.exists()) return
try {
Files.createSymbolicLink(link.toPath(), target.toPath())
logger.lifecycle("Created symbolic link: $target -> $link.")
logger.info("Created symbolic link: $target -> $link.")
} catch (error: Exception) {
logger.lifecycle("Cannot create symbolic link: $target -> $link, because $error.")
logger.lifecycle("Fallback to copy file.")
logger.error("Cannot create symbolic link: $target -> $link, because $error. Fallback to copy file.")
target.copyTo(link, overwrite)
logger.lifecycle("Copied: $target -> $link.")
logger.info("Copied: $target -> $link.")
}
}
4 changes: 2 additions & 2 deletions main/src/run/RunMindustry.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ open class RunMindustryExtension(
name: String = "",
config: AddClientSpec.() -> Unit
): Client {
proj.logger.quiet("Client<$name> was added.")
proj.logger.info("Client<$name> was added.")
val (newName, isAnonymous) = allocModelName(name, clients)
val client = Client(name = newName, isAnonymous = isAnonymous)
client.modpack = ""
Expand Down Expand Up @@ -139,7 +139,7 @@ open class RunMindustryExtension(
name: String = "",
config: AddServerSpec.() -> Unit
): Server {
proj.logger.quiet("Server<$name> was added.")
proj.logger.info("Server<$name> was added.")
val (newName, isAnonymous) = allocModelName(name, servers)
val server = Server(name = newName, isAnonymous = isAnonymous)
server.modpack = ""
Expand Down
2 changes: 1 addition & 1 deletion main/src/run/model/GameSide.kt
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ abstract class AddGameSideSpec<T : GameSide> {

fun useModpack(name: String) {
modpack = formatValidGradleName(name)
proj.logger.quiet("Modpack<$name> was used in game<${name}>.")
proj.logger.info("Modpack<$name> was used in game<${name}>.")
}

fun useModpack(modpack: Modpack) {
Expand Down
2 changes: 1 addition & 1 deletion main/src/run/model/Modpack.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class AddModpackSpec(
private val modpack: Modpack
) {
fun addMod(mod: IMod) {
proj.logger.quiet("$mod was added in modpack<${modpack.name}>")
proj.logger.info("$mod was added in modpack<${modpack.name}>")
modpack.mods.add(mod)
}

Expand Down
4 changes: 3 additions & 1 deletion main/src/run/model/Mods.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ data class LocalMod(
*/
data class UrlMod(
val url: URL,
) : IMod {
) : IDownloadableMod {
constructor(url: String) : this(URL(url))

override fun resolveDownloadSrc() = url

override val fileName4Local: String = "${url.resolve4FileName()}.zip"

override fun resolveCacheFile(): File {
Expand Down
6 changes: 5 additions & 1 deletion main/src/task/ResolveGame.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ open class ResolveGame : DefaultTask() {
is IDownloadableGameLoc -> if (!cacheFile.exists()) loc.download(cacheFile)
else -> throw Exception("Unhandled game loc $loc")
}
createSymbolicLinkOrCopy(link = gameFile, target = cacheFile)
if (cacheFile.exists()) {
createSymbolicLinkOrCopy(link = gameFile, target = cacheFile)
} else {
logger.error("$cacheFile doesn't exist.")
}
}

fun IDownloadableGameLoc.download(cacheFile: File) {
Expand Down
8 changes: 6 additions & 2 deletions main/src/task/ResolveMods.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,13 @@ open class ResolveMods : DefaultTask() {
is LocalMod -> if (!cacheFile.isFile) throw GradleException("Local mod $cacheFile not found.")
is IGitHubMod -> if (!isUpdateToDate(lockFile = cacheFile)) mod.download(cacheFile)
is IDownloadableMod -> if (!cacheFile.exists()) mod.download(cacheFile)
else -> {}
else -> throw Exception("Unhandled mod $mod")
}
if (cacheFile.exists()) {
createSymbolicLinkOrCopy(link = mod.resolveOutputFile(), target = cacheFile)
} else {
logger.error("$cacheFile doesn't exist.")
}
createSymbolicLinkOrCopy(link = mod.resolveOutputFile(), target = cacheFile)
}
}

Expand Down
4 changes: 3 additions & 1 deletion main/src/task/RunClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ open class RunClient : RunMindustryAbstract() {
@TaskAction
override fun exec() {
val dataDir = dataDir.get().resolveDir(this, GameSideType.Client) ?: temporaryDir.resolve(name)
logger.lifecycle("Run client in $dataDir.")
environment[R.env.mindustryDataDir] = dataDir.absoluteFile
workingDir = dataDir
if (dataDir.isDirectory) {
// TODO: Record the mod signature.
Expand All @@ -21,7 +23,7 @@ open class RunClient : RunMindustryAbstract() {
if (modFile.isFile) {
createSymbolicLinkOrCopy(link = modsFolder.resolve(modFile.name), target = modFile)
} else {
logger.warn("Mod<$modFile> doesn't exist.")
logger.error("Mod<$modFile> doesn't exist.")
}
}
standardInput = System.`in`
Expand Down
5 changes: 3 additions & 2 deletions main/src/task/RunServer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ open class RunServer : RunMindustryAbstract() {
@TaskAction
override fun exec() {
val dataDir = dataDir.get().resolveDir(this, GameSideType.Server) ?: temporaryDir.resolve(name)
logger.lifecycle("Run server in $dataDir.")
if (dataDir.isDirectory) {
// TODO: Record the mod signature.
// TODO: Don't always delete all.
Expand All @@ -15,10 +16,10 @@ open class RunServer : RunMindustryAbstract() {
dataDir.mkdirs()
val modsFolder = dataDir.resolve("config").resolve("mods")
for (modFile in mods) {
if (modFile.isFile) {
if (modFile.exists()) {
createSymbolicLinkOrCopy(link = modsFolder.resolve(modFile.name), target = modFile)
} else {
logger.warn("Mod<$modFile> doesn't exist.")
logger.error("Mod<$modFile> doesn't exist.")
}
}
standardInput = System.`in`
Expand Down

0 comments on commit 87ad7b8

Please sign in to comment.