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:
Léo Lam
2017-05-14 15:30:42 +02:00
parent afcda22da9
commit c8bffb0153
8 changed files with 87 additions and 75 deletions
+1
View File
@@ -3,6 +3,7 @@ set(SRCS
Disassembler.cpp
UICommon.cpp
USBUtils.cpp
WiiUtils.cpp
)
if(USE_X11)
+3 -1
View File
@@ -59,12 +59,14 @@
<ClCompile Include="USBUtils.cpp">
<DisableSpecificWarnings>4200;%(DisableSpecificWarnings)</DisableSpecificWarnings>
</ClCompile>
<ClCompile Include="WiiUtils.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="CommandLineParse.h" />
<ClInclude Include="UICommon.h" />
<ClInclude Include="Disassembler.h" />
<ClInclude Include="USBUtils.h" />
<ClInclude Include="WiiUtils.h" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(ExternalsDir)cpp-optparse\cpp-optparse.vcxproj">
@@ -74,4 +76,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
+64
View File
@@ -0,0 +1,64 @@
// Copyright 2017 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include "UICommon/WiiUtils.h"
#include "Common/CommonTypes.h"
#include "Common/MsgHandler.h"
#include "Core/IOS/ES/ES.h"
#include "Core/IOS/ES/Formats.h"
#include "Core/IOS/IOS.h"
#include "DiscIO/NANDContentLoader.h"
#include "DiscIO/WiiWad.h"
namespace WiiUtils
{
bool InstallWAD(const std::string& wad_path)
{
const DiscIO::WiiWAD wad{wad_path};
if (!wad.IsValid())
{
PanicAlertT("WAD installation failed: The selected file is not a valid WAD.");
return false;
}
const auto tmd = wad.GetTMD();
IOS::HLE::Kernel ios;
const auto es = ios.GetES();
IOS::HLE::Device::ES::Context context;
if (es->ImportTicket(wad.GetTicket().GetRawTicket()) < 0 ||
es->ImportTitleInit(context, tmd.GetRawTMD()) < 0)
{
PanicAlertT("WAD installation failed: Could not initialise title import.");
return false;
}
const bool contents_imported = [&]() {
const u64 title_id = tmd.GetTitleId();
for (const IOS::ES::Content& content : tmd.GetContents())
{
const std::vector<u8> data = wad.GetContent(content.index);
if (es->ImportContentBegin(context, title_id, content.id) < 0 ||
es->ImportContentData(context, 0, data.data(), static_cast<u32>(data.size())) < 0 ||
es->ImportContentEnd(context, 0) < 0)
{
PanicAlertT("WAD installation failed: Could not import content %08x.", content.id);
return false;
}
}
return true;
}();
if ((contents_imported && es->ImportTitleDone(context) < 0) ||
(!contents_imported && es->ImportTitleCancel(context) < 0))
{
PanicAlertT("WAD installation failed: Could not finalise title import.");
return false;
}
DiscIO::CNANDContentManager::Access().ClearCache();
return true;
}
}
+14
View File
@@ -0,0 +1,14 @@
// Copyright 2017 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include <string>
// Small utility functions for common Wii related tasks.
namespace WiiUtils
{
bool InstallWAD(const std::string& wad_path);
}