summaryrefslogtreecommitdiff
path: root/Source/Core/DiscIO/FileHandlerARC.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Core/DiscIO/FileHandlerARC.cpp')
-rw-r--r--Source/Core/DiscIO/FileHandlerARC.cpp83
1 files changed, 33 insertions, 50 deletions
diff --git a/Source/Core/DiscIO/FileHandlerARC.cpp b/Source/Core/DiscIO/FileHandlerARC.cpp
index ee24158053..6215b0a100 100644
--- a/Source/Core/DiscIO/FileHandlerARC.cpp
+++ b/Source/Core/DiscIO/FileHandlerARC.cpp
@@ -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"
@@ -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");
@@ -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));
@@ -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;
@@ -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