From 52e02941662268d3da1a3f02715a98950fca8668 Mon Sep 17 00:00:00 2001 From: Techjar Date: Sat, 23 May 2020 03:13:26 -0400 Subject: [PATCH] Add option to disallow SD card writes --- Source/Core/Core/Config/MainSettings.cpp | 1 + Source/Core/Core/Config/MainSettings.h | 1 + .../Core/ConfigLoaders/IsSettingSaveable.cpp | 3 ++- Source/Core/Core/IOS/SDIO/SDIOSlot0.cpp | 6 +++++- Source/Core/DolphinQt/NetPlay/NetPlayDialog.cpp | 2 ++ Source/Core/DolphinQt/Settings/WiiPane.cpp | 16 +++++++++++----- Source/Core/DolphinQt/Settings/WiiPane.h | 1 + 7 files changed, 23 insertions(+), 7 deletions(-) diff --git a/Source/Core/Core/Config/MainSettings.cpp b/Source/Core/Core/Config/MainSettings.cpp index 32819ddf53..1c97e21cdb 100644 --- a/Source/Core/Core/Config/MainSettings.cpp +++ b/Source/Core/Core/Config/MainSettings.cpp @@ -105,6 +105,7 @@ const Info MAIN_CUSTOM_RTC_ENABLE{{System::Main, "Core", "EnableCustomRTC" // Default to seconds between 1.1.1970 and 1.1.2000 const Info MAIN_CUSTOM_RTC_VALUE{{System::Main, "Core", "CustomRTCValue"}, 946684800}; const Info MAIN_AUTO_DISC_CHANGE{{System::Main, "Core", "AutoDiscChange"}, false}; +const Info MAIN_ALLOW_SD_WRITES{{System::Main, "Core", "WiiSDCardAllowWrites"}, true}; // Main.Display diff --git a/Source/Core/Core/Config/MainSettings.h b/Source/Core/Core/Config/MainSettings.h index 3f3881a81e..61f59069ec 100644 --- a/Source/Core/Core/Config/MainSettings.h +++ b/Source/Core/Core/Config/MainSettings.h @@ -86,6 +86,7 @@ extern const Info MAIN_PERF_MAP_DIR; extern const Info MAIN_CUSTOM_RTC_ENABLE; extern const Info MAIN_CUSTOM_RTC_VALUE; extern const Info MAIN_AUTO_DISC_CHANGE; +extern const Info MAIN_ALLOW_SD_WRITES; // Main.DSP diff --git a/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp b/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp index 98aca975e1..9b98653ee7 100644 --- a/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp +++ b/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp @@ -28,13 +28,14 @@ bool IsSettingSaveable(const Config::Location& config_location) return true; } - static constexpr std::array s_setting_saveable = { + static constexpr std::array s_setting_saveable = { // Main.Core &Config::MAIN_DEFAULT_ISO.location, &Config::MAIN_MEMCARD_A_PATH.location, &Config::MAIN_MEMCARD_B_PATH.location, &Config::MAIN_AUTO_DISC_CHANGE.location, + &Config::MAIN_ALLOW_SD_WRITES.location, &Config::MAIN_DPL2_DECODER.location, &Config::MAIN_DPL2_QUALITY.location, &Config::MAIN_RAM_OVERRIDE_ENABLE.location, diff --git a/Source/Core/Core/IOS/SDIO/SDIOSlot0.cpp b/Source/Core/Core/IOS/SDIO/SDIOSlot0.cpp index 78ec7a0ce3..0de7c93ec5 100644 --- a/Source/Core/Core/IOS/SDIO/SDIOSlot0.cpp +++ b/Source/Core/Core/IOS/SDIO/SDIOSlot0.cpp @@ -15,6 +15,7 @@ #include "Common/FileUtil.h" #include "Common/Logging/Log.h" #include "Common/SDCardUtil.h" +#include "Core/Config/MainSettings.h" #include "Core/ConfigManager.h" #include "Core/HW/Memmap.h" #include "Core/IOS/IOS.h" @@ -25,6 +26,8 @@ namespace IOS::HLE::Device SDIOSlot0::SDIOSlot0(Kernel& ios, const std::string& device_name) : Device(ios, device_name), m_sdhc_supported(HasFeature(ios.GetVersion(), Feature::SDv2)) { + if (!Config::Get(Config::MAIN_ALLOW_SD_WRITES)) + INFO_LOG(IOS_SD, "Writes to SD card disabled by user"); } void SDIOSlot0::DoState(PointerWrap& p) @@ -274,7 +277,8 @@ s32 SDIOSlot0::ExecuteCommand(const Request& request, u32 buffer_in, u32 buffer_ INFO_LOG(IOS_SD, "%sWrite %i Block(s) from 0x%08x bsize %i to offset 0x%08x!", req.isDMA ? "DMA " : "", req.blocks, req.addr, req.bsize, req.arg); - if (m_card && SConfig::GetInstance().bEnableMemcardSdWriting) + if (m_card && SConfig::GetInstance().bEnableMemcardSdWriting && + Config::Get(Config::MAIN_ALLOW_SD_WRITES)) { u32 size = req.bsize * req.blocks; u64 address = GetAddressFromRequest(req.arg); diff --git a/Source/Core/DolphinQt/NetPlay/NetPlayDialog.cpp b/Source/Core/DolphinQt/NetPlay/NetPlayDialog.cpp index caa0037d81..77ceb45523 100644 --- a/Source/Core/DolphinQt/NetPlay/NetPlayDialog.cpp +++ b/Source/Core/DolphinQt/NetPlay/NetPlayDialog.cpp @@ -105,6 +105,8 @@ void NetPlayDialog::CreateMainLayout() m_data_menu = m_menu_bar->addMenu(tr("Data")); m_data_menu->setToolTipsVisible(true); m_save_sd_action = m_data_menu->addAction(tr("Write Save/SD Data")); + m_save_sd_action->setToolTip( + tr("If \"Allow Writes to SD Card\" is disabled this does not override it.")); m_save_sd_action->setCheckable(true); m_load_wii_action = m_data_menu->addAction(tr("Load Wii Save")); m_load_wii_action->setCheckable(true); diff --git a/Source/Core/DolphinQt/Settings/WiiPane.cpp b/Source/Core/DolphinQt/Settings/WiiPane.cpp index 6cdf0670b6..c3b4e48d93 100644 --- a/Source/Core/DolphinQt/Settings/WiiPane.cpp +++ b/Source/Core/DolphinQt/Settings/WiiPane.cpp @@ -19,6 +19,7 @@ #include "Common/Config/Config.h" #include "Common/StringUtil.h" +#include "Core/Config/MainSettings.h" #include "Core/Config/SYSCONFSettings.h" #include "Core/ConfigManager.h" #include "Core/Core.h" @@ -71,6 +72,7 @@ void WiiPane::ConnectLayout() connect(m_screensaver_checkbox, &QCheckBox::toggled, this, &WiiPane::OnSaveConfig); connect(m_pal60_mode_checkbox, &QCheckBox::toggled, this, &WiiPane::OnSaveConfig); connect(m_sd_card_checkbox, &QCheckBox::toggled, this, &WiiPane::OnSaveConfig); + connect(m_allow_sd_writes_checkbox, &QCheckBox::toggled, this, &WiiPane::OnSaveConfig); connect(m_connect_keyboard_checkbox, &QCheckBox::toggled, this, &WiiPane::OnSaveConfig); connect(&Settings::Instance(), &Settings::SDCardInsertionChanged, m_sd_card_checkbox, &QCheckBox::setChecked); @@ -105,6 +107,7 @@ void WiiPane::CreateMisc() m_pal60_mode_checkbox = new QCheckBox(tr("Use PAL60 Mode (EuRGB60)")); m_screensaver_checkbox = new QCheckBox(tr("Enable Screen Saver")); m_sd_card_checkbox = new QCheckBox(tr("Insert SD Card")); + m_allow_sd_writes_checkbox = new QCheckBox(tr("Allow Writes to SD Card")); m_connect_keyboard_checkbox = new QCheckBox(tr("Connect USB Keyboard")); m_aspect_ratio_choice_label = new QLabel(tr("Aspect Ratio:")); m_aspect_ratio_choice = new QComboBox(); @@ -133,11 +136,12 @@ void WiiPane::CreateMisc() misc_settings_group_layout->addWidget(m_pal60_mode_checkbox, 0, 0, 1, 1); misc_settings_group_layout->addWidget(m_sd_card_checkbox, 0, 1, 1, 1); misc_settings_group_layout->addWidget(m_screensaver_checkbox, 1, 0, 1, 1); - misc_settings_group_layout->addWidget(m_connect_keyboard_checkbox, 1, 1, 1, 1); - misc_settings_group_layout->addWidget(m_aspect_ratio_choice_label, 2, 0, 1, 1); - misc_settings_group_layout->addWidget(m_aspect_ratio_choice, 2, 1, 1, 1); - misc_settings_group_layout->addWidget(m_system_language_choice_label, 3, 0, 1, 1); - misc_settings_group_layout->addWidget(m_system_language_choice, 3, 1, 1, 1); + misc_settings_group_layout->addWidget(m_allow_sd_writes_checkbox, 1, 1, 1, 1); + misc_settings_group_layout->addWidget(m_connect_keyboard_checkbox, 2, 1, 1, 1); + misc_settings_group_layout->addWidget(m_aspect_ratio_choice_label, 3, 0, 1, 1); + misc_settings_group_layout->addWidget(m_aspect_ratio_choice, 3, 1, 1, 1); + misc_settings_group_layout->addWidget(m_system_language_choice_label, 4, 0, 1, 1); + misc_settings_group_layout->addWidget(m_system_language_choice, 4, 1, 1, 1); } void WiiPane::CreateWhitelistedUSBPassthroughDevices() @@ -210,6 +214,7 @@ void WiiPane::LoadConfig() m_screensaver_checkbox->setChecked(Config::Get(Config::SYSCONF_SCREENSAVER)); m_pal60_mode_checkbox->setChecked(Config::Get(Config::SYSCONF_PAL60)); m_sd_card_checkbox->setChecked(Settings::Instance().IsSDCardInserted()); + m_allow_sd_writes_checkbox->setChecked(Config::Get(Config::MAIN_ALLOW_SD_WRITES)); m_connect_keyboard_checkbox->setChecked(Settings::Instance().IsUSBKeyboardConnected()); m_aspect_ratio_choice->setCurrentIndex(Config::Get(Config::SYSCONF_WIDESCREEN)); m_system_language_choice->setCurrentIndex(Config::Get(Config::SYSCONF_LANGUAGE)); @@ -230,6 +235,7 @@ void WiiPane::OnSaveConfig() Config::SetBase(Config::SYSCONF_SCREENSAVER, m_screensaver_checkbox->isChecked()); Config::SetBase(Config::SYSCONF_PAL60, m_pal60_mode_checkbox->isChecked()); Settings::Instance().SetSDCardInserted(m_sd_card_checkbox->isChecked()); + Config::SetBase(Config::MAIN_ALLOW_SD_WRITES, m_allow_sd_writes_checkbox->isChecked()); Settings::Instance().SetUSBKeyboardConnected(m_connect_keyboard_checkbox->isChecked()); Config::SetBase(Config::SYSCONF_SENSOR_BAR_POSITION, diff --git a/Source/Core/DolphinQt/Settings/WiiPane.h b/Source/Core/DolphinQt/Settings/WiiPane.h index 375ac99b81..db9f75e914 100644 --- a/Source/Core/DolphinQt/Settings/WiiPane.h +++ b/Source/Core/DolphinQt/Settings/WiiPane.h @@ -44,6 +44,7 @@ private: QCheckBox* m_screensaver_checkbox; QCheckBox* m_pal60_mode_checkbox; QCheckBox* m_sd_card_checkbox; + QCheckBox* m_allow_sd_writes_checkbox; QCheckBox* m_connect_keyboard_checkbox; QComboBox* m_system_language_choice; QLabel* m_system_language_choice_label;