mirror of
https://github.com/skyline-emu/skyline.git
synced 2024-11-04 23:35:12 +01:00
Automatically import key files from search location
This commit is contained in:
parent
6cf2ef8fb9
commit
882b939335
@ -19,6 +19,20 @@ object KeyReader {
|
||||
|
||||
companion object {
|
||||
fun parse(keyName : String) = values().first { it.keyName == keyName }
|
||||
fun parse(documentFile : DocumentFile) = values().first { it.fileName == documentFile.name }
|
||||
fun parseOrNull(documentFile : DocumentFile) = values().find { it.fileName == documentFile.name }
|
||||
}
|
||||
}
|
||||
|
||||
fun importFromLocation(context : Context, searchLocation : Uri) = importFromDirectory(context, DocumentFile.fromTreeUri(context, searchLocation)!!)
|
||||
|
||||
private fun importFromDirectory(context : Context, directory : DocumentFile) {
|
||||
directory.listFiles().forEach { file ->
|
||||
if (file.isDirectory) {
|
||||
importFromDirectory(context, file)
|
||||
} else {
|
||||
KeyType.parseOrNull(file)?.let { import(context, file.uri, it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -292,7 +292,7 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
private fun loadRoms(loadFromFile : Boolean) {
|
||||
viewModel.loadRoms(loadFromFile, Uri.parse(settings.searchLocation), settings.systemLanguage)
|
||||
viewModel.loadRoms(this, loadFromFile, Uri.parse(settings.searchLocation), settings.systemLanguage)
|
||||
settings.refreshRequired = false
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ class MainViewModel @Inject constructor(@ApplicationContext context : Context, p
|
||||
*
|
||||
* @param loadFromFile If this is false then trying to load cached adapter data is skipped entirely
|
||||
*/
|
||||
fun loadRoms(loadFromFile : Boolean, searchLocation : Uri, systemLanguage : Int) {
|
||||
fun loadRoms(context : Context, loadFromFile : Boolean, searchLocation : Uri, systemLanguage : Int) {
|
||||
if (state == MainState.Loading) return
|
||||
state = MainState.Loading
|
||||
|
||||
@ -62,6 +62,7 @@ class MainViewModel @Inject constructor(@ApplicationContext context : Context, p
|
||||
MainState.Loaded(HashMap())
|
||||
} else {
|
||||
try {
|
||||
KeyReader.importFromLocation(context, searchLocation)
|
||||
val romElements = romProvider.loadRoms(searchLocation, systemLanguage)
|
||||
romElements.toFile(romsFile)
|
||||
MainState.Loaded(romElements)
|
||||
|
Loading…
Reference in New Issue
Block a user