mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 14:19:46 -06:00
Move WiiUtils to Core
Allows reusing the WAD import logic more easily, whereas UICommon code can only be used from UICommon and UI. And managing what's on the NAND is the Core's responsability, not UI.
This commit is contained in:
@ -19,6 +19,7 @@ set(SRCS
|
||||
State.cpp
|
||||
TitleDatabase.cpp
|
||||
WiiRoot.cpp
|
||||
WiiUtils.cpp
|
||||
Boot/Boot_BS2Emu.cpp
|
||||
Boot/Boot.cpp
|
||||
Boot/Boot_WiiWAD.cpp
|
||||
|
@ -290,6 +290,7 @@
|
||||
<ClCompile Include="State.cpp" />
|
||||
<ClCompile Include="TitleDatabase.cpp" />
|
||||
<ClCompile Include="WiiRoot.cpp" />
|
||||
<ClCompile Include="WiiUtils.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="ActionReplay.h" />
|
||||
@ -524,6 +525,7 @@
|
||||
<ClInclude Include="Titles.h" />
|
||||
<ClInclude Include="TitleDatabase.h" />
|
||||
<ClInclude Include="WiiRoot.h" />
|
||||
<ClInclude Include="WiiUtils.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Text Include="CMakeLists.txt" />
|
||||
|
@ -179,6 +179,7 @@
|
||||
<ClCompile Include="State.cpp" />
|
||||
<ClCompile Include="TitleDatabase.cpp" />
|
||||
<ClCompile Include="WiiRoot.cpp" />
|
||||
<ClCompile Include="WiiUtils.cpp" />
|
||||
<ClCompile Include="ActionReplay.cpp">
|
||||
<Filter>ActionReplay</Filter>
|
||||
</ClCompile>
|
||||
@ -898,6 +899,7 @@
|
||||
<ClInclude Include="Titles.h" />
|
||||
<ClInclude Include="TitleDatabase.h" />
|
||||
<ClInclude Include="WiiRoot.h" />
|
||||
<ClInclude Include="WiiUtils.h" />
|
||||
<ClInclude Include="ActionReplay.h">
|
||||
<Filter>ActionReplay</Filter>
|
||||
</ClInclude>
|
||||
@ -1543,4 +1545,4 @@
|
||||
<ItemGroup>
|
||||
<Text Include="CMakeLists.txt" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
77
Source/Core/Core/WiiUtils.cpp
Normal file
77
Source/Core/Core/WiiUtils.cpp
Normal file
@ -0,0 +1,77 @@
|
||||
// Copyright 2017 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "Core/WiiUtils.h"
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/MsgHandler.h"
|
||||
#include "Core/ConfigManager.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;
|
||||
IOS::HLE::ReturnCode ret;
|
||||
const bool checks_enabled = SConfig::GetInstance().m_enable_signature_checks;
|
||||
while ((ret = es->ImportTicket(wad.GetTicket().GetBytes(), wad.GetCertificateChain())) < 0 ||
|
||||
(ret = es->ImportTitleInit(context, tmd.GetBytes(), wad.GetCertificateChain())) < 0)
|
||||
{
|
||||
if (checks_enabled && ret == IOS::HLE::IOSC_FAIL_CHECKVALUE &&
|
||||
AskYesNoT("This WAD has not been signed by Nintendo. Continue to import?"))
|
||||
{
|
||||
SConfig::GetInstance().m_enable_signature_checks = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
SConfig::GetInstance().m_enable_signature_checks = checks_enabled;
|
||||
PanicAlertT("WAD installation failed: Could not initialise title import.");
|
||||
return false;
|
||||
}
|
||||
SConfig::GetInstance().m_enable_signature_checks = checks_enabled;
|
||||
|
||||
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::NANDContentManager::Access().ClearCache();
|
||||
return true;
|
||||
}
|
||||
}
|
14
Source/Core/Core/WiiUtils.h
Normal file
14
Source/Core/Core/WiiUtils.h
Normal 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);
|
||||
}
|
Reference in New Issue
Block a user