summaryrefslogtreecommitdiff
path: root/Source/Core/DiscIO/NANDImporter.cpp
diff options
context:
space:
mode:
authorStarsam80 <samraskauskas@gmail.com>2021-12-29 17:49:16 -0700
committerStarsam80 <samraskauskas@gmail.com>2022-03-01 19:24:59 -0700
commit6758c77c39b094555ab2797b0419217de40e202e (patch)
tree71b43dc6cd4d88ed139da5f68620143152164de2 /Source/Core/DiscIO/NANDImporter.cpp
parent2ccd9744719a03bd37b47ebbfde7d67d89491749 (diff)
NANDImporter: Reduce recursion in `ProcessEntry`
It also simplifies the code flow, as it no longer goes backwards through the filesystem chain.
Diffstat (limited to 'Source/Core/DiscIO/NANDImporter.cpp')
-rw-r--r--Source/Core/DiscIO/NANDImporter.cpp50
1 files changed, 22 insertions, 28 deletions
diff --git a/Source/Core/DiscIO/NANDImporter.cpp b/Source/Core/DiscIO/NANDImporter.cpp
index 32dafdd58d..322dd548d7 100644
--- a/Source/Core/DiscIO/NANDImporter.cpp
+++ b/Source/Core/DiscIO/NANDImporter.cpp
@@ -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)
{
NANDFSTEntry entry;
- memcpy(&entry, &m_nand[m_nand_fst_offset + sizeof(NANDFSTEntry) * entry_number],
- sizeof(NANDFSTEntry));
-
- if (entry.sib != 0xffff)
- ProcessEntry(entry.sib, parent_path);
-
- Type type = static_cast<Type>(entry.mode & 3);
- if (type == Type::File)
- ProcessFile(entry, parent_path);
- else if (type == Type::Directory)
- ProcessDirectory(entry, parent_path);
- else
- ERROR_LOG_FMT(DISCIO, "Ignoring unknown entry type for {}", entry);
+ while (entry_number != 0xffff)
+ {
+ memcpy(&entry, &m_nand[m_nand_fst_offset + sizeof(NANDFSTEntry) * entry_number],
+ sizeof(NANDFSTEntry));
+
+ const std::string path = GetPath(entry, parent_path);
+ INFO_LOG_FMT(DISCIO, "Entry: {} Path: {}", entry, path);
+ m_update_callback();
+
+ Type type = static_cast<Type>(entry.mode & 3);
+ if (type == Type::File)
+ ProcessFile(entry, path);
+ else if (type == Type::Directory)
+ ProcessDirectory(entry, path);
+ else
+ 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);
-
- if (entry.sub != 0xffff)
- ProcessEntry(entry.sub, path);
-
- INFO_LOG_FMT(DISCIO, "Path: {}", parent_path);
+ ProcessEntry(entry.sub, 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_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");
std::array<u8, 16> key{};
std::copy(&m_nand_keys[NAND_AES_KEY_OFFSET], &m_nand_keys[NAND_AES_KEY_OFFSET + key.size()],