___IMPLEMENT_FS2__INSPIERED_BY_3DSHELL__

This commit is contained in:
skymz4
2022-04-16 16:02:44 +02:00
committed by GitHub
parent 651a43574f
commit b03633e010
2 changed files with 146 additions and 6 deletions

View File

@@ -2,6 +2,8 @@
#include "log.hpp"
#include <regex>
FS_Archive archive, sdmc_archive, nand_archive;
#define RGBA8(r, g, b, a) ((((r) & 0xFF) << 0) | (((g) & 0xFF) << 8) | (((b) & 0xFF) << 16) | (((a) & 0xFF) << 24))
#define D7_NOTHING C2D_Color32(0, 0, 0, 0)
#define CFGVER "1"
@@ -1055,3 +1057,123 @@ bool RenderD7::Console::Update()
return dr_sc;
}
*/
//FS2
Result RenderD7::FS2::OpenArchive(FS_Archive *archive, FS_ArchiveID id)
{
Result ret = 0;
if (R_FAILED(ret = FSUSER_OpenArchive(archive, id, fsMakePath(PATH_EMPTY, ""))))
return ret;
return 0;
}
Result RenderD7::FS2::CloseArchive(FS_Archive archive)
{
Result ret = 0;
if (R_FAILED(ret = FSUSER_CloseArchive(archive)))
return ret;
return 0;
}
bool RenderD7::FS2::DirExists(FS_Archive archive, const std::string &path)
{
Handle handle;
std::u16string path_u16 = std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>{}.from_bytes(path.data());
if (R_FAILED(FSUSER_OpenDirectory(&handle, archive, fsMakePath(PATH_UTF16, path_u16.c_str()))))
return false;
if (R_FAILED(FSDIR_Close(handle)))
return false;
return true;
}
u64 RenderD7::FS2::GetTotalStorage(FS_SystemMediaType mediatype) {
Result ret = 0;
FS_ArchiveResource resource = { 0 };
if (R_FAILED(ret = FSUSER_GetArchiveResource(&resource, mediatype)))
{
return ret;
}
return (static_cast<u64>(resource.totalClusters) * static_cast<u64>(resource.clusterSize));
}
u64 RenderD7::FS2::GetUsedStorage(FS_SystemMediaType mediatype)
{
Result ret = 0;
FS_ArchiveResource resource = { 0 };
if (R_FAILED(ret = FSUSER_GetArchiveResource(&resource, mediatype)))
{
return ret;
}
return ((static_cast<u64>(resource.totalClusters) * static_cast<u64>(resource.clusterSize)) -
(static_cast<u64>(resource.freeClusters) * static_cast<u64>(resource.clusterSize)));
}
static bool Sort(const FS_DirectoryEntry &entryA, const FS_DirectoryEntry &entryB) {
if ((entryA.attributes & FS_ATTRIBUTE_DIRECTORY) && !(entryB.attributes & FS_ATTRIBUTE_DIRECTORY))
return true;
else if (!(entryA.attributes & FS_ATTRIBUTE_DIRECTORY) && (entryB.attributes & FS_ATTRIBUTE_DIRECTORY))
return false;
else {
std::u16string entryA_name = reinterpret_cast<const char16_t *>(entryA.name);
std::u16string entryB_name = reinterpret_cast<const char16_t *>(entryB.name);
std::transform(entryA_name.begin(), entryA_name.end(), entryA_name.begin(), [](unsigned char c){ return std::tolower(c); });
std::transform(entryB_name.begin(), entryB_name.end(), entryB_name.begin(), [](unsigned char c){ return std::tolower(c); });
if (entryA_name.compare(entryB_name) < 0)
return true;
break;
}
return false;
}
Result RenderD7::FS2::GetDirList(const std::string &path, std::vector<FS_DirectoryEntry> &entries)
{
if (!entries.empty())
entries.clear();
Result ret = 0;
Handle dir = 0;
std::u16string path_u16 = std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>{}.from_bytes(path.data());
if (R_FAILED(ret = FSUSER_OpenDirectory(&dir, archive, fsMakePath(PATH_UTF16, path_u16.c_str())))) {
return ret;
}
u32 entry_count = 0;
do {
FS_DirectoryEntry entry;
if (R_FAILED(ret = FSDIR_Read(dir, &entry_count, 1, &entry))) {
return ret;
}
if (entry_count == 1)
entries.push_back(entry);
} while(entry_count > 0);
std::sort(entries.begin(), entries.end(), Sort);
if (R_FAILED(ret = FSDIR_Close(dir))) {
return ret;
}
return 0;
}
void RenderD7::FS2::Convert(std::vector<FS_DirectoryEntry> &entries, std::vector<RenderD7::DirContent> &converted)
{
RenderD7::DirContent temp;
for (int i = 0; i < (int)entries.size(); i++)
{
const std::u16string entry_name_utf16 = reinterpret_cast<const char16_t *>(entries[i].name);
const std::string filename = std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>{}.to_bytes(entry_name_utf16.data());
temp.name = filename;
if ((entryA.attributes & FS_ATTRIBUTE_DIRECTORY)) temp.isDir = true;
converted.push_back(temp);
}
}
void RenderD7::FS2::GetContents(std::string path, std::vector<RenderD7::DirContent> &converted)
{
}