Compare commits
9 Commits
leviathan
...
clean-shor
Author | SHA1 | Date | |
---|---|---|---|
|
7114b9669a | ||
|
56e5d99684 | ||
|
1a4874e178 | ||
|
c00b63b9e1 | ||
|
c8602e1b1f | ||
|
faa6c35e78 | ||
|
a5fb9de6fa | ||
|
c4ec76edba | ||
|
26f9d1f122 |
@@ -15,13 +15,9 @@ import androidx.annotation.Keep
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import java.lang.ref.WeakReference
|
||||
import org.yuzu.yuzu_emu.YuzuApplication.Companion.appContext
|
||||
import org.yuzu.yuzu_emu.activities.EmulationActivity
|
||||
import org.yuzu.yuzu_emu.utils.DocumentsTree.Companion.isNativePath
|
||||
import org.yuzu.yuzu_emu.utils.FileUtil.exists
|
||||
import org.yuzu.yuzu_emu.utils.FileUtil.getFileSize
|
||||
import org.yuzu.yuzu_emu.utils.FileUtil.isDirectory
|
||||
import org.yuzu.yuzu_emu.utils.FileUtil.openContentUri
|
||||
import org.yuzu.yuzu_emu.utils.FileUtil
|
||||
import org.yuzu.yuzu_emu.utils.Log
|
||||
import org.yuzu.yuzu_emu.utils.SerializableHelper.serializable
|
||||
|
||||
@@ -75,7 +71,7 @@ object NativeLibrary {
|
||||
return if (isNativePath(path!!)) {
|
||||
YuzuApplication.documentsTree!!.openContentUri(path, openmode)
|
||||
} else {
|
||||
openContentUri(appContext, path, openmode)
|
||||
FileUtil.openContentUri(path, openmode)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,7 +81,7 @@ object NativeLibrary {
|
||||
return if (isNativePath(path!!)) {
|
||||
YuzuApplication.documentsTree!!.getFileSize(path)
|
||||
} else {
|
||||
getFileSize(appContext, path)
|
||||
FileUtil.getFileSize(path)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,7 +91,7 @@ object NativeLibrary {
|
||||
return if (isNativePath(path!!)) {
|
||||
YuzuApplication.documentsTree!!.exists(path)
|
||||
} else {
|
||||
exists(appContext, path)
|
||||
FileUtil.exists(path)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,7 +101,7 @@ object NativeLibrary {
|
||||
return if (isNativePath(path!!)) {
|
||||
YuzuApplication.documentsTree!!.isDirectory(path)
|
||||
} else {
|
||||
isDirectory(appContext, path)
|
||||
FileUtil.isDirectory(path)
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -47,7 +47,7 @@ class YuzuApplication : Application() {
|
||||
application = this
|
||||
documentsTree = DocumentsTree()
|
||||
DirectoryInitialization.start()
|
||||
GpuDriverHelper.initializeDriverParameters(applicationContext)
|
||||
GpuDriverHelper.initializeDriverParameters()
|
||||
NativeLibrary.logDeviceInfo()
|
||||
|
||||
createNotificationChannels()
|
||||
|
@@ -0,0 +1,117 @@
|
||||
// SPDX-FileCopyrightText: 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
package org.yuzu.yuzu_emu.adapters
|
||||
|
||||
import android.text.TextUtils
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.AsyncDifferConfig
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.ListAdapter
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import org.yuzu.yuzu_emu.R
|
||||
import org.yuzu.yuzu_emu.databinding.CardDriverOptionBinding
|
||||
import org.yuzu.yuzu_emu.model.DriverViewModel
|
||||
import org.yuzu.yuzu_emu.utils.GpuDriverHelper
|
||||
import org.yuzu.yuzu_emu.utils.GpuDriverMetadata
|
||||
|
||||
class DriverAdapter(private val driverViewModel: DriverViewModel) :
|
||||
ListAdapter<Pair<String, GpuDriverMetadata>, DriverAdapter.DriverViewHolder>(
|
||||
AsyncDifferConfig.Builder(DiffCallback()).build()
|
||||
) {
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): DriverViewHolder {
|
||||
val binding =
|
||||
CardDriverOptionBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||
return DriverViewHolder(binding)
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = currentList.size
|
||||
|
||||
override fun onBindViewHolder(holder: DriverViewHolder, position: Int) =
|
||||
holder.bind(currentList[position])
|
||||
|
||||
private fun onSelectDriver(position: Int) {
|
||||
driverViewModel.setSelectedDriverIndex(position)
|
||||
notifyItemChanged(driverViewModel.previouslySelectedDriver)
|
||||
notifyItemChanged(driverViewModel.selectedDriver)
|
||||
}
|
||||
|
||||
private fun onDeleteDriver(driverData: Pair<String, GpuDriverMetadata>, position: Int) {
|
||||
if (driverViewModel.selectedDriver > position) {
|
||||
driverViewModel.setSelectedDriverIndex(driverViewModel.selectedDriver - 1)
|
||||
}
|
||||
if (GpuDriverHelper.customDriverData == driverData.second) {
|
||||
driverViewModel.setSelectedDriverIndex(0)
|
||||
}
|
||||
driverViewModel.driversToDelete.add(driverData.first)
|
||||
driverViewModel.removeDriver(driverData)
|
||||
notifyItemRemoved(position)
|
||||
notifyItemChanged(driverViewModel.selectedDriver)
|
||||
}
|
||||
|
||||
inner class DriverViewHolder(val binding: CardDriverOptionBinding) :
|
||||
RecyclerView.ViewHolder(binding.root) {
|
||||
private lateinit var driverData: Pair<String, GpuDriverMetadata>
|
||||
|
||||
fun bind(driverData: Pair<String, GpuDriverMetadata>) {
|
||||
this.driverData = driverData
|
||||
val driver = driverData.second
|
||||
|
||||
binding.apply {
|
||||
radioButton.isChecked = driverViewModel.selectedDriver == bindingAdapterPosition
|
||||
root.setOnClickListener {
|
||||
onSelectDriver(bindingAdapterPosition)
|
||||
}
|
||||
buttonDelete.setOnClickListener {
|
||||
onDeleteDriver(driverData, bindingAdapterPosition)
|
||||
}
|
||||
|
||||
// Delay marquee by 3s
|
||||
title.postDelayed(
|
||||
{
|
||||
title.isSelected = true
|
||||
title.ellipsize = TextUtils.TruncateAt.MARQUEE
|
||||
version.isSelected = true
|
||||
version.ellipsize = TextUtils.TruncateAt.MARQUEE
|
||||
description.isSelected = true
|
||||
description.ellipsize = TextUtils.TruncateAt.MARQUEE
|
||||
},
|
||||
3000
|
||||
)
|
||||
if (driver.name == null) {
|
||||
title.setText(R.string.system_gpu_driver)
|
||||
description.text = ""
|
||||
version.text = ""
|
||||
version.visibility = View.GONE
|
||||
description.visibility = View.GONE
|
||||
buttonDelete.visibility = View.GONE
|
||||
} else {
|
||||
title.text = driver.name
|
||||
version.text = driver.version
|
||||
description.text = driver.description
|
||||
version.visibility = View.VISIBLE
|
||||
description.visibility = View.VISIBLE
|
||||
buttonDelete.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class DiffCallback : DiffUtil.ItemCallback<Pair<String, GpuDriverMetadata>>() {
|
||||
override fun areItemsTheSame(
|
||||
oldItem: Pair<String, GpuDriverMetadata>,
|
||||
newItem: Pair<String, GpuDriverMetadata>
|
||||
): Boolean {
|
||||
return oldItem.first == newItem.first
|
||||
}
|
||||
|
||||
override fun areContentsTheSame(
|
||||
oldItem: Pair<String, GpuDriverMetadata>,
|
||||
newItem: Pair<String, GpuDriverMetadata>
|
||||
): Boolean {
|
||||
return oldItem.second == newItem.second
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,185 @@
|
||||
// SPDX-FileCopyrightText: 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
package org.yuzu.yuzu_emu.fragments
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.core.view.updatePadding
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.navigation.findNavController
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import com.google.android.material.transition.MaterialSharedAxis
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import kotlinx.coroutines.launch
|
||||
import org.yuzu.yuzu_emu.R
|
||||
import org.yuzu.yuzu_emu.adapters.DriverAdapter
|
||||
import org.yuzu.yuzu_emu.databinding.FragmentDriverManagerBinding
|
||||
import org.yuzu.yuzu_emu.model.DriverViewModel
|
||||
import org.yuzu.yuzu_emu.model.HomeViewModel
|
||||
import org.yuzu.yuzu_emu.utils.FileUtil
|
||||
import org.yuzu.yuzu_emu.utils.GpuDriverHelper
|
||||
import java.io.IOException
|
||||
|
||||
class DriverManagerFragment : Fragment() {
|
||||
private var _binding: FragmentDriverManagerBinding? = null
|
||||
private val binding get() = _binding!!
|
||||
|
||||
private val homeViewModel: HomeViewModel by activityViewModels()
|
||||
private val driverViewModel: DriverViewModel by activityViewModels()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
enterTransition = MaterialSharedAxis(MaterialSharedAxis.X, true)
|
||||
returnTransition = MaterialSharedAxis(MaterialSharedAxis.X, false)
|
||||
reenterTransition = MaterialSharedAxis(MaterialSharedAxis.X, false)
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
_binding = FragmentDriverManagerBinding.inflate(inflater)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
homeViewModel.setNavigationVisibility(visible = false, animated = true)
|
||||
homeViewModel.setStatusBarShadeVisibility(visible = false)
|
||||
|
||||
if (!driverViewModel.isInteractionAllowed) {
|
||||
DriversLoadingDialogFragment().show(
|
||||
childFragmentManager,
|
||||
DriversLoadingDialogFragment.TAG
|
||||
)
|
||||
}
|
||||
|
||||
binding.toolbarDrivers.setNavigationOnClickListener {
|
||||
binding.root.findNavController().popBackStack()
|
||||
}
|
||||
|
||||
binding.buttonInstall.setOnClickListener {
|
||||
getDriver.launch(arrayOf("application/zip"))
|
||||
}
|
||||
|
||||
binding.listDrivers.apply {
|
||||
layoutManager = GridLayoutManager(
|
||||
requireContext(),
|
||||
resources.getInteger(R.integer.grid_columns)
|
||||
)
|
||||
adapter = DriverAdapter(driverViewModel)
|
||||
}
|
||||
|
||||
viewLifecycleOwner.lifecycleScope.apply {
|
||||
launch {
|
||||
driverViewModel.driverList.collectLatest {
|
||||
(binding.listDrivers.adapter as DriverAdapter).submitList(it)
|
||||
}
|
||||
}
|
||||
launch {
|
||||
driverViewModel.newDriverInstalled.collect {
|
||||
if (_binding != null && it) {
|
||||
(binding.listDrivers.adapter as DriverAdapter).apply {
|
||||
notifyItemChanged(driverViewModel.previouslySelectedDriver)
|
||||
notifyItemChanged(driverViewModel.selectedDriver)
|
||||
driverViewModel.setNewDriverInstalled(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setInsets()
|
||||
}
|
||||
|
||||
// Start installing requested driver
|
||||
override fun onStop() {
|
||||
super.onStop()
|
||||
driverViewModel.onCloseDriverManager()
|
||||
}
|
||||
|
||||
private fun setInsets() =
|
||||
ViewCompat.setOnApplyWindowInsetsListener(
|
||||
binding.root
|
||||
) { _: View, windowInsets: WindowInsetsCompat ->
|
||||
val barInsets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
|
||||
val cutoutInsets = windowInsets.getInsets(WindowInsetsCompat.Type.displayCutout())
|
||||
|
||||
val leftInsets = barInsets.left + cutoutInsets.left
|
||||
val rightInsets = barInsets.right + cutoutInsets.right
|
||||
|
||||
val mlpAppBar = binding.toolbarDrivers.layoutParams as ViewGroup.MarginLayoutParams
|
||||
mlpAppBar.leftMargin = leftInsets
|
||||
mlpAppBar.rightMargin = rightInsets
|
||||
binding.toolbarDrivers.layoutParams = mlpAppBar
|
||||
|
||||
val mlplistDrivers = binding.listDrivers.layoutParams as ViewGroup.MarginLayoutParams
|
||||
mlplistDrivers.leftMargin = leftInsets
|
||||
mlplistDrivers.rightMargin = rightInsets
|
||||
binding.listDrivers.layoutParams = mlplistDrivers
|
||||
|
||||
val fabSpacing = resources.getDimensionPixelSize(R.dimen.spacing_fab)
|
||||
val mlpFab =
|
||||
binding.buttonInstall.layoutParams as ViewGroup.MarginLayoutParams
|
||||
mlpFab.leftMargin = leftInsets + fabSpacing
|
||||
mlpFab.rightMargin = rightInsets + fabSpacing
|
||||
mlpFab.bottomMargin = barInsets.bottom + fabSpacing
|
||||
binding.buttonInstall.layoutParams = mlpFab
|
||||
|
||||
binding.listDrivers.updatePadding(
|
||||
bottom = barInsets.bottom +
|
||||
resources.getDimensionPixelSize(R.dimen.spacing_bottom_list_fab)
|
||||
)
|
||||
|
||||
windowInsets
|
||||
}
|
||||
|
||||
private val getDriver =
|
||||
registerForActivityResult(ActivityResultContracts.OpenDocument()) { result ->
|
||||
if (result == null) {
|
||||
return@registerForActivityResult
|
||||
}
|
||||
|
||||
IndeterminateProgressDialogFragment.newInstance(
|
||||
requireActivity(),
|
||||
R.string.installing_driver,
|
||||
false
|
||||
) {
|
||||
// Ignore file exceptions when a user selects an invalid zip
|
||||
try {
|
||||
GpuDriverHelper.copyDriverToInternalStorage(result)
|
||||
} catch (_: IOException) {
|
||||
return@newInstance getString(R.string.select_gpu_driver_error)
|
||||
}
|
||||
|
||||
val driverData = GpuDriverHelper.customDriverData
|
||||
if (driverData.name == null) {
|
||||
return@newInstance getString(R.string.select_gpu_driver_error)
|
||||
}
|
||||
|
||||
val driverInList =
|
||||
driverViewModel.driverList.value.firstOrNull { it.second == driverData }
|
||||
if (driverInList != null) {
|
||||
return@newInstance getString(R.string.driver_already_installed)
|
||||
} else {
|
||||
driverViewModel.addDriver(
|
||||
Pair(
|
||||
"${GpuDriverHelper.driverStoragePath}/${FileUtil.getFilename(result)}",
|
||||
driverData
|
||||
)
|
||||
)
|
||||
driverViewModel.setNewDriverInstalled(true)
|
||||
}
|
||||
return@newInstance Any()
|
||||
}.show(childFragmentManager, IndeterminateProgressDialogFragment.TAG)
|
||||
}
|
||||
}
|
@@ -0,0 +1,75 @@
|
||||
// SPDX-FileCopyrightText: 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
package org.yuzu.yuzu_emu.fragments
|
||||
|
||||
import android.app.Dialog
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.lifecycle.repeatOnLifecycle
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import kotlinx.coroutines.launch
|
||||
import org.yuzu.yuzu_emu.R
|
||||
import org.yuzu.yuzu_emu.databinding.DialogProgressBarBinding
|
||||
import org.yuzu.yuzu_emu.model.DriverViewModel
|
||||
|
||||
class DriversLoadingDialogFragment : DialogFragment() {
|
||||
private val driverViewModel: DriverViewModel by activityViewModels()
|
||||
|
||||
private lateinit var binding: DialogProgressBarBinding
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
binding = DialogProgressBarBinding.inflate(layoutInflater)
|
||||
binding.progressBar.isIndeterminate = true
|
||||
|
||||
isCancelable = false
|
||||
|
||||
return MaterialAlertDialogBuilder(requireContext())
|
||||
.setTitle(R.string.loading)
|
||||
.setView(binding.root)
|
||||
.create()
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View = binding.root
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
viewLifecycleOwner.lifecycleScope.apply {
|
||||
launch {
|
||||
repeatOnLifecycle(Lifecycle.State.RESUMED) {
|
||||
driverViewModel.areDriversLoading.collect { checkForDismiss() }
|
||||
}
|
||||
}
|
||||
launch {
|
||||
repeatOnLifecycle(Lifecycle.State.RESUMED) {
|
||||
driverViewModel.isDriverReady.collect { checkForDismiss() }
|
||||
}
|
||||
}
|
||||
launch {
|
||||
repeatOnLifecycle(Lifecycle.State.RESUMED) {
|
||||
driverViewModel.isDeletingDrivers.collect { checkForDismiss() }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkForDismiss() {
|
||||
if (driverViewModel.isInteractionAllowed) {
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val TAG = "DriversLoadingDialogFragment"
|
||||
}
|
||||
}
|
@@ -39,6 +39,7 @@ import androidx.window.layout.WindowLayoutInfo
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.google.android.material.slider.Slider
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.collect
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import kotlinx.coroutines.launch
|
||||
import org.yuzu.yuzu_emu.HomeNavigationDirections
|
||||
@@ -50,6 +51,7 @@ import org.yuzu.yuzu_emu.databinding.DialogOverlayAdjustBinding
|
||||
import org.yuzu.yuzu_emu.databinding.FragmentEmulationBinding
|
||||
import org.yuzu.yuzu_emu.features.settings.model.IntSetting
|
||||
import org.yuzu.yuzu_emu.features.settings.model.Settings
|
||||
import org.yuzu.yuzu_emu.model.DriverViewModel
|
||||
import org.yuzu.yuzu_emu.model.Game
|
||||
import org.yuzu.yuzu_emu.model.EmulationViewModel
|
||||
import org.yuzu.yuzu_emu.overlay.InputOverlay
|
||||
@@ -70,6 +72,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
||||
private lateinit var game: Game
|
||||
|
||||
private val emulationViewModel: EmulationViewModel by activityViewModels()
|
||||
private val driverViewModel: DriverViewModel by activityViewModels()
|
||||
|
||||
private var isInFoldableLayout = false
|
||||
|
||||
@@ -299,6 +302,21 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
||||
}
|
||||
}
|
||||
}
|
||||
launch {
|
||||
repeatOnLifecycle(Lifecycle.State.RESUMED) {
|
||||
driverViewModel.isDriverReady.collect {
|
||||
if (it && !emulationState.isRunning) {
|
||||
if (!DirectoryInitialization.areDirectoriesReady) {
|
||||
DirectoryInitialization.start()
|
||||
}
|
||||
|
||||
updateScreenLayout()
|
||||
|
||||
emulationState.run(emulationActivity!!.isActivityRecreated)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -332,17 +350,6 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
if (!DirectoryInitialization.areDirectoriesReady) {
|
||||
DirectoryInitialization.start()
|
||||
}
|
||||
|
||||
updateScreenLayout()
|
||||
|
||||
emulationState.run(emulationActivity!!.isActivityRecreated)
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
if (emulationState.isRunning && emulationActivity?.isInPictureInPictureMode != true) {
|
||||
emulationState.pause()
|
||||
|
@@ -5,7 +5,6 @@ package org.yuzu.yuzu_emu.fragments
|
||||
|
||||
import android.Manifest
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.DialogInterface
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Bundle
|
||||
@@ -28,7 +27,6 @@ import androidx.fragment.app.activityViewModels
|
||||
import androidx.navigation.findNavController
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.google.android.material.transition.MaterialSharedAxis
|
||||
import org.yuzu.yuzu_emu.BuildConfig
|
||||
import org.yuzu.yuzu_emu.HomeNavigationDirections
|
||||
@@ -37,6 +35,7 @@ import org.yuzu.yuzu_emu.adapters.HomeSettingAdapter
|
||||
import org.yuzu.yuzu_emu.databinding.FragmentHomeSettingsBinding
|
||||
import org.yuzu.yuzu_emu.features.DocumentProvider
|
||||
import org.yuzu.yuzu_emu.features.settings.model.Settings
|
||||
import org.yuzu.yuzu_emu.model.DriverViewModel
|
||||
import org.yuzu.yuzu_emu.model.HomeSetting
|
||||
import org.yuzu.yuzu_emu.model.HomeViewModel
|
||||
import org.yuzu.yuzu_emu.ui.main.MainActivity
|
||||
@@ -50,6 +49,7 @@ class HomeSettingsFragment : Fragment() {
|
||||
private lateinit var mainActivity: MainActivity
|
||||
|
||||
private val homeViewModel: HomeViewModel by activityViewModels()
|
||||
private val driverViewModel: DriverViewModel by activityViewModels()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@@ -107,13 +107,17 @@ class HomeSettingsFragment : Fragment() {
|
||||
)
|
||||
add(
|
||||
HomeSetting(
|
||||
R.string.install_gpu_driver,
|
||||
R.string.gpu_driver_manager,
|
||||
R.string.install_gpu_driver_description,
|
||||
R.drawable.ic_exit,
|
||||
{ driverInstaller() },
|
||||
R.drawable.ic_build,
|
||||
{
|
||||
binding.root.findNavController()
|
||||
.navigate(R.id.action_homeSettingsFragment_to_driverManagerFragment)
|
||||
},
|
||||
{ GpuDriverHelper.supportsCustomDriverLoading() },
|
||||
R.string.custom_driver_not_supported,
|
||||
R.string.custom_driver_not_supported_description
|
||||
R.string.custom_driver_not_supported_description,
|
||||
driverViewModel.selectedDriverMetadata
|
||||
)
|
||||
)
|
||||
add(
|
||||
@@ -292,31 +296,6 @@ class HomeSettingsFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun driverInstaller() {
|
||||
// Get the driver name for the dialog message.
|
||||
var driverName = GpuDriverHelper.customDriverName
|
||||
if (driverName == null) {
|
||||
driverName = getString(R.string.system_gpu_driver)
|
||||
}
|
||||
|
||||
MaterialAlertDialogBuilder(requireContext())
|
||||
.setTitle(getString(R.string.select_gpu_driver_title))
|
||||
.setMessage(driverName)
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.setNeutralButton(R.string.select_gpu_driver_default) { _: DialogInterface?, _: Int ->
|
||||
GpuDriverHelper.installDefaultDriver(requireContext())
|
||||
Toast.makeText(
|
||||
requireContext(),
|
||||
R.string.select_gpu_driver_use_default,
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
.setPositiveButton(R.string.select_gpu_driver_install) { _: DialogInterface?, _: Int ->
|
||||
mainActivity.getDriver.launch(arrayOf("application/zip"))
|
||||
}
|
||||
.show()
|
||||
}
|
||||
|
||||
private fun shareLog() {
|
||||
val file = DocumentFile.fromSingleUri(
|
||||
mainActivity,
|
||||
|
@@ -10,8 +10,8 @@ import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
@@ -78,6 +78,10 @@ class IndeterminateProgressDialogFragment : DialogFragment() {
|
||||
requireActivity().supportFragmentManager,
|
||||
MessageDialogFragment.TAG
|
||||
)
|
||||
|
||||
else -> {
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
taskViewModel.clear()
|
||||
}
|
||||
@@ -115,7 +119,7 @@ class IndeterminateProgressDialogFragment : DialogFragment() {
|
||||
private const val CANCELLABLE = "Cancellable"
|
||||
|
||||
fun newInstance(
|
||||
activity: AppCompatActivity,
|
||||
activity: FragmentActivity,
|
||||
titleId: Int,
|
||||
cancellable: Boolean = false,
|
||||
task: () -> Any
|
||||
|
@@ -0,0 +1,158 @@
|
||||
// SPDX-FileCopyrightText: 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
package org.yuzu.yuzu_emu.model
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.yuzu.yuzu_emu.R
|
||||
import org.yuzu.yuzu_emu.YuzuApplication
|
||||
import org.yuzu.yuzu_emu.utils.FileUtil
|
||||
import org.yuzu.yuzu_emu.utils.GpuDriverHelper
|
||||
import org.yuzu.yuzu_emu.utils.GpuDriverMetadata
|
||||
import java.io.BufferedOutputStream
|
||||
import java.io.File
|
||||
|
||||
class DriverViewModel : ViewModel() {
|
||||
private val _areDriversLoading = MutableStateFlow(false)
|
||||
val areDriversLoading: StateFlow<Boolean> get() = _areDriversLoading
|
||||
|
||||
private val _isDriverReady = MutableStateFlow(true)
|
||||
val isDriverReady: StateFlow<Boolean> get() = _isDriverReady
|
||||
|
||||
private val _isDeletingDrivers = MutableStateFlow(false)
|
||||
val isDeletingDrivers: StateFlow<Boolean> get() = _isDeletingDrivers
|
||||
|
||||
private val _driverList = MutableStateFlow(mutableListOf<Pair<String, GpuDriverMetadata>>())
|
||||
val driverList: StateFlow<MutableList<Pair<String, GpuDriverMetadata>>> get() = _driverList
|
||||
|
||||
var previouslySelectedDriver = 0
|
||||
var selectedDriver = -1
|
||||
|
||||
private val _selectedDriverMetadata =
|
||||
MutableStateFlow(
|
||||
GpuDriverHelper.customDriverData.name
|
||||
?: YuzuApplication.appContext.getString(R.string.system_gpu_driver)
|
||||
)
|
||||
val selectedDriverMetadata: StateFlow<String> get() = _selectedDriverMetadata
|
||||
|
||||
private val _newDriverInstalled = MutableStateFlow(false)
|
||||
val newDriverInstalled: StateFlow<Boolean> get() = _newDriverInstalled
|
||||
|
||||
val driversToDelete = mutableListOf<String>()
|
||||
|
||||
val isInteractionAllowed
|
||||
get() = !areDriversLoading.value && isDriverReady.value && !isDeletingDrivers.value
|
||||
|
||||
init {
|
||||
_areDriversLoading.value = true
|
||||
viewModelScope.launch {
|
||||
withContext(Dispatchers.IO) {
|
||||
val drivers = GpuDriverHelper.getDrivers()
|
||||
val currentDriverMetadata = GpuDriverHelper.customDriverData
|
||||
for (i in drivers.indices) {
|
||||
if (drivers[i].second == currentDriverMetadata) {
|
||||
setSelectedDriverIndex(i)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// If a user had installed a driver before the manager was implemented, this zips
|
||||
// the installed driver to UserData/gpu_drivers/CustomDriver.zip so that it can
|
||||
// be indexed and exported as expected.
|
||||
if (selectedDriver == -1) {
|
||||
val driverToSave =
|
||||
File(GpuDriverHelper.driverStoragePath, "CustomDriver.zip")
|
||||
driverToSave.createNewFile()
|
||||
FileUtil.zipFromInternalStorage(
|
||||
File(GpuDriverHelper.driverInstallationPath!!),
|
||||
GpuDriverHelper.driverInstallationPath!!,
|
||||
BufferedOutputStream(driverToSave.outputStream())
|
||||
)
|
||||
drivers.add(Pair(driverToSave.path, currentDriverMetadata))
|
||||
setSelectedDriverIndex(drivers.size - 1)
|
||||
}
|
||||
|
||||
_driverList.value = drivers
|
||||
_areDriversLoading.value = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun setSelectedDriverIndex(value: Int) {
|
||||
if (selectedDriver != -1) {
|
||||
previouslySelectedDriver = selectedDriver
|
||||
}
|
||||
selectedDriver = value
|
||||
}
|
||||
|
||||
fun setNewDriverInstalled(value: Boolean) {
|
||||
_newDriverInstalled.value = value
|
||||
}
|
||||
|
||||
fun addDriver(driverData: Pair<String, GpuDriverMetadata>) {
|
||||
val driverIndex = _driverList.value.indexOfFirst { it == driverData }
|
||||
if (driverIndex == -1) {
|
||||
setSelectedDriverIndex(_driverList.value.size)
|
||||
_driverList.value.add(driverData)
|
||||
_selectedDriverMetadata.value = driverData.second.name
|
||||
?: YuzuApplication.appContext.getString(R.string.system_gpu_driver)
|
||||
} else {
|
||||
setSelectedDriverIndex(driverIndex)
|
||||
}
|
||||
}
|
||||
|
||||
fun removeDriver(driverData: Pair<String, GpuDriverMetadata>) {
|
||||
_driverList.value.remove(driverData)
|
||||
}
|
||||
|
||||
fun onCloseDriverManager() {
|
||||
_isDeletingDrivers.value = true
|
||||
viewModelScope.launch {
|
||||
withContext(Dispatchers.IO) {
|
||||
driversToDelete.forEach {
|
||||
val driver = File(it)
|
||||
if (driver.exists()) {
|
||||
driver.delete()
|
||||
}
|
||||
}
|
||||
driversToDelete.clear()
|
||||
_isDeletingDrivers.value = false
|
||||
}
|
||||
}
|
||||
|
||||
if (GpuDriverHelper.customDriverData == driverList.value[selectedDriver].second) {
|
||||
return
|
||||
}
|
||||
|
||||
_isDriverReady.value = false
|
||||
viewModelScope.launch {
|
||||
withContext(Dispatchers.IO) {
|
||||
if (selectedDriver == 0) {
|
||||
GpuDriverHelper.installDefaultDriver()
|
||||
setDriverReady()
|
||||
return@withContext
|
||||
}
|
||||
|
||||
val driverToInstall = File(driverList.value[selectedDriver].first)
|
||||
if (driverToInstall.exists()) {
|
||||
GpuDriverHelper.installCustomDriver(driverToInstall)
|
||||
} else {
|
||||
GpuDriverHelper.installDefaultDriver()
|
||||
}
|
||||
setDriverReady()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun setDriverReady() {
|
||||
_isDriverReady.value = true
|
||||
_selectedDriverMetadata.value = GpuDriverHelper.customDriverData.name
|
||||
?: YuzuApplication.appContext.getString(R.string.system_gpu_driver)
|
||||
}
|
||||
}
|
@@ -29,12 +29,10 @@ import androidx.navigation.fragment.NavHostFragment
|
||||
import androidx.navigation.ui.setupWithNavController
|
||||
import androidx.preference.PreferenceManager
|
||||
import com.google.android.material.color.MaterialColors
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.google.android.material.navigation.NavigationBarView
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import java.io.File
|
||||
import java.io.FilenameFilter
|
||||
import java.io.IOException
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
@@ -43,7 +41,6 @@ import org.yuzu.yuzu_emu.NativeLibrary
|
||||
import org.yuzu.yuzu_emu.R
|
||||
import org.yuzu.yuzu_emu.activities.EmulationActivity
|
||||
import org.yuzu.yuzu_emu.databinding.ActivityMainBinding
|
||||
import org.yuzu.yuzu_emu.databinding.DialogProgressBarBinding
|
||||
import org.yuzu.yuzu_emu.features.DocumentProvider
|
||||
import org.yuzu.yuzu_emu.features.settings.model.Settings
|
||||
import org.yuzu.yuzu_emu.fragments.IndeterminateProgressDialogFragment
|
||||
@@ -343,11 +340,10 @@ class MainActivity : AppCompatActivity(), ThemeProvider {
|
||||
|
||||
val dstPath = DirectoryInitialization.userDirectory + "/keys/"
|
||||
if (FileUtil.copyUriToInternalStorage(
|
||||
applicationContext,
|
||||
result,
|
||||
dstPath,
|
||||
"prod.keys"
|
||||
)
|
||||
) != null
|
||||
) {
|
||||
if (NativeLibrary.reloadKeys()) {
|
||||
Toast.makeText(
|
||||
@@ -446,11 +442,10 @@ class MainActivity : AppCompatActivity(), ThemeProvider {
|
||||
|
||||
val dstPath = DirectoryInitialization.userDirectory + "/keys/"
|
||||
if (FileUtil.copyUriToInternalStorage(
|
||||
applicationContext,
|
||||
result,
|
||||
dstPath,
|
||||
"key_retail.bin"
|
||||
)
|
||||
) != null
|
||||
) {
|
||||
if (NativeLibrary.reloadKeys()) {
|
||||
Toast.makeText(
|
||||
@@ -469,59 +464,6 @@ class MainActivity : AppCompatActivity(), ThemeProvider {
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
contentResolver.takePersistableUriPermission(
|
||||
result,
|
||||
takeFlags
|
||||
)
|
||||
|
||||
val progressBinding = DialogProgressBarBinding.inflate(layoutInflater)
|
||||
progressBinding.progressBar.isIndeterminate = true
|
||||
val installationDialog = MaterialAlertDialogBuilder(this)
|
||||
.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(applicationContext, result)
|
||||
} catch (_: IOException) {
|
||||
}
|
||||
|
||||
withContext(Dispatchers.Main) {
|
||||
installationDialog.dismiss()
|
||||
|
||||
val driverName = GpuDriverHelper.customDriverName
|
||||
if (driverName != null) {
|
||||
Toast.makeText(
|
||||
applicationContext,
|
||||
getString(
|
||||
R.string.select_gpu_driver_install_success,
|
||||
driverName
|
||||
),
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
} else {
|
||||
Toast.makeText(
|
||||
applicationContext,
|
||||
R.string.select_gpu_driver_error,
|
||||
Toast.LENGTH_LONG
|
||||
).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val installGameUpdate = registerForActivityResult(
|
||||
ActivityResultContracts.OpenMultipleDocuments()
|
||||
) { documents: List<Uri> ->
|
||||
|
@@ -7,7 +7,6 @@ import android.net.Uri
|
||||
import androidx.documentfile.provider.DocumentFile
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
import org.yuzu.yuzu_emu.YuzuApplication
|
||||
import org.yuzu.yuzu_emu.model.MinimalDocumentFile
|
||||
|
||||
class DocumentsTree {
|
||||
@@ -22,7 +21,7 @@ class DocumentsTree {
|
||||
|
||||
fun openContentUri(filepath: String, openMode: String?): Int {
|
||||
val node = resolvePath(filepath) ?: return -1
|
||||
return FileUtil.openContentUri(YuzuApplication.appContext, node.uri.toString(), openMode)
|
||||
return FileUtil.openContentUri(node.uri.toString(), openMode)
|
||||
}
|
||||
|
||||
fun getFileSize(filepath: String): Long {
|
||||
@@ -30,7 +29,7 @@ class DocumentsTree {
|
||||
return if (node == null || node.isDirectory) {
|
||||
0
|
||||
} else {
|
||||
FileUtil.getFileSize(YuzuApplication.appContext, node.uri.toString())
|
||||
FileUtil.getFileSize(node.uri.toString())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +66,7 @@ class DocumentsTree {
|
||||
* @param parent parent node of this level
|
||||
*/
|
||||
private fun structTree(parent: DocumentsNode) {
|
||||
val documents = FileUtil.listFiles(YuzuApplication.appContext, parent.uri!!)
|
||||
val documents = FileUtil.listFiles(parent.uri!!)
|
||||
for (document in documents) {
|
||||
val node = DocumentsNode(document)
|
||||
node.parent = parent
|
||||
|
@@ -3,7 +3,6 @@
|
||||
|
||||
package org.yuzu.yuzu_emu.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.database.Cursor
|
||||
import android.net.Uri
|
||||
import android.provider.DocumentsContract
|
||||
@@ -11,7 +10,6 @@ import androidx.documentfile.provider.DocumentFile
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import java.io.BufferedInputStream
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
import java.net.URLDecoder
|
||||
@@ -21,6 +19,8 @@ import org.yuzu.yuzu_emu.YuzuApplication
|
||||
import org.yuzu.yuzu_emu.model.MinimalDocumentFile
|
||||
import org.yuzu.yuzu_emu.model.TaskState
|
||||
import java.io.BufferedOutputStream
|
||||
import java.lang.NullPointerException
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.util.zip.ZipOutputStream
|
||||
|
||||
object FileUtil {
|
||||
@@ -29,6 +29,8 @@ object FileUtil {
|
||||
const val APPLICATION_OCTET_STREAM = "application/octet-stream"
|
||||
const val TEXT_PLAIN = "text/plain"
|
||||
|
||||
private val context get() = YuzuApplication.appContext
|
||||
|
||||
/**
|
||||
* Create a file from directory with filename.
|
||||
* @param context Application context
|
||||
@@ -36,11 +38,11 @@ object FileUtil {
|
||||
* @param filename file display name.
|
||||
* @return boolean
|
||||
*/
|
||||
fun createFile(context: Context?, directory: String?, filename: String): DocumentFile? {
|
||||
fun createFile(directory: String?, filename: String): DocumentFile? {
|
||||
var decodedFilename = filename
|
||||
try {
|
||||
val directoryUri = Uri.parse(directory)
|
||||
val parent = DocumentFile.fromTreeUri(context!!, directoryUri) ?: return null
|
||||
val parent = DocumentFile.fromTreeUri(context, directoryUri) ?: return null
|
||||
decodedFilename = URLDecoder.decode(decodedFilename, DECODE_METHOD)
|
||||
var mimeType = APPLICATION_OCTET_STREAM
|
||||
if (decodedFilename.endsWith(".txt")) {
|
||||
@@ -56,16 +58,15 @@ object FileUtil {
|
||||
|
||||
/**
|
||||
* Create a directory from directory with filename.
|
||||
* @param context Application context
|
||||
* @param directory parent path for directory.
|
||||
* @param directoryName directory display name.
|
||||
* @return boolean
|
||||
*/
|
||||
fun createDir(context: Context?, directory: String?, directoryName: String?): DocumentFile? {
|
||||
fun createDir(directory: String?, directoryName: String?): DocumentFile? {
|
||||
var decodedDirectoryName = directoryName
|
||||
try {
|
||||
val directoryUri = Uri.parse(directory)
|
||||
val parent = DocumentFile.fromTreeUri(context!!, directoryUri) ?: return null
|
||||
val parent = DocumentFile.fromTreeUri(context, directoryUri) ?: return null
|
||||
decodedDirectoryName = URLDecoder.decode(decodedDirectoryName, DECODE_METHOD)
|
||||
val isExist = parent.findFile(decodedDirectoryName)
|
||||
return isExist ?: parent.createDirectory(decodedDirectoryName)
|
||||
@@ -77,13 +78,12 @@ object FileUtil {
|
||||
|
||||
/**
|
||||
* Open content uri and return file descriptor to JNI.
|
||||
* @param context Application context
|
||||
* @param path Native content uri path
|
||||
* @param openMode will be one of "r", "r", "rw", "wa", "rwa"
|
||||
* @return file descriptor
|
||||
*/
|
||||
@JvmStatic
|
||||
fun openContentUri(context: Context, path: String, openMode: String?): Int {
|
||||
fun openContentUri(path: String, openMode: String?): Int {
|
||||
try {
|
||||
val uri = Uri.parse(path)
|
||||
val parcelFileDescriptor = context.contentResolver.openFileDescriptor(uri, openMode!!)
|
||||
@@ -103,11 +103,10 @@ object FileUtil {
|
||||
/**
|
||||
* Reference: https://stackoverflow.com/questions/42186820/documentfile-is-very-slow
|
||||
* This function will be faster than DoucmentFile.listFiles
|
||||
* @param context Application context
|
||||
* @param uri Directory uri.
|
||||
* @return CheapDocument lists.
|
||||
*/
|
||||
fun listFiles(context: Context, uri: Uri): Array<MinimalDocumentFile> {
|
||||
fun listFiles(uri: Uri): Array<MinimalDocumentFile> {
|
||||
val resolver = context.contentResolver
|
||||
val columns = arrayOf(
|
||||
DocumentsContract.Document.COLUMN_DOCUMENT_ID,
|
||||
@@ -145,7 +144,7 @@ object FileUtil {
|
||||
* @param path Native content uri path
|
||||
* @return bool
|
||||
*/
|
||||
fun exists(context: Context, path: String?): Boolean {
|
||||
fun exists(path: String?): Boolean {
|
||||
var c: Cursor? = null
|
||||
try {
|
||||
val mUri = Uri.parse(path)
|
||||
@@ -165,7 +164,7 @@ object FileUtil {
|
||||
* @param path content uri path
|
||||
* @return bool
|
||||
*/
|
||||
fun isDirectory(context: Context, path: String): Boolean {
|
||||
fun isDirectory(path: String): Boolean {
|
||||
val resolver = context.contentResolver
|
||||
val columns = arrayOf(
|
||||
DocumentsContract.Document.COLUMN_MIME_TYPE
|
||||
@@ -210,10 +209,10 @@ object FileUtil {
|
||||
return filename
|
||||
}
|
||||
|
||||
fun getFilesName(context: Context, path: String): Array<String> {
|
||||
fun getFilesName(path: String): Array<String> {
|
||||
val uri = Uri.parse(path)
|
||||
val files: MutableList<String> = ArrayList()
|
||||
for (file in listFiles(context, uri)) {
|
||||
for (file in listFiles(uri)) {
|
||||
files.add(file.filename)
|
||||
}
|
||||
return files.toTypedArray()
|
||||
@@ -225,7 +224,7 @@ object FileUtil {
|
||||
* @return long file size
|
||||
*/
|
||||
@JvmStatic
|
||||
fun getFileSize(context: Context, path: String): Long {
|
||||
fun getFileSize(path: String): Long {
|
||||
val resolver = context.contentResolver
|
||||
val columns = arrayOf(
|
||||
DocumentsContract.Document.COLUMN_SIZE
|
||||
@@ -245,43 +244,37 @@ object FileUtil {
|
||||
return size
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an input stream with a given [Uri] and copies its data to the given path. This will
|
||||
* overwrite any pre-existing files.
|
||||
*
|
||||
* @param sourceUri The [Uri] to copy data from
|
||||
* @param destinationParentPath Destination directory
|
||||
* @param destinationFilename Optionally renames the file once copied
|
||||
*/
|
||||
fun copyUriToInternalStorage(
|
||||
context: Context,
|
||||
sourceUri: Uri?,
|
||||
sourceUri: Uri,
|
||||
destinationParentPath: String,
|
||||
destinationFilename: String
|
||||
): Boolean {
|
||||
var input: InputStream? = null
|
||||
var output: FileOutputStream? = null
|
||||
destinationFilename: String = ""
|
||||
): File? =
|
||||
try {
|
||||
input = context.contentResolver.openInputStream(sourceUri!!)
|
||||
output = FileOutputStream("$destinationParentPath/$destinationFilename")
|
||||
val buffer = ByteArray(1024)
|
||||
var len: Int
|
||||
while (input!!.read(buffer).also { len = it } != -1) {
|
||||
output.write(buffer, 0, len)
|
||||
val fileName =
|
||||
if (destinationFilename == "") getFilename(sourceUri) else "/$destinationFilename"
|
||||
val inputStream = context.contentResolver.openInputStream(sourceUri)!!
|
||||
|
||||
val destinationFile = File("$destinationParentPath$fileName")
|
||||
if (destinationFile.exists()) {
|
||||
destinationFile.delete()
|
||||
}
|
||||
output.flush()
|
||||
return true
|
||||
} catch (e: Exception) {
|
||||
Log.error("[FileUtil]: Cannot copy file, error: " + e.message)
|
||||
} finally {
|
||||
if (input != null) {
|
||||
try {
|
||||
input.close()
|
||||
|
||||
destinationFile.outputStream().use { fos ->
|
||||
inputStream.use { it.copyTo(fos) }
|
||||
}
|
||||
destinationFile
|
||||
} catch (e: IOException) {
|
||||
Log.error("[FileUtil]: Cannot close input file, error: " + e.message)
|
||||
}
|
||||
}
|
||||
if (output != null) {
|
||||
try {
|
||||
output.close()
|
||||
} catch (e: IOException) {
|
||||
Log.error("[FileUtil]: Cannot close output file, error: " + e.message)
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
null
|
||||
} catch (e: NullPointerException) {
|
||||
null
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -368,4 +361,12 @@ object FileUtil {
|
||||
return fileName.substring(fileName.lastIndexOf(".") + 1)
|
||||
.lowercase()
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
fun getStringFromFile(file: File): String =
|
||||
String(file.readBytes(), StandardCharsets.UTF_8)
|
||||
|
||||
@Throws(IOException::class)
|
||||
fun getStringFromInputStream(stream: InputStream): String =
|
||||
String(stream.readBytes(), StandardCharsets.UTF_8)
|
||||
}
|
||||
|
@@ -30,7 +30,7 @@ object GameHelper {
|
||||
// Ensure keys are loaded so that ROM metadata can be decrypted.
|
||||
NativeLibrary.reloadKeys()
|
||||
|
||||
addGamesRecursive(games, FileUtil.listFiles(context, gamesUri), 3)
|
||||
addGamesRecursive(games, FileUtil.listFiles(gamesUri), 3)
|
||||
|
||||
// Cache list of games found on disk
|
||||
val serializedGames = mutableSetOf<String>()
|
||||
@@ -58,7 +58,7 @@ object GameHelper {
|
||||
if (it.isDirectory) {
|
||||
addGamesRecursive(
|
||||
games,
|
||||
FileUtil.listFiles(YuzuApplication.appContext, it.uri),
|
||||
FileUtil.listFiles(it.uri),
|
||||
depth - 1
|
||||
)
|
||||
} else {
|
||||
|
@@ -3,64 +3,33 @@
|
||||
|
||||
package org.yuzu.yuzu_emu.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import java.io.BufferedInputStream
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
import java.io.FileOutputStream
|
||||
import java.io.IOException
|
||||
import java.util.zip.ZipInputStream
|
||||
import org.yuzu.yuzu_emu.NativeLibrary
|
||||
import org.yuzu.yuzu_emu.utils.FileUtil.copyUriToInternalStorage
|
||||
import org.yuzu.yuzu_emu.YuzuApplication
|
||||
import java.util.zip.ZipException
|
||||
import java.util.zip.ZipFile
|
||||
|
||||
object GpuDriverHelper {
|
||||
private const val META_JSON_FILENAME = "meta.json"
|
||||
private const val DRIVER_INTERNAL_FILENAME = "gpu_driver.zip"
|
||||
private var fileRedirectionPath: String? = null
|
||||
private var driverInstallationPath: String? = null
|
||||
var driverInstallationPath: String? = null
|
||||
private var hookLibPath: String? = null
|
||||
|
||||
@Throws(IOException::class)
|
||||
private fun unzip(zipFilePath: String, destDir: String) {
|
||||
val dir = File(destDir)
|
||||
val driverStoragePath get() = DirectoryInitialization.userDirectory!! + "/gpu_drivers/"
|
||||
|
||||
// Create output directory if it doesn't exist
|
||||
if (!dir.exists()) dir.mkdirs()
|
||||
|
||||
// Unpack the files.
|
||||
val inputStream = FileInputStream(zipFilePath)
|
||||
val zis = ZipInputStream(BufferedInputStream(inputStream))
|
||||
val buffer = ByteArray(1024)
|
||||
var ze = zis.nextEntry
|
||||
while (ze != null) {
|
||||
val newFile = File(destDir, ze.name)
|
||||
val canonicalPath = newFile.canonicalPath
|
||||
if (!canonicalPath.startsWith(destDir + ze.name)) {
|
||||
throw SecurityException("Zip file attempted path traversal! " + ze.name)
|
||||
}
|
||||
|
||||
newFile.parentFile!!.mkdirs()
|
||||
val fos = FileOutputStream(newFile)
|
||||
var len: Int
|
||||
while (zis.read(buffer).also { len = it } > 0) {
|
||||
fos.write(buffer, 0, len)
|
||||
}
|
||||
fos.close()
|
||||
zis.closeEntry()
|
||||
ze = zis.nextEntry
|
||||
}
|
||||
zis.closeEntry()
|
||||
}
|
||||
|
||||
fun initializeDriverParameters(context: Context) {
|
||||
fun initializeDriverParameters() {
|
||||
try {
|
||||
// Initialize the file redirection directory.
|
||||
fileRedirectionPath =
|
||||
context.getExternalFilesDir(null)!!.canonicalPath + "/gpu/vk_file_redirect/"
|
||||
fileRedirectionPath = YuzuApplication.appContext
|
||||
.getExternalFilesDir(null)!!.canonicalPath + "/gpu/vk_file_redirect/"
|
||||
|
||||
// Initialize the driver installation directory.
|
||||
driverInstallationPath = context.filesDir.canonicalPath + "/gpu_driver/"
|
||||
driverInstallationPath = YuzuApplication.appContext
|
||||
.filesDir.canonicalPath + "/gpu_driver/"
|
||||
} catch (e: IOException) {
|
||||
throw RuntimeException(e)
|
||||
}
|
||||
@@ -69,68 +38,169 @@ object GpuDriverHelper {
|
||||
initializeDirectories()
|
||||
|
||||
// Initialize hook libraries directory.
|
||||
hookLibPath = context.applicationInfo.nativeLibraryDir + "/"
|
||||
hookLibPath = YuzuApplication.appContext.applicationInfo.nativeLibraryDir + "/"
|
||||
|
||||
// Initialize GPU driver.
|
||||
NativeLibrary.initializeGpuDriver(
|
||||
hookLibPath,
|
||||
driverInstallationPath,
|
||||
customDriverLibraryName,
|
||||
customDriverData.libraryName,
|
||||
fileRedirectionPath
|
||||
)
|
||||
}
|
||||
|
||||
fun installDefaultDriver(context: Context) {
|
||||
// Removing the installed driver will result in the backend using the default system driver.
|
||||
val driverInstallationDir = File(driverInstallationPath!!)
|
||||
deleteRecursive(driverInstallationDir)
|
||||
initializeDriverParameters(context)
|
||||
fun getDrivers(): MutableList<Pair<String, GpuDriverMetadata>> {
|
||||
val driverZips = File(driverStoragePath).listFiles()
|
||||
val drivers: MutableList<Pair<String, GpuDriverMetadata>> =
|
||||
driverZips
|
||||
?.mapNotNull {
|
||||
val metadata = getMetadataFromZip(it)
|
||||
metadata.name?.let { _ -> Pair(it.path, metadata) }
|
||||
}
|
||||
?.sortedByDescending { it: Pair<String, GpuDriverMetadata> -> it.second.name }
|
||||
?.distinct()
|
||||
?.toMutableList() ?: mutableListOf()
|
||||
|
||||
// TODO: Get system driver information
|
||||
drivers.add(0, Pair("", GpuDriverMetadata()))
|
||||
return drivers
|
||||
}
|
||||
|
||||
fun installCustomDriver(context: Context, driverPathUri: Uri?) {
|
||||
fun installDefaultDriver() {
|
||||
// Removing the installed driver will result in the backend using the default system driver.
|
||||
File(driverInstallationPath!!).deleteRecursively()
|
||||
initializeDriverParameters()
|
||||
}
|
||||
|
||||
fun copyDriverToInternalStorage(driverUri: Uri): Boolean {
|
||||
// Ensure we have directories.
|
||||
initializeDirectories()
|
||||
|
||||
// Copy the zip file URI to user data
|
||||
val copiedFile =
|
||||
FileUtil.copyUriToInternalStorage(driverUri, driverStoragePath) ?: return false
|
||||
|
||||
// Validate driver
|
||||
val metadata = getMetadataFromZip(copiedFile)
|
||||
if (metadata.name == null) {
|
||||
copiedFile.delete()
|
||||
return false
|
||||
}
|
||||
|
||||
if (metadata.minApi > Build.VERSION.SDK_INT) {
|
||||
copiedFile.delete()
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies driver zip into user data directory so that it can be exported along with
|
||||
* other user data and also unzipped into the installation directory
|
||||
*/
|
||||
fun installCustomDriver(driverUri: Uri): Boolean {
|
||||
// Revert to system default in the event the specified driver is bad.
|
||||
installDefaultDriver(context)
|
||||
installDefaultDriver()
|
||||
|
||||
// Ensure we have directories.
|
||||
initializeDirectories()
|
||||
|
||||
// Copy the zip file URI into our private storage.
|
||||
copyUriToInternalStorage(
|
||||
context,
|
||||
driverPathUri,
|
||||
driverInstallationPath!!,
|
||||
DRIVER_INTERNAL_FILENAME
|
||||
)
|
||||
// Copy the zip file URI to user data
|
||||
val copiedFile =
|
||||
FileUtil.copyUriToInternalStorage(driverUri, driverStoragePath) ?: return false
|
||||
|
||||
// Validate driver
|
||||
val metadata = getMetadataFromZip(copiedFile)
|
||||
if (metadata.name == null) {
|
||||
copiedFile.delete()
|
||||
return false
|
||||
}
|
||||
|
||||
if (metadata.minApi > Build.VERSION.SDK_INT) {
|
||||
copiedFile.delete()
|
||||
return false
|
||||
}
|
||||
|
||||
// Unzip the driver.
|
||||
try {
|
||||
unzip(driverInstallationPath + DRIVER_INTERNAL_FILENAME, driverInstallationPath!!)
|
||||
FileUtil.unzipToInternalStorage(
|
||||
BufferedInputStream(copiedFile.inputStream()),
|
||||
File(driverInstallationPath!!)
|
||||
)
|
||||
} catch (e: SecurityException) {
|
||||
return
|
||||
return false
|
||||
}
|
||||
|
||||
// Initialize the driver parameters.
|
||||
initializeDriverParameters(context)
|
||||
initializeDriverParameters()
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* Unzips driver into installation directory
|
||||
*/
|
||||
fun installCustomDriver(driver: File): Boolean {
|
||||
// Revert to system default in the event the specified driver is bad.
|
||||
installDefaultDriver()
|
||||
|
||||
// Ensure we have directories.
|
||||
initializeDirectories()
|
||||
|
||||
// Validate driver
|
||||
val metadata = getMetadataFromZip(driver)
|
||||
if (metadata.name == null) {
|
||||
driver.delete()
|
||||
return false
|
||||
}
|
||||
|
||||
// Unzip the driver to the private installation directory
|
||||
try {
|
||||
FileUtil.unzipToInternalStorage(
|
||||
BufferedInputStream(driver.inputStream()),
|
||||
File(driverInstallationPath!!)
|
||||
)
|
||||
} catch (e: SecurityException) {
|
||||
return false
|
||||
}
|
||||
|
||||
// Initialize the driver parameters.
|
||||
initializeDriverParameters()
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes in a zip file and reads the meta.json file for presentation to the UI
|
||||
*
|
||||
* @param driver Zip containing driver and meta.json file
|
||||
* @return A non-null [GpuDriverMetadata] instance that may have null members
|
||||
*/
|
||||
fun getMetadataFromZip(driver: File): GpuDriverMetadata {
|
||||
try {
|
||||
ZipFile(driver).use { zf ->
|
||||
val entries = zf.entries()
|
||||
while (entries.hasMoreElements()) {
|
||||
val entry = entries.nextElement()
|
||||
if (!entry.isDirectory && entry.name.lowercase().contains(".json")) {
|
||||
zf.getInputStream(entry).use {
|
||||
return GpuDriverMetadata(it, entry.size)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (_: ZipException) {
|
||||
}
|
||||
return GpuDriverMetadata()
|
||||
}
|
||||
|
||||
external fun supportsCustomDriverLoading(): Boolean
|
||||
|
||||
// Parse the custom driver metadata to retrieve the name.
|
||||
val customDriverName: String?
|
||||
get() {
|
||||
val metadata = GpuDriverMetadata(driverInstallationPath + META_JSON_FILENAME)
|
||||
return metadata.name
|
||||
}
|
||||
val customDriverData: GpuDriverMetadata
|
||||
get() = GpuDriverMetadata(File(driverInstallationPath + META_JSON_FILENAME))
|
||||
|
||||
// Parse the custom driver metadata to retrieve the library name.
|
||||
private val customDriverLibraryName: String?
|
||||
get() {
|
||||
// Parse the custom driver metadata to retrieve the library name.
|
||||
val metadata = GpuDriverMetadata(driverInstallationPath + META_JSON_FILENAME)
|
||||
return metadata.libraryName
|
||||
}
|
||||
|
||||
private fun initializeDirectories() {
|
||||
fun initializeDirectories() {
|
||||
// Ensure the file redirection directory exists.
|
||||
val fileRedirectionDir = File(fileRedirectionPath!!)
|
||||
if (!fileRedirectionDir.exists()) {
|
||||
@@ -141,14 +211,10 @@ object GpuDriverHelper {
|
||||
if (!driverInstallationDir.exists()) {
|
||||
driverInstallationDir.mkdirs()
|
||||
}
|
||||
// Ensure the driver storage directory exists
|
||||
val driverStorageDirectory = File(driverStoragePath)
|
||||
if (!driverStorageDirectory.exists()) {
|
||||
driverStorageDirectory.mkdirs()
|
||||
}
|
||||
|
||||
private fun deleteRecursive(fileOrDirectory: File) {
|
||||
if (fileOrDirectory.isDirectory) {
|
||||
for (child in fileOrDirectory.listFiles()!!) {
|
||||
deleteRecursive(child)
|
||||
}
|
||||
}
|
||||
fileOrDirectory.delete()
|
||||
}
|
||||
}
|
||||
|
@@ -4,29 +4,29 @@
|
||||
package org.yuzu.yuzu_emu.utils
|
||||
|
||||
import java.io.IOException
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Paths
|
||||
import org.json.JSONException
|
||||
import org.json.JSONObject
|
||||
import java.io.File
|
||||
import java.io.InputStream
|
||||
|
||||
class GpuDriverMetadata(metadataFilePath: String) {
|
||||
var name: String? = null
|
||||
var description: String? = null
|
||||
var author: String? = null
|
||||
var vendor: String? = null
|
||||
var driverVersion: String? = null
|
||||
var minApi = 0
|
||||
var libraryName: String? = null
|
||||
class GpuDriverMetadata {
|
||||
/**
|
||||
* Tries to get driver metadata information from a meta.json [File]
|
||||
*
|
||||
* @param metadataFile meta.json file provided with a GPU driver
|
||||
*/
|
||||
constructor(metadataFile: File) {
|
||||
if (metadataFile.length() > MAX_META_SIZE_BYTES) {
|
||||
return
|
||||
}
|
||||
|
||||
init {
|
||||
try {
|
||||
val json = JSONObject(getStringFromFile(metadataFilePath))
|
||||
val json = JSONObject(FileUtil.getStringFromFile(metadataFile))
|
||||
name = json.getString("name")
|
||||
description = json.getString("description")
|
||||
author = json.getString("author")
|
||||
vendor = json.getString("vendor")
|
||||
driverVersion = json.getString("driverVersion")
|
||||
version = json.getString("driverVersion")
|
||||
minApi = json.getInt("minApi")
|
||||
libraryName = json.getString("libraryName")
|
||||
} catch (e: JSONException) {
|
||||
@@ -36,12 +36,84 @@ class GpuDriverMetadata(metadataFilePath: String) {
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
@Throws(IOException::class)
|
||||
private fun getStringFromFile(filePath: String): String {
|
||||
val path = Paths.get(filePath)
|
||||
val bytes = Files.readAllBytes(path)
|
||||
return String(bytes, StandardCharsets.UTF_8)
|
||||
/**
|
||||
* Tries to get driver metadata information from an input stream that's intended to be
|
||||
* from a zip file
|
||||
*
|
||||
* @param metadataStream ZipEntry input stream
|
||||
* @param size Size of the file in bytes
|
||||
*/
|
||||
constructor(metadataStream: InputStream, size: Long) {
|
||||
if (size > MAX_META_SIZE_BYTES) {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
val json = JSONObject(FileUtil.getStringFromInputStream(metadataStream))
|
||||
name = json.getString("name")
|
||||
description = json.getString("description")
|
||||
author = json.getString("author")
|
||||
vendor = json.getString("vendor")
|
||||
version = json.getString("driverVersion")
|
||||
minApi = json.getInt("minApi")
|
||||
libraryName = json.getString("libraryName")
|
||||
} catch (e: JSONException) {
|
||||
// JSON is malformed, ignore and treat as unsupported metadata.
|
||||
} catch (e: IOException) {
|
||||
// File is inaccessible, ignore and treat as unsupported metadata.
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an empty metadata instance
|
||||
*/
|
||||
constructor()
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is GpuDriverMetadata) {
|
||||
return false
|
||||
}
|
||||
|
||||
return other.name == name &&
|
||||
other.description == description &&
|
||||
other.author == author &&
|
||||
other.vendor == vendor &&
|
||||
other.version == version &&
|
||||
other.minApi == minApi &&
|
||||
other.libraryName == libraryName
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = name?.hashCode() ?: 0
|
||||
result = 31 * result + (description?.hashCode() ?: 0)
|
||||
result = 31 * result + (author?.hashCode() ?: 0)
|
||||
result = 31 * result + (vendor?.hashCode() ?: 0)
|
||||
result = 31 * result + (version?.hashCode() ?: 0)
|
||||
result = 31 * result + minApi
|
||||
result = 31 * result + (libraryName?.hashCode() ?: 0)
|
||||
return result
|
||||
}
|
||||
|
||||
override fun toString(): String =
|
||||
"""
|
||||
Name - $name
|
||||
Description - $description
|
||||
Author - $author
|
||||
Vendor - $vendor
|
||||
Version - $version
|
||||
Min API - $minApi
|
||||
Library Name - $libraryName
|
||||
""".trimMargin().trimIndent()
|
||||
|
||||
var name: String? = null
|
||||
var description: String? = null
|
||||
var author: String? = null
|
||||
var vendor: String? = null
|
||||
var version: String? = null
|
||||
var minApi = 0
|
||||
var libraryName: String? = null
|
||||
|
||||
companion object {
|
||||
private const val MAX_META_SIZE_BYTES = 500000
|
||||
}
|
||||
}
|
||||
|
9
src/android/app/src/main/res/drawable/ic_build.xml
Normal file
9
src/android/app/src/main/res/drawable/ic_build.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="?attr/colorControlNormal"
|
||||
android:pathData="M22.7,19l-9.1,-9.1c0.9,-2.3 0.4,-5 -1.5,-6.9 -2,-2 -5,-2.4 -7.4,-1.3L9,6 6,9 1.6,4.7C0.4,7.1 0.9,10.1 2.9,12.1c1.9,1.9 4.6,2.4 6.9,1.5l9.1,9.1c0.4,0.4 1,0.4 1.4,0l2.3,-2.3c0.5,-0.4 0.5,-1.1 0.1,-1.4z" />
|
||||
</vector>
|
9
src/android/app/src/main/res/drawable/ic_delete.xml
Normal file
9
src/android/app/src/main/res/drawable/ic_delete.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="?attr/colorControlNormal"
|
||||
android:pathData="M6,19c0,1.1 0.9,2 2,2h8c1.1,0 2,-0.9 2,-2V7H6v12zM19,4h-3.5l-1,-1h-5l-1,1H5v2h14V4z" />
|
||||
</vector>
|
89
src/android/app/src/main/res/layout/card_driver_option.xml
Normal file
89
src/android/app/src/main/res/layout/card_driver_option.xml
Normal file
@@ -0,0 +1,89 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
style="?attr/materialCardViewOutlinedStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="16dp"
|
||||
android:layout_marginVertical="12dp"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:clickable="true"
|
||||
android:focusable="true">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:layout_gravity="center"
|
||||
android:padding="16dp">
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/radio_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:clickable="false"
|
||||
android:checked="false" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical"
|
||||
android:layout_gravity="center_vertical">
|
||||
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
android:id="@+id/title"
|
||||
style="@style/TextAppearance.Material3.TitleMedium"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="none"
|
||||
android:marqueeRepeatLimit="marquee_forever"
|
||||
android:requiresFadingEdge="horizontal"
|
||||
android:singleLine="true"
|
||||
android:textAlignment="viewStart"
|
||||
tools:text="@string/select_gpu_driver_default" />
|
||||
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
android:id="@+id/version"
|
||||
style="@style/TextAppearance.Material3.BodyMedium"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="6dp"
|
||||
android:ellipsize="none"
|
||||
android:marqueeRepeatLimit="marquee_forever"
|
||||
android:requiresFadingEdge="horizontal"
|
||||
android:singleLine="true"
|
||||
android:textAlignment="viewStart"
|
||||
tools:text="@string/install_gpu_driver_description" />
|
||||
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
android:id="@+id/description"
|
||||
style="@style/TextAppearance.Material3.BodyMedium"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="6dp"
|
||||
android:ellipsize="none"
|
||||
android:marqueeRepeatLimit="marquee_forever"
|
||||
android:requiresFadingEdge="horizontal"
|
||||
android:singleLine="true"
|
||||
android:textAlignment="viewStart"
|
||||
tools:text="@string/install_gpu_driver_description" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<Button
|
||||
android:id="@+id/button_delete"
|
||||
style="@style/Widget.Material3.Button.IconButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:contentDescription="@string/delete"
|
||||
android:tooltipText="@string/delete"
|
||||
app:icon="@drawable/ic_delete"
|
||||
app:iconTint="?attr/colorControlNormal" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</com.google.android.material.card.MaterialCardView>
|
@@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/coordinator_licenses"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?attr/colorSurface">
|
||||
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:id="@+id/appbar_drivers"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:fitsSystemWindows="true"
|
||||
app:liftOnScrollTargetViewId="@id/list_drivers">
|
||||
|
||||
<com.google.android.material.appbar.MaterialToolbar
|
||||
android:id="@+id/toolbar_drivers"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
app:navigationIcon="@drawable/ic_back"
|
||||
app:title="@string/gpu_driver_manager" />
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/list_drivers"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clipToPadding="false"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
|
||||
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
|
||||
android:id="@+id/button_install"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:text="@string/install"
|
||||
app:icon="@drawable/ic_add"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
@@ -22,6 +22,9 @@
|
||||
<action
|
||||
android:id="@+id/action_homeSettingsFragment_to_installableFragment"
|
||||
app:destination="@id/installableFragment" />
|
||||
<action
|
||||
android:id="@+id/action_homeSettingsFragment_to_driverManagerFragment"
|
||||
app:destination="@id/driverManagerFragment" />
|
||||
</fragment>
|
||||
|
||||
<fragment
|
||||
@@ -95,5 +98,9 @@
|
||||
android:id="@+id/installableFragment"
|
||||
android:name="org.yuzu.yuzu_emu.fragments.InstallableFragment"
|
||||
android:label="InstallableFragment" />
|
||||
<fragment
|
||||
android:id="@+id/driverManagerFragment"
|
||||
android:name="org.yuzu.yuzu_emu.fragments.DriverManagerFragment"
|
||||
android:label="DriverManagerFragment" />
|
||||
|
||||
</navigation>
|
||||
|
@@ -168,9 +168,7 @@
|
||||
<string name="select_gpu_driver_title">Möchtest du deinen aktuellen GPU-Treiber ersetzen?</string>
|
||||
<string name="select_gpu_driver_install">Installieren</string>
|
||||
<string name="select_gpu_driver_default">Standard</string>
|
||||
<string name="select_gpu_driver_install_success">%s wurde installiert</string>
|
||||
<string name="select_gpu_driver_use_default">Standard GPU-Treiber wird verwendet</string>
|
||||
<string name="select_gpu_driver_error">Ungültiger Treiber ausgewählt, Standard-Treiber wird verwendet!</string>
|
||||
<string name="system_gpu_driver">System GPU-Treiber</string>
|
||||
<string name="installing_driver">Treiber wird installiert...</string>
|
||||
|
||||
|
@@ -171,9 +171,7 @@
|
||||
<string name="select_gpu_driver_title">¿Quiere reemplazar el driver de GPU actual?</string>
|
||||
<string name="select_gpu_driver_install">Instalar</string>
|
||||
<string name="select_gpu_driver_default">Predeterminado</string>
|
||||
<string name="select_gpu_driver_install_success">Instalado %s</string>
|
||||
<string name="select_gpu_driver_use_default">Usando el driver de GPU por defecto </string>
|
||||
<string name="select_gpu_driver_error">¡Driver no válido, utilizando el predeterminado del sistema!</string>
|
||||
<string name="system_gpu_driver">Driver GPU del sistema</string>
|
||||
<string name="installing_driver">Instalando driver...</string>
|
||||
|
||||
|
@@ -171,9 +171,7 @@
|
||||
<string name="select_gpu_driver_title">Souhaitez vous remplacer votre pilote actuel ?</string>
|
||||
<string name="select_gpu_driver_install">Installer</string>
|
||||
<string name="select_gpu_driver_default">Défaut</string>
|
||||
<string name="select_gpu_driver_install_success">%s Installé</string>
|
||||
<string name="select_gpu_driver_use_default">Utilisation du pilote de GPU par défaut</string>
|
||||
<string name="select_gpu_driver_error">Pilote non valide sélectionné, utilisation du paramètre par défaut du système !</string>
|
||||
<string name="system_gpu_driver">Pilote du GPU du système</string>
|
||||
<string name="installing_driver">Installation du pilote...</string>
|
||||
|
||||
|
@@ -171,9 +171,7 @@
|
||||
<string name="select_gpu_driver_title">Vuoi sostituire il driver della tua GPU attuale?</string>
|
||||
<string name="select_gpu_driver_install">Installa</string>
|
||||
<string name="select_gpu_driver_default">Predefinito</string>
|
||||
<string name="select_gpu_driver_install_success">Installato%s</string>
|
||||
<string name="select_gpu_driver_use_default">Utilizza il driver predefinito della GPU.</string>
|
||||
<string name="select_gpu_driver_error">Il driver selezionato è invalido, è in utilizzo quello predefinito di sistema!</string>
|
||||
<string name="system_gpu_driver">Driver GPU del sistema</string>
|
||||
<string name="installing_driver">Installando i driver...</string>
|
||||
|
||||
|
@@ -170,9 +170,7 @@
|
||||
<string name="select_gpu_driver_title">現在のGPUドライバーを置き換えますか?</string>
|
||||
<string name="select_gpu_driver_install">インストール</string>
|
||||
<string name="select_gpu_driver_default">デフォルト</string>
|
||||
<string name="select_gpu_driver_install_success">%s をインストールしました</string>
|
||||
<string name="select_gpu_driver_use_default">デフォルトのGPUドライバーを使用します</string>
|
||||
<string name="select_gpu_driver_error">選択されたドライバが無効なため、システムのデフォルトを使用します!</string>
|
||||
<string name="system_gpu_driver">システムのGPUドライバ</string>
|
||||
<string name="installing_driver">インストール中…</string>
|
||||
|
||||
|
@@ -171,9 +171,7 @@
|
||||
<string name="select_gpu_driver_title">현재 사용 중인 GPU 드라이버를 교체하겠습니까?</string>
|
||||
<string name="select_gpu_driver_install">설치</string>
|
||||
<string name="select_gpu_driver_default">기본값</string>
|
||||
<string name="select_gpu_driver_install_success">설치된 %s</string>
|
||||
<string name="select_gpu_driver_use_default">기본 GPU 드라이버 사용</string>
|
||||
<string name="select_gpu_driver_error">시스템 기본값을 사용하여 잘못된 드라이버를 선택했습니다!</string>
|
||||
<string name="system_gpu_driver">시스템 GPU 드라이버</string>
|
||||
<string name="installing_driver">드라이버 설치 중...</string>
|
||||
|
||||
|
@@ -171,9 +171,7 @@
|
||||
<string name="select_gpu_driver_title">Ønsker du å bytte ut din nåværende GPU-driver?</string>
|
||||
<string name="select_gpu_driver_install">Installer</string>
|
||||
<string name="select_gpu_driver_default">Standard</string>
|
||||
<string name="select_gpu_driver_install_success">Installert %s</string>
|
||||
<string name="select_gpu_driver_use_default">Bruk av standard GPU-driver</string>
|
||||
<string name="select_gpu_driver_error">Ugyldig driver valgt, bruker systemstandard!</string>
|
||||
<string name="system_gpu_driver">Systemets GPU-driver</string>
|
||||
<string name="installing_driver">Installerer driver...</string>
|
||||
|
||||
|
@@ -171,9 +171,7 @@
|
||||
<string name="select_gpu_driver_title">Chcesz zastąpić obecny sterownik układu graficznego?</string>
|
||||
<string name="select_gpu_driver_install">Zainstaluj</string>
|
||||
<string name="select_gpu_driver_default">Domyślne</string>
|
||||
<string name="select_gpu_driver_install_success">Zainstalowano %s</string>
|
||||
<string name="select_gpu_driver_use_default">Aktywny domyślny sterownik GPU</string>
|
||||
<string name="select_gpu_driver_error">Wybrano błędny sterownik, powrót do domyślnego. </string>
|
||||
<string name="system_gpu_driver">Systemowy sterownik GPU</string>
|
||||
<string name="installing_driver">Instalowanie sterownika...</string>
|
||||
|
||||
|
@@ -171,9 +171,7 @@
|
||||
<string name="select_gpu_driver_title">Queres substituir o driver do GPU atual? </string>
|
||||
<string name="select_gpu_driver_install">Instalar</string>
|
||||
<string name="select_gpu_driver_default">Padrão</string>
|
||||
<string name="select_gpu_driver_install_success">Instalado%s</string>
|
||||
<string name="select_gpu_driver_use_default">Usar o driver padrão do GPU</string>
|
||||
<string name="select_gpu_driver_error">Driver selecionado inválido, a usar o padrão do sistema!</string>
|
||||
<string name="system_gpu_driver">Driver do GPU padrão</string>
|
||||
<string name="installing_driver">A instalar o Driver...</string>
|
||||
|
||||
|
@@ -171,9 +171,7 @@
|
||||
<string name="select_gpu_driver_title">Queres substituir o driver do GPU atual? </string>
|
||||
<string name="select_gpu_driver_install">Instalar</string>
|
||||
<string name="select_gpu_driver_default">Padrão</string>
|
||||
<string name="select_gpu_driver_install_success">Instalado%s</string>
|
||||
<string name="select_gpu_driver_use_default">Usar o driver padrão do GPU</string>
|
||||
<string name="select_gpu_driver_error">Driver selecionado inválido, a usar o padrão do sistema!</string>
|
||||
<string name="system_gpu_driver">Driver do GPU padrão</string>
|
||||
<string name="installing_driver">A instalar o Driver...</string>
|
||||
|
||||
|
@@ -171,9 +171,7 @@
|
||||
<string name="select_gpu_driver_title">Хотите заменить текущий драйвер ГП?</string>
|
||||
<string name="select_gpu_driver_install">Установить</string>
|
||||
<string name="select_gpu_driver_default">По умолчанию</string>
|
||||
<string name="select_gpu_driver_install_success">Установлено %s</string>
|
||||
<string name="select_gpu_driver_use_default">Используется стандартный драйвер ГП </string>
|
||||
<string name="select_gpu_driver_error">Выбран неверный драйвер, используется стандартный системный!</string>
|
||||
<string name="system_gpu_driver">Системный драйвер ГП</string>
|
||||
<string name="installing_driver">Установка драйвера...</string>
|
||||
|
||||
|
@@ -171,9 +171,7 @@
|
||||
<string name="select_gpu_driver_title">Хочете замінити поточний драйвер ГП?</string>
|
||||
<string name="select_gpu_driver_install">Встановити</string>
|
||||
<string name="select_gpu_driver_default">За замовчуванням</string>
|
||||
<string name="select_gpu_driver_install_success">Встановлено %s</string>
|
||||
<string name="select_gpu_driver_use_default">Використовується стандартний драйвер ГП</string>
|
||||
<string name="select_gpu_driver_error">Обрано неправильний драйвер, використовується стандартний системний!</string>
|
||||
<string name="system_gpu_driver">Системний драйвер ГП</string>
|
||||
<string name="installing_driver">Встановлення драйвера...</string>
|
||||
|
||||
|
@@ -171,9 +171,7 @@
|
||||
<string name="select_gpu_driver_title">要取代您当前的 GPU 驱动程序吗?</string>
|
||||
<string name="select_gpu_driver_install">安装</string>
|
||||
<string name="select_gpu_driver_default">系统默认</string>
|
||||
<string name="select_gpu_driver_install_success">已安装 %s</string>
|
||||
<string name="select_gpu_driver_use_default">使用默认 GPU 驱动程序</string>
|
||||
<string name="select_gpu_driver_error">选择的驱动程序无效,将使用系统默认的驱动程序!</string>
|
||||
<string name="system_gpu_driver">系统 GPU 驱动程序</string>
|
||||
<string name="installing_driver">正在安装驱动程序…</string>
|
||||
|
||||
|
@@ -171,9 +171,7 @@
|
||||
<string name="select_gpu_driver_title">要取代您目前的 GPU 驅動程式嗎?</string>
|
||||
<string name="select_gpu_driver_install">安裝</string>
|
||||
<string name="select_gpu_driver_default">預設</string>
|
||||
<string name="select_gpu_driver_install_success">已安裝 %s</string>
|
||||
<string name="select_gpu_driver_use_default">使用預設 GPU 驅動程式</string>
|
||||
<string name="select_gpu_driver_error">選取的驅動程式無效,將使用系統預設驅動程式!</string>
|
||||
<string name="system_gpu_driver">系統 GPU 驅動程式</string>
|
||||
<string name="installing_driver">正在安裝驅動程式…</string>
|
||||
|
||||
|
@@ -13,6 +13,8 @@
|
||||
<dimen name="menu_width">256dp</dimen>
|
||||
<dimen name="card_width">165dp</dimen>
|
||||
<dimen name="icon_inset">24dp</dimen>
|
||||
<dimen name="spacing_bottom_list_fab">72dp</dimen>
|
||||
<dimen name="spacing_fab">24dp</dimen>
|
||||
|
||||
<dimen name="dialog_margin">20dp</dimen>
|
||||
<dimen name="elevated_app_bar">3dp</dimen>
|
||||
|
@@ -72,6 +72,7 @@
|
||||
<string name="invalid_keys_error">Invalid encryption keys</string>
|
||||
<string name="dumping_keys_quickstart_link">https://yuzu-emu.org/help/quickstart/#dumping-decryption-keys</string>
|
||||
<string name="install_keys_failure_description">The selected file is incorrect or corrupt. Please redump your keys.</string>
|
||||
<string name="gpu_driver_manager">GPU Driver Manager</string>
|
||||
<string name="install_gpu_driver">Install GPU driver</string>
|
||||
<string name="install_gpu_driver_description">Install alternative drivers for potentially better performance or accuracy</string>
|
||||
<string name="advanced_settings">Advanced settings</string>
|
||||
@@ -234,15 +235,17 @@
|
||||
<string name="export_failed">Export failed</string>
|
||||
<string name="import_failed">Import failed</string>
|
||||
<string name="cancelling">Cancelling</string>
|
||||
<string name="install">Install</string>
|
||||
<string name="delete">Delete</string>
|
||||
|
||||
<!-- GPU driver installation -->
|
||||
<string name="select_gpu_driver">Select GPU driver</string>
|
||||
<string name="select_gpu_driver_title">Would you like to replace your current GPU driver?</string>
|
||||
<string name="select_gpu_driver_install">Install</string>
|
||||
<string name="select_gpu_driver_default">Default</string>
|
||||
<string name="select_gpu_driver_install_success">Installed %s</string>
|
||||
<string name="select_gpu_driver_use_default">Using default GPU driver</string>
|
||||
<string name="select_gpu_driver_error">Invalid driver selected, using system default!</string>
|
||||
<string name="select_gpu_driver_error">Invalid driver selected</string>
|
||||
<string name="driver_already_installed">Driver already installed</string>
|
||||
<string name="system_gpu_driver">System GPU driver</string>
|
||||
<string name="installing_driver">Installing driver…</string>
|
||||
|
||||
|
@@ -3405,6 +3405,11 @@ Result KPageTable::LockMemoryAndOpen(KPageGroup* out_pg, KPhysicalAddress* out_K
|
||||
new_attr, KMemoryBlockDisableMergeAttribute::Locked,
|
||||
KMemoryBlockDisableMergeAttribute::None);
|
||||
|
||||
// If we have an output page group, open.
|
||||
if (out_pg) {
|
||||
out_pg->Open();
|
||||
}
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
|
@@ -826,12 +826,13 @@ void GameList::PopulateAsync(QVector<UISettings::GameDir>& game_dirs) {
|
||||
tree_view->setColumnHidden(COLUMN_SIZE, !UISettings::values.show_size);
|
||||
tree_view->setColumnHidden(COLUMN_PLAY_TIME, !UISettings::values.show_play_time);
|
||||
|
||||
// Before deleting rows, cancel the worker so that it is not using them
|
||||
emit ShouldCancelWorker();
|
||||
|
||||
// Delete any rows that might already exist if we're repopulating
|
||||
item_model->removeRows(0, item_model->rowCount());
|
||||
search_field->clear();
|
||||
|
||||
emit ShouldCancelWorker();
|
||||
|
||||
GameListWorker* worker =
|
||||
new GameListWorker(vfs, provider, game_dirs, compatibility_list, play_time_manager, system);
|
||||
|
||||
|
@@ -293,7 +293,7 @@ void GameListWorker::AddTitlesToGameList(GameListDir* parent_dir) {
|
||||
void GameListWorker::ScanFileSystem(ScanTarget target, const std::string& dir_path, bool deep_scan,
|
||||
GameListDir* parent_dir) {
|
||||
const auto callback = [this, target, parent_dir](const std::filesystem::path& path) -> bool {
|
||||
if (stop_processing) {
|
||||
if (stop_requested) {
|
||||
// Breaks the callback loop.
|
||||
return false;
|
||||
}
|
||||
@@ -399,7 +399,6 @@ void GameListWorker::ScanFileSystem(ScanTarget target, const std::string& dir_pa
|
||||
}
|
||||
|
||||
void GameListWorker::run() {
|
||||
stop_processing = false;
|
||||
provider->ClearAllEntries();
|
||||
|
||||
for (UISettings::GameDir& game_dir : game_dirs) {
|
||||
@@ -427,9 +426,11 @@ void GameListWorker::run() {
|
||||
}
|
||||
|
||||
emit Finished(watch_list);
|
||||
processing_completed.Set();
|
||||
}
|
||||
|
||||
void GameListWorker::Cancel() {
|
||||
this->disconnect();
|
||||
stop_processing = true;
|
||||
stop_requested.store(true);
|
||||
processing_completed.Wait();
|
||||
}
|
||||
|
@@ -12,6 +12,7 @@
|
||||
#include <QRunnable>
|
||||
#include <QString>
|
||||
|
||||
#include "common/thread.h"
|
||||
#include "yuzu/compatibility_list.h"
|
||||
#include "yuzu/play_time_manager.h"
|
||||
|
||||
@@ -82,7 +83,9 @@ private:
|
||||
const PlayTime::PlayTimeManager& play_time_manager;
|
||||
|
||||
QStringList watch_list;
|
||||
std::atomic_bool stop_processing;
|
||||
|
||||
Common::Event processing_completed;
|
||||
std::atomic_bool stop_requested = false;
|
||||
|
||||
Core::System& system;
|
||||
};
|
||||
|
@@ -67,6 +67,7 @@ static FileSys::VirtualFile VfsDirectoryCreateFileWrapper(const FileSys::Virtual
|
||||
#define QT_NO_OPENGL
|
||||
#include <QClipboard>
|
||||
#include <QDesktopServices>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QFileDialog>
|
||||
#include <QInputDialog>
|
||||
@@ -98,7 +99,6 @@ static FileSys::VirtualFile VfsDirectoryCreateFileWrapper(const FileSys::Virtual
|
||||
#include "common/scm_rev.h"
|
||||
#include "common/scope_exit.h"
|
||||
#ifdef _WIN32
|
||||
#include <shlobj.h>
|
||||
#include "common/windows/timer_resolution.h"
|
||||
#endif
|
||||
#ifdef ARCHITECTURE_x86_64
|
||||
@@ -2841,21 +2841,17 @@ void GMainWindow::OnGameListNavigateToGamedbEntry(u64 program_id,
|
||||
|
||||
void GMainWindow::OnGameListCreateShortcut(u64 program_id, const std::string& game_path,
|
||||
GameListShortcutTarget target) {
|
||||
// Get path to yuzu executable
|
||||
const QStringList args = QApplication::arguments();
|
||||
std::filesystem::path yuzu_command = args[0].toStdString();
|
||||
|
||||
// If relative path, make it an absolute path
|
||||
if (yuzu_command.c_str()[0] == '.') {
|
||||
yuzu_command = Common::FS::GetCurrentDir() / yuzu_command;
|
||||
}
|
||||
const auto yuzu_command = QApplication::applicationFilePath();
|
||||
const auto target_directory = GetTargetPath(target);
|
||||
const std::string game_file_name = std::filesystem::path(game_path).filename().string();
|
||||
const std::filesystem::path icon_folder =
|
||||
Common::FS::GetYuzuPathString(Common::FS::YuzuPath::IconsDir);
|
||||
|
||||
#if defined(__linux__)
|
||||
// Warn once if we are making a shortcut to a volatile AppImage
|
||||
const std::string appimage_ending =
|
||||
std::string(Common::g_scm_rev).substr(0, 9).append(".AppImage");
|
||||
if (yuzu_command.string().ends_with(appimage_ending) &&
|
||||
!UISettings::values.shortcut_already_warned) {
|
||||
const QString appimage_ending =
|
||||
QString::fromStdString(std::string(Common::g_scm_rev).substr(0, 9).append(".AppImage"));
|
||||
if (yuzu_command.endsWith(appimage_ending) && !UISettings::values.shortcut_already_warned) {
|
||||
if (QMessageBox::warning(this, tr("Create Shortcut"),
|
||||
tr("This will create a shortcut to the current AppImage. This may "
|
||||
"not work well if you update. Continue?"),
|
||||
@@ -2866,71 +2862,15 @@ void GMainWindow::OnGameListCreateShortcut(u64 program_id, const std::string& ga
|
||||
}
|
||||
UISettings::values.shortcut_already_warned = true;
|
||||
}
|
||||
#endif // __linux__
|
||||
|
||||
std::filesystem::path target_directory{};
|
||||
// Determine target directory for shortcut
|
||||
#if defined(WIN32)
|
||||
const char* home = std::getenv("USERPROFILE");
|
||||
#else
|
||||
const char* home = std::getenv("HOME");
|
||||
#endif
|
||||
const std::filesystem::path home_path = (home == nullptr ? "~" : home);
|
||||
const char* xdg_data_home = std::getenv("XDG_DATA_HOME");
|
||||
|
||||
if (target == GameListShortcutTarget::Desktop) {
|
||||
target_directory = home_path / "Desktop";
|
||||
if (!Common::FS::IsDir(target_directory)) {
|
||||
// Ensure directory exist
|
||||
if (!QDir(target_directory).exists()) {
|
||||
QMessageBox::critical(
|
||||
this, tr("Create Shortcut"),
|
||||
tr("Cannot create shortcut on desktop. Path \"%1\" does not exist.")
|
||||
.arg(QString::fromStdString(target_directory.generic_string())),
|
||||
tr("Cannot create shortcut. Path \"%1\" does not exist.").arg(target_directory),
|
||||
QMessageBox::StandardButton::Ok);
|
||||
return;
|
||||
}
|
||||
} else if (target == GameListShortcutTarget::Applications) {
|
||||
target_directory = (xdg_data_home == nullptr ? home_path / ".local/share" : xdg_data_home) /
|
||||
"applications";
|
||||
if (!Common::FS::CreateDirs(target_directory)) {
|
||||
QMessageBox::critical(
|
||||
this, tr("Create Shortcut"),
|
||||
tr("Cannot create shortcut in applications menu. Path \"%1\" "
|
||||
"does not exist and cannot be created.")
|
||||
.arg(QString::fromStdString(target_directory.generic_string())),
|
||||
QMessageBox::StandardButton::Ok);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const std::string game_file_name = std::filesystem::path(game_path).filename().string();
|
||||
// Determine full paths for icon and shortcut
|
||||
#if defined(__linux__) || defined(__FreeBSD__)
|
||||
std::filesystem::path system_icons_path =
|
||||
(xdg_data_home == nullptr ? home_path / ".local/share/" : xdg_data_home) /
|
||||
"icons/hicolor/256x256";
|
||||
if (!Common::FS::CreateDirs(system_icons_path)) {
|
||||
QMessageBox::critical(
|
||||
this, tr("Create Icon"),
|
||||
tr("Cannot create icon file. Path \"%1\" does not exist and cannot be created.")
|
||||
.arg(QString::fromStdString(system_icons_path)),
|
||||
QMessageBox::StandardButton::Ok);
|
||||
return;
|
||||
}
|
||||
std::filesystem::path icon_path =
|
||||
system_icons_path / (program_id == 0 ? fmt::format("yuzu-{}.png", game_file_name)
|
||||
: fmt::format("yuzu-{:016X}.png", program_id));
|
||||
const std::filesystem::path shortcut_path =
|
||||
target_directory / (program_id == 0 ? fmt::format("yuzu-{}.desktop", game_file_name)
|
||||
: fmt::format("yuzu-{:016X}.desktop", program_id));
|
||||
#elif defined(WIN32)
|
||||
std::filesystem::path icons_path =
|
||||
Common::FS::GetYuzuPathString(Common::FS::YuzuPath::IconsDir);
|
||||
std::filesystem::path icon_path =
|
||||
icons_path / ((program_id == 0 ? fmt::format("yuzu-{}.ico", game_file_name)
|
||||
: fmt::format("yuzu-{:016X}.ico", program_id)));
|
||||
#else
|
||||
std::string icon_extension;
|
||||
#endif
|
||||
|
||||
// Get title from game file
|
||||
const FileSys::PatchManager pm{program_id, system->GetFileSystemController(),
|
||||
@@ -2946,6 +2886,14 @@ void GMainWindow::OnGameListCreateShortcut(u64 program_id, const std::string& ga
|
||||
loader->ReadTitle(title);
|
||||
}
|
||||
|
||||
// Remove characters that are illegal in Windows filenames
|
||||
const std::string illegal_chars = "<>:\"/\\|?*";
|
||||
for (char c : illegal_chars) {
|
||||
std::string temp_tile = "";
|
||||
std::remove_copy(title.begin(), title.end(), std::back_inserter(temp_tile), c);
|
||||
title = temp_tile;
|
||||
}
|
||||
|
||||
// Get icon from game file
|
||||
std::vector<u8> icon_image_file{};
|
||||
if (control.second != nullptr) {
|
||||
@@ -2954,30 +2902,23 @@ void GMainWindow::OnGameListCreateShortcut(u64 program_id, const std::string& ga
|
||||
LOG_WARNING(Frontend, "Could not read icon from {:s}", game_path);
|
||||
}
|
||||
|
||||
QImage icon_data =
|
||||
std::string icon_name{};
|
||||
#ifdef _WIN32
|
||||
icon_name = program_id == 0 ? fmt::format("yuzu-{}.ico", game_file_name)
|
||||
: fmt::format("yuzu-{:016X}.ico", program_id);
|
||||
#else
|
||||
icon_name = program_id == 0 ? fmt::format("yuzu-{}.png", game_file_name)
|
||||
: fmt::format("yuzu-{:016X}.png", program_id);
|
||||
#endif
|
||||
|
||||
const QImage icon_data =
|
||||
QImage::fromData(icon_image_file.data(), static_cast<int>(icon_image_file.size()));
|
||||
#if defined(__linux__) || defined(__FreeBSD__)
|
||||
// Convert and write the icon as a PNG
|
||||
if (!icon_data.save(QString::fromStdString(icon_path.string()))) {
|
||||
LOG_ERROR(Frontend, "Could not write icon as PNG to file");
|
||||
} else {
|
||||
LOG_INFO(Frontend, "Wrote an icon to {}", icon_path.string());
|
||||
}
|
||||
#elif defined(WIN32)
|
||||
if (!SaveIconToFile(icon_path.string(), icon_data)) {
|
||||
const auto qt_icon_file_path =
|
||||
QString::fromStdString(fmt::format("{}/{}", icon_folder.string(), icon_name));
|
||||
if (!SaveIconToFile(qt_icon_file_path, icon_data)) {
|
||||
LOG_ERROR(Frontend, "Could not write icon to file");
|
||||
return;
|
||||
}
|
||||
#endif // __linux__
|
||||
|
||||
#ifdef _WIN32
|
||||
// Replace characters that are illegal in Windows filenames by a dash
|
||||
const std::string illegal_chars = "<>:\"/\\|?*";
|
||||
for (char c : illegal_chars) {
|
||||
std::replace(title.begin(), title.end(), c, '_');
|
||||
}
|
||||
const std::filesystem::path shortcut_path = target_directory / (title + ".lnk").c_str();
|
||||
#endif
|
||||
|
||||
const std::string comment =
|
||||
tr("Start %1 with the yuzu Emulator").arg(QString::fromStdString(title)).toStdString();
|
||||
@@ -2985,8 +2926,17 @@ void GMainWindow::OnGameListCreateShortcut(u64 program_id, const std::string& ga
|
||||
const std::string categories = "Game;Emulator;Qt;";
|
||||
const std::string keywords = "Switch;Nintendo;";
|
||||
|
||||
if (!CreateShortcut(shortcut_path.string(), title, comment, icon_path.string(),
|
||||
yuzu_command.string(), arguments, categories, keywords)) {
|
||||
std::filesystem::path shortcut_path = "";
|
||||
#ifdef _WIN32
|
||||
shortcut_path = fmt::format("{}/{}.lnk", target_directory.toUtf8().toStdString(), title);
|
||||
#else
|
||||
shortcut_path =
|
||||
fmt::format("{}/yuzu-{}.desktop", target_directory.toUtf8().toStdString(), title);
|
||||
#endif
|
||||
|
||||
if (!CreateShortcut(shortcut_path.string(), title, comment,
|
||||
qt_icon_file_path.toUtf8().toStdString(),
|
||||
yuzu_command.toUtf8().toStdString(), arguments, categories, keywords)) {
|
||||
QMessageBox::critical(this, tr("Create Shortcut"),
|
||||
tr("Failed to create a shortcut at %1")
|
||||
.arg(QString::fromStdString(shortcut_path.string())));
|
||||
@@ -3978,66 +3928,6 @@ void GMainWindow::OpenPerGameConfiguration(u64 title_id, const std::string& file
|
||||
}
|
||||
}
|
||||
|
||||
bool GMainWindow::CreateShortcut(const std::string& shortcut_path, const std::string& title,
|
||||
const std::string& comment, const std::string& icon_path,
|
||||
const std::string& command, const std::string& arguments,
|
||||
const std::string& categories, const std::string& keywords) {
|
||||
#if defined(__linux__) || defined(__FreeBSD__)
|
||||
// This desktop file template was writing referencing
|
||||
// https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-1.0.html
|
||||
std::string shortcut_contents{};
|
||||
shortcut_contents.append("[Desktop Entry]\n");
|
||||
shortcut_contents.append("Type=Application\n");
|
||||
shortcut_contents.append("Version=1.0\n");
|
||||
shortcut_contents.append(fmt::format("Name={:s}\n", title));
|
||||
shortcut_contents.append(fmt::format("Comment={:s}\n", comment));
|
||||
shortcut_contents.append(fmt::format("Icon={:s}\n", icon_path));
|
||||
shortcut_contents.append(fmt::format("TryExec={:s}\n", command));
|
||||
shortcut_contents.append(fmt::format("Exec={:s} {:s}\n", command, arguments));
|
||||
shortcut_contents.append(fmt::format("Categories={:s}\n", categories));
|
||||
shortcut_contents.append(fmt::format("Keywords={:s}\n", keywords));
|
||||
|
||||
std::ofstream shortcut_stream(shortcut_path);
|
||||
if (!shortcut_stream.is_open()) {
|
||||
LOG_WARNING(Common, "Failed to create file {:s}", shortcut_path);
|
||||
return false;
|
||||
}
|
||||
shortcut_stream << shortcut_contents;
|
||||
shortcut_stream.close();
|
||||
|
||||
return true;
|
||||
#elif defined(WIN32)
|
||||
IShellLinkW* shell_link;
|
||||
auto hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLinkW,
|
||||
(void**)&shell_link);
|
||||
if (FAILED(hres)) {
|
||||
return false;
|
||||
}
|
||||
shell_link->SetPath(
|
||||
Common::UTF8ToUTF16W(command).data()); // Path to the object we are referring to
|
||||
shell_link->SetArguments(Common::UTF8ToUTF16W(arguments).data());
|
||||
shell_link->SetDescription(Common::UTF8ToUTF16W(comment).data());
|
||||
shell_link->SetIconLocation(Common::UTF8ToUTF16W(icon_path).data(), 0);
|
||||
|
||||
IPersistFile* persist_file;
|
||||
hres = shell_link->QueryInterface(IID_IPersistFile, (void**)&persist_file);
|
||||
if (FAILED(hres)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
hres = persist_file->Save(Common::UTF8ToUTF16W(shortcut_path).data(), TRUE);
|
||||
if (FAILED(hres)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
persist_file->Release();
|
||||
shell_link->Release();
|
||||
|
||||
return true;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
void GMainWindow::OnLoadAmiibo() {
|
||||
if (emu_thread == nullptr || !emu_thread->IsRunning()) {
|
||||
return;
|
||||
|
@@ -426,10 +426,6 @@ private:
|
||||
void ConfigureFilesystemProvider(const std::string& filepath);
|
||||
|
||||
QString GetTasStateDescription() const;
|
||||
bool CreateShortcut(const std::string& shortcut_path, const std::string& title,
|
||||
const std::string& comment, const std::string& icon_path,
|
||||
const std::string& command, const std::string& arguments,
|
||||
const std::string& categories, const std::string& keywords);
|
||||
|
||||
std::unique_ptr<Ui::MainWindow> ui;
|
||||
|
||||
|
@@ -3,11 +3,19 @@
|
||||
|
||||
#include <array>
|
||||
#include <cmath>
|
||||
#include <fstream>
|
||||
#include <QApplication>
|
||||
#include <QPainter>
|
||||
#include "yuzu/util/util.h"
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#include <QStandardPaths>
|
||||
|
||||
#include "common/fs/file.h"
|
||||
#include "common/string_util.h"
|
||||
#include "yuzu/game_list.h"
|
||||
#include "yuzu/util/util.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <shlobj.h>
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
QFont GetMonospaceFont() {
|
||||
@@ -42,7 +50,27 @@ QPixmap CreateCirclePixmapFromColor(const QColor& color) {
|
||||
return circle_pixmap;
|
||||
}
|
||||
|
||||
bool SaveIconToFile(const std::string_view path, const QImage& image) {
|
||||
QString GetTargetPath(GameListShortcutTarget target) {
|
||||
if (target == GameListShortcutTarget::Desktop) {
|
||||
return QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
|
||||
}
|
||||
|
||||
if (target != GameListShortcutTarget::Applications) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const QString applications_path =
|
||||
QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation);
|
||||
|
||||
if (!applications_path.isEmpty()) {
|
||||
return applications_path;
|
||||
}
|
||||
|
||||
// If Qt fails to find the application path try to use the generic location
|
||||
return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation);
|
||||
}
|
||||
|
||||
bool SaveIconToFile(const QString file_path, const QImage& image) {
|
||||
#if defined(WIN32)
|
||||
#pragma pack(push, 2)
|
||||
struct IconDir {
|
||||
@@ -73,7 +101,8 @@ bool SaveIconToFile(const std::string_view path, const QImage& image) {
|
||||
.id_count = static_cast<WORD>(scale_sizes.size()),
|
||||
};
|
||||
|
||||
Common::FS::IOFile icon_file(path, Common::FS::FileAccessMode::Write,
|
||||
Common::FS::IOFile icon_file(file_path.toUtf8().toStdString(),
|
||||
Common::FS::FileAccessMode::Write,
|
||||
Common::FS::FileType::BinaryFile);
|
||||
if (!icon_file.IsOpen()) {
|
||||
return false;
|
||||
@@ -136,6 +165,66 @@ bool SaveIconToFile(const std::string_view path, const QImage& image) {
|
||||
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
return image.save(file_path);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool CreateShortcut(const std::string& shortcut_path, const std::string& title,
|
||||
const std::string& comment, const std::string& icon_path,
|
||||
const std::string& command, const std::string& arguments,
|
||||
const std::string& categories, const std::string& keywords) {
|
||||
#if defined(__linux__) || defined(__FreeBSD__)
|
||||
// This desktop file template was writing referencing
|
||||
// https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-1.0.html
|
||||
std::string shortcut_contents{};
|
||||
shortcut_contents.append("[Desktop Entry]\n");
|
||||
shortcut_contents.append("Type=Application\n");
|
||||
shortcut_contents.append("Version=1.0\n");
|
||||
shortcut_contents.append(fmt::format("Name={:s}\n", title));
|
||||
shortcut_contents.append(fmt::format("Comment={:s}\n", comment));
|
||||
shortcut_contents.append(fmt::format("Icon={:s}\n", icon_path));
|
||||
shortcut_contents.append(fmt::format("TryExec={:s}\n", command));
|
||||
shortcut_contents.append(fmt::format("Exec={:s} {:s}\n", command, arguments));
|
||||
shortcut_contents.append(fmt::format("Categories={:s}\n", categories));
|
||||
shortcut_contents.append(fmt::format("Keywords={:s}\n", keywords));
|
||||
|
||||
std::ofstream shortcut_stream(shortcut_path);
|
||||
if (!shortcut_stream.is_open()) {
|
||||
LOG_WARNING(Common, "Failed to create file {:s}", shortcut_path);
|
||||
return false;
|
||||
}
|
||||
shortcut_stream << shortcut_contents;
|
||||
shortcut_stream.close();
|
||||
|
||||
return true;
|
||||
#elif defined(WIN32)
|
||||
IShellLinkW* shell_link;
|
||||
auto hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLinkW,
|
||||
(void**)&shell_link);
|
||||
if (FAILED(hres)) {
|
||||
return false;
|
||||
}
|
||||
shell_link->SetPath(
|
||||
Common::UTF8ToUTF16W(command).data()); // Path to the object we are referring to
|
||||
shell_link->SetArguments(Common::UTF8ToUTF16W(arguments).data());
|
||||
shell_link->SetDescription(Common::UTF8ToUTF16W(comment).data());
|
||||
shell_link->SetIconLocation(Common::UTF8ToUTF16W(icon_path).data(), 0);
|
||||
|
||||
IPersistFile* persist_file;
|
||||
hres = shell_link->QueryInterface(IID_IPersistFile, (void**)&persist_file);
|
||||
if (FAILED(hres)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
hres = persist_file->Save(Common::UTF8ToUTF16W(shortcut_path).data(), TRUE);
|
||||
if (FAILED(hres)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
persist_file->Release();
|
||||
shell_link->Release();
|
||||
|
||||
return true;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
@@ -4,8 +4,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <QFont>
|
||||
#include <QImage>
|
||||
#include <QString>
|
||||
|
||||
enum class GameListShortcutTarget;
|
||||
|
||||
/// Returns a QFont object appropriate to use as a monospace font for debugging widgets, etc.
|
||||
[[nodiscard]] QFont GetMonospaceFont();
|
||||
|
||||
@@ -19,10 +22,25 @@
|
||||
*/
|
||||
[[nodiscard]] QPixmap CreateCirclePixmapFromColor(const QColor& color);
|
||||
|
||||
/**
|
||||
* Returns the path of the provided shortcut target
|
||||
* @return QString containing the path to the target
|
||||
*/
|
||||
[[nodiscard]] QString GetTargetPath(GameListShortcutTarget target);
|
||||
|
||||
/**
|
||||
* Saves a windows icon to a file
|
||||
* @param path The icons path
|
||||
* @param file_path The icon file path
|
||||
* @param image The image to save
|
||||
* @return bool If the operation succeeded
|
||||
*/
|
||||
[[nodiscard]] bool SaveIconToFile(const std::string_view path, const QImage& image);
|
||||
[[nodiscard]] bool SaveIconToFile(const QString file_path, const QImage& image);
|
||||
|
||||
/**
|
||||
* Creates and saves a shortcut to the shortcut_path
|
||||
* @return bool If the operation succeeded
|
||||
*/
|
||||
bool CreateShortcut(const std::string& shortcut_path, const std::string& title,
|
||||
const std::string& comment, const std::string& icon_path,
|
||||
const std::string& command, const std::string& arguments,
|
||||
const std::string& categories, const std::string& keywords);
|
||||
|
Reference in New Issue
Block a user