mirror of
https://github.com/skyline-emu/skyline.git
synced 2024-06-01 08:38:46 +02:00
Add automatic refreshing games list
This commit is contained in:
parent
d00fcee79d
commit
6076050bb3
|
@ -351,5 +351,7 @@ class MainActivity : AppCompatActivity() {
|
|||
setAppListDecoration()
|
||||
adapter.notifyItemRangeChanged(0, adapter.currentItems.size)
|
||||
}
|
||||
|
||||
viewModel.checkRomHash(this, Uri.parse(appSettings.searchLocation), EmulationSettings.global.systemLanguage)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,12 +11,12 @@ import emu.skyline.loader.AppEntry
|
|||
import emu.skyline.loader.RomFormat
|
||||
import emu.skyline.utils.fromFile
|
||||
import emu.skyline.utils.toFile
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
import kotlin.collections.HashMap
|
||||
|
||||
sealed class MainState {
|
||||
object Loading : MainState()
|
||||
|
@ -73,4 +73,20 @@ class MainViewModel @Inject constructor(@ApplicationContext context : Context, p
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This checks if the roms have changed since the last time they were loaded and if so it reloads them
|
||||
*/
|
||||
fun checkRomHash(context : Context, searchLocation : Uri, systemLanguage : Int) {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
val oldHashFile = File(getApplication<SkylineApplication>().filesDir.canonicalPath + "/roms.txt")
|
||||
val oldHash = if (oldHashFile.exists()) oldHashFile.readText().toIntOrNull() else null
|
||||
val romElements = romProvider.loadRoms(searchLocation, systemLanguage).values.flatten().toList()
|
||||
val newHash = romElements.map { it.name }.toSet().hashCode()
|
||||
if (newHash != oldHash) {
|
||||
loadRoms(context, false, searchLocation, systemLanguage)
|
||||
oldHashFile.writeText(newHash.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user