From 0e0602e8d9bc198fefc3e93675693d9212033314 Mon Sep 17 00:00:00 2001 From: Exzap <13877693+Exzap@users.noreply.github.com> Date: Fri, 9 Sep 2022 00:18:37 +0200 Subject: [PATCH] FSC: Use utf8 for mounting and internal target path --- src/Cafe/CafeSystem.cpp | 4 +-- src/Cafe/Filesystem/fsc.cpp | 32 ++++++++++++----------- src/Cafe/Filesystem/fsc.h | 10 +++---- src/Cafe/Filesystem/fscDeviceHostFS.cpp | 11 +++----- src/Cafe/Filesystem/fscDeviceRedirect.cpp | 2 +- src/Cafe/Filesystem/fscDeviceWua.cpp | 7 ++--- src/Cafe/Filesystem/fscDeviceWud.cpp | 7 ++--- src/Cafe/OS/libs/coreinit/coreinit_FS.cpp | 6 ++--- src/Cafe/OS/libs/nn_acp/nn_acp.cpp | 2 +- src/Cafe/TitleList/TitleInfo.cpp | 6 ++--- 10 files changed, 40 insertions(+), 47 deletions(-) diff --git a/src/Cafe/CafeSystem.cpp b/src/Cafe/CafeSystem.cpp index 22ff67c5..5e01abd9 100644 --- a/src/Cafe/CafeSystem.cpp +++ b/src/Cafe/CafeSystem.cpp @@ -626,7 +626,7 @@ namespace CafeSystem if (fs::is_directory(contentPath, ec)) { // mounting content folder - bool r = FSCDeviceHostFS_Mount(std::string("/vol/content").c_str(), boost::nowide::widen(_utf8Wrapper(contentPath)).c_str(), FSC_PRIORITY_BASE); + bool r = FSCDeviceHostFS_Mount(std::string("/vol/content").c_str(), _utf8Wrapper(contentPath), FSC_PRIORITY_BASE); if (!r) { cemuLog_log(LogType::Force, "Failed to mount {}", _utf8Wrapper(contentPath).c_str()); @@ -635,7 +635,7 @@ namespace CafeSystem } } // mount code folder to a virtual temporary path - FSCDeviceHostFS_Mount(std::string("/internal/code/").c_str(), boost::nowide::widen(_utf8Wrapper(executablePath.parent_path())).c_str(), FSC_PRIORITY_BASE); + FSCDeviceHostFS_Mount(std::string("/internal/code/").c_str(), _utf8Wrapper(executablePath.parent_path()), FSC_PRIORITY_BASE); std::string internalExecutablePath = "/internal/code/"; internalExecutablePath.append(_utf8Wrapper(executablePath.filename())); _pathToExecutable = internalExecutablePath; diff --git a/src/Cafe/Filesystem/fsc.cpp b/src/Cafe/Filesystem/fsc.cpp index bab2d19e..5f9351e8 100644 --- a/src/Cafe/Filesystem/fsc.cpp +++ b/src/Cafe/Filesystem/fsc.cpp @@ -5,10 +5,10 @@ struct FSCMountPathNode std::string path; std::vector subnodes; FSCMountPathNode* parent; - // device target and path (if list_subnodes is nullptr) + // device target and path (if subnodes is empty) fscDeviceC* device{ nullptr }; void* ctx{ nullptr }; - std::wstring targetPath; + std::string deviceTargetPath; // the destination base path for the device, utf8 // priority sint32 priority{}; @@ -119,42 +119,44 @@ FSCMountPathNode* fsc_createMountPath(CoreinitFSParsedPath* parsedMountPath, sin return nullptr; } -// Map a virtual FSC directory to a device and device directory -sint32 fsc_mount(const char* mountPath, const wchar_t* _targetPath, fscDeviceC* fscDevice, void* ctx, sint32 priority) +// Map a virtual FSC directory to a device. targetPath points to the destination base directory within the device +sint32 fsc_mount(std::string_view mountPath, std::string_view targetPath, fscDeviceC* fscDevice, void* ctx, sint32 priority) { - cemu_assert(fscDevice); // device must not be nullptr + cemu_assert(fscDevice); + std::string mountPathTmp(mountPath); // make sure the target path ends with a slash - std::wstring targetPath(_targetPath); - if (!targetPath.empty() && (targetPath.back() != '/' && targetPath.back() != '\\')) - targetPath.push_back('/'); + std::string targetPathWithSlash(targetPath); + if (!targetPathWithSlash.empty() && (targetPathWithSlash.back() != '/' && targetPathWithSlash.back() != '\\')) + targetPathWithSlash.push_back('/'); // parse mount path CoreinitFSParsedPath parsedMountPath; - coreinitFS_parsePath(&parsedMountPath, mountPath); + coreinitFS_parsePath(&parsedMountPath, mountPathTmp.c_str()); // register path fscEnter(); FSCMountPathNode* node = fsc_createMountPath(&parsedMountPath, priority); if( !node ) { // path empty, invalid or already used - cemuLog_log(LogType::Force, "fsc_mount failed (virtual path: %s)", mountPath); + cemuLog_log(LogType::Force, "fsc_mount failed (virtual path: {})", mountPath); fscLeave(); return FSC_STATUS_INVALID_PATH; } node->device = fscDevice; node->ctx = ctx; - node->targetPath = targetPath; + node->deviceTargetPath = targetPathWithSlash; fscLeave(); return FSC_STATUS_OK; } -bool fsc_unmount(const char* mountPath, sint32 priority) +bool fsc_unmount(std::string_view mountPath, sint32 priority) { + std::string _tmp(mountPath); CoreinitFSParsedPath parsedMountPath; - coreinitFS_parsePath(&parsedMountPath, mountPath); + coreinitFS_parsePath(&parsedMountPath, _tmp.c_str()); fscEnter(); - FSCMountPathNode* mountPathNode = fsc_lookupPathVirtualNode(mountPath, priority); + FSCMountPathNode* mountPathNode = fsc_lookupPathVirtualNode(_tmp.c_str(), priority); if (!mountPathNode) { fscLeave(); @@ -218,7 +220,7 @@ bool fsc_lookupPath(const char* path, std::wstring& devicePathOut, fscDeviceC** { if (nodeParent->device) { - devicePathOut = nodeParent->targetPath; + devicePathOut = boost::nowide::widen(nodeParent->deviceTargetPath); for (sint32 f = i; f < parsedPath.numNodes; f++) { const char* nodeName = coreinitFS_getNodeName(&parsedPath, f); diff --git a/src/Cafe/Filesystem/fsc.h b/src/Cafe/Filesystem/fsc.h index 972d5d0a..37e437fb 100644 --- a/src/Cafe/Filesystem/fsc.h +++ b/src/Cafe/Filesystem/fsc.h @@ -161,8 +161,8 @@ struct FSCVirtualFile #define FSC_PRIORITY_COUNT (4) void fsc_init(); -sint32 fsc_mount(const char* mountPath, const wchar_t* targetPath, fscDeviceC* fscDevice, void* ctx, sint32 priority=0); -bool fsc_unmount(const char* mountPath, sint32 priority); +sint32 fsc_mount(std::string_view mountPath, std::string_view targetPath, fscDeviceC* fscDevice, void* ctx, sint32 priority=0); +bool fsc_unmount(std::string_view mountPath, sint32 priority); void fsc_unmountAll(); FSCVirtualFile* fsc_open(const char* path, FSC_ACCESS_FLAG accessFlags, sint32* fscStatus, sint32 maxPriority=FSC_PRIORITY_MAX); @@ -188,14 +188,14 @@ bool fsc_doesFileExist(const char* path, sint32 maxPriority = FSC_PRIORITY_MAX); bool fsc_doesDirectoryExist(const char* path, sint32 maxPriority = FSC_PRIORITY_MAX); // wud device -bool FSCDeviceWUD_Mount(const char* mountPath, std::string_view destinationBaseDir, class FSTVolume* mountedVolume, sint32 priority); +bool FSCDeviceWUD_Mount(std::string_view mountPath, std::string_view destinationBaseDir, class FSTVolume* mountedVolume, sint32 priority); // wua device -bool FSCDeviceWUA_Mount(const char* mountPath, std::string_view destinationBaseDir, class ZArchiveReader* archive, sint32 priority); +bool FSCDeviceWUA_Mount(std::string_view mountPath, std::string_view destinationBaseDir, class ZArchiveReader* archive, sint32 priority); // hostFS device void fscDeviceHostFS_mapBaseDirectories_deprecated(); -bool FSCDeviceHostFS_Mount(const char* mountPath, const wchar_t* hostFSPath, sint32 priority); +bool FSCDeviceHostFS_Mount(std::string_view mountPath, std::string_view hostTargetPath, sint32 priority); // redirect device void fscDeviceRedirect_map(); diff --git a/src/Cafe/Filesystem/fscDeviceHostFS.cpp b/src/Cafe/Filesystem/fscDeviceHostFS.cpp index cb54cacf..d3f93927 100644 --- a/src/Cafe/Filesystem/fscDeviceHostFS.cpp +++ b/src/Cafe/Filesystem/fscDeviceHostFS.cpp @@ -293,14 +293,11 @@ public: void fscDeviceHostFS_mapBaseDirectories_deprecated() { const auto mlc = ActiveSettings::GetMlcPath(); - fsc_mount("/cemuBossStorage/", (mlc / "usr/boss/").generic_wstring().c_str(), &fscDeviceHostFSC::instance(), NULL, FSC_PRIORITY_BASE); - fsc_mount("/vol/storage_mlc01/", (mlc / "").generic_wstring().c_str(), &fscDeviceHostFSC::instance(), NULL, FSC_PRIORITY_BASE); + fsc_mount("/cemuBossStorage/", _utf8Wrapper(mlc / "usr/boss/"), &fscDeviceHostFSC::instance(), NULL, FSC_PRIORITY_BASE); + fsc_mount("/vol/storage_mlc01/", _utf8Wrapper(mlc / ""), &fscDeviceHostFSC::instance(), NULL, FSC_PRIORITY_BASE); } -bool FSCDeviceHostFS_Mount(const char* mountPath, const wchar_t* hostFSPath, sint32 priority) +bool FSCDeviceHostFS_Mount(std::string_view mountPath, std::string_view hostTargetPath, sint32 priority) { - std::wstring hostTargetPath(hostFSPath); - if (!hostTargetPath.empty() && (hostTargetPath.back() != '/' && hostTargetPath.back() != '\\')) - hostTargetPath.push_back('/'); - return fsc_mount(mountPath, hostTargetPath.c_str(), &fscDeviceHostFSC::instance(), nullptr, priority) == FSC_STATUS_OK; + return fsc_mount(mountPath, hostTargetPath, &fscDeviceHostFSC::instance(), nullptr, priority) == FSC_STATUS_OK; } \ No newline at end of file diff --git a/src/Cafe/Filesystem/fscDeviceRedirect.cpp b/src/Cafe/Filesystem/fscDeviceRedirect.cpp index 5d5edb9e..9c658eb3 100644 --- a/src/Cafe/Filesystem/fscDeviceRedirect.cpp +++ b/src/Cafe/Filesystem/fscDeviceRedirect.cpp @@ -52,6 +52,6 @@ void fscDeviceRedirect_map() { if (_redirectMapped) return; - fsc_mount("/", L"/", &fscDeviceTypeRedirect::instance(), nullptr, FSC_PRIORITY_REDIRECT); + fsc_mount("/", "/", &fscDeviceTypeRedirect::instance(), nullptr, FSC_PRIORITY_REDIRECT); _redirectMapped = true; } diff --git a/src/Cafe/Filesystem/fscDeviceWua.cpp b/src/Cafe/Filesystem/fscDeviceWua.cpp index 96eb920a..1aceaf90 100644 --- a/src/Cafe/Filesystem/fscDeviceWua.cpp +++ b/src/Cafe/Filesystem/fscDeviceWua.cpp @@ -169,10 +169,7 @@ public: } }; -bool FSCDeviceWUA_Mount(const char* mountPath, std::string_view destinationBaseDir, ZArchiveReader* archive, sint32 priority) +bool FSCDeviceWUA_Mount(std::string_view mountPath, std::string_view destinationBaseDir, ZArchiveReader* archive, sint32 priority) { - std::wstring hostTargetPath(boost::nowide::widen(destinationBaseDir.data(), destinationBaseDir.size())); - if (!hostTargetPath.empty() && (hostTargetPath.back() != '/' && hostTargetPath.back() != '\\')) - hostTargetPath.push_back('/'); - return fsc_mount(mountPath, hostTargetPath.c_str(), &fscDeviceWUAC::instance(), archive, priority) == FSC_STATUS_OK; + return fsc_mount(mountPath, destinationBaseDir, &fscDeviceWUAC::instance(), archive, priority) == FSC_STATUS_OK; } \ No newline at end of file diff --git a/src/Cafe/Filesystem/fscDeviceWud.cpp b/src/Cafe/Filesystem/fscDeviceWud.cpp index 10054bad..c86c6dbe 100644 --- a/src/Cafe/Filesystem/fscDeviceWud.cpp +++ b/src/Cafe/Filesystem/fscDeviceWud.cpp @@ -157,10 +157,7 @@ public: } }; -bool FSCDeviceWUD_Mount(const char* mountPath, std::string_view destinationBaseDir, FSTVolume* mountedVolume, sint32 priority) +bool FSCDeviceWUD_Mount(std::string_view mountPath, std::string_view destinationBaseDir, FSTVolume* mountedVolume, sint32 priority) { - std::wstring hostTargetPath(boost::nowide::widen(destinationBaseDir.data(), destinationBaseDir.size())); - if (!hostTargetPath.empty() && (hostTargetPath.back() != '/' && hostTargetPath.back() != '\\')) - hostTargetPath.push_back('/'); - return fsc_mount(mountPath, hostTargetPath.c_str(), &fscDeviceWUDC::instance(), mountedVolume, priority) == FSC_STATUS_OK; + return fsc_mount(mountPath, destinationBaseDir, &fscDeviceWUDC::instance(), mountedVolume, priority) == FSC_STATUS_OK; } \ No newline at end of file diff --git a/src/Cafe/OS/libs/coreinit/coreinit_FS.cpp b/src/Cafe/OS/libs/coreinit/coreinit_FS.cpp index 3d13fdbe..2521677c 100644 --- a/src/Cafe/OS/libs/coreinit/coreinit_FS.cpp +++ b/src/Cafe/OS/libs/coreinit/coreinit_FS.cpp @@ -109,7 +109,7 @@ namespace coreinit std::error_code ec; const auto path = ActiveSettings::GetPath("sdcard/"); fs::create_directories(path, ec); - FSCDeviceHostFS_Mount("/vol/external01", path.generic_wstring().c_str() , FSC_PRIORITY_BASE); + FSCDeviceHostFS_Mount("/vol/external01", _utf8Wrapper(path), FSC_PRIORITY_BASE); _sdCard01Mounted = true; } @@ -142,7 +142,7 @@ namespace coreinit std::error_code ec; const auto path = ActiveSettings::GetPath("sdcard/"); fs::create_directories(path, ec); - if (!FSCDeviceHostFS_Mount(mountPathOut, path.generic_wstring().c_str(), FSC_PRIORITY_BASE)) + if (!FSCDeviceHostFS_Mount(mountPathOut, _utf8Wrapper(path), FSC_PRIORITY_BASE)) return FS_RESULT::ERR_PLACEHOLDER; _sdCard01Mounted = true; } @@ -150,7 +150,7 @@ namespace coreinit if (_mlc01Mounted) return FS_RESULT::ERR_PLACEHOLDER; - if (!FSCDeviceHostFS_Mount(mountPathOut, ActiveSettings::GetMlcPath().generic_wstring().c_str(), FSC_PRIORITY_BASE)) + if (!FSCDeviceHostFS_Mount(mountPathOut, _utf8Wrapper(ActiveSettings::GetMlcPath()), FSC_PRIORITY_BASE)) return FS_RESULT::ERR_PLACEHOLDER; _mlc01Mounted = true; } diff --git a/src/Cafe/OS/libs/nn_acp/nn_acp.cpp b/src/Cafe/OS/libs/nn_acp/nn_acp.cpp index 23d21434..0741619e 100644 --- a/src/Cafe/OS/libs/nn_acp/nn_acp.cpp +++ b/src/Cafe/OS/libs/nn_acp/nn_acp.cpp @@ -51,7 +51,7 @@ namespace acp // mount save path const auto mlc = ActiveSettings::GetMlcPath("usr/save/{:08x}/{:08x}/user/", high, low); - FSCDeviceHostFS_Mount("/vol/save/", mlc.generic_wstring().c_str(), FSC_PRIORITY_BASE); + FSCDeviceHostFS_Mount("/vol/save/", _utf8Wrapper(mlc), FSC_PRIORITY_BASE); nnResult mountResult = BUILD_NN_RESULT(NN_RESULT_LEVEL_SUCCESS, NN_RESULT_MODULE_NN_ACP, 0); return _ACPConvertResultToACPStatus(&mountResult, "ACPMountSaveDir", 0x60); } diff --git a/src/Cafe/TitleList/TitleInfo.cpp b/src/Cafe/TitleList/TitleInfo.cpp index 6606c130..ef63956f 100644 --- a/src/Cafe/TitleList/TitleInfo.cpp +++ b/src/Cafe/TitleList/TitleInfo.cpp @@ -370,7 +370,7 @@ bool TitleInfo::Mount(std::string_view virtualPath, std::string_view subfolder, { fs::path hostFSPath = m_fullPath; hostFSPath.append(subfolder); - bool r = FSCDeviceHostFS_Mount(std::string(virtualPath).c_str(), boost::nowide::widen(_utf8Wrapper(hostFSPath)).c_str(), mountPriority); + bool r = FSCDeviceHostFS_Mount(std::string(virtualPath).c_str(), _utf8Wrapper(hostFSPath), mountPriority); cemu_assert_debug(r); if (!r) { @@ -387,7 +387,7 @@ bool TitleInfo::Mount(std::string_view virtualPath, std::string_view subfolder, } if (!m_wudVolume) return false; - bool r = FSCDeviceWUD_Mount(std::string(virtualPath).c_str(), subfolder, m_wudVolume, mountPriority); + bool r = FSCDeviceWUD_Mount(virtualPath, subfolder, m_wudVolume, mountPriority); cemu_assert_debug(r); if (!r) { @@ -404,7 +404,7 @@ bool TitleInfo::Mount(std::string_view virtualPath, std::string_view subfolder, if (!m_zarchive) return false; } - bool r = FSCDeviceWUA_Mount(std::string(virtualPath).c_str(), std::string(m_subPath).append("/").append(subfolder), m_zarchive, mountPriority); + bool r = FSCDeviceWUA_Mount(virtualPath, std::string(m_subPath).append("/").append(subfolder), m_zarchive, mountPriority); if (!r) { cemuLog_log(LogType::Force, "Failed to mount {} to {}", virtualPath, subfolder);