diff --git a/sphaira/include/app.hpp b/sphaira/include/app.hpp index 5bfd9ce..3650397 100644 --- a/sphaira/include/app.hpp +++ b/sphaira/include/app.hpp @@ -80,6 +80,7 @@ public: static auto GetFtpEnable() -> bool; static auto GetNxlinkEnable() -> bool; static auto GetHddEnable() -> bool; + static auto GetWriteProtect() -> bool; static auto GetLogEnable() -> bool; static auto GetReplaceHbmenuEnable() -> bool; static auto GetInstallEnable() -> bool; @@ -96,6 +97,7 @@ public: static void SetFtpEnable(bool enable); static void SetNxlinkEnable(bool enable); static void SetHddEnable(bool enable); + static void SetWriteProtect(bool enable); static void SetLogEnable(bool enable); static void SetReplaceHbmenuEnable(bool enable); static void SetInstallSysmmcEnable(bool enable); @@ -225,10 +227,13 @@ public: bool m_quit{}; + // network option::OptionBool m_nxlink_enabled{INI_SECTION, "nxlink_enabled", true}; option::OptionBool m_mtp_enabled{INI_SECTION, "mtp_enabled", false}; option::OptionBool m_ftp_enabled{INI_SECTION, "ftp_enabled", false}; - option::OptionBool m_hdd_enabled{INI_SECTION, "hdd_enabled", false}; + option::OptionBool m_hdd_enabled{INI_SECTION, "hdd_enabled", true}; + option::OptionBool m_hdd_write_protect{INI_SECTION, "hdd_write_protect", false}; + option::OptionBool m_log_enabled{INI_SECTION, "log_enabled", false}; option::OptionBool m_replace_hbmenu{INI_SECTION, "replace_hbmenu", false}; option::OptionString m_theme_path{INI_SECTION, "theme", DEFAULT_THEME_PATH}; diff --git a/sphaira/source/app.cpp b/sphaira/source/app.cpp index 081290b..62e686d 100644 --- a/sphaira/source/app.cpp +++ b/sphaira/source/app.cpp @@ -617,6 +617,10 @@ auto App::GetHddEnable() -> bool { return g_app->m_hdd_enabled.Get(); } +auto App::GetWriteProtect() -> bool { + return g_app->m_hdd_write_protect.Get(); +} + auto App::GetLogEnable() -> bool { return g_app->m_log_enabled.Get(); } @@ -688,6 +692,9 @@ void App::SetHddEnable(bool enable) { if (App::GetHddEnable() != enable) { g_app->m_hdd_enabled.Set(enable); if (enable) { + if (App::GetWriteProtect()) { + usbHsFsSetFileSystemMountFlags(UsbHsFsMountFlags_ReadOnly); + } usbHsFsInitialize(1); } else { usbHsFsExit(); @@ -695,6 +702,18 @@ void App::SetHddEnable(bool enable) { } } +void App::SetWriteProtect(bool enable) { + if (App::GetWriteProtect() != enable) { + g_app->m_hdd_write_protect.Set(enable); + + if (enable) { + usbHsFsSetFileSystemMountFlags(UsbHsFsMountFlags_ReadOnly); + } else { + usbHsFsSetFileSystemMountFlags(0); + } + } +} + void App::SetLogEnable(bool enable) { if (App::GetLogEnable() != enable) { g_app->m_log_enabled.Set(enable); @@ -1284,6 +1303,7 @@ App::App(const char* argv0) { else if (app->m_mtp_enabled.LoadFrom(Key, Value)) {} else if (app->m_ftp_enabled.LoadFrom(Key, Value)) {} else if (app->m_hdd_enabled.LoadFrom(Key, Value)) {} + else if (app->m_hdd_write_protect.LoadFrom(Key, Value)) {} else if (app->m_log_enabled.LoadFrom(Key, Value)) {} else if (app->m_replace_hbmenu.LoadFrom(Key, Value)) {} else if (app->m_theme_path.LoadFrom(Key, Value)) {} @@ -1311,6 +1331,8 @@ App::App(const char* argv0) { else if (app->m_convert_to_standard_crypto.LoadFrom(Key, Value)) {} else if (app->m_lower_master_key.LoadFrom(Key, Value)) {} else if (app->m_lower_system_version.LoadFrom(Key, Value)) {} + } else if (!std::strcmp(Section, "accessibility")) { + if (app->m_text_scroll_speed.LoadFrom(Key, Value)) {} } return 1; @@ -1338,6 +1360,10 @@ App::App(const char* argv0) { nxlinkInitialize(nxlink_callback); } + if (App::GetWriteProtect()) { + usbHsFsSetFileSystemMountFlags(UsbHsFsMountFlags_ReadOnly); + } + if (App::GetHddEnable()) { usbHsFsInitialize(1); } diff --git a/sphaira/source/location.cpp b/sphaira/source/location.cpp index 4c9ff08..ec24ce1 100644 --- a/sphaira/source/location.cpp +++ b/sphaira/source/location.cpp @@ -86,10 +86,12 @@ auto GetStdio(bool write) -> StdioEntries { log_write("[USBHSFS] got count: %u\n", count); StdioEntries out{}; + const auto write_protect = App::GetWriteProtect(); + for (s32 i = 0; i < count; i++) { const auto& e = devices[i]; - if (write && e.write_protect) { + if (write && (write_protect || e.write_protect)) { log_write("[USBHSFS] skipping write protect\n"); continue; } diff --git a/sphaira/source/ui/menus/filebrowser.cpp b/sphaira/source/ui/menus/filebrowser.cpp index 8a2fd71..d0af089 100644 --- a/sphaira/source/ui/menus/filebrowser.cpp +++ b/sphaira/source/ui/menus/filebrowser.cpp @@ -1192,11 +1192,15 @@ void FsView::OnDeleteCallback() { bool empty{}; m_fs->IsDirEmpty(full_path, &empty); if (empty) { - m_fs->DeleteDirectory(full_path); + if (auto rc = m_fs->DeleteDirectory(full_path); R_FAILED(rc)) { + App::PushErrorBox(rc, "Failed to delete directory"_i18n); + } use_progress_box = false; } } else { - m_fs->DeleteFile(full_path); + if (auto rc = m_fs->DeleteFile(full_path); R_FAILED(rc)) { + App::PushErrorBox(rc, "Failed to delete file"_i18n); + } use_progress_box = false; } } diff --git a/sphaira/source/ui/menus/main_menu.cpp b/sphaira/source/ui/menus/main_menu.cpp index 7532fa9..52ad207 100644 --- a/sphaira/source/ui/menus/main_menu.cpp +++ b/sphaira/source/ui/menus/main_menu.cpp @@ -280,6 +280,10 @@ MainMenu::MainMenu() { App::SetHddEnable(enable); })); + options->Add(std::make_shared("Hdd write protect"_i18n, App::GetWriteProtect(), [](bool& enable){ + App::SetWriteProtect(enable); + })); + if (m_update_state == UpdateState::Update) { options->Add(std::make_shared("Download update: "_i18n + m_update_version, [this](){ App::Push(std::make_shared(0, "Downloading "_i18n, "Sphaira v" + m_update_version, [this](auto pbox) -> Result {