mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 14:19:46 -06:00
NANDImporter: Reduce recursion in ProcessEntry
It also simplifies the code flow, as it no longer goes backwards through the filesystem chain.
This commit is contained in:
@ -129,44 +129,38 @@ std::string NANDImporter::GetPath(const NANDFSTEntry& entry, const std::string&
|
|||||||
void NANDImporter::ProcessEntry(u16 entry_number, const std::string& parent_path)
|
void NANDImporter::ProcessEntry(u16 entry_number, const std::string& parent_path)
|
||||||
{
|
{
|
||||||
NANDFSTEntry entry;
|
NANDFSTEntry entry;
|
||||||
memcpy(&entry, &m_nand[m_nand_fst_offset + sizeof(NANDFSTEntry) * entry_number],
|
while (entry_number != 0xffff)
|
||||||
sizeof(NANDFSTEntry));
|
{
|
||||||
|
memcpy(&entry, &m_nand[m_nand_fst_offset + sizeof(NANDFSTEntry) * entry_number],
|
||||||
|
sizeof(NANDFSTEntry));
|
||||||
|
|
||||||
if (entry.sib != 0xffff)
|
const std::string path = GetPath(entry, parent_path);
|
||||||
ProcessEntry(entry.sib, parent_path);
|
INFO_LOG_FMT(DISCIO, "Entry: {} Path: {}", entry, path);
|
||||||
|
m_update_callback();
|
||||||
|
|
||||||
Type type = static_cast<Type>(entry.mode & 3);
|
Type type = static_cast<Type>(entry.mode & 3);
|
||||||
if (type == Type::File)
|
if (type == Type::File)
|
||||||
ProcessFile(entry, parent_path);
|
ProcessFile(entry, path);
|
||||||
else if (type == Type::Directory)
|
else if (type == Type::Directory)
|
||||||
ProcessDirectory(entry, parent_path);
|
ProcessDirectory(entry, path);
|
||||||
else
|
else
|
||||||
ERROR_LOG_FMT(DISCIO, "Ignoring unknown entry type for {}", entry);
|
ERROR_LOG_FMT(DISCIO, "Ignoring unknown entry type for {}", entry);
|
||||||
|
|
||||||
|
entry_number = entry.sib;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NANDImporter::ProcessDirectory(const NANDFSTEntry& entry, const std::string& parent_path)
|
void NANDImporter::ProcessDirectory(const NANDFSTEntry& entry, const std::string& path)
|
||||||
{
|
{
|
||||||
m_update_callback();
|
|
||||||
INFO_LOG_FMT(DISCIO, "Path: {}", FormatDebugString(entry));
|
|
||||||
|
|
||||||
const std::string path = GetPath(entry, parent_path);
|
|
||||||
File::CreateDir(m_nand_root + path);
|
File::CreateDir(m_nand_root + path);
|
||||||
|
ProcessEntry(entry.sub, path);
|
||||||
if (entry.sub != 0xffff)
|
|
||||||
ProcessEntry(entry.sub, path);
|
|
||||||
|
|
||||||
INFO_LOG_FMT(DISCIO, "Path: {}", parent_path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NANDImporter::ProcessFile(const NANDFSTEntry& entry, const std::string& parent_path)
|
void NANDImporter::ProcessFile(const NANDFSTEntry& entry, const std::string& path)
|
||||||
{
|
{
|
||||||
constexpr size_t NAND_AES_KEY_OFFSET = 0x158;
|
constexpr size_t NAND_AES_KEY_OFFSET = 0x158;
|
||||||
constexpr size_t NAND_FAT_BLOCK_SIZE = 0x4000;
|
constexpr size_t NAND_FAT_BLOCK_SIZE = 0x4000;
|
||||||
|
|
||||||
m_update_callback();
|
|
||||||
INFO_LOG_FMT(DISCIO, "File: {}", FormatDebugString(entry));
|
|
||||||
|
|
||||||
const std::string path = GetPath(entry, parent_path);
|
|
||||||
File::IOFile file(m_nand_root + path, "wb");
|
File::IOFile file(m_nand_root + path, "wb");
|
||||||
std::array<u8, 16> key{};
|
std::array<u8, 16> key{};
|
||||||
std::copy(&m_nand_keys[NAND_AES_KEY_OFFSET], &m_nand_keys[NAND_AES_KEY_OFFSET + key.size()],
|
std::copy(&m_nand_keys[NAND_AES_KEY_OFFSET], &m_nand_keys[NAND_AES_KEY_OFFSET + key.size()],
|
||||||
|
@ -55,8 +55,8 @@ private:
|
|||||||
std::string GetPath(const NANDFSTEntry& entry, const std::string& parent_path);
|
std::string GetPath(const NANDFSTEntry& entry, const std::string& parent_path);
|
||||||
std::string FormatDebugString(const NANDFSTEntry& entry);
|
std::string FormatDebugString(const NANDFSTEntry& entry);
|
||||||
void ProcessEntry(u16 entry_number, const std::string& parent_path);
|
void ProcessEntry(u16 entry_number, const std::string& parent_path);
|
||||||
void ProcessFile(const NANDFSTEntry& entry, const std::string& parent_path);
|
void ProcessFile(const NANDFSTEntry& entry, const std::string& path);
|
||||||
void ProcessDirectory(const NANDFSTEntry& entry, const std::string& parent_path);
|
void ProcessDirectory(const NANDFSTEntry& entry, const std::string& path);
|
||||||
void ExportKeys();
|
void ExportKeys();
|
||||||
|
|
||||||
std::string m_nand_root;
|
std::string m_nand_root;
|
||||||
|
Reference in New Issue
Block a user