|
@@ -10,39 +10,26 @@ import android.view.LayoutInflater
|
|
|
import android.view.View
|
|
import android.view.View
|
|
|
import android.view.ViewGroup
|
|
import android.view.ViewGroup
|
|
|
import android.widget.Toast
|
|
import android.widget.Toast
|
|
|
-import androidx.activity.result.contract.ActivityResultContracts
|
|
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
|
import androidx.appcompat.app.AppCompatActivity
|
|
|
import androidx.core.view.ViewCompat
|
|
import androidx.core.view.ViewCompat
|
|
|
import androidx.core.view.WindowInsetsCompat
|
|
import androidx.core.view.WindowInsetsCompat
|
|
|
import androidx.fragment.app.Fragment
|
|
import androidx.fragment.app.Fragment
|
|
|
-import androidx.fragment.app.activityViewModels
|
|
|
|
|
-import androidx.lifecycle.lifecycleScope
|
|
|
|
|
-import androidx.preference.PreferenceManager
|
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
|
|
-import kotlinx.coroutines.Dispatchers
|
|
|
|
|
-import kotlinx.coroutines.launch
|
|
|
|
|
-import kotlinx.coroutines.withContext
|
|
|
|
|
-import org.yuzu.yuzu_emu.NativeLibrary
|
|
|
|
|
import org.yuzu.yuzu_emu.R
|
|
import org.yuzu.yuzu_emu.R
|
|
|
import org.yuzu.yuzu_emu.adapters.HomeOptionAdapter
|
|
import org.yuzu.yuzu_emu.adapters.HomeOptionAdapter
|
|
|
-import org.yuzu.yuzu_emu.databinding.DialogProgressBarBinding
|
|
|
|
|
import org.yuzu.yuzu_emu.databinding.FragmentOptionsBinding
|
|
import org.yuzu.yuzu_emu.databinding.FragmentOptionsBinding
|
|
|
import org.yuzu.yuzu_emu.features.settings.ui.SettingsActivity
|
|
import org.yuzu.yuzu_emu.features.settings.ui.SettingsActivity
|
|
|
import org.yuzu.yuzu_emu.features.settings.utils.SettingsFile
|
|
import org.yuzu.yuzu_emu.features.settings.utils.SettingsFile
|
|
|
-import org.yuzu.yuzu_emu.model.GamesViewModel
|
|
|
|
|
import org.yuzu.yuzu_emu.model.HomeOption
|
|
import org.yuzu.yuzu_emu.model.HomeOption
|
|
|
-import org.yuzu.yuzu_emu.utils.DirectoryInitialization
|
|
|
|
|
-import org.yuzu.yuzu_emu.utils.FileUtil
|
|
|
|
|
-import org.yuzu.yuzu_emu.utils.GameHelper
|
|
|
|
|
|
|
+import org.yuzu.yuzu_emu.ui.main.MainActivity
|
|
|
import org.yuzu.yuzu_emu.utils.GpuDriverHelper
|
|
import org.yuzu.yuzu_emu.utils.GpuDriverHelper
|
|
|
-import java.io.IOException
|
|
|
|
|
|
|
|
|
|
class OptionsFragment : Fragment() {
|
|
class OptionsFragment : Fragment() {
|
|
|
private var _binding: FragmentOptionsBinding? = null
|
|
private var _binding: FragmentOptionsBinding? = null
|
|
|
private val binding get() = _binding!!
|
|
private val binding get() = _binding!!
|
|
|
|
|
|
|
|
- private val gamesViewModel: GamesViewModel by activityViewModels()
|
|
|
|
|
|
|
+ private lateinit var mainActivity: MainActivity
|
|
|
|
|
|
|
|
override fun onCreateView(
|
|
override fun onCreateView(
|
|
|
inflater: LayoutInflater,
|
|
inflater: LayoutInflater,
|
|
@@ -54,22 +41,24 @@ class OptionsFragment : Fragment() {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
|
|
|
+ mainActivity = requireActivity() as MainActivity
|
|
|
|
|
+
|
|
|
val optionsList: List<HomeOption> = listOf(
|
|
val optionsList: List<HomeOption> = listOf(
|
|
|
HomeOption(
|
|
HomeOption(
|
|
|
R.string.add_games,
|
|
R.string.add_games,
|
|
|
R.string.add_games_description,
|
|
R.string.add_games_description,
|
|
|
R.drawable.ic_add
|
|
R.drawable.ic_add
|
|
|
- ) { getGamesDirectory.launch(Intent(Intent.ACTION_OPEN_DOCUMENT_TREE).data) },
|
|
|
|
|
|
|
+ ) { mainActivity.getGamesDirectory.launch(Intent(Intent.ACTION_OPEN_DOCUMENT_TREE).data) },
|
|
|
HomeOption(
|
|
HomeOption(
|
|
|
R.string.install_prod_keys,
|
|
R.string.install_prod_keys,
|
|
|
R.string.install_prod_keys_description,
|
|
R.string.install_prod_keys_description,
|
|
|
R.drawable.ic_unlock
|
|
R.drawable.ic_unlock
|
|
|
- ) { getProdKey.launch(arrayOf("*/*")) },
|
|
|
|
|
|
|
+ ) { mainActivity.getProdKey.launch(arrayOf("*/*")) },
|
|
|
HomeOption(
|
|
HomeOption(
|
|
|
R.string.install_amiibo_keys,
|
|
R.string.install_amiibo_keys,
|
|
|
R.string.install_amiibo_keys_description,
|
|
R.string.install_amiibo_keys_description,
|
|
|
R.drawable.ic_nfc
|
|
R.drawable.ic_nfc
|
|
|
- ) { getAmiiboKey.launch(arrayOf("*/*")) },
|
|
|
|
|
|
|
+ ) { mainActivity.getAmiiboKey.launch(arrayOf("*/*")) },
|
|
|
HomeOption(
|
|
HomeOption(
|
|
|
R.string.install_gpu_driver,
|
|
R.string.install_gpu_driver,
|
|
|
R.string.install_gpu_driver_description,
|
|
R.string.install_gpu_driver_description,
|
|
@@ -115,7 +104,7 @@ class OptionsFragment : Fragment() {
|
|
|
).show()
|
|
).show()
|
|
|
}
|
|
}
|
|
|
.setNeutralButton(R.string.select_gpu_driver_install) { _: DialogInterface?, _: Int ->
|
|
.setNeutralButton(R.string.select_gpu_driver_install) { _: DialogInterface?, _: Int ->
|
|
|
- getDriver.launch(arrayOf("application/zip"))
|
|
|
|
|
|
|
+ mainActivity.getDriver.launch(arrayOf("application/zip"))
|
|
|
}
|
|
}
|
|
|
.show()
|
|
.show()
|
|
|
}
|
|
}
|
|
@@ -131,144 +120,4 @@ class OptionsFragment : Fragment() {
|
|
|
)
|
|
)
|
|
|
windowInsets
|
|
windowInsets
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- private val getGamesDirectory =
|
|
|
|
|
- registerForActivityResult(ActivityResultContracts.OpenDocumentTree()) { result ->
|
|
|
|
|
- if (result == null)
|
|
|
|
|
- return@registerForActivityResult
|
|
|
|
|
-
|
|
|
|
|
- val takeFlags =
|
|
|
|
|
- Intent.FLAG_GRANT_WRITE_URI_PERMISSION or Intent.FLAG_GRANT_READ_URI_PERMISSION
|
|
|
|
|
- requireActivity().contentResolver.takePersistableUriPermission(
|
|
|
|
|
- result,
|
|
|
|
|
- takeFlags
|
|
|
|
|
- )
|
|
|
|
|
-
|
|
|
|
|
- // When a new directory is picked, we currently will reset the existing games
|
|
|
|
|
- // database. This effectively means that only one game directory is supported.
|
|
|
|
|
- PreferenceManager.getDefaultSharedPreferences(requireContext()).edit()
|
|
|
|
|
- .putString(GameHelper.KEY_GAME_PATH, result.toString())
|
|
|
|
|
- .apply()
|
|
|
|
|
-
|
|
|
|
|
- gamesViewModel.reloadGames(true)
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private val getProdKey =
|
|
|
|
|
- registerForActivityResult(ActivityResultContracts.OpenDocument()) { result ->
|
|
|
|
|
- if (result == null)
|
|
|
|
|
- return@registerForActivityResult
|
|
|
|
|
-
|
|
|
|
|
- val takeFlags =
|
|
|
|
|
- Intent.FLAG_GRANT_WRITE_URI_PERMISSION or Intent.FLAG_GRANT_READ_URI_PERMISSION
|
|
|
|
|
- requireActivity().contentResolver.takePersistableUriPermission(
|
|
|
|
|
- result,
|
|
|
|
|
- takeFlags
|
|
|
|
|
- )
|
|
|
|
|
-
|
|
|
|
|
- val dstPath = DirectoryInitialization.userDirectory + "/keys/"
|
|
|
|
|
- if (FileUtil.copyUriToInternalStorage(requireContext(), result, dstPath, "prod.keys")) {
|
|
|
|
|
- if (NativeLibrary.reloadKeys()) {
|
|
|
|
|
- Toast.makeText(
|
|
|
|
|
- requireContext(),
|
|
|
|
|
- R.string.install_keys_success,
|
|
|
|
|
- Toast.LENGTH_SHORT
|
|
|
|
|
- ).show()
|
|
|
|
|
- gamesViewModel.reloadGames(true)
|
|
|
|
|
- } else {
|
|
|
|
|
- Toast.makeText(
|
|
|
|
|
- requireContext(),
|
|
|
|
|
- R.string.install_keys_failure,
|
|
|
|
|
- Toast.LENGTH_LONG
|
|
|
|
|
- ).show()
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private val getAmiiboKey =
|
|
|
|
|
- registerForActivityResult(ActivityResultContracts.OpenDocument()) { result ->
|
|
|
|
|
- if (result == null)
|
|
|
|
|
- return@registerForActivityResult
|
|
|
|
|
-
|
|
|
|
|
- val takeFlags =
|
|
|
|
|
- Intent.FLAG_GRANT_WRITE_URI_PERMISSION or Intent.FLAG_GRANT_READ_URI_PERMISSION
|
|
|
|
|
- requireActivity().contentResolver.takePersistableUriPermission(
|
|
|
|
|
- result,
|
|
|
|
|
- takeFlags
|
|
|
|
|
- )
|
|
|
|
|
-
|
|
|
|
|
- val dstPath = DirectoryInitialization.userDirectory + "/keys/"
|
|
|
|
|
- if (FileUtil.copyUriToInternalStorage(
|
|
|
|
|
- requireContext(),
|
|
|
|
|
- result,
|
|
|
|
|
- dstPath,
|
|
|
|
|
- "key_retail.bin"
|
|
|
|
|
- )
|
|
|
|
|
- ) {
|
|
|
|
|
- if (NativeLibrary.reloadKeys()) {
|
|
|
|
|
- Toast.makeText(
|
|
|
|
|
- requireContext(),
|
|
|
|
|
- R.string.install_keys_success,
|
|
|
|
|
- Toast.LENGTH_SHORT
|
|
|
|
|
- ).show()
|
|
|
|
|
- } else {
|
|
|
|
|
- Toast.makeText(
|
|
|
|
|
- requireContext(),
|
|
|
|
|
- R.string.install_amiibo_keys_failure,
|
|
|
|
|
- Toast.LENGTH_LONG
|
|
|
|
|
- ).show()
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private val getDriver =
|
|
|
|
|
- registerForActivityResult(ActivityResultContracts.OpenDocument()) { result ->
|
|
|
|
|
- if (result == null)
|
|
|
|
|
- return@registerForActivityResult
|
|
|
|
|
-
|
|
|
|
|
- val takeFlags =
|
|
|
|
|
- Intent.FLAG_GRANT_WRITE_URI_PERMISSION or Intent.FLAG_GRANT_READ_URI_PERMISSION
|
|
|
|
|
- requireActivity().contentResolver.takePersistableUriPermission(
|
|
|
|
|
- result,
|
|
|
|
|
- takeFlags
|
|
|
|
|
- )
|
|
|
|
|
-
|
|
|
|
|
- val progressBinding = DialogProgressBarBinding.inflate(layoutInflater)
|
|
|
|
|
- progressBinding.progressBar.isIndeterminate = true
|
|
|
|
|
- val installationDialog = MaterialAlertDialogBuilder(requireContext())
|
|
|
|
|
- .setTitle(R.string.installing_driver)
|
|
|
|
|
- .setView(progressBinding.root)
|
|
|
|
|
- .show()
|
|
|
|
|
-
|
|
|
|
|
- lifecycleScope.launch {
|
|
|
|
|
- withContext(Dispatchers.IO) {
|
|
|
|
|
- // Ignore file exceptions when a user selects an invalid zip
|
|
|
|
|
- try {
|
|
|
|
|
- GpuDriverHelper.installCustomDriver(requireContext(), result)
|
|
|
|
|
- } catch (_: IOException) {
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- withContext(Dispatchers.Main) {
|
|
|
|
|
- installationDialog.dismiss()
|
|
|
|
|
-
|
|
|
|
|
- val driverName = GpuDriverHelper.customDriverName
|
|
|
|
|
- if (driverName != null) {
|
|
|
|
|
- Toast.makeText(
|
|
|
|
|
- requireContext(),
|
|
|
|
|
- getString(
|
|
|
|
|
- R.string.select_gpu_driver_install_success,
|
|
|
|
|
- driverName
|
|
|
|
|
- ),
|
|
|
|
|
- Toast.LENGTH_SHORT
|
|
|
|
|
- ).show()
|
|
|
|
|
- } else {
|
|
|
|
|
- Toast.makeText(
|
|
|
|
|
- requireContext(),
|
|
|
|
|
- R.string.select_gpu_driver_error,
|
|
|
|
|
- Toast.LENGTH_LONG
|
|
|
|
|
- ).show()
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|