Skip to content

Commit

Permalink
Fix: Deletions not being tracked
Browse files Browse the repository at this point in the history
Fix: Not waiting for modLoader download job to finish
  • Loading branch information
0ffz committed Mar 9, 2024
1 parent b973bbd commit 45f9cb5
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 21 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
group=com.mineinabyss
version=2.0.0-alpha.9
version=2.0.0-alpha.10
idofrontVersion=0.22.3
35 changes: 19 additions & 16 deletions src/main/kotlin/com/mineinabyss/launchy/logic/Launcher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ object Launcher {
minecraftDir: Path,
onStartDownload: (String) -> Unit = {},
onFinishDownload: (String) -> Unit = {}
): Job = AppDispatchers.IO.launch {
): Job {
val downloadJob = Job()
minecraftDir.createParentDirectories()
val dir = MinecraftDirectory(minecraftDir.toFile())
Expand All @@ -98,25 +98,28 @@ object Launcher {
modLoaders.fabricLoader != null -> fabricDownloader()
else -> vanillaDownloader()
}
val callback = object : CallbackAdapter<Version>() {
override fun done(result: Version) {
onFinishDownload("${result.type} $result")
downloader.shutdown()
downloadJob.complete()
}
AppDispatchers.IO.launch {
val callback = object : CallbackAdapter<Version>() {
override fun done(result: Version) {
onFinishDownload("${result.type} $result")
downloader.shutdown()
downloadJob.complete()
}

override fun failed(e: Throwable) {
e.printStackTrace()
downloader.shutdown()
downloadJob.complete()
}
override fun failed(e: Throwable) {
e.printStackTrace()
downloader.shutdown()
downloadJob.complete()
}

override fun <R : Any?> taskStart(task: DownloadTask<R>?): DownloadCallback<R>? {
onStartDownload(modLoaders.fullVersionName)
return null
override fun <R : Any?> taskStart(task: DownloadTask<R>?): DownloadCallback<R>? {
onStartDownload(modLoaders.fullVersionName)
return null
}
}
downloader.downloadIncrementally(dir, modLoaders.fullVersionName, callback)
}
downloader.downloadIncrementally(dir, modLoaders.fullVersionName, callback)
return downloadJob
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ object ModDownloader {
userAgreedDeps = modpack.modLoaders
ensureDependenciesReady(state)
copyOverrides(state)

queued.deletions.forEach {
queued.modDownloadInfo.remove(it.modId)
}

val downloads = queued.needsInstall.map { mod ->
async(AppDispatchers.IOContext) {
mod to download(mod, ignoreCachedCheck)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import com.mineinabyss.launchy.ui.elements.ComfyWidth
import com.mineinabyss.launchy.ui.screens.Screen
import com.mineinabyss.launchy.ui.screens.home.InstanceCard
import com.mineinabyss.launchy.ui.screens.screen
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlin.collections.set
import kotlin.io.path.deleteIfExists
Expand Down Expand Up @@ -99,10 +98,13 @@ fun ImportTab(visible: Boolean, onGetInstance: (GameInstanceConfig) -> Unit = {}
val taskKey = "importCloudInstance"
val downloadPath = Dirs.tmpCloudInstance(urlText)
downloadPath.deleteIfExists()
AppDispatchers.IO.launch(Dispatchers.IO) {
AppDispatchers.IO.launch {
state.inProgressTasks[taskKey] = InProgressTask("Importing cloud instance")
val cloudInstance =
Downloader.download(urlText, downloadPath, skipDownloadIfCached = false).mapCatching {
val cloudInstance = Downloader.download(
urlText,
downloadPath,
skipDownloadIfCached = false
).mapCatching {
GameInstanceConfig.read(downloadPath)
.showDialogOnError("Failed to read cloud instance")
.getOrThrow()
Expand Down

0 comments on commit 45f9cb5

Please sign in to comment.