FileHandlerARC: Remove FileHandlerARC.
This commit is contained in:
parent
a3d9b22c27
commit
cf8d1c9197
|
@ -8,7 +8,6 @@ set(SRCS BannerLoader.cpp
|
|||
DiscScrubber.cpp
|
||||
DriveBlob.cpp
|
||||
FileBlob.cpp
|
||||
FileHandlerARC.cpp
|
||||
FileMonitor.cpp
|
||||
FileSystemGCWii.cpp
|
||||
Filesystem.cpp
|
||||
|
|
|
@ -44,7 +44,6 @@
|
|||
<ClCompile Include="DiscScrubber.cpp" />
|
||||
<ClCompile Include="DriveBlob.cpp" />
|
||||
<ClCompile Include="FileBlob.cpp" />
|
||||
<ClCompile Include="FileHandlerARC.cpp" />
|
||||
<ClCompile Include="FileMonitor.cpp" />
|
||||
<ClCompile Include="Filesystem.cpp" />
|
||||
<ClCompile Include="FileSystemGCWii.cpp" />
|
||||
|
@ -68,7 +67,6 @@
|
|||
<ClInclude Include="DiscScrubber.h" />
|
||||
<ClInclude Include="DriveBlob.h" />
|
||||
<ClInclude Include="FileBlob.h" />
|
||||
<ClInclude Include="FileHandlerARC.h" />
|
||||
<ClInclude Include="FileMonitor.h" />
|
||||
<ClInclude Include="Filesystem.h" />
|
||||
<ClInclude Include="FileSystemGCWii.h" />
|
||||
|
|
|
@ -33,9 +33,6 @@
|
|||
<ClCompile Include="BannerLoaderWii.cpp">
|
||||
<Filter>FileHandler</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="FileHandlerARC.cpp">
|
||||
<Filter>FileHandler</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Filesystem.cpp">
|
||||
<Filter>FileSystem</Filter>
|
||||
</ClCompile>
|
||||
|
@ -101,9 +98,6 @@
|
|||
<ClInclude Include="BannerLoaderGC.h">
|
||||
<Filter>FileHandler</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="FileHandlerARC.h">
|
||||
<Filter>FileHandler</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Filesystem.h">
|
||||
<Filter>FileSystem</Filter>
|
||||
</ClInclude>
|
||||
|
|
|
@ -1,226 +0,0 @@
|
|||
// Copyright 2013 Dolphin Emulator Project
|
||||
// Licensed under GPLv2
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "Common/Common.h"
|
||||
#include "Common/FileUtil.h"
|
||||
#include "Common/StringUtil.h"
|
||||
#include "DiscIO/Blob.h"
|
||||
#include "DiscIO/FileHandlerARC.h"
|
||||
#include "DiscIO/Filesystem.h"
|
||||
|
||||
#define ARC_ID 0x55aa382d
|
||||
|
||||
namespace DiscIO
|
||||
{
|
||||
CARCFile::CARCFile(const std::string& _rFilename)
|
||||
: m_pBuffer(nullptr)
|
||||
, m_Initialized(false)
|
||||
{
|
||||
std::unique_ptr<IBlobReader> reader(DiscIO::CreateBlobReader(_rFilename));
|
||||
if (reader != nullptr)
|
||||
{
|
||||
u64 FileSize = reader->GetDataSize();
|
||||
m_pBuffer = new u8[(u32)FileSize];
|
||||
reader->Read(0, FileSize, m_pBuffer);
|
||||
|
||||
m_Initialized = ParseBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
CARCFile::CARCFile(const std::string& _rFilename, u32 offset)
|
||||
: m_pBuffer(nullptr)
|
||||
, m_Initialized(false)
|
||||
{
|
||||
std::unique_ptr<IBlobReader> reader(DiscIO::CreateBlobReader(_rFilename));
|
||||
if (reader != nullptr)
|
||||
{
|
||||
u64 FileSize = reader->GetDataSize() - offset;
|
||||
m_pBuffer = new u8[(u32)FileSize];
|
||||
reader->Read(offset, FileSize, m_pBuffer);
|
||||
|
||||
m_Initialized = ParseBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
CARCFile::CARCFile(const u8* _pBuffer, size_t _BufferSize)
|
||||
: m_pBuffer(nullptr)
|
||||
, m_Initialized(false)
|
||||
{
|
||||
m_pBuffer = new u8[_BufferSize];
|
||||
|
||||
if (m_pBuffer)
|
||||
{
|
||||
memcpy(m_pBuffer, _pBuffer, _BufferSize);
|
||||
m_Initialized = ParseBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CARCFile::~CARCFile()
|
||||
{
|
||||
delete [] m_pBuffer;
|
||||
}
|
||||
|
||||
|
||||
bool CARCFile::IsInitialized()
|
||||
{
|
||||
return m_Initialized;
|
||||
}
|
||||
|
||||
|
||||
size_t CARCFile::GetFileSize(const std::string& _rFullPath)
|
||||
{
|
||||
if (!m_Initialized)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
const SFileInfo* pFileInfo = FindFileInfo(_rFullPath);
|
||||
|
||||
if (pFileInfo != nullptr)
|
||||
{
|
||||
return (size_t)pFileInfo->m_FileSize;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
size_t CARCFile::ReadFile(const std::string& _rFullPath, u8* _pBuffer, size_t _MaxBufferSize)
|
||||
{
|
||||
if (!m_Initialized)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
const SFileInfo* pFileInfo = FindFileInfo(_rFullPath);
|
||||
|
||||
if (pFileInfo == nullptr)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (pFileInfo->m_FileSize > _MaxBufferSize)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
memcpy(_pBuffer, &m_pBuffer[pFileInfo->m_Offset], (size_t)pFileInfo->m_FileSize);
|
||||
return (size_t) pFileInfo->m_FileSize;
|
||||
}
|
||||
|
||||
|
||||
bool CARCFile::ExportFile(const std::string& _rFullPath, const std::string& _rExportFilename)
|
||||
{
|
||||
if (!m_Initialized)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const SFileInfo* pFileInfo = FindFileInfo(_rFullPath);
|
||||
|
||||
if (pFileInfo == nullptr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
File::IOFile pFile(_rExportFilename, "wb");
|
||||
|
||||
return pFile.WriteBytes(&m_pBuffer[pFileInfo->m_Offset], (size_t) pFileInfo->m_FileSize);
|
||||
}
|
||||
|
||||
|
||||
bool CARCFile::ExportAllFiles(const std::string& _rFullPath)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool CARCFile::ParseBuffer()
|
||||
{
|
||||
// check ID
|
||||
u32 ID = Common::swap32(*(u32*)(m_pBuffer));
|
||||
|
||||
if (ID != ARC_ID)
|
||||
return false;
|
||||
|
||||
// read header
|
||||
u32 FSTOffset = Common::swap32(*(u32*)(m_pBuffer + 0x4));
|
||||
//u32 FSTSize = Common::swap32(*(u32*)(m_pBuffer + 0x8));
|
||||
//u32 FileOffset = Common::swap32(*(u32*)(m_pBuffer + 0xC));
|
||||
|
||||
// read all file infos
|
||||
SFileInfo Root;
|
||||
Root.m_NameOffset = Common::swap32(*(u32*)(m_pBuffer + FSTOffset + 0x0));
|
||||
Root.m_Offset = Common::swap32(*(u32*)(m_pBuffer + FSTOffset + 0x4));
|
||||
Root.m_FileSize = Common::swap32(*(u32*)(m_pBuffer + FSTOffset + 0x8));
|
||||
|
||||
if (Root.IsDirectory())
|
||||
{
|
||||
m_FileInfoVector.resize((unsigned int)Root.m_FileSize);
|
||||
const char* szNameTable = (char*)(m_pBuffer + FSTOffset);
|
||||
|
||||
for (size_t i = 0; i < m_FileInfoVector.size(); i++)
|
||||
{
|
||||
u8* Offset = m_pBuffer + FSTOffset + (i * 0xC);
|
||||
m_FileInfoVector[i].m_NameOffset = Common::swap32(*(u32*)(Offset + 0x0));
|
||||
m_FileInfoVector[i].m_Offset = Common::swap32(*(u32*)(Offset + 0x4));
|
||||
m_FileInfoVector[i].m_FileSize = Common::swap32(*(u32*)(Offset + 0x8));
|
||||
|
||||
szNameTable += 0xC;
|
||||
}
|
||||
|
||||
BuildFilenames(1, m_FileInfoVector.size(), "", szNameTable);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
size_t CARCFile::BuildFilenames(const size_t _FirstIndex, const size_t _LastIndex, const std::string& _szDirectory, const char* _szNameTable)
|
||||
{
|
||||
size_t CurrentIndex = _FirstIndex;
|
||||
|
||||
while (CurrentIndex < _LastIndex)
|
||||
{
|
||||
SFileInfo& rFileInfo = m_FileInfoVector[CurrentIndex];
|
||||
int const uOffset = rFileInfo.m_NameOffset & 0xFFFFFF;
|
||||
|
||||
rFileInfo.m_FullPath = _szDirectory + &_szNameTable[uOffset];
|
||||
|
||||
// check next index
|
||||
if (rFileInfo.IsDirectory())
|
||||
{
|
||||
rFileInfo.m_FullPath += '/';
|
||||
CurrentIndex = BuildFilenames(CurrentIndex + 1, (size_t)rFileInfo.m_FileSize, rFileInfo.m_FullPath, _szNameTable);
|
||||
}
|
||||
else
|
||||
{
|
||||
++CurrentIndex;
|
||||
}
|
||||
}
|
||||
|
||||
return CurrentIndex;
|
||||
}
|
||||
|
||||
|
||||
const SFileInfo* CARCFile::FindFileInfo(const std::string& _rFullPath) const
|
||||
{
|
||||
for (auto& fileInfo : m_FileInfoVector)
|
||||
{
|
||||
if (!strcasecmp(fileInfo.m_FullPath.c_str(), _rFullPath.c_str()))
|
||||
{
|
||||
return &fileInfo;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
} // namespace
|
|
@ -1,54 +0,0 @@
|
|||
// Copyright 2013 Dolphin Emulator Project
|
||||
// Licensed under GPLv2
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "DiscIO/Filesystem.h"
|
||||
|
||||
namespace DiscIO
|
||||
{
|
||||
class CARCFile
|
||||
{
|
||||
public:
|
||||
|
||||
CARCFile(const std::string& _rFilename);
|
||||
|
||||
CARCFile(const std::string& _rFilename, u32 offset);
|
||||
|
||||
CARCFile(const u8* _pBuffer, size_t _BufferSize);
|
||||
|
||||
virtual ~CARCFile();
|
||||
|
||||
bool IsInitialized();
|
||||
|
||||
size_t GetFileSize(const std::string& _rFullPath);
|
||||
|
||||
size_t ReadFile(const std::string& _rFullPath, u8* _pBuffer, size_t _MaxBufferSize);
|
||||
|
||||
bool ExportFile(const std::string& _rFullPath, const std::string& _rExportFilename);
|
||||
|
||||
bool ExportAllFiles(const std::string& _rFullPath);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
u8* m_pBuffer;
|
||||
|
||||
bool m_Initialized;
|
||||
|
||||
typedef std::vector<SFileInfo>CFileInfoVector;
|
||||
CFileInfoVector m_FileInfoVector;
|
||||
|
||||
bool ParseBuffer();
|
||||
|
||||
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;
|
||||
};
|
||||
} // namespace
|
Loading…
Reference in New Issue