diff --git a/app/src/main/java/com/geode/launcher/api/ReleaseViewModel.kt b/app/src/main/java/com/geode/launcher/api/ReleaseViewModel.kt index 8fcb6cda..73c1a02a 100644 --- a/app/src/main/java/com/geode/launcher/api/ReleaseViewModel.kt +++ b/app/src/main/java/com/geode/launcher/api/ReleaseViewModel.kt @@ -138,17 +138,19 @@ class ReleaseViewModel(private val releaseRepository: ReleaseRepository, private _uiState.value = ReleaseUIState.InDownload(progress, outOf) } - val geodeName = LaunchUtils.getGeodeFilename() - - val fallbackPath = File(application.filesDir, "launcher") - val geodeDirectory = application.getExternalFilesDir("") ?: fallbackPath + try { + val geodeName = LaunchUtils.getGeodeFilename() - val geodeFile = File(geodeDirectory, geodeName) + val fallbackPath = File(application.filesDir, "launcher") + val geodeDirectory = application.getExternalFilesDir("") ?: fallbackPath - DownloadUtils.extractFileFromZip(outputFile, geodeFile, geodeName) + val geodeFile = File(geodeDirectory, geodeName) - // delete file now that it's no longer needed - outputFile.delete() + DownloadUtils.extractFileFromZip(outputFile, geodeFile, geodeName) + } finally { + // delete file now that it's no longer needed + outputFile.delete() + } } private fun updatePreferences(release: Release) { diff --git a/app/src/main/java/com/geode/launcher/utils/DownloadUtils.kt b/app/src/main/java/com/geode/launcher/utils/DownloadUtils.kt index 1a256f49..59930940 100644 --- a/app/src/main/java/com/geode/launcher/utils/DownloadUtils.kt +++ b/app/src/main/java/com/geode/launcher/utils/DownloadUtils.kt @@ -162,43 +162,3 @@ object DownloadUtils { } } } - -/* -class DownloadGeode constructor(context: Context) : AsyncTask() { - private val context: Context = context - - override fun doInBackground(vararg params: String?): Boolean { - val url = URL(params[0]) - val connection = url.openConnection() as HttpURLConnection - connection.requestMethod = "GET" - connection.connect() - // downloads a zip file - ZipInputStream(connection.inputStream).use { zip -> - var entry = zip.nextEntry - while (entry != null) { - val file = entry.name - context.getExternalFilesDir(null)?.let { dir-> - val destFile = File(dir, file) - destFile.outputStream().use { output -> - zip.copyTo(output) - Log.d("Geode", "Downloading to $destFile") - } - } - entry = zip.nextEntry - } - } - - return true - } - - override fun onPostExecute(result: Boolean) { - super.onPostExecute(result) - Log.d("Geode", "Downloading Result: $result") - - // update the screen - val intent = Intent(context, MainActivity::class.java) - intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK - context.startActivity(intent) - } -} -*/