From 42e8cc75d66cb9c8475717a7c9ad8210ce378949 Mon Sep 17 00:00:00 2001 From: Gareth Poole <510razor@gmail.com> Date: Sun, 2 Nov 2014 01:08:48 -0400 Subject: [PATCH] Added check in the backend to see if write is disabled --- src/citra/config.cpp | 1 + src/citra_qt/config.cpp | 2 ++ src/core/file_sys/archive_sdmc.cpp | 5 +++++ src/core/file_sys/file_sdmc.cpp | 6 ++++++ src/core/settings.h | 1 + 5 files changed, 15 insertions(+) diff --git a/src/citra/config.cpp b/src/citra/config.cpp index c5ce8a164..bc4315923 100644 --- a/src/citra/config.cpp +++ b/src/citra/config.cpp @@ -63,6 +63,7 @@ void Config::ReadCore() { void Config::ReadData() { Settings::values.use_virtual_sd = glfw_config->GetBoolean("Data Storage", "use_virtual_sd", true); + Settings::values.virtual_sd_writable = glfw_config->GetBoolean("Data Storage", "virtual_sd_writable", true); } void Config::Reload() { diff --git a/src/citra_qt/config.cpp b/src/citra_qt/config.cpp index 63d396439..d0a01ed36 100644 --- a/src/citra_qt/config.cpp +++ b/src/citra_qt/config.cpp @@ -82,12 +82,14 @@ void Config::SaveCore() { void Config::ReadData() { qt_config->beginGroup("Data Storage"); Settings::values.use_virtual_sd = qt_config->value("use_virtual_sd", true).toBool(); + Settings::values.virtual_sd_writable = qt_config->value("virtual_sd_writable", true).toBool(); qt_config->endGroup(); } void Config::SaveData() { qt_config->beginGroup("Data Storage"); qt_config->setValue("use_virtual_sd", Settings::values.use_virtual_sd); + qt_config->setValue("virtual_sd_writable", Settings::values.virtual_sd_writable); qt_config->endGroup(); } diff --git a/src/core/file_sys/archive_sdmc.cpp b/src/core/file_sys/archive_sdmc.cpp index 0b647f7d0..5bedcf4af 100644 --- a/src/core/file_sys/archive_sdmc.cpp +++ b/src/core/file_sys/archive_sdmc.cpp @@ -50,6 +50,11 @@ bool Archive_SDMC::Initialize() { * @return Opened file, or nullptr */ std::unique_ptr Archive_SDMC::OpenFile(const std::string& path, const Mode mode) const { + if((mode.write_flag || mode.create_flag) && !Settings::values.virtual_sd_writable) { + ERROR_LOG(KERNEL, "Cannot open archive %s in write or create mode while the SD card is set to read-only."); + return nullptr; + } + DEBUG_LOG(FILESYS, "called path=%s mode=%d", path.c_str(), mode); File_SDMC* file = new File_SDMC(this, path, mode); if (!file->Open()) diff --git a/src/core/file_sys/file_sdmc.cpp b/src/core/file_sys/file_sdmc.cpp index 26204392c..a0c142cc5 100644 --- a/src/core/file_sys/file_sdmc.cpp +++ b/src/core/file_sys/file_sdmc.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include +#include #include "common/common_types.h" #include "common/file_util.h" @@ -37,6 +38,11 @@ bool File_SDMC::Open() { return false; } + if((mode.write_flag || mode.create_flag) && !Settings::values.virtual_sd_writable) { + ERROR_LOG(KERNEL, "Cannot open file %s in write or create mode while the SD card is set to read-only."); + return false; + } + std::string mode_string; if (mode.read_flag && mode.write_flag) mode_string = "w+"; diff --git a/src/core/settings.h b/src/core/settings.h index 6a6265e18..fde96da04 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -32,6 +32,7 @@ struct Values { // Data Storage bool use_virtual_sd; + bool virtual_sd_writable; } extern values; }