Trophy: Return correct disk space requirements

Closes #3763
This commit is contained in:
VelocityRa 2017-11-20 15:08:35 +02:00 committed by Nekotekina
parent d40aaf0391
commit 489ded43b1
3 changed files with 21 additions and 6 deletions

View file

@ -331,7 +331,7 @@ error_code sceNpTrophyRegisterContext(ppu_thread& ppu, u32 context, u32 handle,
error_code sceNpTrophyGetRequiredDiskSpace(u32 context, u32 handle, vm::ptr<u64> reqspace, u64 options)
{
sceNpTrophy.todo("sceNpTrophyGetRequiredDiskSpace(context=0x%x, handle=0x%x, reqspace=*0x%x, options=0x%llx)", context, handle, reqspace, options);
sceNpTrophy.warning("sceNpTrophyGetRequiredDiskSpace(context=0x%x, handle=0x%x, reqspace=*0x%x, options=0x%llx)", context, handle, reqspace, options);
if (!reqspace)
{
@ -352,12 +352,18 @@ error_code sceNpTrophyGetRequiredDiskSpace(u32 context, u32 handle, vm::ptr<u64>
return SCE_NP_TROPHY_ERROR_UNKNOWN_HANDLE;
}
// TODO: This is not accurate. It's just an approximation of the real value
// The real value can be obtained in TRP.cpp:
// m_headers.trp_file_size - sizeof(m_headers) - (m_headers.trp_files_count * m_headers.trp_element_size);
// TODO: eventually this should be set to 0 when trophys are detected as already installed, setting to 0 now causes some games to not call registerContext, which leads to trophys never getting installed
*reqspace = ctxt->trp_stream.size();
if (!fs::is_dir("/dev_hdd0/home/00000001/trophy/" + ctxt->trp_name))
{
TRPLoader trp(ctxt->trp_stream);
if (trp.LoadHeader())
{
*reqspace = trp.GetRequiredSpace();
return CELL_OK;
}
}
*reqspace = 0;
return CELL_OK;
}

View file

@ -103,6 +103,14 @@ bool TRPLoader::LoadHeader(bool show)
return true;
}
u64 TRPLoader::GetRequiredSpace() const
{
const u64 file_size = m_header.trp_file_size;
const u64 file_element_size = u64{1} * m_header.trp_files_count * m_header.trp_element_size;
return file_size - sizeof(m_header) - file_element_size;
}
bool TRPLoader::ContainsEntry(const char *filename)
{
for (const TRPEntry& entry : m_entries)

View file

@ -32,6 +32,7 @@ public:
bool Install(const std::string& dest, bool show = false);
bool LoadHeader(bool show = false);
u64 GetRequiredSpace() const;
bool ContainsEntry(const char *filename);
void RemoveEntry(const char *filename);