Skip to content

Commit

Permalink
small cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
qimiko committed Jan 1, 2024
1 parent e50bbfc commit 05e9c46
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 48 deletions.
18 changes: 10 additions & 8 deletions app/src/main/java/com/geode/launcher/api/ReleaseViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
40 changes: 0 additions & 40 deletions app/src/main/java/com/geode/launcher/utils/DownloadUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -162,43 +162,3 @@ object DownloadUtils {
}
}
}

/*
class DownloadGeode constructor(context: Context) : AsyncTask<String, Int, Boolean>() {
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)
}
}
*/

0 comments on commit 05e9c46

Please sign in to comment.