mirror of
https://github.com/izzy2lost/dolphin.git
synced 2026-06-19 01:16:48 -07:00
Merge pull request #2820 from JosJuice/filesystem
Filesystem redesign and performance improvements
This commit is contained in:
@@ -88,28 +88,28 @@ void Log(u64 offset, const DiscIO::Partition& partition)
|
||||
if (!s_filesystem)
|
||||
return;
|
||||
|
||||
const std::string filename = s_filesystem->GetFileName(offset);
|
||||
const std::unique_ptr<DiscIO::FileInfo> file_info = s_filesystem->FindFileInfo(offset);
|
||||
|
||||
// Do nothing if no file was found at that offset
|
||||
if (filename.empty())
|
||||
if (!file_info)
|
||||
return;
|
||||
|
||||
const std::string path = file_info->GetPath();
|
||||
|
||||
// Do nothing if we found the same file again
|
||||
if (s_previous_file == filename)
|
||||
if (s_previous_file == path)
|
||||
return;
|
||||
|
||||
const u64 size = s_filesystem->GetFileSize(filename);
|
||||
const std::string size_string = ThousandSeparate(size / 1000, 7);
|
||||
const std::string size_string = ThousandSeparate(file_info->GetSize() / 1000, 7);
|
||||
|
||||
const std::string log_string =
|
||||
StringFromFormat("%s kB %s", size_string.c_str(), filename.c_str());
|
||||
if (IsSoundFile(filename))
|
||||
const std::string log_string = StringFromFormat("%s kB %s", size_string.c_str(), path.c_str());
|
||||
if (IsSoundFile(path))
|
||||
INFO_LOG(FILEMON, "%s", log_string.c_str());
|
||||
else
|
||||
WARN_LOG(FILEMON, "%s", log_string.c_str());
|
||||
|
||||
// Update the last accessed file
|
||||
s_previous_file = filename;
|
||||
s_previous_file = path;
|
||||
}
|
||||
|
||||
} // namespace FileMonitor
|
||||
|
||||
@@ -219,14 +219,21 @@ bool DiscScrubber::ParsePartitionData(const Partition& partition, PartitionHeade
|
||||
MarkAsUsedE(partition_data_offset, header->fst_offset, header->fst_size);
|
||||
|
||||
// Go through the filesystem and mark entries as used
|
||||
for (const FileInfo& file : filesystem->GetFileList())
|
||||
{
|
||||
DEBUG_LOG(DISCIO, "%s", file.m_FullPath.empty() ? "/" : file.m_FullPath.c_str());
|
||||
if ((file.m_NameOffset & 0x1000000) == 0)
|
||||
MarkAsUsedE(partition_data_offset, file.m_Offset, file.m_FileSize);
|
||||
}
|
||||
ParseFileSystemData(partition_data_offset, filesystem->GetRoot());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void DiscScrubber::ParseFileSystemData(u64 partition_data_offset, const FileInfo& directory)
|
||||
{
|
||||
for (const DiscIO::FileInfo& file_info : directory)
|
||||
{
|
||||
DEBUG_LOG(DISCIO, "Scrubbing %s", file_info.GetPath().c_str());
|
||||
if (file_info.IsDirectory())
|
||||
ParseFileSystemData(partition_data_offset, file_info);
|
||||
else
|
||||
MarkAsUsedE(partition_data_offset, file_info.GetOffset(), file_info.GetSize());
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace DiscIO
|
||||
|
||||
@@ -25,6 +25,7 @@ class IOFile;
|
||||
|
||||
namespace DiscIO
|
||||
{
|
||||
class FileInfo;
|
||||
class Volume;
|
||||
struct Partition;
|
||||
|
||||
@@ -64,6 +65,7 @@ private:
|
||||
bool ReadFromVolume(u64 offset, u64& buffer, const Partition& partition);
|
||||
bool ParseDisc();
|
||||
bool ParsePartitionData(const Partition& partition, PartitionHeader* header);
|
||||
void ParseFileSystemData(u64 partition_data_offset, const FileInfo& directory);
|
||||
|
||||
std::string m_filename;
|
||||
std::unique_ptr<Volume> m_disc;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -5,6 +5,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@@ -17,36 +19,97 @@ namespace DiscIO
|
||||
class Volume;
|
||||
struct Partition;
|
||||
|
||||
class FileInfoGCWii : public FileInfo
|
||||
{
|
||||
public:
|
||||
// None of the constructors take ownership of FST pointers
|
||||
|
||||
// Set everything manually
|
||||
FileInfoGCWii(const u8* fst, u8 offset_shift, u32 index, u32 total_file_infos);
|
||||
// For the root object only
|
||||
FileInfoGCWii(const u8* fst, u8 offset_shift);
|
||||
// Copy another object
|
||||
FileInfoGCWii(const FileInfoGCWii& file_info) = default;
|
||||
// Copy data that is common to the whole file system
|
||||
FileInfoGCWii(const FileInfoGCWii& file_info, u32 index);
|
||||
|
||||
~FileInfoGCWii() override;
|
||||
|
||||
std::unique_ptr<FileInfo> clone() const override;
|
||||
const_iterator begin() const override;
|
||||
const_iterator end() const override;
|
||||
|
||||
u64 GetOffset() const override;
|
||||
u32 GetSize() const override;
|
||||
bool IsDirectory() const override;
|
||||
u32 GetTotalChildren() const override;
|
||||
std::string GetName() const override;
|
||||
std::string GetPath() const override;
|
||||
|
||||
bool IsValid(u64 fst_size, const FileInfoGCWii& parent_directory) const;
|
||||
|
||||
protected:
|
||||
uintptr_t GetAddress() const override;
|
||||
FileInfo& operator++() override;
|
||||
|
||||
private:
|
||||
enum class EntryProperty
|
||||
{
|
||||
// NAME_OFFSET's lower 3 bytes are the name's offset within the name table.
|
||||
// NAME_OFFSET's upper 1 byte is 1 for directories and 0 for files.
|
||||
NAME_OFFSET = 0,
|
||||
// For files, FILE_OFFSET is the file offset in the partition,
|
||||
// and for directories, it's the FST index of the parent directory.
|
||||
// The root directory has its parent directory index set to 0.
|
||||
FILE_OFFSET = 1,
|
||||
// For files, FILE_SIZE is the file size, and for directories,
|
||||
// it's the FST index of the next entry that isn't in the directory.
|
||||
FILE_SIZE = 2
|
||||
};
|
||||
|
||||
// For files, returns the index of the next item. For directories,
|
||||
// returns the index of the next item that isn't inside it.
|
||||
u32 GetNextIndex() const;
|
||||
// Returns one of the three properties of this FST entry.
|
||||
// Read the comments in EntryProperty for details.
|
||||
u32 Get(EntryProperty entry_property) const;
|
||||
// Returns the name offset, excluding the directory identification byte
|
||||
u64 GetNameOffset() const;
|
||||
|
||||
const u8* m_fst;
|
||||
u8 m_offset_shift;
|
||||
u32 m_index;
|
||||
u32 m_total_file_infos;
|
||||
};
|
||||
|
||||
class FileSystemGCWii : public FileSystem
|
||||
{
|
||||
public:
|
||||
FileSystemGCWii(const Volume* _rVolume, const Partition& partition);
|
||||
virtual ~FileSystemGCWii();
|
||||
FileSystemGCWii(const Volume* volume, const Partition& partition);
|
||||
~FileSystemGCWii() override;
|
||||
|
||||
bool IsValid() const override { return m_Valid; }
|
||||
u64 GetFileSize(const std::string& _rFullPath) override;
|
||||
const std::vector<FileInfo>& GetFileList() override;
|
||||
std::string GetFileName(u64 _Address) override;
|
||||
u64 ReadFile(const std::string& _rFullPath, u8* _pBuffer, u64 _MaxBufferSize,
|
||||
u64 _OffsetInFile) override;
|
||||
bool ExportFile(const std::string& _rFullPath, const std::string& _rExportFilename) override;
|
||||
bool ExportApploader(const std::string& _rExportFolder) const override;
|
||||
bool ExportDOL(const std::string& _rExportFolder) const override;
|
||||
bool IsValid() const override { return m_valid; }
|
||||
const FileInfo& GetRoot() const override;
|
||||
std::unique_ptr<FileInfo> FindFileInfo(const std::string& path) const override;
|
||||
std::unique_ptr<FileInfo> FindFileInfo(u64 disc_offset) const override;
|
||||
|
||||
u64 ReadFile(const FileInfo* file_info, u8* buffer, u64 max_buffer_size,
|
||||
u64 offset_in_file) const override;
|
||||
bool ExportFile(const FileInfo* file_info, const std::string& export_filename) const override;
|
||||
bool ExportApploader(const std::string& export_folder) const override;
|
||||
bool ExportDOL(const std::string& export_folder) const override;
|
||||
std::optional<u64> GetBootDOLOffset() const override;
|
||||
std::optional<u32> GetBootDOLSize(u64 dol_offset) const override;
|
||||
|
||||
private:
|
||||
bool m_Initialized;
|
||||
bool m_Valid;
|
||||
bool m_valid;
|
||||
u32 m_offset_shift;
|
||||
std::vector<FileInfo> m_FileInfoVector;
|
||||
std::vector<u8> m_file_system_table;
|
||||
FileInfoGCWii m_root;
|
||||
// Maps the end offset of files to FST indexes
|
||||
mutable std::map<u64, u32> m_offset_file_info_cache;
|
||||
|
||||
std::string GetStringFromOffset(u64 _Offset) const;
|
||||
const FileInfo* FindFileInfo(const std::string& _rFullPath);
|
||||
bool DetectFileSystem();
|
||||
void InitFileSystem();
|
||||
size_t BuildFilenames(const size_t _FirstIndex, const size_t _LastIndex,
|
||||
const std::string& _szDirectory, u64 _NameTableOffset);
|
||||
std::unique_ptr<FileInfo> FindFileInfo(const std::string& path, const FileInfo& file_info) const;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -9,14 +9,14 @@
|
||||
|
||||
namespace DiscIO
|
||||
{
|
||||
FileSystem::FileSystem(const Volume* _rVolume, const Partition& partition)
|
||||
: m_rVolume(_rVolume), m_partition(partition)
|
||||
FileInfo::~FileInfo() = default;
|
||||
|
||||
FileSystem::FileSystem(const Volume* volume, const Partition& partition)
|
||||
: m_volume(volume), m_partition(partition)
|
||||
{
|
||||
}
|
||||
|
||||
FileSystem::~FileSystem()
|
||||
{
|
||||
}
|
||||
FileSystem::~FileSystem() = default;
|
||||
|
||||
std::unique_ptr<FileSystem> CreateFileSystem(const Volume* volume, const Partition& partition)
|
||||
{
|
||||
|
||||
+101
-22
@@ -4,6 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iterator>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
@@ -15,47 +16,125 @@
|
||||
namespace DiscIO
|
||||
{
|
||||
// file info of an FST entry
|
||||
struct FileInfo
|
||||
class FileInfo
|
||||
{
|
||||
u64 m_NameOffset = 0u;
|
||||
u64 m_Offset = 0u;
|
||||
u64 m_FileSize = 0u;
|
||||
std::string m_FullPath;
|
||||
friend class const_iterator;
|
||||
|
||||
bool IsDirectory() const { return (m_NameOffset & 0xFF000000) != 0; }
|
||||
FileInfo(u64 name_offset, u64 offset, u64 filesize)
|
||||
: m_NameOffset(name_offset), m_Offset(offset), m_FileSize(filesize)
|
||||
public:
|
||||
class const_iterator final
|
||||
{
|
||||
}
|
||||
public:
|
||||
using iterator_category = std::forward_iterator_tag;
|
||||
using value_type = const FileInfo;
|
||||
using difference_type = std::ptrdiff_t;
|
||||
using pointer = value_type*;
|
||||
using reference = value_type&;
|
||||
|
||||
FileInfo(FileInfo const&) = default;
|
||||
FileInfo() = default;
|
||||
const_iterator() : m_file_info(nullptr) {}
|
||||
const_iterator(std::unique_ptr<FileInfo> file_info) : m_file_info(std::move(file_info)) {}
|
||||
const_iterator(const const_iterator& it) : m_file_info(it.m_file_info->clone()) {}
|
||||
const_iterator(const_iterator&& it) : m_file_info(std::move(it.m_file_info)) {}
|
||||
~const_iterator() = default;
|
||||
const_iterator& operator=(const const_iterator& it)
|
||||
{
|
||||
m_file_info = it.m_file_info ? it.m_file_info->clone() : nullptr;
|
||||
return *this;
|
||||
}
|
||||
const_iterator& operator=(const_iterator&& it)
|
||||
{
|
||||
m_file_info = std::move(it.m_file_info);
|
||||
return *this;
|
||||
}
|
||||
const_iterator& operator++()
|
||||
{
|
||||
++*m_file_info;
|
||||
return *this;
|
||||
}
|
||||
const_iterator operator++(int)
|
||||
{
|
||||
const_iterator old = *this;
|
||||
++*m_file_info;
|
||||
return old;
|
||||
}
|
||||
bool operator==(const const_iterator& it) const
|
||||
{
|
||||
return m_file_info ? (it.m_file_info && *m_file_info == *it.m_file_info) : (!it.m_file_info);
|
||||
}
|
||||
bool operator!=(const const_iterator& it) const { return !operator==(it); }
|
||||
// Incrementing or destroying an iterator will invalidate its returned references and
|
||||
// pointers, but will not invalidate copies of the iterator or file info object.
|
||||
const FileInfo& operator*() const { return *m_file_info.get(); }
|
||||
const FileInfo* operator->() const { return m_file_info.get(); }
|
||||
private:
|
||||
std::unique_ptr<FileInfo> m_file_info;
|
||||
};
|
||||
|
||||
virtual ~FileInfo();
|
||||
|
||||
bool operator==(const FileInfo& other) const { return GetAddress() == other.GetAddress(); }
|
||||
bool operator!=(const FileInfo& other) const { return !operator==(other); }
|
||||
virtual std::unique_ptr<FileInfo> clone() const = 0;
|
||||
virtual const_iterator cbegin() const { return begin(); }
|
||||
virtual const_iterator cend() const { return end(); }
|
||||
virtual const_iterator begin() const = 0;
|
||||
virtual const_iterator end() const = 0;
|
||||
|
||||
// The offset of a file on the disc (inside the partition, if there is one).
|
||||
// Not guaranteed to return a meaningful value for directories.
|
||||
virtual u64 GetOffset() const = 0;
|
||||
// The size of a file.
|
||||
// Not guaranteed to return a meaningful value for directories.
|
||||
virtual u32 GetSize() const = 0;
|
||||
virtual bool IsDirectory() const = 0;
|
||||
// The number of files and directories in a directory, including those in subdirectories.
|
||||
// Not guaranteed to return a meaningful value for files.
|
||||
virtual u32 GetTotalChildren() const = 0;
|
||||
virtual std::string GetName() const = 0;
|
||||
// GetPath will find the parents of the current object and call GetName on them,
|
||||
// so it's slower than other functions. If you're traversing through folders
|
||||
// to get a file and its path, building the path while traversing is faster.
|
||||
virtual std::string GetPath() const = 0;
|
||||
|
||||
protected:
|
||||
// Only used for comparisons with other file info objects
|
||||
virtual uintptr_t GetAddress() const = 0;
|
||||
|
||||
// Called by iterators
|
||||
virtual FileInfo& operator++() = 0;
|
||||
};
|
||||
|
||||
class FileSystem
|
||||
{
|
||||
public:
|
||||
FileSystem(const Volume* _rVolume, const Partition& partition);
|
||||
|
||||
FileSystem(const Volume* volume, const Partition& partition);
|
||||
virtual ~FileSystem();
|
||||
|
||||
// If IsValid is false, GetRoot must not be called. CreateFileSystem
|
||||
// takes care of this automatically, so other code is recommended to use it.
|
||||
virtual bool IsValid() const = 0;
|
||||
virtual const std::vector<FileInfo>& GetFileList() = 0;
|
||||
virtual u64 GetFileSize(const std::string& _rFullPath) = 0;
|
||||
virtual u64 ReadFile(const std::string& _rFullPath, u8* _pBuffer, u64 _MaxBufferSize,
|
||||
u64 _OffsetInFile = 0) = 0;
|
||||
virtual bool ExportFile(const std::string& _rFullPath, const std::string& _rExportFilename) = 0;
|
||||
virtual bool ExportApploader(const std::string& _rExportFolder) const = 0;
|
||||
virtual bool ExportDOL(const std::string& _rExportFolder) const = 0;
|
||||
virtual std::string GetFileName(u64 _Address) = 0;
|
||||
// The object returned by GetRoot and all objects created from it
|
||||
// are only valid for as long as the file system object is valid.
|
||||
virtual const FileInfo& GetRoot() const = 0;
|
||||
// Returns nullptr if not found
|
||||
virtual std::unique_ptr<FileInfo> FindFileInfo(const std::string& path) const = 0;
|
||||
// Returns nullptr if not found
|
||||
virtual std::unique_ptr<FileInfo> FindFileInfo(u64 disc_offset) const = 0;
|
||||
|
||||
virtual u64 ReadFile(const FileInfo* file_info, u8* buffer, u64 max_buffer_size,
|
||||
u64 offset_in_file = 0) const = 0;
|
||||
virtual bool ExportFile(const FileInfo* file_info, const std::string& export_filename) const = 0;
|
||||
virtual bool ExportApploader(const std::string& export_folder) const = 0;
|
||||
virtual bool ExportDOL(const std::string& export_folder) const = 0;
|
||||
virtual std::optional<u64> GetBootDOLOffset() const = 0;
|
||||
virtual std::optional<u32> GetBootDOLSize(u64 dol_offset) const = 0;
|
||||
|
||||
virtual const Partition GetPartition() const { return m_partition; }
|
||||
protected:
|
||||
const Volume* const m_rVolume;
|
||||
const Volume* const m_volume;
|
||||
const Partition m_partition;
|
||||
};
|
||||
|
||||
// Returns nullptr if a valid file system could not be created
|
||||
std::unique_ptr<FileSystem> CreateFileSystem(const Volume* volume, const Partition& partition);
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -177,7 +177,11 @@ void VolumeGC::LoadBannerFile() const
|
||||
if (!file_system)
|
||||
return;
|
||||
|
||||
size_t file_size = static_cast<size_t>(file_system->GetFileSize("opening.bnr"));
|
||||
std::unique_ptr<FileInfo> file_info = file_system->FindFileInfo("opening.bnr");
|
||||
if (!file_info)
|
||||
return;
|
||||
|
||||
size_t file_size = static_cast<size_t>(file_info->GetSize());
|
||||
constexpr int BNR1_MAGIC = 0x31524e42;
|
||||
constexpr int BNR2_MAGIC = 0x32524e42;
|
||||
if (file_size != BNR1_SIZE && file_size != BNR2_SIZE)
|
||||
@@ -186,7 +190,12 @@ void VolumeGC::LoadBannerFile() const
|
||||
return;
|
||||
}
|
||||
|
||||
file_system->ReadFile("opening.bnr", reinterpret_cast<u8*>(&banner_file), file_size);
|
||||
if (file_size !=
|
||||
file_system->ReadFile(file_info.get(), reinterpret_cast<u8*>(&banner_file), file_size))
|
||||
{
|
||||
WARN_LOG(DISCIO, "Could not read opening.bnr.");
|
||||
return;
|
||||
}
|
||||
|
||||
bool is_bnr1;
|
||||
if (banner_file.id == BNR1_MAGIC && file_size == BNR1_SIZE)
|
||||
|
||||
@@ -274,8 +274,9 @@ std::map<Language, std::string> VolumeWii::GetLongNames() const
|
||||
return {};
|
||||
|
||||
std::vector<u8> opening_bnr(NAMES_TOTAL_BYTES);
|
||||
size_t size = file_system->ReadFile("opening.bnr", opening_bnr.data(), opening_bnr.size(), 0x5C);
|
||||
opening_bnr.resize(size);
|
||||
std::unique_ptr<FileInfo> file_info = file_system->FindFileInfo("opening.bnr");
|
||||
opening_bnr.resize(
|
||||
file_system->ReadFile(file_info.get(), opening_bnr.data(), opening_bnr.size(), 0x5C));
|
||||
return ReadWiiNames(opening_bnr);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
#include "DolphinWX/ISOProperties/FilesystemPanel.h"
|
||||
|
||||
#include <array>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include <wx/bitmap.h>
|
||||
@@ -83,55 +85,22 @@ wxImageList* LoadIconBitmaps(const wxWindow* context)
|
||||
return icon_list;
|
||||
}
|
||||
|
||||
size_t CreateDirectoryTree(wxTreeCtrl* tree_ctrl, wxTreeItemId parent,
|
||||
const std::vector<DiscIO::FileInfo>& file_infos,
|
||||
const size_t first_index, const size_t last_index)
|
||||
void CreateDirectoryTree(wxTreeCtrl* tree_ctrl, wxTreeItemId parent,
|
||||
const DiscIO::FileInfo& directory)
|
||||
{
|
||||
size_t current_index = first_index;
|
||||
|
||||
while (current_index < last_index)
|
||||
for (const DiscIO::FileInfo& file_info : directory)
|
||||
{
|
||||
const DiscIO::FileInfo& file_info = file_infos[current_index];
|
||||
std::string file_path = file_info.m_FullPath;
|
||||
|
||||
// Trim the trailing '/' if it exists.
|
||||
if (file_path.back() == DIR_SEP_CHR)
|
||||
{
|
||||
file_path.pop_back();
|
||||
}
|
||||
|
||||
// Cut off the path up to the actual filename or folder.
|
||||
// Say we have "/music/stream/stream1.strm", the result will be "stream1.strm".
|
||||
const size_t dir_sep_index = file_path.rfind(DIR_SEP_CHR);
|
||||
if (dir_sep_index != std::string::npos)
|
||||
{
|
||||
file_path = file_path.substr(dir_sep_index + 1);
|
||||
}
|
||||
|
||||
// check next index
|
||||
const wxString name = StrToWxStr(file_info.GetName());
|
||||
if (file_info.IsDirectory())
|
||||
{
|
||||
const wxTreeItemId item = tree_ctrl->AppendItem(parent, StrToWxStr(file_path), ICON_FOLDER);
|
||||
current_index = CreateDirectoryTree(tree_ctrl, item, file_infos, current_index + 1,
|
||||
static_cast<size_t>(file_info.m_FileSize));
|
||||
wxTreeItemId item = tree_ctrl->AppendItem(parent, name, ICON_FOLDER);
|
||||
CreateDirectoryTree(tree_ctrl, item, file_info);
|
||||
}
|
||||
else
|
||||
{
|
||||
tree_ctrl->AppendItem(parent, StrToWxStr(file_path), ICON_FILE);
|
||||
current_index++;
|
||||
tree_ctrl->AppendItem(parent, name, ICON_FILE);
|
||||
}
|
||||
}
|
||||
|
||||
return current_index;
|
||||
}
|
||||
|
||||
size_t CreateDirectoryTree(wxTreeCtrl* tree_ctrl, wxTreeItemId parent,
|
||||
const std::vector<DiscIO::FileInfo>& file_infos)
|
||||
{
|
||||
if (file_infos.empty())
|
||||
return 0;
|
||||
|
||||
return CreateDirectoryTree(tree_ctrl, parent, file_infos, 1, file_infos.at(0).m_FileSize);
|
||||
}
|
||||
|
||||
WiiPartition* FindWiiPartition(wxTreeCtrl* tree_ctrl, const wxString& label)
|
||||
@@ -213,7 +182,7 @@ bool FilesystemPanel::PopulateFileSystemTree()
|
||||
WiiPartition* const partition = new WiiPartition(std::move(file_system));
|
||||
|
||||
m_tree_ctrl->SetItemData(partition_root, partition);
|
||||
CreateDirectoryTree(m_tree_ctrl, partition_root, partition->filesystem->GetFileList());
|
||||
CreateDirectoryTree(m_tree_ctrl, partition_root, partition->filesystem->GetRoot());
|
||||
|
||||
if (partitions[i] == m_opened_iso->GetGamePartition())
|
||||
m_tree_ctrl->Expand(partition_root);
|
||||
@@ -226,7 +195,7 @@ bool FilesystemPanel::PopulateFileSystemTree()
|
||||
if (!m_filesystem)
|
||||
return false;
|
||||
|
||||
CreateDirectoryTree(m_tree_ctrl, m_tree_ctrl->GetRootItem(), m_filesystem->GetFileList());
|
||||
CreateDirectoryTree(m_tree_ctrl, m_tree_ctrl->GetRootItem(), m_filesystem->GetRoot());
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -394,13 +363,13 @@ void FilesystemPanel::ExtractAllFiles(const wxString& output_folder)
|
||||
while (item.IsOk())
|
||||
{
|
||||
const auto* const partition = static_cast<WiiPartition*>(m_tree_ctrl->GetItemData(item));
|
||||
ExtractDirectories("", WxStrToStr(output_folder), partition->filesystem.get());
|
||||
ExtractDirectories("", WxStrToStr(output_folder), *partition->filesystem);
|
||||
item = m_tree_ctrl->GetNextChild(root, cookie);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ExtractDirectories("", WxStrToStr(output_folder), m_filesystem.get());
|
||||
ExtractDirectories("", WxStrToStr(output_folder), *m_filesystem);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -417,12 +386,14 @@ void FilesystemPanel::ExtractSingleFile(const wxString& output_file_path) const
|
||||
// Remove "Partition x/"
|
||||
selection_file_path.erase(0, slash_index + 1);
|
||||
|
||||
partition->filesystem->ExportFile(WxStrToStr(selection_file_path),
|
||||
WxStrToStr(output_file_path));
|
||||
partition->filesystem->ExportFile(
|
||||
partition->filesystem->FindFileInfo(WxStrToStr(selection_file_path)).get(),
|
||||
WxStrToStr(output_file_path));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_filesystem->ExportFile(WxStrToStr(selection_file_path), WxStrToStr(output_file_path));
|
||||
m_filesystem->ExportFile(m_filesystem->FindFileInfo(WxStrToStr(selection_file_path)).get(),
|
||||
WxStrToStr(output_file_path));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -440,100 +411,71 @@ void FilesystemPanel::ExtractSingleDirectory(const wxString& output_folder)
|
||||
directory_path.erase(0, slash_index + 1);
|
||||
|
||||
ExtractDirectories(WxStrToStr(directory_path), WxStrToStr(output_folder),
|
||||
partition->filesystem.get());
|
||||
*partition->filesystem);
|
||||
}
|
||||
else
|
||||
{
|
||||
ExtractDirectories(WxStrToStr(directory_path), WxStrToStr(output_folder), m_filesystem.get());
|
||||
ExtractDirectories(WxStrToStr(directory_path), WxStrToStr(output_folder), *m_filesystem);
|
||||
}
|
||||
}
|
||||
|
||||
void ExtractDir(const std::string& full_path, const std::string& output_folder,
|
||||
const DiscIO::FileSystem& file_system, const DiscIO::FileInfo& directory,
|
||||
const std::function<bool(const std::string& path)>& 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, file_system, file_info, update_progress);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (File::Exists(output_path))
|
||||
NOTICE_LOG(DISCIO, "%s already exists", output_path.c_str());
|
||||
else if (!file_system.ExportFile(&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,
|
||||
DiscIO::FileSystem* filesystem)
|
||||
const DiscIO::FileSystem& filesystem)
|
||||
{
|
||||
const std::vector<DiscIO::FileInfo>& fst = filesystem->GetFileList();
|
||||
|
||||
u32 index = 0;
|
||||
u32 size = 0;
|
||||
|
||||
// Extract all
|
||||
if (full_path.empty())
|
||||
if (full_path.empty()) // Root
|
||||
{
|
||||
size = static_cast<u32>(fst.size());
|
||||
|
||||
filesystem->ExportApploader(output_folder);
|
||||
filesystem->ExportDOL(output_folder);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Look for the dir we are going to extract
|
||||
for (index = 0; index < fst.size(); ++index)
|
||||
{
|
||||
if (fst[index].m_FullPath == full_path)
|
||||
{
|
||||
INFO_LOG(DISCIO, "Found the directory at %u", index);
|
||||
size = static_cast<u32>(fst[index].m_FileSize);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
INFO_LOG(DISCIO, "Directory found from %u to %u\nextracting to: %s", index, size,
|
||||
output_folder.c_str());
|
||||
filesystem.ExportApploader(output_folder);
|
||||
filesystem.ExportDOL(output_folder);
|
||||
}
|
||||
|
||||
const auto dialog_title = (index != 0) ? _("Extracting Directory") : _("Extracting All Files");
|
||||
wxProgressDialog dialog(dialog_title, _("Extracting..."), static_cast<int>(size - 1), this,
|
||||
std::unique_ptr<DiscIO::FileInfo> file_info = filesystem.FindFileInfo(full_path);
|
||||
u32 size = file_info->GetTotalChildren();
|
||||
u32 progress = 0;
|
||||
|
||||
wxString dialog_title = full_path.empty() ? _("Extracting All Files") : _("Extracting Directory");
|
||||
wxProgressDialog dialog(dialog_title, _("Extracting..."), size, this,
|
||||
wxPD_APP_MODAL | wxPD_AUTO_HIDE | wxPD_CAN_ABORT | wxPD_ELAPSED_TIME |
|
||||
wxPD_ESTIMATED_TIME | wxPD_REMAINING_TIME | wxPD_SMOOTH);
|
||||
|
||||
// Extraction
|
||||
for (u32 i = index; i < size; i++)
|
||||
{
|
||||
File::CreateFullPath(output_folder + "/" + full_path);
|
||||
ExtractDir(full_path, output_folder, filesystem, *file_info, [&](const std::string& path) {
|
||||
dialog.SetTitle(wxString::Format(
|
||||
"%s : %u%%", dialog_title.c_str(),
|
||||
static_cast<u32>((static_cast<float>(i - index) / static_cast<float>(size - index)) *
|
||||
100)));
|
||||
|
||||
dialog.Update(i, wxString::Format(_("Extracting %s"), StrToWxStr(fst[i].m_FullPath)));
|
||||
|
||||
if (dialog.WasCancelled())
|
||||
break;
|
||||
|
||||
if (fst[i].IsDirectory())
|
||||
{
|
||||
const std::string export_name =
|
||||
StringFromFormat("%s/%s/", output_folder.c_str(), fst[i].m_FullPath.c_str());
|
||||
INFO_LOG(DISCIO, "%s", export_name.c_str());
|
||||
|
||||
if (!File::Exists(export_name) && !File::CreateFullPath(export_name))
|
||||
{
|
||||
ERROR_LOG(DISCIO, "Could not create the path %s", export_name.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!File::IsDirectory(export_name))
|
||||
ERROR_LOG(DISCIO, "%s already exists and is not a directory", export_name.c_str());
|
||||
|
||||
ERROR_LOG(DISCIO, "Folder %s already exists", export_name.c_str());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
const std::string export_name =
|
||||
StringFromFormat("%s/%s", output_folder.c_str(), fst[i].m_FullPath.c_str());
|
||||
INFO_LOG(DISCIO, "%s", export_name.c_str());
|
||||
|
||||
if (!File::Exists(export_name) && !filesystem->ExportFile(fst[i].m_FullPath, export_name))
|
||||
{
|
||||
ERROR_LOG(DISCIO, "Could not export %s", export_name.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
ERROR_LOG(DISCIO, "%s already exists", export_name.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
"%s : %d%%", dialog_title.c_str(),
|
||||
static_cast<u32>((static_cast<float>(progress) / static_cast<float>(size)) * 100)));
|
||||
dialog.Update(progress, wxString::Format(_("Extracting %s"), StrToWxStr(path)));
|
||||
++progress;
|
||||
return dialog.WasCancelled();
|
||||
});
|
||||
}
|
||||
|
||||
wxString FilesystemPanel::BuildFilePathFromSelection() const
|
||||
|
||||
@@ -51,7 +51,7 @@ private:
|
||||
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,
|
||||
DiscIO::FileSystem* filesystem);
|
||||
const DiscIO::FileSystem& filesystem);
|
||||
|
||||
wxString BuildFilePathFromSelection() const;
|
||||
wxString BuildDirectoryPathFromSelection() const;
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
Reference in New Issue
Block a user