Skip to content

Commit

Permalink
Fix proper write-access handling
Browse files Browse the repository at this point in the history
  • Loading branch information
XorTroll committed Aug 17, 2023
1 parent 29aea23 commit a446262
Show file tree
Hide file tree
Showing 14 changed files with 77 additions and 47 deletions.
11 changes: 10 additions & 1 deletion Goldleaf/include/fs/fs_Explorer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ namespace fs {
std::string mnt_name;
std::string cwd;
bool warn_write;
bool block_write;
FileMode started_file_mode;

public:
Explorer() : warn_write(false), started_file_mode(FileMode::None) {}
Explorer() : warn_write(false), block_write(false), started_file_mode(FileMode::None) {}
virtual ~Explorer() {}

void SetNames(const std::string &mount_name, const std::string &display_name);
Expand Down Expand Up @@ -150,6 +151,14 @@ namespace fs {
return this->warn_write;
}

inline void SetWriteAccessBlocked(const bool should_warn) {
this->block_write = should_warn;
}

inline bool IsWriteAccessBlocked() {
return this->block_write;
}

virtual std::vector<std::string> GetDirectories(const std::string &path) = 0;
virtual std::vector<std::string> GetFiles(const std::string &path) = 0;
virtual bool Exists(const std::string &path) = 0;
Expand Down
2 changes: 1 addition & 1 deletion Goldleaf/include/ui/ui_PartitionBrowserLayout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace ui {
void HandleFileDirectly(const std::string &path);
void PromptDeleteFile(const std::string &path);
bool GoBack();
bool WarnWriteAccess();
bool CheckWriteAccess();
void fsItems_DefaultKey(const std::string &item);
void fsItems_Y(const std::string &item);

Expand Down
3 changes: 2 additions & 1 deletion Goldleaf/romfs/Strings/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -474,5 +474,6 @@
"Copying file...",
"Copying directory...",
"Ignore hidden files/directories",
"Show deletion prompt after NSP installs"
"Show deletion prompt after NSP installs",
"Write access is blocked here..."
]
3 changes: 2 additions & 1 deletion Goldleaf/romfs/Strings/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -474,5 +474,6 @@
"Copying file...",
"Copying directory...",
"Ignore hidden files/directories",
"Show deletion prompt after NSP installs"
"Show deletion prompt after NSP installs",
"Write access is blocked here..."
]
3 changes: 2 additions & 1 deletion Goldleaf/romfs/Strings/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -474,5 +474,6 @@
"Copiando archivo...",
"Copiando carpeta...",
"Ignorar archivos/carpetas ocultas",
"Mostrar diálogo de eliminación tras instalar NSPs"
"Mostrar diálogo de eliminación tras instalar NSPs",
"El acceso a escritura está bloqueado aquí..."
]
3 changes: 2 additions & 1 deletion Goldleaf/romfs/Strings/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -474,5 +474,6 @@
"Copying file...",
"Copying directory...",
"Ignore hidden files/directories",
"Show deletion prompt after NSP installs"
"Show deletion prompt after NSP installs",
"Write access is blocked here..."
]
3 changes: 2 additions & 1 deletion Goldleaf/romfs/Strings/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -474,5 +474,6 @@
"Copying file...",
"Copying directory...",
"Ignore hidden files/directories",
"Show deletion prompt after NSP installs"
"Show deletion prompt after NSP installs",
"Write access is blocked here..."
]
3 changes: 2 additions & 1 deletion Goldleaf/romfs/Strings/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -474,5 +474,6 @@
"Copying file...",
"Copying directory...",
"Ignore hidden files/directories",
"Show deletion prompt after NSP installs"
"Show deletion prompt after NSP installs",
"Write access is blocked here..."
]
3 changes: 2 additions & 1 deletion Goldleaf/romfs/Strings/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -474,5 +474,6 @@
"파일 복사 중...",
"디렉터리 복사 중...",
"Ignore hidden files/directories",
"Show deletion prompt after NSP installs"
"Show deletion prompt after NSP installs",
"Write access is blocked here..."
]
3 changes: 2 additions & 1 deletion Goldleaf/romfs/Strings/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -474,5 +474,6 @@
"Copying file...",
"Copying directory...",
"Ignore hidden files/directories",
"Show deletion prompt after NSP installs"
"Show deletion prompt after NSP installs",
"Write access is blocked here..."
]
3 changes: 2 additions & 1 deletion Goldleaf/romfs/Strings/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -474,5 +474,6 @@
"Copying file...",
"Copying directory...",
"Ignore hidden files/directories",
"Show deletion prompt after NSP installs"
"Show deletion prompt after NSP installs",
"Write access is blocked here..."
]
3 changes: 2 additions & 1 deletion Goldleaf/romfs/Strings/zh-Hans.json
Original file line number Diff line number Diff line change
Expand Up @@ -474,5 +474,6 @@
"正在复制文件...",
"正在复制文件夹...",
"Ignore hidden files/directories",
"Show deletion prompt after NSP installs"
"Show deletion prompt after NSP installs",
"Write access is blocked here..."
]
3 changes: 2 additions & 1 deletion Goldleaf/romfs/Strings/zh-Hant.json
Original file line number Diff line number Diff line change
Expand Up @@ -474,5 +474,6 @@
"Copying file...",
"Copying directory...",
"Ignore hidden files/directories",
"Show deletion prompt after NSP installs"
"Show deletion prompt after NSP installs",
"Write access is blocked here..."
]
78 changes: 44 additions & 34 deletions Goldleaf/source/ui/ui_PartitionBrowserLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ namespace ui {
}

