Skip to content

Commit

Permalink
renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
liplum committed Dec 26, 2023
1 parent 3962201 commit 03d6153
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
8 changes: 5 additions & 3 deletions main/src/SharedCache.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
16 changes: 11 additions & 5 deletions main/src/task/ResolveGame.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,7 +23,7 @@ open class ResolveGame : DefaultTask() {
temporaryDir.resolve(location.get().fileName4Local)
})
outputs.upToDateWhen {
gameFile.get().exists()
false
}
}

Expand All @@ -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()) {
Expand Down
17 changes: 13 additions & 4 deletions main/src/task/ResolveModpack.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,6 +27,9 @@ open class ResolveModpack : DefaultTask() {
}
}
)
outputs.upToDateWhen {
false
}
}

fun IMod.resolveOutputFile(): File {
Expand All @@ -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()) {
Expand Down

0 comments on commit 03d6153

Please sign in to comment.