Skip to content

Commit db53f3b

Browse files
committed
Fixes for titles in NUS format
Symlinks were not handled correctly
1 parent 29c823f commit db53f3b

File tree

5 files changed

+28
-17
lines changed

5 files changed

+28
-17
lines changed

src/Cafe/Filesystem/FST/FST.cpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -686,33 +686,33 @@ bool FSTVolume::OpenFile(std::string_view path, FSTFileHandle& fileHandleOut, bo
686686
return true;
687687
}
688688

689-
bool FSTVolume::IsDirectory(FSTFileHandle& fileHandle) const
689+
bool FSTVolume::IsDirectory(const FSTFileHandle& fileHandle) const
690690
{
691691
cemu_assert_debug(fileHandle.m_fstIndex < m_entries.size());
692692
return m_entries[fileHandle.m_fstIndex].GetType() == FSTEntry::TYPE::DIRECTORY;
693693
};
694694

695-
bool FSTVolume::IsFile(FSTFileHandle& fileHandle) const
695+
bool FSTVolume::IsFile(const FSTFileHandle& fileHandle) const
696696
{
697697
cemu_assert_debug(fileHandle.m_fstIndex < m_entries.size());
698698
return m_entries[fileHandle.m_fstIndex].GetType() == FSTEntry::TYPE::FILE;
699699
};
700700

701-
bool FSTVolume::HasLinkFlag(FSTFileHandle& fileHandle) const
701+
bool FSTVolume::HasLinkFlag(const FSTFileHandle& fileHandle) const
702702
{
703703
cemu_assert_debug(fileHandle.m_fstIndex < m_entries.size());
704704
return HAS_FLAG(m_entries[fileHandle.m_fstIndex].GetFlags(), FSTEntry::FLAGS::FLAG_LINK);
705705
};
706706

707-
std::string_view FSTVolume::GetName(FSTFileHandle& fileHandle) const
707+
std::string_view FSTVolume::GetName(const FSTFileHandle& fileHandle) const
708708
{
709709
if (fileHandle.m_fstIndex > m_entries.size())
710710
return "";
711711
const char* entryName = m_nameStringTable.data() + m_entries[fileHandle.m_fstIndex].nameOffset;
712712
return entryName;
713713
}
714714

715-
std::string FSTVolume::GetPath(FSTFileHandle& fileHandle) const
715+
std::string FSTVolume::GetPath(const FSTFileHandle& fileHandle) const
716716
{
717717
std::string path;
718718
auto& entry = m_entries[fileHandle.m_fstIndex];
@@ -743,7 +743,7 @@ std::string FSTVolume::GetPath(FSTFileHandle& fileHandle) const
743743
return path;
744744
}
745745

