mirror of
https://git.h3cjp.net/H3cJP/yuzu.git
synced 2024-11-15 22:22:49 +00:00
android: Rework config lifecycle
Exposes options for initializing, unloading, reloading, and saving settings that let us update the config much more granularly based on what's happening in the UI.
This commit is contained in:
parent
e744c06f61
commit
e637ec0c38
|
@ -230,8 +230,6 @@ object NativeLibrary {
|
|||
*/
|
||||
external fun onTouchReleased(finger_id: Int)
|
||||
|
||||
external fun reloadSettings()
|
||||
|
||||
external fun initGameIni(gameID: String?)
|
||||
|
||||
external fun setAppDirectory(directory: String)
|
||||
|
|
|
@ -7,7 +7,7 @@ import android.text.TextUtils
|
|||
import android.widget.Toast
|
||||
import org.yuzu.yuzu_emu.R
|
||||
import org.yuzu.yuzu_emu.YuzuApplication
|
||||
import org.yuzu.yuzu_emu.features.settings.utils.SettingsFile
|
||||
import org.yuzu.yuzu_emu.utils.NativeConfig
|
||||
|
||||
object Settings {
|
||||
private val context get() = YuzuApplication.appContext
|
||||
|
@ -19,7 +19,7 @@ object Settings {
|
|||
context.getString(R.string.ini_saved),
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
SettingsFile.saveFile(SettingsFile.FILE_NAME_CONFIG)
|
||||
NativeConfig.saveSettings()
|
||||
} else {
|
||||
// TODO: Save custom game settings
|
||||
Toast.makeText(
|
||||
|
|
|
@ -21,7 +21,6 @@ import androidx.navigation.navArgs
|
|||
import com.google.android.material.color.MaterialColors
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import kotlinx.coroutines.launch
|
||||
import org.yuzu.yuzu_emu.NativeLibrary
|
||||
import java.io.IOException
|
||||
import org.yuzu.yuzu_emu.R
|
||||
import org.yuzu.yuzu_emu.databinding.ActivitySettingsBinding
|
||||
|
@ -165,11 +164,12 @@ class SettingsActivity : AppCompatActivity() {
|
|||
settingsViewModel.shouldSave = false
|
||||
|
||||
// Delete settings file because the user may have changed values that do not exist in the UI
|
||||
NativeConfig.unloadConfig()
|
||||
val settingsFile = SettingsFile.getSettingsFile(SettingsFile.FILE_NAME_CONFIG)
|
||||
if (!settingsFile.delete()) {
|
||||
throw IOException("Failed to delete $settingsFile")
|
||||
}
|
||||
NativeLibrary.reloadSettings()
|
||||
NativeConfig.initializeConfig()
|
||||
|
||||
Toast.makeText(
|
||||
applicationContext,
|
||||
|
|
|
@ -625,6 +625,7 @@ class MainActivity : AppCompatActivity(), ThemeProvider {
|
|||
}
|
||||
|
||||
// Clear existing user data
|
||||
NativeConfig.unloadConfig()
|
||||
File(DirectoryInitialization.userDirectory!!).deleteRecursively()
|
||||
|
||||
// Copy archive to internal storage
|
||||
|
@ -643,6 +644,7 @@ class MainActivity : AppCompatActivity(), ThemeProvider {
|
|||
|
||||
// Reinitialize relevant data
|
||||
NativeLibrary.initializeSystem(true)
|
||||
NativeConfig.initializeConfig()
|
||||
gamesViewModel.reloadGames(false)
|
||||
|
||||
return@newInstance getString(R.string.user_data_import_success)
|
||||
|
|
|
@ -16,6 +16,7 @@ object DirectoryInitialization {
|
|||
if (!areDirectoriesReady) {
|
||||
initializeInternalStorage()
|
||||
NativeLibrary.initializeSystem(false)
|
||||
NativeConfig.initializeConfig()
|
||||
areDirectoriesReady = true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,30 @@
|
|||
package org.yuzu.yuzu_emu.utils
|
||||
|
||||
object NativeConfig {
|
||||
/**
|
||||
* Creates a Config object and opens the emulation config.
|
||||
*/
|
||||
@Synchronized
|
||||
external fun initializeConfig()
|
||||
|
||||
/**
|
||||
* Destroys the stored config object. This automatically saves the existing config.
|
||||
*/
|
||||
@Synchronized
|
||||
external fun unloadConfig()
|
||||
|
||||
/**
|
||||
* Reads values saved to the config file and saves them.
|
||||
*/
|
||||
@Synchronized
|
||||
external fun reloadSettings()
|
||||
|
||||
/**
|
||||
* Saves settings values in memory to disk.
|
||||
*/
|
||||
@Synchronized
|
||||
external fun saveSettings()
|
||||
|
||||
external fun getBoolean(key: String, getDefault: Boolean): Boolean
|
||||
external fun setBoolean(key: String, value: Boolean)
|
||||
|
||||
|
|
Loading…
Reference in a new issue