Skip to content

Commit

Permalink
Merge pull request #171 from lioncash/rarc-cleanup
Browse files Browse the repository at this point in the history
File tree building cleanup
  • Loading branch information
Sonicadvance1 committed Mar 23, 2014
2 parents b8f469d + bd1ce18 commit a3e18cd
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 128 deletions.
23 changes: 10 additions & 13 deletions Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_DI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,19 +201,17 @@ u32 CWII_IPC_HLE_Device_di::ExecuteCommand(u32 _BufferIn, u32 _BufferInSize, u32
// Don't do anything if the log is unselected
if (LogManager::GetInstance()->IsEnabled(LogTypes::FILEMON))
{
const char *pFilename = nullptr;
if (m_pFileSystem)
pFilename = m_pFileSystem->GetFileName(DVDAddress);
if (pFilename != nullptr)
{
const std::string filename = m_pFileSystem->GetFileName(DVDAddress);

INFO_LOG(WII_IPC_DVD, "DVDLowRead: %s (0x%" PRIx64 ") - (DVDAddr: 0x%" PRIx64 ", Size: 0x%x)",
pFilename, m_pFileSystem->GetFileSize(pFilename), DVDAddress, Size);
FileMon::CheckFile(std::string(pFilename), (int)m_pFileSystem->GetFileSize(pFilename));
filename.c_str(), m_pFileSystem->GetFileSize(filename), DVDAddress, Size);
FileMon::CheckFile(filename, (int)m_pFileSystem->GetFileSize(filename));
}
else
{
INFO_LOG(WII_IPC_DVD, "DVDLowRead: file unknown - (DVDAddr: 0x%" PRIx64 ", Size: 0x%x)",
DVDAddress, Size);
ERROR_LOG(WII_IPC_DVD, "Filesystem is invalid.");
}
}

Expand Down Expand Up @@ -338,18 +336,17 @@ u32 CWII_IPC_HLE_Device_di::ExecuteCommand(u32 _BufferIn, u32 _BufferInSize, u32
case DVDLowSeek:
{
u64 DVDAddress = Memory::Read_U32(_BufferIn + 0x4) << 2;
const char *pFilename = nullptr;

if (m_pFileSystem)
pFilename = m_pFileSystem->GetFileName(DVDAddress);
if (pFilename != nullptr)
{
const std::string filename = m_pFileSystem->GetFileName(DVDAddress);

INFO_LOG(WII_IPC_DVD, "DVDLowSeek: %s (0x%" PRIx64 ") - (DVDAddr: 0x%" PRIx64 ")",
pFilename, m_pFileSystem->GetFileSize(pFilename), DVDAddress);
filename.c_str(), m_pFileSystem->GetFileSize(filename), DVDAddress);
}
else
{
INFO_LOG(WII_IPC_DVD, "DVDLowSeek: file unknown - (DVDAddr: 0x%" PRIx64 ")",
DVDAddress);
ERROR_LOG(WII_IPC_DVD, "Filesystem is invalid.");
}
}
break;
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/DiscIO/DiscScrubber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
83 changes: 33 additions & 50 deletions Source/Core/DiscIO/FileHandlerARC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -69,70 +70,66 @@ CARCFile::~CARCFile()
}


bool
CARCFile::IsInitialized()
bool CARCFile::IsInitialized()
{
return(m_Initialized);
return m_Initialized;
}


size_t
CARCFile::GetFileSize(const std::string& _rFullPath)
size_t CARCFile::GetFileSize(const std::string& _rFullPath)
{
if (!m_Initialized)
{
return(0);
return 0;
}

const SFileInfo* pFileInfo = FindFileInfo(_rFullPath);

if (pFileInfo != nullptr)
{
return((size_t) pFileInfo->m_FileSize);
return (size_t)pFileInfo->m_FileSize;
}

return(0);
return 0;
}


size_t
CARCFile::ReadFile(const std::string& _rFullPath, u8* _pBuffer, size_t _MaxBufferSize)
size_t CARCFile::ReadFile(const std::string& _rFullPath, u8* _pBuffer, size_t _MaxBufferSize)
{
if (!m_Initialized)
{
return(0);
return 0;
}

const SFileInfo* pFileInfo = FindFileInfo(_rFullPath);

if (pFileInfo == nullptr)
{
return(0);
return 0;
}

if (pFileInfo->m_FileSize > _MaxBufferSize)
{
return(0);
return 0;
}

memcpy(_pBuffer, &m_pBuffer[pFileInfo->m_Offset], (size_t)pFileInfo->m_FileSize);
return((size_t) pFileInfo->m_FileSize);
return (size_t) pFileInfo->m_FileSize;
}


bool
CARCFile::ExportFile(const std::string& _rFullPath, const std::string& _rExportFilename)
bool CARCFile::ExportFile(const std::string& _rFullPath, const std::string& _rExportFilename)
{
if (!m_Initialized)
{
return(false);
return false;
}

const SFileInfo* pFileInfo = FindFileInfo(_rFullPath);

if (pFileInfo == nullptr)
{
return(false);
return false;
}

File::IOFile pFile(_rExportFilename, "wb");
Expand All @@ -141,15 +138,13 @@ CARCFile::ExportFile(const std::string& _rFullPath, const std::string& _rExportF
}


bool
CARCFile::ExportAllFiles(const std::string& _rFullPath)
bool CARCFile::ExportAllFiles(const std::string& _rFullPath)
{
return(false);
return false;
}


bool
CARCFile::ParseBuffer()
bool CARCFile::ParseBuffer()
{
// check ID
u32 ID = Common::swap32(*(u32*)(m_pBuffer));
Expand Down Expand Up @@ -183,15 +178,14 @@ CARCFile::ParseBuffer()
szNameTable += 0xC;
}

BuildFilenames(1, m_FileInfoVector.size(), nullptr, szNameTable);
BuildFilenames(1, m_FileInfoVector.size(), "", szNameTable);
}

return(true);
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;

Expand All @@ -203,49 +197,38 @@ CARCFile::BuildFilenames(const size_t _FirstIndex, const size_t _LastIndex, cons
// 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++;
}
}

return(CurrentIndex);
return CurrentIndex;
}


const SFileInfo*
CARCFile::FindFileInfo(std::string _rFullPath) const
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);
return &fileInfo;
}
}

return(nullptr);
return nullptr;
}
} // namespace
4 changes: 2 additions & 2 deletions Source/Core/DiscIO/FileHandlerARC.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ 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(std::string _rFullPath) const;
const SFileInfo* FindFileInfo(const std::string& _rFullPath) const;
};
} // namespace
8 changes: 2 additions & 6 deletions Source/Core/DiscIO/FileMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
26 changes: 11 additions & 15 deletions Source/Core/DiscIO/FileSystemGCWii.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;

Expand All @@ -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++;
}
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/DiscIO/FileSystemGCWii.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class CFileSystemGCWii : public IFileSystem
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;
Expand All @@ -43,7 +43,7 @@ class CFileSystemGCWii : public IFileSystem
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
16 changes: 8 additions & 8 deletions Source/Core/DiscIO/Filesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}
};

Expand All @@ -49,7 +49,7 @@ class IFileSystem
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;

Expand Down
Loading

0 comments on commit a3e18cd

Please sign in to comment.