Files can be deleted (probably).

This commit is contained in:
David Given
2022-09-05 23:11:39 +02:00
parent 59e5f3d27e
commit 7106882212
6 changed files with 67 additions and 20 deletions

View File

@@ -60,7 +60,7 @@ public:
uint32_t capabilities() const
{
return OP_GETFSDATA | OP_CREATE | OP_LIST | OP_GETFILE | OP_PUTFILE |
OP_GETDIRENT;
OP_GETDIRENT | OP_DELETE;
}
std::map<std::string, std::string> getMetadata() override
@@ -193,6 +193,21 @@ public:
adfCloseFile(file);
}
void deleteFile(const Path& path) override
{
AdfMount m(this);
if (path.size() == 0)
throw BadPathException();
auto* vol = m.mount();
changeDirButOne(vol, path);
int res =
adfRemoveEntry(vol, vol->curDirPtr, (char*)path.back().c_str());
if (res != RC_OK)
throw CannotWriteException();
}
private:
std::shared_ptr<Dirent> toDirent(struct Entry* entry, const Path& container)
{

View File

@@ -177,6 +177,14 @@ public:
f_close(&fil);
}
void deleteFile(const Path& path) override
{
mount();
auto pathstr = path.to_str();
FRESULT res = f_unlink(pathstr.c_str());
throwError(res);
}
private:
std::shared_ptr<Dirent> toDirent(FILINFO& filinfo, const Path& parent)
{

View File

@@ -158,6 +158,17 @@ public:
writeBytes(file, a.rsrc);
}
void deleteFile(const Path& path) override
{
HfsMount m(this);
if (path.size() == 0)
throw BadPathException();
auto pathstr = ":" + path.to_str(":");
if (!hfs_delete(_vol, pathstr.c_str()))
throw CannotWriteException();
}
private:
std::shared_ptr<Dirent> toDirent(hfsdirent& de, const Path& parent)
{

View File

@@ -324,7 +324,7 @@ MainWindowGen::MainWindowGen( wxWindow* parent, wxWindowID id, const wxString& t
fgSizer23->Add( browserToolbar, 0, wxEXPAND, 5 );
browserTree = new wxDataViewCtrl( browsePanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxDV_MULTIPLE );
browserTree = new wxDataViewCtrl( browsePanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxDV_SINGLE );
m_dataViewColumn1 = browserTree->AppendIconTextColumn( wxT("Filename"), 0, wxDATAVIEW_CELL_INERT, 250, static_cast<wxAlignment>(wxALIGN_LEFT), wxDATAVIEW_COL_RESIZABLE );
m_dataViewColumn2 = browserTree->AppendTextColumn( wxT("Size"), 1, wxDATAVIEW_CELL_INERT, -1, static_cast<wxAlignment>(wxALIGN_RIGHT), wxDATAVIEW_COL_RESIZABLE );
m_dataViewColumn3 = browserTree->AppendTextColumn( wxT("Mode"), 2, wxDATAVIEW_CELL_INERT, -1, static_cast<wxAlignment>(wxALIGN_LEFT), wxDATAVIEW_COL_RESIZABLE );

View File

@@ -2499,7 +2499,7 @@
<property name="permission">protected</property>
<property name="pos"></property>
<property name="size"></property>
<property name="style">wxDV_MULTIPLE</property>
<property name="style">wxDV_SINGLE</property>
<property name="subclass">; ; forward_declare</property>
<property name="tooltip"></property>
<property name="window_extra_style"></property>

View File

@@ -603,6 +603,26 @@ public:
});
}
void OnBrowserDeleteMenuItem(wxCommandEvent&) override
{
auto item = browserTree->GetSelection();
auto dc = (DirentContainer*)_filesystemModel->GetItemData(item);
auto diskPath = dc->dirent->path;
auto parentItem = _filesystemModel->GetParent(item);
QueueBrowserOperation(
[this, diskPath, parentItem]()
{
_filesystem->deleteFile(diskPath);
runOnUiThread(
[&]()
{
RepopulateBrowser(parentItem);
});
});
}
void OnBrowserFormatButton(wxCommandEvent&) override
{
FormatDialog d(this, wxID_ANY);
@@ -700,7 +720,8 @@ public:
UpdateState();
}
/* --- Config management ------------------------------------------------ */
/* --- Config management
* ------------------------------------------------ */
/* This sets the *global* config object. That's safe provided the worker
* thread isn't running, otherwise you'll get a race. */
@@ -1034,8 +1055,7 @@ public:
{
dataNotebook->SetSelection(2);
wxDataViewItemArray selection;
browserTree->GetSelections(selection);
bool selection = browserTree->GetSelection().IsOk();
browserToolbar->EnableTool(
browserBackTool->GetId(), _state == STATE_BROWSING_IDLE);
@@ -1044,26 +1064,19 @@ public:
_filesystem ? _filesystem->capabilities() : 0;
browserToolbar->EnableTool(browserInfoTool->GetId(),
(capabilities & Filesystem::OP_GETDIRENT) &&
(selection.size() == 1));
(capabilities & Filesystem::OP_GETDIRENT) && selection);
browserToolbar->EnableTool(browserViewTool->GetId(),
(capabilities & Filesystem::OP_GETFILE) &&
(selection.size() == 1));
(capabilities & Filesystem::OP_GETFILE) && selection);
browserToolbar->EnableTool(browserSaveTool->GetId(),
(capabilities & Filesystem::OP_GETFILE) &&
(selection.size() == 1));
(capabilities & Filesystem::OP_GETFILE) && selection);
browserFileMenu->Enable(browserAddMenuItem->GetId(),
(capabilities & Filesystem::OP_PUTFILE) &&
(selection.size() <= 1));
capabilities & Filesystem::OP_PUTFILE);
browserFileMenu->Enable(browserNewDirectoryMenuItem->GetId(),
(capabilities & Filesystem::OP_CREATEDIR) &&
(selection.size() <= 1));
capabilities & Filesystem::OP_CREATEDIR);
browserFileMenu->Enable(browserRenameMenuItem->GetId(),
(capabilities & Filesystem::OP_MOVE) &&
(selection.size() == 1));
(capabilities & Filesystem::OP_MOVE) && selection);
browserFileMenu->Enable(browserDeleteMenuItem->GetId(),
(capabilities & Filesystem::OP_DELETE) &&
(selection.size() >= 1));
(capabilities & Filesystem::OP_DELETE) && selection);
browserToolbar->EnableTool(browserFormatTool->GetId(),
capabilities & Filesystem::OP_CREATE);