diff --git a/app/src/main/java/emu/skyline/KeyReader.kt b/app/src/main/java/emu/skyline/KeyReader.kt index 8c93375b..c816f1ea 100644 --- a/app/src/main/java/emu/skyline/KeyReader.kt +++ b/app/src/main/java/emu/skyline/KeyReader.kt @@ -47,40 +47,41 @@ object KeyReader { val tmpOutputFile = File("${context.filesDir.canonicalFile}/${keyType.fileName}.tmp") - val inputStream = context.contentResolver.openInputStream(uri) - tmpOutputFile.bufferedWriter().use { writer -> - val valid = inputStream!!.bufferedReader().useLines { - for (line in it) { - if (line.startsWith(";") || line.isBlank()) continue + context.contentResolver.openInputStream(uri).use { inputStream -> + tmpOutputFile.bufferedWriter().use { writer -> + val valid = inputStream!!.bufferedReader().useLines { + for (line in it) { + if (line.startsWith(";") || line.isBlank()) continue - val pair = line.split("=") - if (pair.size != 2) - return@useLines false + val pair = line.split("=") + if (pair.size != 2) + return@useLines false - val key = pair[0].trim() - val value = pair[1].trim() - when (keyType) { - KeyType.Title -> { - if (key.length != 32 && !isHexString(key)) - return@useLines false - if (value.length != 32 && !isHexString(value)) - return@useLines false - } - KeyType.Prod -> { - if (!key.contains("_")) - return@useLines false - if (!isHexString(value)) - return@useLines false + val key = pair[0].trim() + val value = pair[1].trim() + when (keyType) { + KeyType.Title -> { + if (key.length != 32 && !isHexString(key)) + return@useLines false + if (value.length != 32 && !isHexString(value)) + return@useLines false + } + KeyType.Prod -> { + if (!key.contains("_")) + return@useLines false + if (!isHexString(value)) + return@useLines false + } } + + writer.append("$key=$value\n") } - - writer.append("$key=$value\n") + true } - true - } - if (valid) tmpOutputFile.renameTo(File("${tmpOutputFile.parent}/${keyType.fileName}")) - return valid + if (valid) tmpOutputFile.renameTo(File("${tmpOutputFile.parent}/${keyType.fileName}")) + return valid + } } }