Replace Helpers.getPath() with file.getAbsolutePath()

This commit is contained in:
TSR Berry 2023-07-23 23:47:02 +02:00 committed by Emmanuel Hansen
parent fa16c9c3bd
commit fae788f698
2 changed files with 19 additions and 12 deletions

View File

@ -4,8 +4,8 @@ import androidx.compose.runtime.snapshots.SnapshotStateList
import androidx.compose.ui.text.intl.Locale import androidx.compose.ui.text.intl.Locale
import androidx.compose.ui.text.toLowerCase import androidx.compose.ui.text.toLowerCase
import com.anggrayudi.storage.SimpleStorageHelper import com.anggrayudi.storage.SimpleStorageHelper
import com.anggrayudi.storage.file.getAbsolutePath
import com.google.gson.Gson import com.google.gson.Gson
import org.ryujinx.android.Helpers
import org.ryujinx.android.MainActivity import org.ryujinx.android.MainActivity
import java.io.File import java.io.File
import kotlin.math.max import kotlin.math.max
@ -39,8 +39,8 @@ class TitleUpdateViewModel(val titleId: String) {
{ {
val file = files.firstOrNull() val file = files.firstOrNull()
file?.apply { file?.apply {
val path = Helpers.getPath(storageHelper.storage.context, file.uri) val path = file.getAbsolutePath(storageHelper.storage.context)
if(!path.isNullOrEmpty()){ if(path.isNotEmpty()){
data?.apply { data?.apply {
if(!paths.contains(path)) { if(!paths.contains(path)) {
paths.add(path) paths.add(path)

View File

@ -2,10 +2,12 @@ package org.ryujinx.android.viewmodels
import androidx.compose.runtime.MutableState import androidx.compose.runtime.MutableState
import com.anggrayudi.storage.file.extension import com.anggrayudi.storage.file.extension
import com.anggrayudi.storage.file.getAbsolutePath
import com.google.gson.Gson import com.google.gson.Gson
import org.ryujinx.android.Helpers
import org.ryujinx.android.MainActivity import org.ryujinx.android.MainActivity
import java.io.BufferedOutputStream
import java.io.File import java.io.File
import java.io.FileOutputStream
import java.util.zip.ZipFile import java.util.zip.ZipFile
class VulkanDriverViewModel(val activity: MainActivity) { class VulkanDriverViewModel(val activity: MainActivity) {
@ -55,7 +57,7 @@ class VulkanDriverViewModel(val activity: MainActivity) {
val gson = Gson() val gson = Gson()
for (folder in folders){ for (folder in folders){
if(folder.isDirectory() && folder.parent == driverFolder.absolutePath){ if(folder.isDirectory && folder.parent == driverFolder.absolutePath){
val meta = File(folder.absolutePath + "/meta.json") val meta = File(folder.absolutePath + "/meta.json")
if(meta.exists()){ if(meta.exists()){
@ -104,23 +106,28 @@ class VulkanDriverViewModel(val activity: MainActivity) {
{ {
val file = files.firstOrNull() val file = files.firstOrNull()
file?.apply { file?.apply {
val path = Helpers.getPath(storage.context, file.uri) val path = file.getAbsolutePath(storage.context)
if(!path.isNullOrEmpty()){ if (path.isNotEmpty()){
val name = file.name?.removeSuffix("." + file.extension) ?: "" val name = file.name?.removeSuffix("." + file.extension) ?: ""
val driverFolder = ensureDriverPath() val driverFolder = ensureDriverPath()
val extractionFolder = File(driverFolder.absolutePath + "/${name}") val extractionFolder = File(driverFolder.absolutePath + "/${name}")
extractionFolder.deleteRecursively()
extractionFolder.mkdirs() extractionFolder.mkdirs()
ZipFile(path)?.use { zip -> ZipFile(path).use { zip ->
zip.entries().asSequence().forEach { entry -> zip.entries().asSequence().forEach { entry ->
zip.getInputStream(entry).use { input -> zip.getInputStream(entry).use { input ->
val filePath = extractionFolder.absolutePath + File.separator + entry.name val filePath = extractionFolder.absolutePath + File.separator + entry.name
if (!entry.isDirectory) { if (!entry.isDirectory) {
val length = input.available() File(filePath).delete()
val bytesIn = ByteArray(length) val bos = BufferedOutputStream(FileOutputStream(filePath))
input.read(bytesIn) val bytesIn = ByteArray(4096)
File(filePath).writeBytes(bytesIn) var read: Int
while (input.read(bytesIn).also { read = it } != -1) {
bos.write(bytesIn, 0, read)
}
bos.close()
} else { } else {
val dir = File(filePath) val dir = File(filePath)
dir.mkdir() dir.mkdir()