void PartitionBrowserLayout::PromptDeleteFile(const std::string &path) {
if(this->WarnWriteAccess()) {
if(this->CheckWriteAccess()) {
const auto option = g_MainApplication->CreateShowDialog(cfg::Strings.GetString(127), cfg::Strings.GetString(128), { cfg::Strings.GetString(111), cfg::Strings.GetString(18) }, true);
if(option < 0) {
return;
Expand All @@ -209,12 +209,18 @@ namespace ui {
return this->cur_exp->NavigateBack();
}

bool PartitionBrowserLayout::WarnWriteAccess() {
if(!this->cur_exp->ShouldWarnOnWriteAccess()) {
bool PartitionBrowserLayout::CheckWriteAccess() {
if(this->cur_exp->IsWriteAccessBlocked()) {
g_MainApplication->ShowNotification(cfg::Strings.GetString(476));
return false;
}
else if(this->cur_exp->ShouldWarnOnWriteAccess()) {
const auto option = g_MainApplication->CreateShowDialog(cfg::Strings.GetString(50), cfg::Strings.GetString(51), { cfg::Strings.GetString(111), cfg::Strings.GetString(18) }, true);
return option == 0;
}
else {
return true;
}
const auto option = g_MainApplication->CreateShowDialog(cfg::Strings.GetString(50), cfg::Strings.GetString(51), { cfg::Strings.GetString(111), cfg::Strings.GetString(18) }, true);
return option == 0;
}

void PartitionBrowserLayout::fsItems_DefaultKey(const std::string &item) {
Expand Down Expand Up @@ -373,7 +379,7 @@ namespace ui {
const auto rc = romfsMountFromFsdev(full_item.c_str(), romfs_offset, mnt_name.c_str());
if(R_SUCCEEDED(rc)) {
auto romfs_exp = new fs::RomFsExplorer("NroRomFs-" + romfs_id, mnt_name, true);
romfs_exp->SetShouldWarnOnWriteAccess(true);
romfs_exp->SetWriteAccessBlocked(true);
g_MainApplication->GetExploreMenuLayout()->AddMountedExplorer(romfs_exp, "RomFs (" + fs::GetBaseName(full_item) + ")", g_Settings.PathForResource("/Common/NAND.png"));
g_MainApplication->ShowNotification(cfg::Strings.GetString(454));
}
Expand Down Expand Up @@ -606,19 +612,21 @@ namespace ui {
this->PromptDeleteFile(full_item);
}
else if(option_1 == static_cast<s32>(rename_option)) {
const auto new_name = ShowKeyboard(cfg::Strings.GetString(130), item);
if(!new_name.empty()) {
if(new_name == item) {
return;
}
const auto new_path = this->cur_exp->FullPathFor(new_name);
if(this->cur_exp->IsFile(new_path) || this->cur_exp->IsDirectory(new_path)) {
HandleResult(rc::goldleaf::ResultEntryAlreadyPresent, cfg::Strings.GetString(254));
}
else if(this->WarnWriteAccess()) {
this->cur_exp->RenameFile(full_item, new_path);
g_MainApplication->ShowNotification(cfg::Strings.GetString(133));
this->UpdateElements(this->browse_menu->GetSelectedIndex());
if(this->CheckWriteAccess()) {
const auto new_name = ShowKeyboard(cfg::Strings.GetString(130), item);
if(!new_name.empty()) {
if(new_name == item) {
return;
}
const auto new_path = this->cur_exp->FullPathFor(new_name);
if(this->cur_exp->IsFile(new_path) || this->cur_exp->IsDirectory(new_path)) {
HandleResult(rc::goldleaf::ResultEntryAlreadyPresent, cfg::Strings.GetString(254));
}
else {
this->cur_exp->RenameFile(full_item, new_path);
g_MainApplication->ShowNotification(cfg::Strings.GetString(133));
this->UpdateElements(this->browse_menu->GetSelectedIndex());
}
}
}
}
Expand Down Expand Up @@ -705,7 +713,7 @@ namespace ui {
break;
}
case 2: {
if(this->WarnWriteAccess()) {
if(this->CheckWriteAccess()) {
const auto option_2 = g_MainApplication->CreateShowDialog(cfg::Strings.GetString(325), cfg::Strings.GetString(326), { cfg::Strings.GetString(111), cfg::Strings.GetString(18) }, true);
if(option_2 < 0) {
return;
Expand All @@ -717,20 +725,22 @@ namespace ui {
break;
}
case 3: {
const auto new_name = ShowKeyboard(cfg::Strings.GetString(238), item);
if(!new_name.empty()) {
if(new_name == item) {
// TODO: special handling?
return;
}
const auto new_path = this->cur_exp->FullPathFor(new_name);
if(this->cur_exp->IsFile(new_path) || this->cur_exp->IsDirectory(new_path)) {
HandleResult(rc::goldleaf::ResultEntryAlreadyPresent, cfg::Strings.GetString(254));
}
else if(this->WarnWriteAccess()) {
this->cur_exp->RenameDirectory(full_item, new_path);
g_MainApplication->ShowNotification(cfg::Strings.GetString(139));
this->UpdateElements();
if(this->CheckWriteAccess()) {
const auto new_name = ShowKeyboard(cfg::Strings.GetString(238), item);
if(!new_name.empty()) {
if(new_name == item) {
// TODO: special handling?
return;
}
const auto new_path = this->cur_exp->FullPathFor(new_name);
if(this->cur_exp->IsFile(new_path) || this->cur_exp->IsDirectory(new_path)) {
HandleResult(rc::goldleaf::ResultEntryAlreadyPresent, cfg::Strings.GetString(254));
}
else {
this->cur_exp->RenameDirectory(full_item, new_path);
g_MainApplication->ShowNotification(cfg::Strings.GetString(139));
this->UpdateElements();
}
}
}
break;
Expand Down

0 comments on commit a446262

Please sign in to comment.