From 0b068d84d58e4e6584672c5e1a632df8ad67df5c Mon Sep 17 00:00:00 2001 From: JosJuice Date: Tue, 20 Jun 2017 15:41:17 +0200 Subject: [PATCH] FilesystemPanel: Overhaul the right-click menu --- Source/Core/DiscIO/DiscExtractor.cpp | 9 ++ Source/Core/DiscIO/DiscExtractor.h | 3 + .../ISOProperties/FilesystemPanel.cpp | 131 +++++++++--------- .../DolphinWX/ISOProperties/FilesystemPanel.h | 3 +- 4 files changed, 80 insertions(+), 66 deletions(-) diff --git a/Source/Core/DiscIO/DiscExtractor.cpp b/Source/Core/DiscIO/DiscExtractor.cpp index 9a2dd16487..d0d7500897 100644 --- a/Source/Core/DiscIO/DiscExtractor.cpp +++ b/Source/Core/DiscIO/DiscExtractor.cpp @@ -176,4 +176,13 @@ bool ExportDOL(const Volume& volume, const Partition& partition, const std::stri return ExportData(volume, partition, *dol_offset, *dol_size, export_filename); } +bool ExportSystemData(const Volume& volume, const Partition& partition, + const std::string& export_folder) +{ + bool success = true; + success &= ExportApploader(volume, partition, export_folder + "/apploader.img"); + success &= ExportDOL(volume, partition, export_folder + "/boot.dol"); + return success; +} + } // namespace DiscIO diff --git a/Source/Core/DiscIO/DiscExtractor.h b/Source/Core/DiscIO/DiscExtractor.h index 1372f2a8cd..c2db7f7a46 100644 --- a/Source/Core/DiscIO/DiscExtractor.h +++ b/Source/Core/DiscIO/DiscExtractor.h @@ -37,4 +37,7 @@ std::optional GetBootDOLSize(const Volume& volume, const Partition& partiti bool ExportDOL(const Volume& volume, const Partition& partition, const std::string& export_filename); +bool ExportSystemData(const Volume& volume, const Partition& partition, + const std::string& export_folder); + } // namespace DiscIO diff --git a/Source/Core/DolphinWX/ISOProperties/FilesystemPanel.cpp b/Source/Core/DolphinWX/ISOProperties/FilesystemPanel.cpp index 1ecadba87e..24d0d8a3ee 100644 --- a/Source/Core/DolphinWX/ISOProperties/FilesystemPanel.cpp +++ b/Source/Core/DolphinWX/ISOProperties/FilesystemPanel.cpp @@ -124,7 +124,7 @@ void FilesystemPanel::BindEvents() m_tree_ctrl->Bind(wxEVT_TREE_ITEM_RIGHT_CLICK, &FilesystemPanel::OnRightClickTree, this); Bind(wxEVT_MENU, &FilesystemPanel::OnExtractFile, this, ID_EXTRACT_FILE); - Bind(wxEVT_MENU, &FilesystemPanel::OnExtractDirectories, this, ID_EXTRACT_ALL); + Bind(wxEVT_MENU, &FilesystemPanel::OnExtractAll, this, ID_EXTRACT_ALL); Bind(wxEVT_MENU, &FilesystemPanel::OnExtractDirectories, this, ID_EXTRACT_DIR); Bind(wxEVT_MENU, &FilesystemPanel::OnExtractHeaderData, this, ID_EXTRACT_APPLOADER); Bind(wxEVT_MENU, &FilesystemPanel::OnExtractHeaderData, this, ID_EXTRACT_DOL); @@ -190,36 +190,34 @@ void FilesystemPanel::OnRightClickTree(wxTreeEvent& event) wxMenu menu; - const auto selection = m_tree_ctrl->GetSelection(); - const auto first_visible_item = m_tree_ctrl->GetFirstVisibleItem(); + const wxTreeItemId selection = m_tree_ctrl->GetSelection(); + const wxTreeItemId first_visible_item = m_tree_ctrl->GetFirstVisibleItem(); const int image_type = m_tree_ctrl->GetItemImage(selection); + const bool is_parent_of_partitions = m_has_partitions && first_visible_item == selection; - if (image_type == ICON_DISC && first_visible_item != selection) - { - menu.Append(ID_EXTRACT_DIR, _("Extract Partition...")); - } - else if (image_type == ICON_FOLDER) - { - menu.Append(ID_EXTRACT_DIR, _("Extract Directory...")); - } - else if (image_type == ICON_FILE) - { + if (image_type == ICON_FILE) menu.Append(ID_EXTRACT_FILE, _("Extract File...")); - } + else if (!is_parent_of_partitions) + menu.Append(ID_EXTRACT_DIR, _("Extract Files...")); - menu.Append(ID_EXTRACT_ALL, _("Extract All Files...")); - - if (!m_has_partitions || (image_type == ICON_DISC && first_visible_item != selection)) + if (image_type == ICON_DISC) { - menu.AppendSeparator(); - menu.Append(ID_EXTRACT_APPLOADER, _("Extract Apploader...")); - menu.Append(ID_EXTRACT_DOL, _("Extract DOL...")); - } + if (!is_parent_of_partitions) + { + menu.Append(ID_EXTRACT_APPLOADER, _("Extract Apploader...")); + menu.Append(ID_EXTRACT_DOL, _("Extract DOL...")); + } - if (image_type == ICON_DISC && first_visible_item != selection) - { - menu.AppendSeparator(); - menu.Append(ID_CHECK_INTEGRITY, _("Check Partition Integrity")); + if (first_visible_item == selection) + menu.Append(ID_EXTRACT_ALL, _("Extract Entire Disc...")); + else + menu.Append(ID_EXTRACT_ALL, _("Extract Entire Partition...")); + + if (first_visible_item != selection) + { + menu.AppendSeparator(); + menu.Append(ID_CHECK_INTEGRITY, _("Check Partition Integrity")); + } } PopupMenu(&menu); @@ -245,18 +243,8 @@ void FilesystemPanel::OnExtractDirectories(wxCommandEvent& event) const wxString selected_directory_label = m_tree_ctrl->GetItemText(m_tree_ctrl->GetSelection()); const wxString extract_path = wxDirSelector(_("Choose the folder to extract to")); - if (extract_path.empty() || selected_directory_label.empty()) - return; - - switch (event.GetId()) - { - case ID_EXTRACT_ALL: - ExtractAllFiles(extract_path); - break; - case ID_EXTRACT_DIR: + if (!extract_path.empty() && !selected_directory_label.empty()) ExtractSingleDirectory(extract_path); - break; - } } void FilesystemPanel::OnExtractHeaderData(wxCommandEvent& event) @@ -296,6 +284,41 @@ void FilesystemPanel::OnExtractHeaderData(wxCommandEvent& event) } } +void FilesystemPanel::OnExtractAll(wxCommandEvent& event) +{ + const wxString extract_path = wxDirSelector(_("Choose the folder to extract to")); + + if (extract_path.empty()) + return; + + const wxTreeItemId selection = m_tree_ctrl->GetSelection(); + const bool first_item_selected = m_tree_ctrl->GetFirstVisibleItem() == selection; + + if (m_has_partitions && first_item_selected) + { + const wxTreeItemId root = m_tree_ctrl->GetRootItem(); + + wxTreeItemIdValue cookie; + wxTreeItemId item = m_tree_ctrl->GetFirstChild(root, cookie); + + while (item.IsOk()) + { + const auto* const partition = static_cast(m_tree_ctrl->GetItemData(item)); + ExtractPartition(WxStrToStr(extract_path), *partition->filesystem); + item = m_tree_ctrl->GetNextChild(root, cookie); + } + } + else if (m_has_partitions && !first_item_selected) + { + const auto* const partition = static_cast(m_tree_ctrl->GetItemData(selection)); + ExtractPartition(WxStrToStr(extract_path), *partition->filesystem); + } + else + { + ExtractPartition(WxStrToStr(extract_path), *m_filesystem); + } +} + void FilesystemPanel::OnCheckPartitionIntegrity(wxCommandEvent& WXUNUSED(event)) { // Normally we can't enter this function if we're analyzing a volume that @@ -331,28 +354,6 @@ void FilesystemPanel::OnCheckPartitionIntegrity(wxCommandEvent& WXUNUSED(event)) } } -void FilesystemPanel::ExtractAllFiles(const wxString& output_folder) -{ - if (m_has_partitions) - { - const wxTreeItemId root = m_tree_ctrl->GetRootItem(); - - wxTreeItemIdValue cookie; - wxTreeItemId item = m_tree_ctrl->GetFirstChild(root, cookie); - - while (item.IsOk()) - { - const auto* const partition = static_cast(m_tree_ctrl->GetItemData(item)); - ExtractDirectories("", WxStrToStr(output_folder), *partition->filesystem); - item = m_tree_ctrl->GetNextChild(root, cookie); - } - } - else - { - ExtractDirectories("", WxStrToStr(output_folder), *m_filesystem); - } -} - void FilesystemPanel::ExtractSingleFile(const wxString& output_file_path) const { const std::pair path = BuildFilePathFromSelection(); @@ -371,13 +372,6 @@ void FilesystemPanel::ExtractDirectories(const std::string& full_path, const std::string& output_folder, const DiscIO::FileSystem& filesystem) { - if (full_path.empty()) // Root - { - DiscIO::ExportApploader(*m_opened_iso, filesystem.GetPartition(), - output_folder + "/apploader.img"); - DiscIO::ExportDOL(*m_opened_iso, filesystem.GetPartition(), output_folder + "/boot.dol"); - } - std::unique_ptr file_info = filesystem.FindFileInfo(full_path); u32 size = file_info->GetTotalChildren(); u32 progress = 0; @@ -399,6 +393,13 @@ void FilesystemPanel::ExtractDirectories(const std::string& full_path, }); } +void FilesystemPanel::ExtractPartition(const std::string& output_folder, + const DiscIO::FileSystem& filesystem) +{ + ExtractDirectories("", output_folder, filesystem); + DiscIO::ExportSystemData(*m_opened_iso, filesystem.GetPartition(), output_folder); +} + std::pair FilesystemPanel::BuildFilePathFromSelection() const { const wxTreeItemId root_node = m_tree_ctrl->GetRootItem(); diff --git a/Source/Core/DolphinWX/ISOProperties/FilesystemPanel.h b/Source/Core/DolphinWX/ISOProperties/FilesystemPanel.h index 9aef184262..040c2b79ad 100644 --- a/Source/Core/DolphinWX/ISOProperties/FilesystemPanel.h +++ b/Source/Core/DolphinWX/ISOProperties/FilesystemPanel.h @@ -46,13 +46,14 @@ private: void OnExtractFile(wxCommandEvent&); void OnExtractDirectories(wxCommandEvent&); void OnExtractHeaderData(wxCommandEvent&); + void OnExtractAll(wxCommandEvent&); void OnCheckPartitionIntegrity(wxCommandEvent&); - void ExtractAllFiles(const wxString& output_folder); void ExtractSingleFile(const wxString& output_file_path) const; void ExtractSingleDirectory(const wxString& output_folder); void ExtractDirectories(const std::string& full_path, const std::string& output_folder, const DiscIO::FileSystem& filesystem); + void ExtractPartition(const std::string& output_folder, const DiscIO::FileSystem& filesystem); std::pair BuildFilePathFromSelection() const; std::pair BuildDirectoryPathFromSelection() const;