mount hdd by default, add hdd write protect option.

This commit is contained in:
ITotalJustice
2025-05-26 19:25:09 +01:00
parent 793b36fd59
commit 3ca82463cc
5 changed files with 45 additions and 4 deletions

View File

@@ -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);
}

View File

@@ -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;
}

View File

@@ -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;
}
}

View File

@@ -280,6 +280,10 @@ MainMenu::MainMenu() {
App::SetHddEnable(enable);
}));
options->Add(std::make_shared<SidebarEntryBool>("Hdd write protect"_i18n, App::GetWriteProtect(), [](bool& enable){
App::SetWriteProtect(enable);
}));
if (m_update_state == UpdateState::Update) {
options->Add(std::make_shared<SidebarEntryCallback>("Download update: "_i18n + m_update_version, [this](){
App::Push(std::make_shared<ProgressBox>(0, "Downloading "_i18n, "Sphaira v" + m_update_version, [this](auto pbox) -> Result {