From 03d6153579bafeeb9fd675236e8b027aa65c04ad Mon Sep 17 00:00:00 2001 From: Liplum Date: Tue, 26 Dec 2023 08:10:33 +0800 Subject: [PATCH] renaming --- main/src/SharedCache.kt | 8 +++++--- main/src/task/ResolveGame.kt | 16 +++++++++++----- main/src/task/ResolveModpack.kt | 17 +++++++++++++---- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/main/src/SharedCache.kt b/main/src/SharedCache.kt index 80cf50c..e1f3e9a 100644 --- a/main/src/SharedCache.kt +++ b/main/src/SharedCache.kt @@ -7,6 +7,7 @@ import io.github.liplum.dsl.gson import org.gradle.api.Project import org.gradle.api.logging.Logger import kotlin.math.absoluteValue +import kotlin.math.log private @@ -111,22 +112,23 @@ object SharedCache { } internal - fun isUpdateToDate( + fun checkUpdateToDate( lockFile: File, outOfDate: Long = R.outOfDataDuration, + logger: Logger? = null, ): Boolean { val infoFi = File("$lockFile.$lockFileEx") if (!lockFile.exists()) { if (infoFi.exists()) infoFi.delete() return false } - val meta = tryReadDownloadTrack(infoFi) + val meta = tryReadAndUpdateDownloadLock(infoFi, logger = logger) val curTime = System.currentTimeMillis() return curTime - meta.lastUpdateTimestamp < outOfDate } internal - fun tryReadDownloadTrack( + fun tryReadAndUpdateDownloadLock( infoFile: File, logger: Logger? = null, ): DownloadLock { diff --git a/main/src/task/ResolveGame.kt b/main/src/task/ResolveGame.kt index 8d98e03..00aa627 100644 --- a/main/src/task/ResolveGame.kt +++ b/main/src/task/ResolveGame.kt @@ -3,7 +3,7 @@ package io.github.liplum.mindustry import io.github.liplum.dsl.* import io.github.liplum.dsl.fileProp import io.github.liplum.dsl.prop -import io.github.liplum.mindustry.SharedCache.isUpdateToDate +import io.github.liplum.mindustry.SharedCache.checkUpdateToDate import org.gradle.api.DefaultTask import org.gradle.api.GradleException import org.gradle.api.tasks.Input @@ -23,7 +23,7 @@ open class ResolveGame : DefaultTask() { temporaryDir.resolve(location.get().fileName4Local) }) outputs.upToDateWhen { - gameFile.get().exists() + false } } @@ -34,9 +34,15 @@ open class ResolveGame : DefaultTask() { val cacheFile = loc.resolveCacheFile() cacheFile.ensureParentDir() when (loc) { - is LocalGameLoc -> if (!cacheFile.isFile) throw GradleException("Local game $cacheFile doesn't exists.") - is ILatestDownloadableGameLoc -> if (!isUpdateToDate(lockFile = cacheFile)) loc.download(cacheFile) - is IDownloadableGameLoc -> if (!cacheFile.exists()) loc.download(cacheFile) + is LocalGameLoc -> if (!cacheFile.isFile) { + throw GradleException("Local game $cacheFile doesn't exists.") + } + is ILatestDownloadableGameLoc -> if (!checkUpdateToDate(lockFile = cacheFile, logger = logger)) { + loc.download(cacheFile) + } + is IDownloadableGameLoc -> if (!cacheFile.exists()) { + loc.download(cacheFile) + } else -> throw Exception("Unhandled game loc $loc") } if (cacheFile.exists()) { diff --git a/main/src/task/ResolveModpack.kt b/main/src/task/ResolveModpack.kt index 89df0d9..6557a53 100644 --- a/main/src/task/ResolveModpack.kt +++ b/main/src/task/ResolveModpack.kt @@ -2,7 +2,7 @@ package io.github.liplum.mindustry import io.github.liplum.dsl.* import io.github.liplum.dsl.listProp -import io.github.liplum.mindustry.SharedCache.isUpdateToDate +import io.github.liplum.mindustry.SharedCache.checkUpdateToDate import org.gradle.api.DefaultTask import org.gradle.api.GradleException import org.gradle.api.tasks.Input @@ -27,6 +27,9 @@ open class ResolveModpack : DefaultTask() { } } ) + outputs.upToDateWhen { + false + } } fun IMod.resolveOutputFile(): File { @@ -45,9 +48,15 @@ open class ResolveModpack : DefaultTask() { val cacheFile = mod.resolveCacheFile() cacheFile.ensureParentDir() when (mod) { - 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) + is LocalMod -> if (!cacheFile.isFile) { + throw GradleException("Local mod $cacheFile not found.") + } + is IGitHubMod -> if (!checkUpdateToDate(lockFile = cacheFile, logger = logger)) { + mod.download(cacheFile) + } + is IDownloadableMod -> if (!cacheFile.exists()) { + mod.download(cacheFile) + } else -> throw Exception("Unhandled mod $mod") } if (cacheFile.exists()) {