Something like this maybe?

This commit is contained in:
goeiecool9999 2022-09-07 20:25:03 +02:00 committed by klaas
parent 7a848be8a8
commit 3922ef5e85
8 changed files with 21 additions and 64 deletions

View file

@ -1,6 +1,7 @@
#include "config/ActiveSettings.h" #include "config/ActiveSettings.h"
#include "Cafe/Filesystem/fsc.h" #include "Cafe/Filesystem/fsc.h"
#include "Cafe/Filesystem/fscDeviceHostFS.h" #include "Cafe/Filesystem/fscDeviceHostFS.h"
#include "Cafe/Filesystem/FSPath.h"
#include "Common/FileStream.h" #include "Common/FileStream.h"
@ -157,7 +158,7 @@ bool FSCVirtualFile_Host::fscDirNext(FSCDirEntry* dirEntry)
return true; return true;
} }
FSCVirtualFile* FSCVirtualFile_Host::OpenFile(const fs::path& path, FSC_ACCESS_FLAG accessFlags, sint32& fscStatus) FSCVirtualFile* FSCVirtualFile_Host::OpenFile(const FSPath& path, FSC_ACCESS_FLAG accessFlags, sint32& fscStatus)
{ {
if (!HAS_FLAG(accessFlags, FSC_ACCESS_FLAG::OPEN_FILE) && !HAS_FLAG(accessFlags, FSC_ACCESS_FLAG::OPEN_DIR)) if (!HAS_FLAG(accessFlags, FSC_ACCESS_FLAG::OPEN_FILE) && !HAS_FLAG(accessFlags, FSC_ACCESS_FLAG::OPEN_DIR))
cemu_assert_debug(false); // not allowed. At least one of both flags must be set cemu_assert_debug(false); // not allowed. At least one of both flags must be set
@ -226,55 +227,7 @@ class fscDeviceHostFSC : public fscDeviceC {
// todo: implement caching. // todo: implement caching.
*fscStatus = FSC_STATUS_OK; *fscStatus = FSC_STATUS_OK;
// explore directories recursively and find the matching cases. FSPath correctedPath = FSPath::Convert(pathString);
std::filesystem::path path = pathString;
std::filesystem::path relPath = path.relative_path();
std::filesystem::path correctedPath = path.root_path();
// helper function to convert a path's alphabet characters to lowercase.
auto static lowercase_path = [](std::filesystem::path const & path)
{
std::wstring string = path.wstring();
for (auto& i : string)
{
i = std::isalpha(i) ? std::tolower(i) : i;
}
return string;
};
bool found;
for (auto const &it : relPath)
{
found = false;
std::error_code listErr;
for (auto const& dirEntry : std::filesystem::directory_iterator{correctedPath, listErr})
{
std::filesystem::path entryName = dirEntry.path().filename();
if (lowercase_path(entryName) == lowercase_path(it))
{
correctedPath /= entryName;
found = true;
break;
}
}
// if we can't iterate directory, just copy the original case.
if(listErr)
{
correctedPath /= it;
found = true;
}
if (!found)
break;
}
if(!found)
{
*fscStatus = FSC_STATUS_FILE_NOT_FOUND;
return nullptr;
}
return FSCVirtualFile_Host::OpenFile(correctedPath, accessFlags, *fscStatus); return FSCVirtualFile_Host::OpenFile(correctedPath, accessFlags, *fscStatus);
} }

View file

@ -1,9 +1,10 @@
#include "Cafe/Filesystem/fsc.h" #include "Cafe/Filesystem/fsc.h"
#include "FSPath.h"
class FSCVirtualFile_Host : public FSCVirtualFile class FSCVirtualFile_Host : public FSCVirtualFile
{ {
public: public:
static FSCVirtualFile* OpenFile(const fs::path& path, FSC_ACCESS_FLAG accessFlags, sint32& fscStatus); static FSCVirtualFile* OpenFile(const FSPath& path, FSC_ACCESS_FLAG accessFlags, sint32& fscStatus);
~FSCVirtualFile_Host() override; ~FSCVirtualFile_Host() override;
sint32 fscGetType() override; sint32 fscGetType() override;

View file

@ -649,7 +649,7 @@ namespace iosu
// create/open fad db content // create/open fad db content
BossStorageFadFile fad_content{}; BossStorageFadFile fad_content{};
fs::path db_file = ActiveSettings::GetMlcPath("usr/boss/{:08x}/{:08x}/user/common/{:08x}/{}", (uint32)(it->title_id >> 32), (uint32)(it->title_id & 0xFFFFFFFF), it->account_id, taskIdStr); FSPath db_file = ActiveSettings::GetMlcPath("usr/boss/{:08x}/{:08x}/user/common/{:08x}/{}", (uint32)(it->title_id >> 32), (uint32)(it->title_id & 0xFFFFFFFF), it->account_id, taskIdStr);
if (!fs::exists(db_file)) if (!fs::exists(db_file))
fs::create_directories(db_file); fs::create_directories(db_file);
@ -800,7 +800,7 @@ namespace iosu
strncpy(fileName, (char*)&it->task_settings.settings[TaskSetting::kFileName], TaskSetting::kFileNameLen); strncpy(fileName, (char*)&it->task_settings.settings[TaskSetting::kFileName], TaskSetting::kFileNameLen);
// mcl01\usr\boss\00050000\1018dd00\user\<persistentId>\<storageName>\<filename> // mcl01\usr\boss\00050000\1018dd00\user\<persistentId>\<storageName>\<filename>
fs::path path = ActiveSettings::GetMlcPath("usr/boss/{:08x}/{:08x}/user/{:08x}", (uint32)(it->title_id >> 32), FSPath path = ActiveSettings::GetMlcPath("usr/boss/{:08x}/{:08x}/user/{:08x}", (uint32)(it->title_id >> 32),
(uint32)(it->title_id & 0xFFFFFFFF), iosuAct_getAccountIdOfCurrentAccount()); (uint32)(it->title_id & 0xFFFFFFFF), iosuAct_getAccountIdOfCurrentAccount());
path /= directoryName; path /= directoryName;

View file

@ -289,7 +289,7 @@ void TitleInfo::CalcUID()
} }
std::error_code ec; std::error_code ec;
// get absolute normalized path // get absolute normalized path
fs::path normalizedPath; FSPath normalizedPath;
if (m_fullPath.is_relative()) if (m_fullPath.is_relative())
{ {
normalizedPath = ActiveSettings::GetPath(); normalizedPath = ActiveSettings::GetPath();

View file

@ -10,7 +10,7 @@ FileStream* FileStream::openFile(const wchar_t* path, bool allowWrite)
return openFile2(path, allowWrite); return openFile2(path, allowWrite);
} }
FileStream* FileStream::openFile2(const fs::path& path, bool allowWrite) FileStream* FileStream::openFile2(const FSPath& path, bool allowWrite)
{ {
//return openFile(path.generic_wstring().c_str(), allowWrite); //return openFile(path.generic_wstring().c_str(), allowWrite);
FileStream* fs = new FileStream(path, true, allowWrite); FileStream* fs = new FileStream(path, true, allowWrite);

View file

@ -1,4 +1,5 @@
#pragma once #pragma once
#include <Cafe/Filesystem/FSPath.h>
#include "Common/precompiled.h" #include "Common/precompiled.h"
class FileStream class FileStream
@ -6,7 +7,7 @@ class FileStream
public: public:
static FileStream* openFile(std::string_view path); static FileStream* openFile(std::string_view path);
static FileStream* openFile(const wchar_t* path, bool allowWrite = false); static FileStream* openFile(const wchar_t* path, bool allowWrite = false);
static FileStream* openFile2(const fs::path& path, bool allowWrite = false); static FileStream* openFile2(const FSPath& path, bool allowWrite = false);
static FileStream* createFile(const wchar_t* path); static FileStream* createFile(const wchar_t* path);
static FileStream* createFile(std::string_view path); static FileStream* createFile(std::string_view path);

View file

@ -209,7 +209,7 @@ bool ActiveSettings::ForceSamplerRoundToPrecision()
return false; return false;
} }
fs::path ActiveSettings::GetMlcPath() FSPath ActiveSettings::GetMlcPath()
{ {
if(const auto launch_mlc = LaunchSettings::GetMLCPath(); launch_mlc.has_value()) if(const auto launch_mlc = LaunchSettings::GetMLCPath(); launch_mlc.has_value())
return launch_mlc.value(); return launch_mlc.value();
@ -220,6 +220,12 @@ fs::path ActiveSettings::GetMlcPath()
return GetDefaultMLCPath(); return GetDefaultMLCPath();
} }
FSPath ActiveSettings::GetMlcPath(std::string_view p)
{
std::basic_string_view<char8_t> s((const char8_t*)p.data(), p.size());
return GetMlcPath() / fs::path(s);
}
fs::path ActiveSettings::GetDefaultMLCPath() fs::path ActiveSettings::GetDefaultMLCPath()
{ {
return GetPath("mlc01"); return GetPath("mlc01");

View file

@ -12,7 +12,7 @@ public:
[[nodiscard]] static fs::path GetPath() { return s_path; } [[nodiscard]] static fs::path GetPath() { return s_path; }
[[nodiscard]] static fs::path GetFilename() { return s_filename; } [[nodiscard]] static fs::path GetFilename() { return s_filename; }
[[nodiscard]] static fs::path GetMlcPath(); [[nodiscard]] static FSPath GetMlcPath();
[[nodiscard]] static fs::path GetPath(std::string_view p) [[nodiscard]] static fs::path GetPath(std::string_view p)
{ {
@ -20,12 +20,8 @@ public:
return s_path / fs::path(s); return s_path / fs::path(s);
} }
[[nodiscard]] static fs::path GetMlcPath(std::string_view p) [[nodiscard]] static FSPath GetMlcPath(std::string_view p);
{
std::basic_string_view<char8_t> s((const char8_t*)p.data(), p.size());
return GetMlcPath() / fs::path(s);
}
template <typename ...TArgs> template <typename ...TArgs>
[[nodiscard]] static fs::path GetPath(std::string_view format, TArgs&&... args) [[nodiscard]] static fs::path GetPath(std::string_view format, TArgs&&... args)
{ {