mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 14:19:46 -06:00
Simplify file tree building for the filesystem view.
Technically this also simplifies on disc filename building in general.
This commit is contained in:
@ -317,7 +317,7 @@ bool ParsePartitionData(SPartition& _rPartition)
|
||||
// Go through the filesystem and mark entries as used
|
||||
for (size_t currentFile = 0; currentFile < numFiles; currentFile++)
|
||||
{
|
||||
DEBUG_LOG(DISCIO, "%s", currentFile ? (*Files.at(currentFile)).m_FullPath : "/");
|
||||
DEBUG_LOG(DISCIO, "%s", currentFile ? (*Files.at(currentFile)).m_FullPath.c_str() : "/");
|
||||
// Just 1byte for directory? - it will end up reserving a cluster this way
|
||||
if ((*Files.at(currentFile)).m_NameOffset & 0x1000000)
|
||||
MarkAsUsedE(_rPartition.Offset
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
#include "Common/Common.h"
|
||||
#include "Common/FileUtil.h"
|
||||
#include "Common/StringUtil.h"
|
||||
#include "DiscIO/Blob.h"
|
||||
#include "DiscIO/FileHandlerARC.h"
|
||||
#include "DiscIO/Filesystem.h"
|
||||
@ -86,7 +87,7 @@ size_t CARCFile::GetFileSize(const std::string& _rFullPath)
|
||||
|
||||
if (pFileInfo != nullptr)
|
||||
{
|
||||
return (size_t) pFileInfo->m_FileSize;
|
||||
return (size_t)pFileInfo->m_FileSize;
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -177,14 +178,14 @@ bool CARCFile::ParseBuffer()
|
||||
szNameTable += 0xC;
|
||||
}
|
||||
|
||||
BuildFilenames(1, m_FileInfoVector.size(), nullptr, szNameTable);
|
||||
BuildFilenames(1, m_FileInfoVector.size(), "", szNameTable);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
size_t CARCFile::BuildFilenames(const size_t _FirstIndex, const size_t _LastIndex, const char* _szDirectory, const char* _szNameTable)
|
||||
size_t CARCFile::BuildFilenames(const size_t _FirstIndex, const size_t _LastIndex, const std::string& _szDirectory, const char* _szNameTable)
|
||||
{
|
||||
size_t CurrentIndex = _FirstIndex;
|
||||
|
||||
@ -196,29 +197,19 @@ size_t CARCFile::BuildFilenames(const size_t _FirstIndex, const size_t _LastInde
|
||||
// check next index
|
||||
if (rFileInfo.IsDirectory())
|
||||
{
|
||||
// this is a directory, build up the new szDirectory
|
||||
if (_szDirectory != nullptr)
|
||||
{
|
||||
sprintf(rFileInfo.m_FullPath, "%s%s/", _szDirectory, &_szNameTable[uOffset]);
|
||||
}
|
||||
if (_szDirectory.empty())
|
||||
rFileInfo.m_FullPath += StringFromFormat("%s/", &_szNameTable[uOffset]);
|
||||
else
|
||||
{
|
||||
sprintf(rFileInfo.m_FullPath, "%s/", &_szNameTable[uOffset]);
|
||||
}
|
||||
rFileInfo.m_FullPath += StringFromFormat("%s%s/", _szDirectory.c_str(), &_szNameTable[uOffset]);
|
||||
|
||||
CurrentIndex = BuildFilenames(CurrentIndex + 1, (size_t) rFileInfo.m_FileSize, rFileInfo.m_FullPath, _szNameTable);
|
||||
}
|
||||
else
|
||||
else // This is a filename
|
||||
{
|
||||
// this is a filename
|
||||
if (_szDirectory != nullptr)
|
||||
{
|
||||
sprintf(rFileInfo.m_FullPath, "%s%s", _szDirectory, &_szNameTable[uOffset]);
|
||||
}
|
||||
if (_szDirectory.empty())
|
||||
rFileInfo.m_FullPath += StringFromFormat("%s", &_szNameTable[uOffset]);
|
||||
else
|
||||
{
|
||||
sprintf(rFileInfo.m_FullPath, "%s", &_szNameTable[uOffset]);
|
||||
}
|
||||
rFileInfo.m_FullPath += StringFromFormat("%s%s", _szDirectory.c_str(), &_szNameTable[uOffset]);
|
||||
|
||||
CurrentIndex++;
|
||||
}
|
||||
@ -232,7 +223,7 @@ const SFileInfo* CARCFile::FindFileInfo(const std::string& _rFullPath) const
|
||||
{
|
||||
for (auto& fileInfo : m_FileInfoVector)
|
||||
{
|
||||
if (!strcasecmp(fileInfo.m_FullPath, _rFullPath.c_str()))
|
||||
if (!strcasecmp(fileInfo.m_FullPath.c_str(), _rFullPath.c_str()))
|
||||
{
|
||||
return &fileInfo;
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ class CARCFile
|
||||
|
||||
bool ParseBuffer();
|
||||
|
||||
size_t BuildFilenames(const size_t _FirstIndex, const size_t _LastIndex, const char* _szDirectory, const char* _szNameTable);
|
||||
size_t BuildFilenames(const size_t _FirstIndex, const size_t _LastIndex, const std::string& _szDirectory, const char* _szNameTable);
|
||||
|
||||
const SFileInfo* FindFileInfo(const std::string& _rFullPath) const;
|
||||
};
|
||||
|
@ -142,13 +142,9 @@ void FindFilename(u64 offset)
|
||||
return;
|
||||
}
|
||||
|
||||
const char *fname = pFileSystem->GetFileName(offset);
|
||||
const std::string filename = pFileSystem->GetFileName(offset);
|
||||
|
||||
// There's something wrong with the paths
|
||||
if (!fname || (strlen(fname) == 512))
|
||||
return;
|
||||
|
||||
CheckFile(fname, pFileSystem->GetFileSize(fname));
|
||||
CheckFile(filename, pFileSystem->GetFileSize(filename));
|
||||
}
|
||||
|
||||
void Close()
|
||||
|
@ -46,7 +46,7 @@ u64 CFileSystemGCWii::GetFileSize(const std::string& _rFullPath)
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char* CFileSystemGCWii::GetFileName(u64 _Address)
|
||||
const std::string CFileSystemGCWii::GetFileName(u64 _Address)
|
||||
{
|
||||
if (!m_Initialized)
|
||||
InitFileSystem();
|
||||
@ -239,7 +239,7 @@ const SFileInfo* CFileSystemGCWii::FindFileInfo(const std::string& _rFullPath)
|
||||
|
||||
for (auto& fileInfo : m_FileInfoVector)
|
||||
{
|
||||
if (!strcasecmp(fileInfo.m_FullPath, _rFullPath.c_str()))
|
||||
if (!strcasecmp(fileInfo.m_FullPath.c_str(), _rFullPath.c_str()))
|
||||
return &fileInfo;
|
||||
}
|
||||
|
||||
@ -297,13 +297,11 @@ void CFileSystemGCWii::InitFileSystem()
|
||||
NameTableOffset += 0xC;
|
||||
}
|
||||
|
||||
BuildFilenames(1, m_FileInfoVector.size(), nullptr, NameTableOffset);
|
||||
BuildFilenames(1, m_FileInfoVector.size(), "", NameTableOffset);
|
||||
}
|
||||
}
|
||||
|
||||
// Changed this stuff from C++ string to C strings for speed in debug mode. Doesn't matter in release, but
|
||||
// std::string is SLOW in debug mode.
|
||||
size_t CFileSystemGCWii::BuildFilenames(const size_t _FirstIndex, const size_t _LastIndex, const char* _szDirectory, u64 _NameTableOffset)
|
||||
size_t CFileSystemGCWii::BuildFilenames(const size_t _FirstIndex, const size_t _LastIndex, const std::string& _szDirectory, u64 _NameTableOffset)
|
||||
{
|
||||
size_t CurrentIndex = _FirstIndex;
|
||||
|
||||
@ -316,21 +314,19 @@ size_t CFileSystemGCWii::BuildFilenames(const size_t _FirstIndex, const size_t _
|
||||
// check next index
|
||||
if (rFileInfo->IsDirectory())
|
||||
{
|
||||
// this is a directory, build up the new szDirectory
|
||||
if (_szDirectory != nullptr)
|
||||
CharArrayFromFormat(rFileInfo->m_FullPath, "%s%s/", _szDirectory, filename.c_str());
|
||||
if (_szDirectory.empty())
|
||||
rFileInfo->m_FullPath += StringFromFormat("%s/", filename.c_str());
|
||||
else
|
||||
CharArrayFromFormat(rFileInfo->m_FullPath, "%s/", filename.c_str());
|
||||
rFileInfo->m_FullPath += StringFromFormat("%s%s/", _szDirectory.c_str(), filename.c_str());
|
||||
|
||||
CurrentIndex = BuildFilenames(CurrentIndex + 1, (size_t) rFileInfo->m_FileSize, rFileInfo->m_FullPath, _NameTableOffset);
|
||||
}
|
||||
else
|
||||
else // This is a filename
|
||||
{
|
||||
// this is a filename
|
||||
if (_szDirectory != nullptr)
|
||||
CharArrayFromFormat(rFileInfo->m_FullPath, "%s%s", _szDirectory, filename.c_str());
|
||||
if (_szDirectory.empty())
|
||||
rFileInfo->m_FullPath += filename;
|
||||
else
|
||||
CharArrayFromFormat(rFileInfo->m_FullPath, "%s", filename.c_str());
|
||||
rFileInfo->m_FullPath += StringFromFormat("%s%s", _szDirectory.c_str(), filename.c_str());
|
||||
|
||||
CurrentIndex++;
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ public:
|
||||
virtual bool IsValid() const override { return m_Valid; }
|
||||
virtual u64 GetFileSize(const std::string& _rFullPath) override;
|
||||
virtual size_t GetFileList(std::vector<const SFileInfo *> &_rFilenames) override;
|
||||
virtual const char* GetFileName(u64 _Address) override;
|
||||
virtual const std::string GetFileName(u64 _Address) override;
|
||||
virtual u64 ReadFile(const std::string& _rFullPath, u8* _pBuffer, size_t _MaxBufferSize) override;
|
||||
virtual bool ExportFile(const std::string& _rFullPath, const std::string&_rExportFilename) override;
|
||||
virtual bool ExportApploader(const std::string& _rExportFolder) const override;
|
||||
@ -43,7 +43,7 @@ private:
|
||||
const SFileInfo* FindFileInfo(const std::string& _rFullPath);
|
||||
bool DetectFileSystem();
|
||||
void InitFileSystem();
|
||||
size_t BuildFilenames(const size_t _FirstIndex, const size_t _LastIndex, const char* _szDirectory, u64 _NameTableOffset);
|
||||
size_t BuildFilenames(const size_t _FirstIndex, const size_t _LastIndex, const std::string& _szDirectory, u64 _NameTableOffset);
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
@ -22,17 +22,17 @@ struct SFileInfo
|
||||
u64 m_NameOffset;
|
||||
u64 m_Offset;
|
||||
u64 m_FileSize;
|
||||
char m_FullPath[512];
|
||||
std::string m_FullPath;
|
||||
|
||||
bool IsDirectory() const { return (m_NameOffset & 0xFF000000) != 0 ? true : false; }
|
||||
bool IsDirectory() const { return (m_NameOffset & 0xFF000000) != 0; }
|
||||
|
||||
SFileInfo() : m_NameOffset(0), m_Offset(0), m_FileSize(0) {
|
||||
memset(m_FullPath, 0, sizeof(m_FullPath));
|
||||
SFileInfo() : m_NameOffset(0), m_Offset(0), m_FileSize(0)
|
||||
{
|
||||
}
|
||||
|
||||
SFileInfo(const SFileInfo &rhs) : m_NameOffset(rhs.m_NameOffset),
|
||||
m_Offset(rhs.m_Offset), m_FileSize(rhs.m_FileSize) {
|
||||
memcpy(m_FullPath, rhs.m_FullPath, strlen(rhs.m_FullPath) + 1);
|
||||
SFileInfo(const SFileInfo& rhs) : m_NameOffset(rhs.m_NameOffset),
|
||||
m_Offset(rhs.m_Offset), m_FileSize(rhs.m_FileSize), m_FullPath(rhs.m_FullPath)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
@ -49,7 +49,7 @@ public:
|
||||
virtual bool ExportFile(const std::string& _rFullPath, const std::string& _rExportFilename) = 0;
|
||||
virtual bool ExportApploader(const std::string& _rExportFolder) const = 0;
|
||||
virtual bool ExportDOL(const std::string& _rExportFolder) const = 0;
|
||||
virtual const char* GetFileName(u64 _Address) = 0;
|
||||
virtual const std::string GetFileName(u64 _Address) = 0;
|
||||
virtual bool GetBootDOL(u8* &buffer, u32 DolSize) const = 0;
|
||||
virtual u32 GetBootDOLSize() const = 0;
|
||||
|
||||
|
Reference in New Issue
Block a user