mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-21 05:09:34 -06:00
Reuse the IOS code for WAD installation
* Less code and logic duplication. * Fixes a bug with the data dir not being created, steps being done in the wrong order.
This commit is contained in:
@ -246,74 +246,6 @@ void CNANDContentManager::ClearCache()
|
||||
m_map.clear();
|
||||
}
|
||||
|
||||
u64 CNANDContentManager::Install_WiiWAD(const std::string& filename)
|
||||
{
|
||||
if (filename.find(".wad") == std::string::npos)
|
||||
return 0;
|
||||
const CNANDContentLoader& content_loader = GetNANDLoader(filename);
|
||||
if (content_loader.IsValid() == false)
|
||||
return 0;
|
||||
|
||||
const u64 title_id = content_loader.GetTMD().GetTitleId();
|
||||
|
||||
// copy WAD's TMD header and contents to content directory
|
||||
|
||||
std::string content_path(Common::GetTitleContentPath(title_id, Common::FROM_CONFIGURED_ROOT));
|
||||
std::string tmd_filename(Common::GetTMDFileName(title_id, Common::FROM_CONFIGURED_ROOT));
|
||||
File::CreateFullPath(tmd_filename);
|
||||
|
||||
File::IOFile tmd_file(tmd_filename, "wb");
|
||||
if (!tmd_file)
|
||||
{
|
||||
PanicAlertT("WAD installation failed: error creating %s", tmd_filename.c_str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
const auto& raw_tmd = content_loader.GetTMD().GetRawTMD();
|
||||
tmd_file.WriteBytes(raw_tmd.data(), raw_tmd.size());
|
||||
|
||||
IOS::ES::SharedContentMap shared_content{Common::FromWhichRoot::FROM_CONFIGURED_ROOT};
|
||||
for (const auto& content : content_loader.GetContent())
|
||||
{
|
||||
std::string app_filename;
|
||||
if (content.m_metadata.IsShared())
|
||||
app_filename = shared_content.AddSharedContent(content.m_metadata.sha1);
|
||||
else
|
||||
app_filename = StringFromFormat("%s%08x.app", content_path.c_str(), content.m_metadata.id);
|
||||
|
||||
if (!File::Exists(app_filename))
|
||||
{
|
||||
File::CreateFullPath(app_filename);
|
||||
File::IOFile app_file(app_filename, "wb");
|
||||
if (!app_file)
|
||||
{
|
||||
PanicAlertT("WAD installation failed: error creating %s", app_filename.c_str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
app_file.WriteBytes(content.m_Data->Get().data(), content.m_metadata.size);
|
||||
}
|
||||
else
|
||||
{
|
||||
INFO_LOG(DISCIO, "Content %s already exists.", app_filename.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
// Extract and copy WAD's ticket to ticket directory
|
||||
if (!AddTicket(content_loader.GetTicket()))
|
||||
{
|
||||
PanicAlertT("WAD installation failed: error creating ticket");
|
||||
return 0;
|
||||
}
|
||||
|
||||
IOS::ES::UIDSys uid_sys{Common::FromWhichRoot::FROM_CONFIGURED_ROOT};
|
||||
uid_sys.GetOrInsertUIDForTitle(title_id);
|
||||
|
||||
ClearCache();
|
||||
|
||||
return title_id;
|
||||
}
|
||||
|
||||
bool AddTicket(const IOS::ES::TicketReader& signed_ticket)
|
||||
{
|
||||
if (!signed_ticket.IsValid())
|
||||
|
Reference in New Issue
Block a user