746-
uint32 FSTVolume::GetFileSize(FSTFileHandle& fileHandle) const
746+
uint32 FSTVolume::GetFileSize(const FSTFileHandle& fileHandle) const
747747
{
748748
if (m_entries[fileHandle.m_fstIndex].GetType() != FSTEntry::TYPE::FILE)
749749
return 0;
@@ -994,6 +994,7 @@ bool FSTVolume::OpenDirectoryIterator(std::string_view path, FSTDirectoryIterato
994994
if (!IsDirectory(fileHandle))
995995
return false;
996996
auto const& fstEntry = m_entries[fileHandle.m_fstIndex];
997+
directoryIteratorOut.dirHandle = fileHandle;
997998
directoryIteratorOut.startIndex = fileHandle.m_fstIndex + 1;
998999
directoryIteratorOut.endIndex = fstEntry.dirInfo.endIndex;
9991000
directoryIteratorOut.currentIndex = directoryIteratorOut.startIndex;

src/Cafe/Filesystem/FST/FST.h

+12-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ struct FSTFileHandle
1111
struct FSTDirectoryIterator
1212
{
1313
friend class FSTVolume;
14+
15+
const FSTFileHandle& GetDirHandle() const
16+
{
17+
return dirHandle;
18+
}
1419
private:
20+
FSTFileHandle dirHandle;
1521
uint32 startIndex;
1622
uint32 endIndex;
1723
uint32 currentIndex;
@@ -43,15 +49,15 @@ class FSTVolume
4349
bool OpenFile(std::string_view path, FSTFileHandle& fileHandleOut, bool openOnlyFiles = false);
4450

4551
// file and directory functions
46-
bool IsDirectory(FSTFileHandle& fileHandle) const;
47-
bool IsFile(FSTFileHandle& fileHandle) const;
48-
bool HasLinkFlag(FSTFileHandle& fileHandle) const;
52+
bool IsDirectory(const FSTFileHandle& fileHandle) const;
53+
bool IsFile(const FSTFileHandle& fileHandle) const;
54+
bool HasLinkFlag(const FSTFileHandle& fileHandle) const;
4955

50-
std::string_view GetName(FSTFileHandle& fileHandle) const;
51-
std::string GetPath(FSTFileHandle& fileHandle) const;
56+
std::string_view GetName(const FSTFileHandle& fileHandle) const;
57+
std::string GetPath(const FSTFileHandle& fileHandle) const;
5258

5359
// file functions
54-
uint32 GetFileSize(FSTFileHandle& fileHandle) const;
60+
uint32 GetFileSize(const FSTFileHandle& fileHandle) const;
5561
uint32 ReadFile(FSTFileHandle& fileHandle, uint32 offset, uint32 size, void* dataOut);
5662

5763
// directory iterator

src/Cafe/Filesystem/fscDeviceWud.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class fscDeviceWUDC : public fscDeviceC
128128
if (HAS_FLAG(accessFlags, FSC_ACCESS_FLAG::OPEN_FILE))
129129
{
130130
FSTFileHandle fstFileHandle;
131-
if (mountedVolume->OpenFile(path, fstFileHandle, true))
131+
if (mountedVolume->OpenFile(path, fstFileHandle, true) && !mountedVolume->HasLinkFlag(fstFileHandle))
132132
{
133133
*fscStatus = FSC_STATUS_OK;
134134
return new FSCDeviceWudFileCtx(mountedVolume, fstFileHandle);
@@ -137,7 +137,7 @@ class fscDeviceWUDC : public fscDeviceC
137137
if (HAS_FLAG(accessFlags, FSC_ACCESS_FLAG::OPEN_DIR))
138138
{
139139
FSTDirectoryIterator dirIterator;
140-
if (mountedVolume->OpenDirectoryIterator(path, dirIterator))
140+
if (mountedVolume->OpenDirectoryIterator(path, dirIterator) && !mountedVolume->HasLinkFlag(dirIterator.GetDirHandle()))
141141
{
142142
*fscStatus = FSC_STATUS_OK;
143143
return new FSCDeviceWudFileCtx(mountedVolume, dirIterator);

src/Cafe/TitleList/GameInfo.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ class GameInfo2
136136
// this is to stay consistent with previous Cemu versions which did not support NUS format at all
137137
TitleInfo::TitleDataFormat currentFormat = currentTitle.GetFormat();
138138
TitleInfo::TitleDataFormat newFormat = newTitle.GetFormat();
139-
if (currentFormat != newFormat && currentFormat == TitleInfo::TitleDataFormat::NUS)
140-
return true;
139+
if (currentFormat != TitleInfo::TitleDataFormat::NUS && newFormat == TitleInfo::TitleDataFormat::NUS)
140+
return false;
141141
return true;
142142
};
143143

src/Cemu/Tools/DownloadManager/DownloadManager.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,11 @@ bool DownloadManager::asyncPackageInstallRecursiveExtractFiles(Package* package,
12861286
setPackageError(package, "Internal error");
12871287
return false;
12881288
}
1289-
1289+
if (fstVolume->HasLinkFlag(dirItr.GetDirHandle()))
1290+
{
1291+
cemu_assert_suspicious();
1292+
return true;
1293+
}
12901294
FSTFileHandle itr;
12911295
while (fstVolume->Next(dirItr, itr))
12921296
{

0 commit comments

Comments
 (0)