mirror of
https://github.com/wiiu-env/ftpiiu_plugin.git
synced 2024-11-16 17:59:19 +01:00
Improve performance when reading directories
This commit is contained in:
parent
bfc82df26f
commit
d566a7155e
@ -37,6 +37,9 @@
|
|||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <cinttypes>
|
#include <cinttypes>
|
||||||
|
#ifdef __WIIU__
|
||||||
|
#include <coreinit/filesystem_fsa.h>
|
||||||
|
#endif
|
||||||
#include <cstdarg>
|
#include <cstdarg>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
@ -1634,6 +1637,44 @@ void FtpSession::sendResponse (std::string_view const response_)
|
|||||||
m_responseBuffer.markUsed (response_.size ());
|
m_responseBuffer.markUsed (response_.size ());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __WIIU__
|
||||||
|
#ifndef FSA_DIRITER_MAGIC
|
||||||
|
#define FSA_DIRITER_MAGIC 0x77696975
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// TODO: make this less hacky. Ideally this should be handled by newlib.
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint32_t magic;
|
||||||
|
FSADirectoryHandle fd;
|
||||||
|
FSADirectoryEntry entry_data;
|
||||||
|
// Some fields are missing here!!!!
|
||||||
|
} __wut_fsa_dir_incomplete_t;
|
||||||
|
|
||||||
|
extern "C" void __wut_fsa_translate_stat (FSAClientHandle clientHandle,
|
||||||
|
FSStat *fsStat,
|
||||||
|
ino_t ino,
|
||||||
|
struct stat *posStat);
|
||||||
|
|
||||||
|
static bool __wut_fsa_get_stat_from_dir (DIR *dp, struct stat *posStat)
|
||||||
|
{
|
||||||
|
if (dp == NULL || dp->dirData == NULL || dp->dirData->dirStruct == NULL || posStat == NULL)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto const magic = *(uint32_t *)(dp->dirData->dirStruct);
|
||||||
|
if (magic == FSA_DIRITER_MAGIC)
|
||||||
|
{
|
||||||
|
__wut_fsa_dir_incomplete_t *dir = (__wut_fsa_dir_incomplete_t *)dp->dirData->dirStruct;
|
||||||
|
__wut_fsa_translate_stat (0, &dir->entry_data.info, 0, posStat);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
bool FtpSession::listTransfer ()
|
bool FtpSession::listTransfer ()
|
||||||
{
|
{
|
||||||
// check if we sent all available data
|
// check if we sent all available data
|
||||||
@ -1690,8 +1731,15 @@ bool FtpSession::listTransfer ()
|
|||||||
// build the path
|
// build the path
|
||||||
auto const fullPath = buildPath (m_lwd, dent->d_name);
|
auto const fullPath = buildPath (m_lwd, dent->d_name);
|
||||||
struct stat st = {};
|
struct stat st = {};
|
||||||
|
#ifdef __WIIU__
|
||||||
#ifdef __3DS__
|
auto const dp = static_cast<DIR *> (m_dir);
|
||||||
|
if (__wut_fsa_get_stat_from_dir (dp, &st))
|
||||||
|
{
|
||||||
|
// success!
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{ // fallback to lstat
|
||||||
|
#elifdef __3DS__
|
||||||
// the sdmc directory entry already has the type and size, so no need to do a slow stat
|
// the sdmc directory entry already has the type and size, so no need to do a slow stat
|
||||||
auto const dp = static_cast<DIR *> (m_dir);
|
auto const dp = static_cast<DIR *> (m_dir);
|
||||||
auto const magic = *reinterpret_cast<u32 *> (dp->dirData->dirStruct);
|
auto const magic = *reinterpret_cast<u32 *> (dp->dirData->dirStruct);
|
||||||
@ -1738,6 +1786,7 @@ bool FtpSession::listTransfer ()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
#endif
|
#endif
|
||||||
// lstat the entry
|
// lstat the entry
|
||||||
if (IOAbstraction::lstat (fullPath.c_str (), &st) != 0)
|
if (IOAbstraction::lstat (fullPath.c_str (), &st) != 0)
|
||||||
@ -1783,6 +1832,9 @@ bool FtpSession::listTransfer ()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
#if defined(__WIIU__) || defined(__3DS__)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
auto const path = encodePath (dent->d_name);
|
auto const path = encodePath (dent->d_name);
|
||||||
auto const rc = fillDirent (st, path);
|
auto const rc = fillDirent (st, path);
|
||||||
|
Loading…
Reference in New Issue
Block a user