Z3DS: Fix minor issues and add Android cia compress setting

This commit is contained in:
PabloMK7 2025-07-13 00:32:56 +01:00
parent 8dafecd528
commit db8aaacb35
10 changed files with 46 additions and 10 deletions

View File

@ -48,7 +48,8 @@ enum class BooleanSetting(
DEBUG_RENDERER("renderer_debug", Settings.SECTION_DEBUG, false),
DISABLE_RIGHT_EYE_RENDER("disable_right_eye_render", Settings.SECTION_RENDERER, false),
USE_ARTIC_BASE_CONTROLLER("use_artic_base_controller", Settings.SECTION_CONTROLS, false),
UPRIGHT_SCREEN("upright_screen", Settings.SECTION_LAYOUT, false);
UPRIGHT_SCREEN("upright_screen", Settings.SECTION_LAYOUT, false),
COMPRESS_INSTALLED_CIA_CONTENT("compress_cia_installs", Settings.SECTION_STORAGE, false);
override var boolean: Boolean = defaultValue
@ -80,7 +81,8 @@ enum class BooleanSetting(
CPU_JIT,
ASYNC_CUSTOM_LOADING,
SHADERS_ACCURATE_MUL,
USE_ARTIC_BASE_CONTROLLER
USE_ARTIC_BASE_CONTROLLER,
COMPRESS_INSTALLED_CIA_CONTENT,
)
fun from(key: String): BooleanSetting? =

View File

@ -112,6 +112,7 @@ class Settings {
const val SECTION_CUSTOM_LANDSCAPE = "Custom Landscape Layout"
const val SECTION_CUSTOM_PORTRAIT = "Custom Portrait Layout"
const val SECTION_PERFORMANCE_OVERLAY = "Performance Overlay"
const val SECTION_STORAGE = "Storage"
const val KEY_BUTTON_A = "button_a"
const val KEY_BUTTON_B = "button_b"
@ -237,6 +238,7 @@ class Settings {
SECTION_CONTROLS,
SECTION_RENDERER,
SECTION_LAYOUT,
SECTION_STORAGE,
SECTION_UTILITY,
SECTION_AUDIO,
SECTION_DEBUG

View File

@ -565,6 +565,16 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
BooleanSetting.ALLOW_PLUGIN_LOADER.defaultValue
)
)
add(HeaderSetting(R.string.storage))
add(
SwitchSetting(
BooleanSetting.COMPRESS_INSTALLED_CIA_CONTENT,
R.string.compress_cia_installs,
R.string.compress_cia_installs_description,
BooleanSetting.COMPRESS_INSTALLED_CIA_CONTENT.key,
BooleanSetting.COMPRESS_INSTALLED_CIA_CONTENT.defaultValue
)
)
}
}

View File

@ -218,6 +218,9 @@ void Config::ReadValues() {
ReadSetting("Layout", Settings::values.custom_portrait_bottom_width);
ReadSetting("Layout", Settings::values.custom_portrait_bottom_height);
// Storage
ReadSetting("Storage", Settings::values.compress_cia_installs);
// Utility
ReadSetting("Utility", Settings::values.dump_textures);
ReadSetting("Utility", Settings::values.custom_textures);

View File

@ -210,6 +210,11 @@ disable_right_eye_render =
# 5: Custom Layout
layout_option =
[Storage]
# Whether to compress the installed CIA contents
# 0 (default): Do not compress, 1: Compress
compress_cia_installs =
# Position of the performance overlay
# 0: Top Left
# 1: Center Top

View File

@ -214,6 +214,9 @@
<string name="region_mismatch">Region Mismatch Warning</string>
<string name="region_mismatch_emulated">The country setting is not valid for the selected emulated region.</string>
<string name="region_mismatch_console">The country setting is not valid for the current linked console.</string>
<string name="storage">Storage</string>
<string name="compress_cia_installs">Compress installed CIA content</string>
<string name="compress_cia_installs_description">Compresses the content of CIA files when installed to the emulated SD card. Only affects CIA content which is installed while the setting is enabled.</string>
<!-- Camera settings strings -->
<string name="inner_camera">Inner Camera</string>

View File

@ -3081,7 +3081,7 @@ void GMainWindow::OnCompressFile() {
compress_info.recommended_compressed_extension = "zcia";
compress_info.recommended_uncompressed_extension = "cia";
compress_info.underlying_magic = std::array<u8, 4>({'C', 'I', 'A', '\0'});
frame_size = FileUtil::Z3DSWriteIOFile::MAX_FRAME_SIZE;
frame_size = FileUtil::Z3DSWriteIOFile::DEFAULT_CIA_FRAME_SIZE;
}
}
}

View File

@ -184,10 +184,10 @@
<item>
<widget class="QCheckBox" name="toggle_compress_cia">
<property name="text">
<string>Compress installed CIA contents</string>
<string>Compress installed CIA content</string>
</property>
<property name="toolTip">
<string>Enables compressing the contents of CIA files when they are installed to the emulated SD.</string>
<string>Compresses the content of CIA files when installed to the emulated SD card. Only affects CIA content which is installed while the setting is enabled.</string>
</property>
</widget>
</item>

View File

@ -115,9 +115,13 @@ Z3DSMetadata::Z3DSMetadata(const std::span<u8>& source_data) {
while (!in.eof()) {
Item item;
ReadFromIStream(in, &item, sizeof(Item));
// If end item is reached, stop processing
if (item.type == Item::TYPE_END) {
break;
}
// Only binary type supported for now
if (item.type != Item::TYPE_BINARY) {
break;
continue;
}
std::string name(item.name_len, '\0');
std::vector<u8> data(item.data_len);
@ -145,6 +149,10 @@ std::vector<u8> Z3DSMetadata::AsBinary() {
WriteToOStream(out, it.second.data(), item.data_len);
}
// Write end item
Item end{};
WriteToOStream(out, &end, sizeof(end));
std::string out_str = out.str();
return std::vector<u8>(out_str.begin(), out_str.end());
}

View File

@ -55,11 +55,12 @@ namespace FileUtil {
struct Z3DSFileHeader {
static constexpr std::array<u8, 4> EXPECTED_MAGIC = {'Z', '3', 'D', 'S'};
static constexpr u16 EXPECTED_VERSION = 1;
static constexpr u8 EXPECTED_VERSION = 1;
std::array<u8, 4> magic = EXPECTED_MAGIC;
std::array<u8, 4> underlying_magic{};
u16 version = EXPECTED_VERSION;
u8 version = EXPECTED_VERSION;
u8 reserved = 0;
u16 header_size = 0;
u32 metadata_size = 0;
u64 compressed_size = 0;
@ -70,6 +71,7 @@ struct Z3DSFileHeader {
ar & magic;
ar & underlying_magic;
ar & version;
ar & reserved;
ar & header_size;
ar & metadata_size;
ar & compressed_size;
@ -126,8 +128,9 @@ private:
class Z3DSWriteIOFile : public IOFile {
public:
static constexpr size_t DEFAULT_FRAME_SIZE = 256 * 1024; // 256KiB
static constexpr size_t MAX_FRAME_SIZE = 0; // Let the lib decide, usually 1GiB
static constexpr size_t DEFAULT_FRAME_SIZE = 256 * 1024; // 256KiB
static constexpr size_t DEFAULT_CIA_FRAME_SIZE = 32 * 1024 * 1024; // 32MiB
static constexpr size_t MAX_FRAME_SIZE = 0; // Let the lib decide, usually 1GiB
Z3DSWriteIOFile();