From db53f3b98020160e0890a1b237755d15c091bd83 Mon Sep 17 00:00:00 2001 From: Exzap <13877693+Exzap@users.noreply.github.com> Date: Mon, 2 Oct 2023 21:24:50 +0200 Subject: [PATCH] Fixes for titles in NUS format Symlinks were not handled correctly --- src/Cafe/Filesystem/FST/FST.cpp | 13 +++++++------ src/Cafe/Filesystem/FST/FST.h | 18 ++++++++++++------ src/Cafe/Filesystem/fscDeviceWud.cpp | 4 ++-- src/Cafe/TitleList/GameInfo.h | 4 ++-- .../Tools/DownloadManager/DownloadManager.cpp | 6 +++++- 5 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/Cafe/Filesystem/FST/FST.cpp b/src/Cafe/Filesystem/FST/FST.cpp index 10ae659d..570671d4 100644 --- a/src/Cafe/Filesystem/FST/FST.cpp +++ b/src/Cafe/Filesystem/FST/FST.cpp @@ -686,25 +686,25 @@ bool FSTVolume::OpenFile(std::string_view path, FSTFileHandle& fileHandleOut, bo return true; } -bool FSTVolume::IsDirectory(FSTFileHandle& fileHandle) const +bool FSTVolume::IsDirectory(const FSTFileHandle& fileHandle) const { cemu_assert_debug(fileHandle.m_fstIndex < m_entries.size()); return m_entries[fileHandle.m_fstIndex].GetType() == FSTEntry::TYPE::DIRECTORY; }; -bool FSTVolume::IsFile(FSTFileHandle& fileHandle) const +bool FSTVolume::IsFile(const FSTFileHandle& fileHandle) const { cemu_assert_debug(fileHandle.m_fstIndex < m_entries.size()); return m_entries[fileHandle.m_fstIndex].GetType() == FSTEntry::TYPE::FILE; }; -bool FSTVolume::HasLinkFlag(FSTFileHandle& fileHandle) const +bool FSTVolume::HasLinkFlag(const FSTFileHandle& fileHandle) const { cemu_assert_debug(fileHandle.m_fstIndex < m_entries.size()); return HAS_FLAG(m_entries[fileHandle.m_fstIndex].GetFlags(), FSTEntry::FLAGS::FLAG_LINK); }; -std::string_view FSTVolume::GetName(FSTFileHandle& fileHandle) const +std::string_view FSTVolume::GetName(const FSTFileHandle& fileHandle) const { if (fileHandle.m_fstIndex > m_entries.size()) return ""; @@ -712,7 +712,7 @@ std::string_view FSTVolume::GetName(FSTFileHandle& fileHandle) const return entryName; } -std::string FSTVolume::GetPath(FSTFileHandle& fileHandle) const +std::string FSTVolume::GetPath(const FSTFileHandle& fileHandle) const { std::string path; auto& entry = m_entries[fileHandle.m_fstIndex]; @@ -743,7 +743,7 @@ std::string FSTVolume::GetPath(FSTFileHandle& fileHandle) const return path; } -uint32 FSTVolume::GetFileSize(FSTFileHandle& fileHandle) const +uint32 FSTVolume::GetFileSize(const FSTFileHandle& fileHandle) const { if (m_entries[fileHandle.m_fstIndex].GetType() != FSTEntry::TYPE::FILE) return 0; @@ -994,6 +994,7 @@ bool FSTVolume::OpenDirectoryIterator(std::string_view path, FSTDirectoryIterato if (!IsDirectory(fileHandle)) return false; auto const& fstEntry = m_entries[fileHandle.m_fstIndex]; + directoryIteratorOut.dirHandle = fileHandle; directoryIteratorOut.startIndex = fileHandle.m_fstIndex + 1; directoryIteratorOut.endIndex = fstEntry.dirInfo.endIndex; directoryIteratorOut.currentIndex = directoryIteratorOut.startIndex; diff --git a/src/Cafe/Filesystem/FST/FST.h b/src/Cafe/Filesystem/FST/FST.h index 98bf1ae6..24fc39ea 100644 --- a/src/Cafe/Filesystem/FST/FST.h +++ b/src/Cafe/Filesystem/FST/FST.h @@ -11,7 +11,13 @@ private: struct FSTDirectoryIterator { friend class FSTVolume; + + const FSTFileHandle& GetDirHandle() const + { + return dirHandle; + } private: + FSTFileHandle dirHandle; uint32 startIndex; uint32 endIndex; uint32 currentIndex; @@ -43,15 +49,15 @@ public: bool OpenFile(std::string_view path, FSTFileHandle& fileHandleOut, bool openOnlyFiles = false); // file and directory functions - bool IsDirectory(FSTFileHandle& fileHandle) const; - bool IsFile(FSTFileHandle& fileHandle) const; - bool HasLinkFlag(FSTFileHandle& fileHandle) const; + bool IsDirectory(const FSTFileHandle& fileHandle) const; + bool IsFile(const FSTFileHandle& fileHandle) const; + bool HasLinkFlag(const FSTFileHandle& fileHandle) const; - std::string_view GetName(FSTFileHandle& fileHandle) const; - std::string GetPath(FSTFileHandle& fileHandle) const; + std::string_view GetName(const FSTFileHandle& fileHandle) const; + std::string GetPath(const FSTFileHandle& fileHandle) const; // file functions - uint32 GetFileSize(FSTFileHandle& fileHandle) const; + uint32 GetFileSize(const FSTFileHandle& fileHandle) const; uint32 ReadFile(FSTFileHandle& fileHandle, uint32 offset, uint32 size, void* dataOut); // directory iterator diff --git a/src/Cafe/Filesystem/fscDeviceWud.cpp b/src/Cafe/Filesystem/fscDeviceWud.cpp index bf43bf3e..517c8573 100644 --- a/src/Cafe/Filesystem/fscDeviceWud.cpp +++ b/src/Cafe/Filesystem/fscDeviceWud.cpp @@ -128,7 +128,7 @@ class fscDeviceWUDC : public fscDeviceC if (HAS_FLAG(accessFlags, FSC_ACCESS_FLAG::OPEN_FILE)) { FSTFileHandle fstFileHandle; - if (mountedVolume->OpenFile(path, fstFileHandle, true)) + if (mountedVolume->OpenFile(path, fstFileHandle, true) && !mountedVolume->HasLinkFlag(fstFileHandle)) { *fscStatus = FSC_STATUS_OK; return new FSCDeviceWudFileCtx(mountedVolume, fstFileHandle); @@ -137,7 +137,7 @@ class fscDeviceWUDC : public fscDeviceC if (HAS_FLAG(accessFlags, FSC_ACCESS_FLAG::OPEN_DIR)) { FSTDirectoryIterator dirIterator; - if (mountedVolume->OpenDirectoryIterator(path, dirIterator)) + if (mountedVolume->OpenDirectoryIterator(path, dirIterator) && !mountedVolume->HasLinkFlag(dirIterator.GetDirHandle())) { *fscStatus = FSC_STATUS_OK; return new FSCDeviceWudFileCtx(mountedVolume, dirIterator); diff --git a/src/Cafe/TitleList/GameInfo.h b/src/Cafe/TitleList/GameInfo.h index 8836d1e4..6e922b93 100644 --- a/src/Cafe/TitleList/GameInfo.h +++ b/src/Cafe/TitleList/GameInfo.h @@ -136,8 +136,8 @@ private: // this is to stay consistent with previous Cemu versions which did not support NUS format at all TitleInfo::TitleDataFormat currentFormat = currentTitle.GetFormat(); TitleInfo::TitleDataFormat newFormat = newTitle.GetFormat(); - if (currentFormat != newFormat && currentFormat == TitleInfo::TitleDataFormat::NUS) - return true; + if (currentFormat != TitleInfo::TitleDataFormat::NUS && newFormat == TitleInfo::TitleDataFormat::NUS) + return false; return true; }; diff --git a/src/Cemu/Tools/DownloadManager/DownloadManager.cpp b/src/Cemu/Tools/DownloadManager/DownloadManager.cpp index 09093792..807a4e72 100644 --- a/src/Cemu/Tools/DownloadManager/DownloadManager.cpp +++ b/src/Cemu/Tools/DownloadManager/DownloadManager.cpp @@ -1286,7 +1286,11 @@ bool DownloadManager::asyncPackageInstallRecursiveExtractFiles(Package* package, setPackageError(package, "Internal error"); return false; } - + if (fstVolume->HasLinkFlag(dirItr.GetDirHandle())) + { + cemu_assert_suspicious(); + return true; + } FSTFileHandle itr; while (fstVolume->Next(dirItr, itr)) {