mirror of
https://github.com/rafaelvcaetano/melonDS-android.git
synced 2024-11-30 09:00:49 +00:00
Fix BIOS directory validation requiring storage permission
This commit is contained in:
parent
42ebe64fec
commit
89ffaff58c
@ -5,8 +5,6 @@ import android.content.res.AssetFileDescriptor
|
||||
import android.net.Uri
|
||||
import androidx.documentfile.provider.DocumentFile
|
||||
import me.magnum.melonds.domain.model.ConsoleType
|
||||
import me.magnum.melonds.utils.FileUtils.getAbsolutePathFromSAFUri
|
||||
import java.io.File
|
||||
import java.io.FileNotFoundException
|
||||
|
||||
object ConfigurationUtils {
|
||||
@ -32,9 +30,8 @@ object ConfigurationUtils {
|
||||
return ConfigurationDirResult(ConfigurationDirStatus.UNSET, requiredFiles, fileResults.toTypedArray())
|
||||
}
|
||||
|
||||
val dirPath = getAbsolutePathFromSAFUri(context, configurationDir)
|
||||
val dir = File(dirPath)
|
||||
if (!dir.isDirectory) {
|
||||
val dirDocument = DocumentFile.fromTreeUri(context, configurationDir)
|
||||
if (dirDocument?.isDirectory != true) {
|
||||
val requiredFiles = getRequiredFiles(consoleType)
|
||||
val fileResults = requiredFiles.map { it to ConfigurationFileStatus.MISSING }
|
||||
return ConfigurationDirResult(ConfigurationDirStatus.INVALID, requiredFiles, fileResults.toTypedArray())
|
||||
@ -43,16 +40,16 @@ object ConfigurationUtils {
|
||||
val requiredFiles = getRequiredFiles(consoleType)
|
||||
val fileResults = if (consoleType == ConsoleType.DS) {
|
||||
listOf(
|
||||
"bios7.bin" to getDSBios7Status(context, dir),
|
||||
"bios9.bin" to getDSBios9Status(context, dir),
|
||||
"firmware.bin" to getDSFirmwareStatus(context, dir)
|
||||
"bios7.bin" to getDSBios7Status(context, dirDocument),
|
||||
"bios9.bin" to getDSBios9Status(context, dirDocument),
|
||||
"firmware.bin" to getDSFirmwareStatus(context, dirDocument)
|
||||
)
|
||||
} else {
|
||||
listOf(
|
||||
"bios7.bin" to getDSiBios7Status(context, dir),
|
||||
"bios9.bin" to getDSiBios9Status(context, dir),
|
||||
"firmware.bin" to getDSiFirmwareStatus(context, dir),
|
||||
"nand.bin" to getDSiNandStatus(dir)
|
||||
"bios7.bin" to getDSiBios7Status(context, dirDocument),
|
||||
"bios9.bin" to getDSiBios9Status(context, dirDocument),
|
||||
"firmware.bin" to getDSiFirmwareStatus(context, dirDocument),
|
||||
"nand.bin" to getDSiNandStatus(dirDocument)
|
||||
)
|
||||
}
|
||||
val result = if (fileResults.any { it.second != ConfigurationFileStatus.PRESENT }) {
|
||||
@ -63,16 +60,16 @@ object ConfigurationUtils {
|
||||
return ConfigurationDirResult(result, requiredFiles, fileResults.toTypedArray())
|
||||
}
|
||||
|
||||
private fun getDSBios7Status(context: Context, configurationDir: File): ConfigurationFileStatus {
|
||||
private fun getDSBios7Status(context: Context, configurationDir: DocumentFile): ConfigurationFileStatus {
|
||||
return getBiosFileStatus(context, configurationDir, "bios7.bin", 0x4000.toLong())
|
||||
}
|
||||
|
||||
private fun getDSBios9Status(context: Context, configurationDir: File): ConfigurationFileStatus {
|
||||
private fun getDSBios9Status(context: Context, configurationDir: DocumentFile): ConfigurationFileStatus {
|
||||
return getBiosFileStatus(context, configurationDir, "bios9.bin", 0x1000.toLong())
|
||||
}
|
||||
|
||||
private fun getDSFirmwareStatus(context: Context, configurationDir: File): ConfigurationFileStatus {
|
||||
val firmwareDocument = DocumentFile.fromFile(File(configurationDir, "firmware.bin"))
|
||||
private fun getDSFirmwareStatus(context: Context, configurationDir: DocumentFile): ConfigurationFileStatus {
|
||||
val firmwareDocument =configurationDir.findFile("firmware.bin") ?: return ConfigurationFileStatus.MISSING
|
||||
return try {
|
||||
context.contentResolver.openAssetFileDescriptor(firmwareDocument.uri, "r")?.use {
|
||||
when (it.length) {
|
||||
@ -88,16 +85,16 @@ object ConfigurationUtils {
|
||||
}
|
||||
}
|
||||
|
||||
private fun getDSiBios7Status(context: Context, configurationDir: File): ConfigurationFileStatus {
|
||||
private fun getDSiBios7Status(context: Context, configurationDir: DocumentFile): ConfigurationFileStatus {
|
||||
return getBiosFileStatus(context, configurationDir, "bios7.bin", 0x10000.toLong())
|
||||
}
|
||||
|
||||
private fun getDSiBios9Status(context: Context, configurationDir: File): ConfigurationFileStatus {
|
||||
private fun getDSiBios9Status(context: Context, configurationDir: DocumentFile): ConfigurationFileStatus {
|
||||
return getBiosFileStatus(context, configurationDir, "bios9.bin", 0x10000.toLong())
|
||||
}
|
||||
|
||||
private fun getDSiFirmwareStatus(context: Context, configurationDir: File): ConfigurationFileStatus {
|
||||
val firmwareDocument = DocumentFile.fromFile(File(configurationDir, "firmware.bin"))
|
||||
private fun getDSiFirmwareStatus(context: Context, configurationDir: DocumentFile): ConfigurationFileStatus {
|
||||
val firmwareDocument = configurationDir.findFile("firmware.bin") ?: return ConfigurationFileStatus.MISSING
|
||||
return try {
|
||||
context.contentResolver.openAssetFileDescriptor(firmwareDocument.uri, "r")?.use {
|
||||
when (it.length) {
|
||||
@ -111,13 +108,13 @@ object ConfigurationUtils {
|
||||
}
|
||||
}
|
||||
|
||||
private fun getDSiNandStatus(configurationDir: File): ConfigurationFileStatus {
|
||||
val firmwareDocument = DocumentFile.fromFile(File(configurationDir, "nand.bin"))
|
||||
return if (firmwareDocument.isFile) ConfigurationFileStatus.PRESENT else ConfigurationFileStatus.MISSING
|
||||
private fun getDSiNandStatus(configurationDir: DocumentFile): ConfigurationFileStatus {
|
||||
val firmwareDocument = configurationDir.findFile("nand.bin")
|
||||
return if (firmwareDocument?.isFile == true) ConfigurationFileStatus.PRESENT else ConfigurationFileStatus.MISSING
|
||||
}
|
||||
|
||||
private fun getBiosFileStatus(context: Context, configurationDir: File, fileName: String, requiredSize: Long): ConfigurationFileStatus {
|
||||
val biosDocument = DocumentFile.fromFile(File(configurationDir, fileName))
|
||||
private fun getBiosFileStatus(context: Context, configurationDir: DocumentFile, fileName: String, requiredSize: Long): ConfigurationFileStatus {
|
||||
val biosDocument = configurationDir.findFile(fileName) ?: return ConfigurationFileStatus.MISSING
|
||||
return try {
|
||||
context.contentResolver.openAssetFileDescriptor(biosDocument.uri, "r")?.use {
|
||||
when (it.length) {
|
||||
|
Loading…
Reference in New Issue
Block a user