Skip to content

Commit

Permalink
Fixes for titles in NUS format
Browse files Browse the repository at this point in the history
Symlinks were not handled correctly
  • Loading branch information
Exzap committed Oct 2, 2023
1 parent 29c823f commit db53f3b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 17 deletions.
13 changes: 7 additions & 6 deletions src/Cafe/Filesystem/FST/FST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -686,33 +686,33 @@ 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 "";
const char* entryName = m_nameStringTable.data() + m_entries[fileHandle.m_fstIndex].nameOffset;
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];
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
18 changes: 12 additions & 6 deletions src/Cafe/Filesystem/FST/FST.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ struct FSTFileHandle
struct FSTDirectoryIterator
{
friend class FSTVolume;

const FSTFileHandle& GetDirHandle() const
{
return dirHandle;
}
private:
FSTFileHandle dirHandle;
uint32 startIndex;
uint32 endIndex;
uint32 currentIndex;
Expand Down Expand Up @@ -43,15 +49,15 @@ class FSTVolume
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
Expand Down
4 changes: 2 additions & 2 deletions src/Cafe/Filesystem/fscDeviceWud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/Cafe/TitleList/GameInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ class GameInfo2
// 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;
};

Expand Down
6 changes: 5 additions & 1 deletion src/Cemu/Tools/DownloadManager/DownloadManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down

0 comments on commit db53f3b

Please sign in to comment.