FilesystemPanel: Refactor partition name stripping

This commit is contained in:
JosJuice 2017-06-18 12:44:32 +02:00
parent baf3a3b188
commit 5778e8bdba
2 changed files with 29 additions and 47 deletions

View File

@ -356,49 +356,16 @@ void FilesystemPanel::ExtractAllFiles(const wxString& output_folder)
void FilesystemPanel::ExtractSingleFile(const wxString& output_file_path) const
{
wxString selection_file_path = BuildFilePathFromSelection();
if (m_has_partitions)
{
const size_t slash_index = selection_file_path.find('/');
const wxString partition_label = selection_file_path.substr(0, slash_index);
const auto* const partition = FindWiiPartition(m_tree_ctrl, partition_label);
// Remove "Partition x/"
selection_file_path.erase(0, slash_index + 1);
DiscIO::ExportFile(*m_opened_iso, partition->filesystem->GetPartition(),
partition->filesystem->FindFileInfo(WxStrToStr(selection_file_path)).get(),
WxStrToStr(output_file_path));
}
else
{
DiscIO::ExportFile(*m_opened_iso, DiscIO::PARTITION_NONE,
m_filesystem->FindFileInfo(WxStrToStr(selection_file_path)).get(),
WxStrToStr(output_file_path));
}
const std::pair<wxString, const DiscIO::FileSystem&> path = BuildFilePathFromSelection();
DiscIO::ExportFile(*m_opened_iso, path.second.GetPartition(),
path.second.FindFileInfo(WxStrToStr(path.first)).get(),
WxStrToStr(output_file_path));
}
void FilesystemPanel::ExtractSingleDirectory(const wxString& output_folder)
{
wxString directory_path = BuildDirectoryPathFromSelection();
if (m_has_partitions)
{
const size_t slash_index = directory_path.find('/');
const wxString partition_label = directory_path.substr(0, slash_index);
const auto* const partition = FindWiiPartition(m_tree_ctrl, partition_label);
// Remove "Partition x/"
directory_path.erase(0, slash_index + 1);
ExtractDirectories(WxStrToStr(directory_path), WxStrToStr(output_folder),
*partition->filesystem);
}
else
{
ExtractDirectories(WxStrToStr(directory_path), WxStrToStr(output_folder), *m_filesystem);
}
const std::pair<wxString, const DiscIO::FileSystem&> path = BuildDirectoryPathFromSelection();
ExtractDirectories(WxStrToStr(path.first), WxStrToStr(output_folder), path.second);
}
static void ExtractDir(const std::string& full_path, const std::string& output_folder,
@ -464,7 +431,7 @@ void FilesystemPanel::ExtractDirectories(const std::string& full_path,
});
}
wxString FilesystemPanel::BuildFilePathFromSelection() const
std::pair<wxString, const DiscIO::FileSystem&> FilesystemPanel::BuildFilePathFromSelection() const
{
wxString file_path = m_tree_ctrl->GetItemText(m_tree_ctrl->GetSelection());
@ -477,12 +444,26 @@ wxString FilesystemPanel::BuildFilePathFromSelection() const
node = m_tree_ctrl->GetItemParent(node);
}
return file_path;
if (m_has_partitions)
{
const size_t slash_index = file_path.find('/');
const wxString partition_label = file_path.substr(0, slash_index);
const auto* const partition = FindWiiPartition(m_tree_ctrl, partition_label);
// Remove "Partition x/"
file_path.erase(0, slash_index + 1);
return {file_path, *partition->filesystem};
}
else
{
return {file_path, *m_filesystem};
}
}
wxString FilesystemPanel::BuildDirectoryPathFromSelection() const
std::pair<wxString, const DiscIO::FileSystem&>
FilesystemPanel::BuildDirectoryPathFromSelection() const
{
wxString directory_path = BuildFilePathFromSelection();
directory_path += DIR_SEP_CHR;
return directory_path;
const std::pair<wxString, const DiscIO::FileSystem&> result = BuildFilePathFromSelection();
return {result.first + DIR_SEP_CHR, result.second};
}

View File

@ -6,6 +6,7 @@
#include <memory>
#include <string>
#include <utility>
#include <wx/panel.h>
class GameListItem;
@ -53,8 +54,8 @@ private:
void ExtractDirectories(const std::string& full_path, const std::string& output_folder,
const DiscIO::FileSystem& filesystem);
wxString BuildFilePathFromSelection() const;
wxString BuildDirectoryPathFromSelection() const;
std::pair<wxString, const DiscIO::FileSystem&> BuildFilePathFromSelection() const;
std::pair<wxString, const DiscIO::FileSystem&> BuildDirectoryPathFromSelection() const;
wxTreeCtrl* m_tree_ctrl;