diff --git a/Source/Core/DiscIO/DiscExtractor.cpp b/Source/Core/DiscIO/DiscExtractor.cpp index 323fe706f2..dbd5a7a821 100644 --- a/Source/Core/DiscIO/DiscExtractor.cpp +++ b/Source/Core/DiscIO/DiscExtractor.cpp @@ -71,6 +71,38 @@ bool ExportFile(const Volume& volume, const Partition& partition, const FileInfo export_filename); } +void ExportDirectory(const Volume& volume, const Partition partition, const FileInfo& directory, + bool recursive, const std::string& filesystem_path, + const std::string& export_folder, + const std::function& update_progress) +{ + for (const FileInfo& file_info : directory) + { + const std::string path = + filesystem_path + file_info.GetName() + (file_info.IsDirectory() ? "/" : ""); + const std::string export_path = export_folder + '/' + path; + + if (update_progress(path)) + return; + + DEBUG_LOG(DISCIO, "%s", export_path.c_str()); + + if (!file_info.IsDirectory()) + { + if (File::Exists(export_path)) + NOTICE_LOG(DISCIO, "%s already exists", export_path.c_str()); + else if (!ExportFile(volume, partition, &file_info, export_path)) + ERROR_LOG(DISCIO, "Could not export %s", export_path.c_str()); + } + else if (recursive) + { + File::CreateFullPath(export_path); + ExportDirectory(volume, partition, file_info, recursive, path, export_folder, + update_progress); + } + } +} + bool ExportApploader(const Volume& volume, const Partition& partition, const std::string& export_filename) { diff --git a/Source/Core/DiscIO/DiscExtractor.h b/Source/Core/DiscIO/DiscExtractor.h index 6061075b9f..1372f2a8cd 100644 --- a/Source/Core/DiscIO/DiscExtractor.h +++ b/Source/Core/DiscIO/DiscExtractor.h @@ -4,6 +4,7 @@ #pragma once +#include #include #include "Common/CommonTypes.h" @@ -20,6 +21,15 @@ bool ExportData(const Volume& volume, const Partition& partition, u64 offset, u6 const std::string& export_filename); bool ExportFile(const Volume& volume, const Partition& partition, const FileInfo* file_info, const std::string& export_filename); + +// update_progress is called once for each child (file or directory). +// If update_progress returns true, the extraction gets cancelled. +// filesystem_path is supposed to be the path corresponding to the directory argument. +void ExportDirectory(const Volume& volume, const Partition partition, const FileInfo& directory, + bool recursive, const std::string& filesystem_path, + const std::string& export_folder, + const std::function& update_progress); + bool ExportApploader(const Volume& volume, const Partition& partition, const std::string& export_filename); std::optional GetBootDOLOffset(const Volume& volume, const Partition& partition); diff --git a/Source/Core/DolphinWX/ISOProperties/FilesystemPanel.cpp b/Source/Core/DolphinWX/ISOProperties/FilesystemPanel.cpp index 226540857d..f0f7cd429a 100644 --- a/Source/Core/DolphinWX/ISOProperties/FilesystemPanel.cpp +++ b/Source/Core/DolphinWX/ISOProperties/FilesystemPanel.cpp @@ -6,7 +6,6 @@ #include #include -#include #include #include #include @@ -368,36 +367,6 @@ void FilesystemPanel::ExtractSingleDirectory(const wxString& output_folder) ExtractDirectories(WxStrToStr(path.first), WxStrToStr(output_folder), path.second); } -static void ExtractDir(const std::string& full_path, const std::string& output_folder, - const DiscIO::Volume& volume, const DiscIO::Partition partition, - const DiscIO::FileInfo& directory, - const std::function& update_progress) -{ - for (const DiscIO::FileInfo& file_info : directory) - { - const std::string path = full_path + file_info.GetName() + (file_info.IsDirectory() ? "/" : ""); - const std::string output_path = output_folder + DIR_SEP_CHR + path; - - if (update_progress(path)) - return; - - DEBUG_LOG(DISCIO, "%s", output_path.c_str()); - - if (file_info.IsDirectory()) - { - File::CreateFullPath(output_path); - ExtractDir(path, output_folder, volume, partition, file_info, update_progress); - } - else - { - if (File::Exists(output_path)) - NOTICE_LOG(DISCIO, "%s already exists", output_path.c_str()); - else if (!DiscIO::ExportFile(volume, partition, &file_info, output_path)) - ERROR_LOG(DISCIO, "Could not export %s", output_path.c_str()); - } - } -} - void FilesystemPanel::ExtractDirectories(const std::string& full_path, const std::string& output_folder, const DiscIO::FileSystem& filesystem) @@ -419,8 +388,8 @@ void FilesystemPanel::ExtractDirectories(const std::string& full_path, wxPD_ESTIMATED_TIME | wxPD_REMAINING_TIME | wxPD_SMOOTH); File::CreateFullPath(output_folder + "/" + full_path); - ExtractDir( - full_path, output_folder, *m_opened_iso, filesystem.GetPartition(), *file_info, + DiscIO::ExportDirectory( + *m_opened_iso, filesystem.GetPartition(), *file_info, true, full_path, output_folder, [&](const std::string& path) { dialog.SetTitle(wxString::Format( "%s : %d%%", dialog_title.c_str(),