mirror of
https://git.ryujinx.app/kenji-nx/ryujinx.git
synced 2025-12-16 22:37:06 +00:00
feat: Refactor autoloadContent to streamline directory scanning for NSPs
This commit is contained in:
parent
42fa39672b
commit
4e94f4731b
1 changed files with 65 additions and 75 deletions
|
|
@ -15,8 +15,8 @@ import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.GlobalScope
|
import kotlinx.coroutines.GlobalScope
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.kenjinx.android.KenjinxNative
|
import org.kenjinx.android.KenjinxNative
|
||||||
import org.kenjinx.android.KeyboardMode
|
|
||||||
import org.kenjinx.android.MainActivity
|
import org.kenjinx.android.MainActivity
|
||||||
|
import java.io.File
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
import kotlin.concurrent.thread
|
import kotlin.concurrent.thread
|
||||||
|
|
||||||
|
|
@ -125,7 +125,7 @@ class HomeViewModel(
|
||||||
|
|
||||||
// Helper function to compare update versions from filenames
|
// Helper function to compare update versions from filenames
|
||||||
// Returns true if newPath represents a newer version than currentPath
|
// Returns true if newPath represents a newer version than currentPath
|
||||||
private fun shouldSelectNewerUpdate(currentPath: String, newPath: String, allPaths: List<String>): Boolean {
|
private fun shouldSelectNewerUpdate(currentPath: String, newPath: String): Boolean {
|
||||||
// Extract version numbers from filenames using regex pattern [vXXXXXX]
|
// Extract version numbers from filenames using regex pattern [vXXXXXX]
|
||||||
val versionPattern = Regex("\\[v(\\d+)]")
|
val versionPattern = Regex("\\[v(\\d+)]")
|
||||||
|
|
||||||
|
|
@ -135,21 +135,13 @@ class HomeViewModel(
|
||||||
return newVersion > currentVersion
|
return newVersion > currentVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scans configured directories for NSPs containing DLCs/Updates and associates them to known titles.
|
// Scans configured directory for NSPs containing DLCs/Updates and associates them to known titles.
|
||||||
private fun autoloadContent() {
|
private fun autoloadContent() {
|
||||||
val prefs = sharedPref ?: return
|
val prefs = sharedPref ?: return
|
||||||
|
|
||||||
// Prefer a single, explicitly selected updates/DLC folder (updatesFolder). Fallback to legacy autoloadDirs.
|
|
||||||
val updatesFolder = prefs.getString("updatesFolder", "") ?: ""
|
val updatesFolder = prefs.getString("updatesFolder", "") ?: ""
|
||||||
val dirs: List<String> = if (updatesFolder.isNotBlank()) {
|
|
||||||
listOf(updatesFolder.trim())
|
|
||||||
} else {
|
|
||||||
// Legacy: semicolon-separated list under key autoloadDirs
|
|
||||||
val raw = prefs.getString("autoloadDirs", "") ?: ""
|
|
||||||
if (raw.isBlank()) emptyList() else raw.split(';').map { it.trim() }.filter { it.isNotEmpty() }
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dirs.isEmpty()) return
|
if (updatesFolder.isEmpty()) return
|
||||||
|
|
||||||
// Build a map of titleId -> helpers
|
// Build a map of titleId -> helpers
|
||||||
val gamesByTitle = loadedCache.mapNotNull { g ->
|
val gamesByTitle = loadedCache.mapNotNull { g ->
|
||||||
|
|
@ -160,9 +152,8 @@ class HomeViewModel(
|
||||||
var updatesAdded = 0
|
var updatesAdded = 0
|
||||||
var dlcAdded = 0
|
var dlcAdded = 0
|
||||||
|
|
||||||
for (dir in dirs) {
|
val base = File(updatesFolder)
|
||||||
val base = java.io.File(dir)
|
if (!base.exists() || !base.isDirectory) return
|
||||||
if (!base.exists() || !base.isDirectory) continue
|
|
||||||
|
|
||||||
base.walkTopDown().forEach fileLoop@{ f ->
|
base.walkTopDown().forEach fileLoop@{ f ->
|
||||||
if (!f.isFile) return@fileLoop
|
if (!f.isFile) return@fileLoop
|
||||||
|
|
@ -230,7 +221,7 @@ class HomeViewModel(
|
||||||
// or if no update is currently selected
|
// or if no update is currently selected
|
||||||
val currentSelected = vm.data?.selected ?: ""
|
val currentSelected = vm.data?.selected ?: ""
|
||||||
val shouldSelect = currentSelected.isEmpty() ||
|
val shouldSelect = currentSelected.isEmpty() ||
|
||||||
shouldSelectNewerUpdate(currentSelected, path, vm.data?.paths ?: mutableListOf())
|
shouldSelectNewerUpdate(currentSelected, path)
|
||||||
|
|
||||||
if (shouldSelect) {
|
if (shouldSelect) {
|
||||||
vm.data?.selected = path
|
vm.data?.selected = path
|
||||||
|
|
@ -243,4 +234,3 @@ class HomeViewModel(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue