From c3fa970dd572b6cd5daa836840d47315caaa5e81 Mon Sep 17 00:00:00 2001 From: pineappleEA Date: Thu, 4 Jan 2024 23:54:31 +0100 Subject: [PATCH] early-access version 4046 --- README.md | 2 +- .../features/settings/model/Settings.kt | 17 +++++++++-- .../yuzu_emu/fragments/EmulationFragment.kt | 28 +++++++++++++------ .../fragments/GamePropertiesFragment.kt | 3 +- .../org/yuzu/yuzu_emu/model/GamesViewModel.kt | 5 ++-- .../org/yuzu/yuzu_emu/ui/main/MainActivity.kt | 3 +- .../java/org/yuzu/yuzu_emu/utils/FileUtil.kt | 12 +++++++- .../app/src/main/jni/android_config.cpp | 6 ---- src/android/app/src/main/jni/android_config.h | 1 - .../app/src/main/res/values/arrays.xml | 16 ++++++++--- .../app/src/main/res/values/strings.xml | 8 ++++-- .../hid/controllers/npad/npad_data.cpp | 2 ++ src/frontend_common/config.cpp | 16 ++--------- src/frontend_common/config.h | 16 +++++++---- 14 files changed, 87 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index 067cd8d0b..ce76e0b28 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ yuzu emulator early access ============= -This is the source code for early-access 4045. +This is the source code for early-access 4046. ## Legal Notice diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/Settings.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/Settings.kt index 43caac989..fee80bb21 100755 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/Settings.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/Settings.kt @@ -79,7 +79,18 @@ object Settings { const val PREF_THEME_MODE = "ThemeMode" const val PREF_BLACK_BACKGROUNDS = "BlackBackgrounds" - const val LayoutOption_Unspecified = 0 - const val LayoutOption_MobilePortrait = 4 - const val LayoutOption_MobileLandscape = 5 + enum class EmulationOrientation(val int: Int) { + Unspecified(0), + SensorLandscape(5), + Landscape(1), + ReverseLandscape(2), + SensorPortrait(6), + Portrait(4), + ReversePortrait(3); + + companion object { + fun from(int: Int): EmulationOrientation = + entries.firstOrNull { it.int == int } ?: Unspecified + } + } } diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt index 510b2b5eb..9efc1705d 100755 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt @@ -50,6 +50,7 @@ import org.yuzu.yuzu_emu.databinding.FragmentEmulationBinding import org.yuzu.yuzu_emu.features.settings.model.BooleanSetting import org.yuzu.yuzu_emu.features.settings.model.IntSetting import org.yuzu.yuzu_emu.features.settings.model.Settings +import org.yuzu.yuzu_emu.features.settings.model.Settings.EmulationOrientation import org.yuzu.yuzu_emu.features.settings.utils.SettingsFile import org.yuzu.yuzu_emu.model.DriverViewModel import org.yuzu.yuzu_emu.model.Game @@ -99,6 +100,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { */ override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + updateOrientation() val intentUri: Uri? = requireActivity().intent.data var intentGame: Game? = null @@ -458,13 +460,23 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { @SuppressLint("SourceLockedOrientationActivity") private fun updateOrientation() { emulationActivity?.let { - it.requestedOrientation = when (IntSetting.RENDERER_SCREEN_LAYOUT.getInt()) { - Settings.LayoutOption_MobileLandscape -> + val orientationSetting = + EmulationOrientation.from(IntSetting.RENDERER_SCREEN_LAYOUT.getInt()) + it.requestedOrientation = when (orientationSetting) { + EmulationOrientation.Unspecified -> ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED + EmulationOrientation.SensorLandscape -> ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE - Settings.LayoutOption_MobilePortrait -> - ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT - Settings.LayoutOption_Unspecified -> ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED - else -> ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE + + EmulationOrientation.Landscape -> ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE + EmulationOrientation.ReverseLandscape -> + ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE + + EmulationOrientation.SensorPortrait -> + ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT + + EmulationOrientation.Portrait -> ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + EmulationOrientation.ReversePortrait -> + ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT } } } @@ -651,7 +663,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { @SuppressLint("SourceLockedOrientationActivity") private fun startConfiguringControls() { // Lock the current orientation to prevent editing inconsistencies - if (IntSetting.RENDERER_SCREEN_LAYOUT.getInt() == Settings.LayoutOption_Unspecified) { + if (IntSetting.RENDERER_SCREEN_LAYOUT.getInt() == EmulationOrientation.Unspecified.int) { emulationActivity?.let { it.requestedOrientation = if (resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT) { @@ -669,7 +681,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { binding.doneControlConfig.visibility = View.GONE binding.surfaceInputOverlay.setIsInEditMode(false) // Unlock the orientation if it was locked for editing - if (IntSetting.RENDERER_SCREEN_LAYOUT.getInt() == Settings.LayoutOption_Unspecified) { + if (IntSetting.RENDERER_SCREEN_LAYOUT.getInt() == EmulationOrientation.Unspecified.int) { emulationActivity?.let { it.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/GamePropertiesFragment.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/GamePropertiesFragment.kt index b1d3c0040..b04d1208f 100755 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/GamePropertiesFragment.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/GamePropertiesFragment.kt @@ -445,7 +445,8 @@ class GamePropertiesFragment : Fragment() { val zipResult = FileUtil.zipFromInternalStorage( File(saveLocation), saveLocation.replaceAfterLast("/", ""), - BufferedOutputStream(requireContext().contentResolver.openOutputStream(result)) + BufferedOutputStream(requireContext().contentResolver.openOutputStream(result)), + compression = false ) return@newInstance when (zipResult) { TaskState.Completed -> getString(R.string.export_success) diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/GamesViewModel.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/GamesViewModel.kt index d19f20dc2..5ae05b5cc 100755 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/GamesViewModel.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/GamesViewModel.kt @@ -167,13 +167,14 @@ class GamesViewModel : ViewModel() { } } - fun onCloseGameFoldersFragment() = + fun onCloseGameFoldersFragment() { + NativeConfig.saveGlobalConfig() viewModelScope.launch { withContext(Dispatchers.IO) { - NativeConfig.saveGlobalConfig() getGameDirs(true) } } + } private fun getGameDirs(reloadList: Boolean = false) { val gameDirs = NativeConfig.getGameDirs() diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt index b4117d761..622ae996e 100755 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt @@ -625,7 +625,8 @@ class MainActivity : AppCompatActivity(), ThemeProvider { File(DirectoryInitialization.userDirectory!!), DirectoryInitialization.userDirectory!!, BufferedOutputStream(contentResolver.openOutputStream(result)), - taskViewModel.cancelled + taskViewModel.cancelled, + compression = false ) return@newInstance when (zipResult) { TaskState.Completed -> getString(R.string.user_data_export_success) diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/FileUtil.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/FileUtil.kt index 00c6bf90e..132f002fb 100755 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/FileUtil.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/FileUtil.kt @@ -21,6 +21,7 @@ import org.yuzu.yuzu_emu.model.TaskState import java.io.BufferedOutputStream import java.lang.NullPointerException import java.nio.charset.StandardCharsets +import java.util.zip.Deflater import java.util.zip.ZipOutputStream import kotlin.IllegalStateException @@ -312,15 +313,23 @@ object FileUtil { * @param inputFile File representation of the item that will be zipped * @param rootDir Directory containing the inputFile * @param outputStream Stream where the zip file will be output + * @param cancelled [StateFlow] that reports whether this process has been cancelled + * @param compression Disables compression if true */ fun zipFromInternalStorage( inputFile: File, rootDir: String, outputStream: BufferedOutputStream, - cancelled: StateFlow? = null + cancelled: StateFlow? = null, + compression: Boolean = true ): TaskState { try { ZipOutputStream(outputStream).use { zos -> + if (!compression) { + zos.setMethod(ZipOutputStream.DEFLATED) + zos.setLevel(Deflater.NO_COMPRESSION) + } + inputFile.walkTopDown().forEach { file -> if (cancelled?.value == true) { return TaskState.Cancelled @@ -338,6 +347,7 @@ object FileUtil { } } } catch (e: Exception) { + Log.error("[FileUtil] Failed creating zip file - ${e.message}") return TaskState.Failed } return TaskState.Completed diff --git a/src/android/app/src/main/jni/android_config.cpp b/src/android/app/src/main/jni/android_config.cpp index c86aa1c39..08aed3216 100755 --- a/src/android/app/src/main/jni/android_config.cpp +++ b/src/android/app/src/main/jni/android_config.cpp @@ -14,12 +14,6 @@ AndroidConfig::AndroidConfig(const std::string& config_name, ConfigType config_t } } -AndroidConfig::~AndroidConfig() { - if (global) { - AndroidConfig::SaveAllValues(); - } -} - void AndroidConfig::ReloadAllValues() { Reload(); ReadAndroidValues(); diff --git a/src/android/app/src/main/jni/android_config.h b/src/android/app/src/main/jni/android_config.h index d83852de9..693e1e3f0 100755 --- a/src/android/app/src/main/jni/android_config.h +++ b/src/android/app/src/main/jni/android_config.h @@ -9,7 +9,6 @@ class AndroidConfig final : public Config { public: explicit AndroidConfig(const std::string& config_name = "config", ConfigType config_type = ConfigType::GlobalConfig); - ~AndroidConfig() override; void ReloadAllValues() override; void SaveAllValues() override; diff --git a/src/android/app/src/main/res/values/arrays.xml b/src/android/app/src/main/res/values/arrays.xml index 45d57c3ea..0363ff3b6 100755 --- a/src/android/app/src/main/res/values/arrays.xml +++ b/src/android/app/src/main/res/values/arrays.xml @@ -118,15 +118,23 @@ - @string/screen_layout_landscape - @string/screen_layout_portrait @string/screen_layout_auto + @string/screen_layout_sensor_landscape + @string/screen_layout_landscape + @string/screen_layout_reverse_landscape + @string/screen_layout_sensor_portrait + @string/screen_layout_portrait + @string/screen_layout_reverse_portrait - 5 - 4 0 + 5 + 1 + 2 + 6 + 4 + 3 diff --git a/src/android/app/src/main/res/values/strings.xml b/src/android/app/src/main/res/values/strings.xml index 1bedcb1ef..83aa1b781 100755 --- a/src/android/app/src/main/res/values/strings.xml +++ b/src/android/app/src/main/res/values/strings.xml @@ -463,9 +463,13 @@ SMAA - Landscape - Portrait Auto + Sensor landscape + Landscape + Reverse landscape + Sensor portrait + Portrait + Reverse portrait Default (16:9) diff --git a/src/core/hle/service/hid/controllers/npad/npad_data.cpp b/src/core/hle/service/hid/controllers/npad/npad_data.cpp index c8cfe5d0e..d2423b6d3 100755 --- a/src/core/hle/service/hid/controllers/npad/npad_data.cpp +++ b/src/core/hle/service/hid/controllers/npad/npad_data.cpp @@ -153,6 +153,8 @@ bool NPadData::IsNpadStyleIndexSupported(Core::HID::NpadStyleIndex style_index) switch (style_index) { case Core::HID::NpadStyleIndex::ProController: return style.fullkey.As(); + case Core::HID::NpadStyleIndex::Handheld: + return style.handheld.As(); case Core::HID::NpadStyleIndex::JoyconDual: return style.joycon_dual.As(); case Core::HID::NpadStyleIndex::JoyconLeft: diff --git a/src/frontend_common/config.cpp b/src/frontend_common/config.cpp index 51576b4ee..20de91ff4 100755 --- a/src/frontend_common/config.cpp +++ b/src/frontend_common/config.cpp @@ -762,17 +762,6 @@ void Config::WriteBooleanSetting(const std::string& key, const bool& value, WritePreparedSetting(key, AdjustOutputString(ToString(value)), string_default, use_global); } -template -std::enable_if_t> Config::WriteIntegerSetting( - const std::string& key, const T& value, const std::optional& default_value, - const std::optional& use_global) { - std::optional string_default = std::nullopt; - if (default_value.has_value()) { - string_default = std::make_optional(ToString(default_value.value())); - } - WritePreparedSetting(key, AdjustOutputString(ToString(value)), string_default, use_global); -} - void Config::WriteDoubleSetting(const std::string& key, const double& value, const std::optional& default_value, const std::optional& use_global) { @@ -894,9 +883,10 @@ void Config::WriteSettingGeneric(const Settings::BasicSetting* const setting) { WriteBooleanSetting(std::string(key).append("\\use_global"), setting->UsingGlobal()); } if (global || !setting->UsingGlobal()) { + auto value = global ? setting->ToStringGlobal() : setting->ToString(); WriteBooleanSetting(std::string(key).append("\\default"), - setting->ToString() == setting->DefaultToString()); - WriteStringSetting(key, setting->ToString()); + value == setting->DefaultToString()); + WriteStringSetting(key, value); } } else if (global) { WriteBooleanSetting(std::string(key).append("\\default"), diff --git a/src/frontend_common/config.h b/src/frontend_common/config.h index 0c4d505b8..b01631649 100755 --- a/src/frontend_common/config.h +++ b/src/frontend_common/config.h @@ -157,17 +157,23 @@ protected: void WriteBooleanSetting(const std::string& key, const bool& value, const std::optional& default_value = std::nullopt, const std::optional& use_global = std::nullopt); - template - std::enable_if_t> WriteIntegerSetting( - const std::string& key, const T& value, - const std::optional& default_value = std::nullopt, - const std::optional& use_global = std::nullopt); void WriteDoubleSetting(const std::string& key, const double& value, const std::optional& default_value = std::nullopt, const std::optional& use_global = std::nullopt); void WriteStringSetting(const std::string& key, const std::string& value, const std::optional& default_value = std::nullopt, const std::optional& use_global = std::nullopt); + template + std::enable_if_t> WriteIntegerSetting( + const std::string& key, const T& value, + const std::optional& default_value = std::nullopt, + const std::optional& use_global = std::nullopt) { + std::optional string_default = std::nullopt; + if (default_value.has_value()) { + string_default = std::make_optional(ToString(default_value.value())); + } + WritePreparedSetting(key, AdjustOutputString(ToString(value)), string_default, use_global); + } void ReadCategory(Settings::Category category); void WriteCategory(Settings::Category category);