mirror of
https://github.com/starr-dusT/yuzu-mainline
synced 2024-03-05 21:12:25 -08:00
android: Fix game content installer
Before this would run on the main thread and freeze the device. Additionally this fixes the result dialog not appearing if a config change happens during the installation by getting the activity's fragment manager when needed.
This commit is contained in:
parent
d833fc383d
commit
50d4e0f4f7
@ -34,7 +34,7 @@ class IndeterminateProgressDialogFragment : DialogFragment() {
|
|||||||
when (val result = taskViewModel.result.value) {
|
when (val result = taskViewModel.result.value) {
|
||||||
is String -> Toast.makeText(requireContext(), result, Toast.LENGTH_LONG).show()
|
is String -> Toast.makeText(requireContext(), result, Toast.LENGTH_LONG).show()
|
||||||
is MessageDialogFragment -> result.show(
|
is MessageDialogFragment -> result.show(
|
||||||
parentFragmentManager,
|
requireActivity().supportFragmentManager,
|
||||||
MessageDialogFragment.TAG
|
MessageDialogFragment.TAG
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -501,96 +501,91 @@ class MainActivity : AppCompatActivity(), ThemeProvider {
|
|||||||
var errorBaseGame = 0
|
var errorBaseGame = 0
|
||||||
var errorExtension = 0
|
var errorExtension = 0
|
||||||
var errorOther = 0
|
var errorOther = 0
|
||||||
var errorTotal = 0
|
documents.forEach {
|
||||||
lifecycleScope.launch {
|
when (NativeLibrary.installFileToNand(it.toString())) {
|
||||||
documents.forEach {
|
NativeLibrary.InstallFileToNandResult.Success -> {
|
||||||
when (NativeLibrary.installFileToNand(it.toString())) {
|
installSuccess += 1
|
||||||
NativeLibrary.InstallFileToNandResult.Success -> {
|
|
||||||
installSuccess += 1
|
|
||||||
}
|
|
||||||
|
|
||||||
NativeLibrary.InstallFileToNandResult.SuccessFileOverwritten -> {
|
|
||||||
installOverwrite += 1
|
|
||||||
}
|
|
||||||
|
|
||||||
NativeLibrary.InstallFileToNandResult.ErrorBaseGame -> {
|
|
||||||
errorBaseGame += 1
|
|
||||||
}
|
|
||||||
|
|
||||||
NativeLibrary.InstallFileToNandResult.ErrorFilenameExtension -> {
|
|
||||||
errorExtension += 1
|
|
||||||
}
|
|
||||||
|
|
||||||
else -> {
|
|
||||||
errorOther += 1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
withContext(Dispatchers.Main) {
|
NativeLibrary.InstallFileToNandResult.SuccessFileOverwritten -> {
|
||||||
val separator = System.getProperty("line.separator") ?: "\n"
|
installOverwrite += 1
|
||||||
val installResult = StringBuilder()
|
|
||||||
if (installSuccess > 0) {
|
|
||||||
installResult.append(
|
|
||||||
getString(
|
|
||||||
R.string.install_game_content_success_install,
|
|
||||||
installSuccess
|
|
||||||
)
|
|
||||||
)
|
|
||||||
installResult.append(separator)
|
|
||||||
}
|
}
|
||||||
if (installOverwrite > 0) {
|
|
||||||
installResult.append(
|
NativeLibrary.InstallFileToNandResult.ErrorBaseGame -> {
|
||||||
getString(
|
errorBaseGame += 1
|
||||||
R.string.install_game_content_success_overwrite,
|
|
||||||
installOverwrite
|
|
||||||
)
|
|
||||||
)
|
|
||||||
installResult.append(separator)
|
|
||||||
}
|
}
|
||||||
errorTotal = errorBaseGame + errorExtension + errorOther
|
|
||||||
if (errorTotal > 0) {
|
NativeLibrary.InstallFileToNandResult.ErrorFilenameExtension -> {
|
||||||
installResult.append(separator)
|
errorExtension += 1
|
||||||
installResult.append(
|
}
|
||||||
getString(
|
|
||||||
R.string.install_game_content_failed_count,
|
else -> {
|
||||||
errorTotal
|
errorOther += 1
|
||||||
)
|
|
||||||
)
|
|
||||||
installResult.append(separator)
|
|
||||||
if (errorBaseGame > 0) {
|
|
||||||
installResult.append(separator)
|
|
||||||
installResult.append(
|
|
||||||
getString(R.string.install_game_content_failure_base)
|
|
||||||
)
|
|
||||||
installResult.append(separator)
|
|
||||||
}
|
|
||||||
if (errorExtension > 0) {
|
|
||||||
installResult.append(separator)
|
|
||||||
installResult.append(
|
|
||||||
getString(R.string.install_game_content_failure_file_extension)
|
|
||||||
)
|
|
||||||
installResult.append(separator)
|
|
||||||
}
|
|
||||||
if (errorOther > 0) {
|
|
||||||
installResult.append(
|
|
||||||
getString(R.string.install_game_content_failure_description)
|
|
||||||
)
|
|
||||||
installResult.append(separator)
|
|
||||||
}
|
|
||||||
MessageDialogFragment.newInstance(
|
|
||||||
titleId = R.string.install_game_content_failure,
|
|
||||||
descriptionString = installResult.toString().trim(),
|
|
||||||
helpLinkId = R.string.install_game_content_help_link
|
|
||||||
).show(supportFragmentManager, MessageDialogFragment.TAG)
|
|
||||||
} else {
|
|
||||||
MessageDialogFragment.newInstance(
|
|
||||||
titleId = R.string.install_game_content_success,
|
|
||||||
descriptionString = installResult.toString().trim()
|
|
||||||
).show(supportFragmentManager, MessageDialogFragment.TAG)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return@newInstance installSuccess + installOverwrite + errorTotal
|
|
||||||
|
val separator = System.getProperty("line.separator") ?: "\n"
|
||||||
|
val installResult = StringBuilder()
|
||||||
|
if (installSuccess > 0) {
|
||||||
|
installResult.append(
|
||||||
|
getString(
|
||||||
|
R.string.install_game_content_success_install,
|
||||||
|
installSuccess
|
||||||
|
)
|
||||||
|
)
|
||||||
|
installResult.append(separator)
|
||||||
|
}
|
||||||
|
if (installOverwrite > 0) {
|
||||||
|
installResult.append(
|
||||||
|
getString(
|
||||||
|
R.string.install_game_content_success_overwrite,
|
||||||
|
installOverwrite
|
||||||
|
)
|
||||||
|
)
|
||||||
|
installResult.append(separator)
|
||||||
|
}
|
||||||
|
val errorTotal: Int = errorBaseGame + errorExtension + errorOther
|
||||||
|
if (errorTotal > 0) {
|
||||||
|
installResult.append(separator)
|
||||||
|
installResult.append(
|
||||||
|
getString(
|
||||||
|
R.string.install_game_content_failed_count,
|
||||||
|
errorTotal
|
||||||
|
)
|
||||||
|
)
|
||||||
|
installResult.append(separator)
|
||||||
|
if (errorBaseGame > 0) {
|
||||||
|
installResult.append(separator)
|
||||||
|
installResult.append(
|
||||||
|
getString(R.string.install_game_content_failure_base)
|
||||||
|
)
|
||||||
|
installResult.append(separator)
|
||||||
|
}
|
||||||
|
if (errorExtension > 0) {
|
||||||
|
installResult.append(separator)
|
||||||
|
installResult.append(
|
||||||
|
getString(R.string.install_game_content_failure_file_extension)
|
||||||
|
)
|
||||||
|
installResult.append(separator)
|
||||||
|
}
|
||||||
|
if (errorOther > 0) {
|
||||||
|
installResult.append(
|
||||||
|
getString(R.string.install_game_content_failure_description)
|
||||||
|
)
|
||||||
|
installResult.append(separator)
|
||||||
|
}
|
||||||
|
return@newInstance MessageDialogFragment.newInstance(
|
||||||
|
titleId = R.string.install_game_content_failure,
|
||||||
|
descriptionString = installResult.toString().trim(),
|
||||||
|
helpLinkId = R.string.install_game_content_help_link
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
return@newInstance MessageDialogFragment.newInstance(
|
||||||
|
titleId = R.string.install_game_content_success,
|
||||||
|
descriptionString = installResult.toString().trim()
|
||||||
|
)
|
||||||
|
}
|
||||||
}.show(supportFragmentManager, IndeterminateProgressDialogFragment.TAG)
|
}.show(supportFragmentManager, IndeterminateProgressDialogFragment.TAG)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user