rpcsx/rpcs3/Loader/TRP.cpp

118 lines
1.8 KiB
C++
Raw Normal View History

#include "stdafx.h"
#include "Emu/System.h"
#include "TRP.h"
2016-02-01 22:47:09 +01:00
TRPLoader::TRPLoader(const fs::file& f)
: trp_f(f)
{
}
2016-02-01 22:47:09 +01:00
bool TRPLoader::Install(const std::string& dest, bool show)
{
2016-02-01 22:47:09 +01:00
if (!trp_f)
2015-07-26 10:14:56 +02:00
{
return false;
2015-07-26 10:14:56 +02:00
}
2016-02-01 22:47:09 +01:00
const std::string& local_path = vfs::get(dest);
2016-05-13 16:01:48 +02:00
if (!fs::create_dir(local_path) && fs::g_tls_error != fs::error::exist)
2015-07-15 15:21:41 +02:00
{
2016-02-01 22:47:09 +01:00
return false;
2015-07-15 15:21:41 +02:00
}
2016-02-01 22:47:09 +01:00
std::vector<char> buffer; buffer.reserve(65536);
for (const TRPEntry& entry : m_entries)
{
2016-02-01 22:47:09 +01:00
trp_f.seek(entry.offset);
buffer.resize(entry.size);
if (!trp_f.read(buffer)) continue; // ???
fs::file(local_path + '/' + entry.name, fs::rewrite).write(buffer);
}
return true;
}
bool TRPLoader::LoadHeader(bool show)
{
2016-02-01 22:47:09 +01:00
if (!trp_f)
2015-07-26 10:14:56 +02:00
{
return false;
2015-07-26 10:14:56 +02:00
}
2016-02-01 22:47:09 +01:00
trp_f.seek(0);
2015-07-26 10:14:56 +02:00
2016-02-01 22:47:09 +01:00
if (!trp_f.read(m_header))
2015-07-26 10:14:56 +02:00
{
return false;
2015-07-26 10:14:56 +02:00
}
if (m_header.trp_magic != 0xDCA24D00)
2015-07-26 10:14:56 +02:00
{
return false;
2015-07-26 10:14:56 +02:00
}
if (show)
2015-07-26 10:14:56 +02:00
{
2014-09-29 17:38:04 +02:00
LOG_NOTICE(LOADER, "TRP version: 0x%x", m_header.trp_version);
2015-07-26 10:14:56 +02:00
}
m_entries.clear();
m_entries.resize(m_header.trp_files_count);
2015-07-26 10:14:56 +02:00
for (u32 i = 0; i < m_header.trp_files_count; i++)
{
2016-02-01 22:47:09 +01:00
if (!trp_f.read(m_entries[i]))
2015-07-26 10:14:56 +02:00
{
return false;
2015-07-26 10:14:56 +02:00
}
if (show)
2015-07-26 10:14:56 +02:00
{
LOG_NOTICE(LOADER, "TRP entry #%d: %s", m_entries[i].name);
2015-07-26 10:14:56 +02:00
}
}
return true;
}
bool TRPLoader::ContainsEntry(const char *filename)
{
2015-07-26 10:14:56 +02:00
for (const TRPEntry& entry : m_entries)
{
if (!strcmp(entry.name, filename))
2015-07-26 10:14:56 +02:00
{
return true;
2015-07-26 10:14:56 +02:00
}
}
return false;
}
void TRPLoader::RemoveEntry(const char *filename)
{
std::vector<TRPEntry>::iterator i = m_entries.begin();
2015-07-26 10:14:56 +02:00
while (i != m_entries.end())
{
if (!strcmp(i->name, filename))
2015-07-26 10:14:56 +02:00
{
i = m_entries.erase(i);
2015-07-26 10:14:56 +02:00
}
else
2015-07-26 10:14:56 +02:00
{
i++;
2015-07-26 10:14:56 +02:00
}
}
}
void TRPLoader::RenameEntry(const char *oldname, const char *newname)
{
2015-07-26 10:14:56 +02:00
for (const TRPEntry& entry : m_entries)
{
if (!strcmp(entry.name, oldname))
2015-07-26 10:14:56 +02:00
{
memcpy((void*)entry.name, newname, 32);
2015-07-26 10:14:56 +02:00
}
}
}