summaryrefslogtreecommitdiff
path: root/Source/Core/DiscIO
diff options
context:
space:
mode:
authorLeo Lam <leolino.lam@gmail.com>2017-10-26 17:15:02 +0200
committerGitHub <noreply@github.com>2017-10-26 17:15:02 +0200
commitc4914fbb8b9d90e1acdd77ce7504a0e4c4dfd21f (patch)
treecbe6d36771633db3eab33dc8b6d643f3bc7440fb /Source/Core/DiscIO
parent5393575c552c733be0df89fddf2493ab7437b389 (diff)
parent4cc1bd972a12186b320d5e1142f10ab145df3203 (diff)
Merge pull request #6094 from leoetlino/drop-wad-hack
Drop the direct WAD launch hack
Diffstat (limited to 'Source/Core/DiscIO')
-rw-r--r--Source/Core/DiscIO/CMakeLists.txt1
-rw-r--r--Source/Core/DiscIO/DiscIO.vcxproj2
-rw-r--r--Source/Core/DiscIO/DiscIO.vcxproj.filters6
-rw-r--r--Source/Core/DiscIO/NANDContentLoader.cpp268
-rw-r--r--Source/Core/DiscIO/NANDContentLoader.h126
-rw-r--r--Source/Core/DiscIO/NANDImporter.cpp4
-rw-r--r--Source/Core/DiscIO/VolumeGC.h2
-rw-r--r--Source/Core/DiscIO/VolumeWad.h4
-rw-r--r--Source/Core/DiscIO/VolumeWii.h2
-rw-r--r--Source/Core/DiscIO/WiiWad.h2
10 files changed, 2 insertions, 415 deletions
diff --git a/Source/Core/DiscIO/CMakeLists.txt b/Source/Core/DiscIO/CMakeLists.txt
index 1b6bb3b51d..9e095f464e 100644
--- a/Source/Core/DiscIO/CMakeLists.txt
+++ b/Source/Core/DiscIO/CMakeLists.txt
@@ -11,7 +11,6 @@ set(SRCS
FileBlob.cpp
FileSystemGCWii.cpp
Filesystem.cpp
- NANDContentLoader.cpp
NANDImporter.cpp
TGCBlob.cpp
Volume.cpp
diff --git a/Source/Core/DiscIO/DiscIO.vcxproj b/Source/Core/DiscIO/DiscIO.vcxproj
index b20dae68bc..4c8b542a6f 100644
--- a/Source/Core/DiscIO/DiscIO.vcxproj
+++ b/Source/Core/DiscIO/DiscIO.vcxproj
@@ -47,7 +47,6 @@
<ClCompile Include="FileBlob.cpp" />
<ClCompile Include="Filesystem.cpp" />
<ClCompile Include="FileSystemGCWii.cpp" />
- <ClCompile Include="NANDContentLoader.cpp" />
<ClCompile Include="NANDImporter.cpp" />
<ClCompile Include="TGCBlob.cpp" />
<ClCompile Include="Volume.cpp" />
@@ -70,7 +69,6 @@
<ClInclude Include="FileBlob.h" />
<ClInclude Include="Filesystem.h" />
<ClInclude Include="FileSystemGCWii.h" />
- <ClInclude Include="NANDContentLoader.h" />
<ClInclude Include="NANDImporter.h" />
<ClInclude Include="TGCBlob.h" />
<ClInclude Include="Volume.h" />
diff --git a/Source/Core/DiscIO/DiscIO.vcxproj.filters b/Source/Core/DiscIO/DiscIO.vcxproj.filters
index 89cfed8abb..c196ae25aa 100644
--- a/Source/Core/DiscIO/DiscIO.vcxproj.filters
+++ b/Source/Core/DiscIO/DiscIO.vcxproj.filters
@@ -33,9 +33,6 @@
<ClCompile Include="WiiWad.cpp">
<Filter>NAND</Filter>
</ClCompile>
- <ClCompile Include="NANDContentLoader.cpp">
- <Filter>NAND</Filter>
- </ClCompile>
<ClCompile Include="NANDImporter.cpp">
<Filter>NAND</Filter>
</ClCompile>
@@ -98,9 +95,6 @@
<ClInclude Include="WiiWad.h">
<Filter>NAND</Filter>
</ClInclude>
- <ClInclude Include="NANDContentLoader.h">
- <Filter>NAND</Filter>
- </ClInclude>
<ClInclude Include="NANDImporter.h">
<Filter>NAND</Filter>
</ClInclude>
diff --git a/Source/Core/DiscIO/NANDContentLoader.cpp b/Source/Core/DiscIO/NANDContentLoader.cpp
deleted file mode 100644
index 47ea26c81a..0000000000
--- a/Source/Core/DiscIO/NANDContentLoader.cpp
+++ /dev/null
@@ -1,268 +0,0 @@
-// Copyright 2009 Dolphin Emulator Project
-// Licensed under GPLv2+
-// Refer to the license.txt file included.
-
-#include "DiscIO/NANDContentLoader.h"
-
-#include <algorithm>
-#include <array>
-#include <cinttypes>
-#include <cstddef>
-#include <cstdio>
-#include <cstring>
-#include <functional>
-#include <map>
-#include <string>
-#include <utility>
-#include <vector>
-
-#include "Common/Align.h"
-#include "Common/CommonTypes.h"
-#include "Common/Crypto/AES.h"
-#include "Common/File.h"
-#include "Common/FileUtil.h"
-#include "Common/Logging/Log.h"
-#include "Common/MsgHandler.h"
-#include "Common/NandPaths.h"
-#include "Common/StringUtil.h"
-#include "Common/Swap.h"
-// TODO: kill this dependency.
-#include "Core/IOS/ES/Formats.h"
-
-#include "DiscIO/WiiWad.h"
-
-namespace DiscIO
-{
-NANDContentData::~NANDContentData() = default;
-
-NANDContentDataFile::NANDContentDataFile(const std::string& filename) : m_filename{filename}
-{
-}
-
-NANDContentDataFile::~NANDContentDataFile() = default;
-
-void NANDContentDataFile::EnsureOpen()
-{
- if (!m_file)
- m_file = std::make_unique<File::IOFile>(m_filename, "rb");
- else if (!m_file->IsOpen())
- m_file->Open(m_filename, "rb");
-}
-void NANDContentDataFile::Open()
-{
- EnsureOpen();
-}
-std::vector<u8> NANDContentDataFile::Get()
-{
- EnsureOpen();
-
- if (!m_file->IsGood())
- return {};
-
- u64 size = m_file->GetSize();
- if (size == 0)
- return {};
-
- std::vector<u8> result(size);
- m_file->ReadBytes(result.data(), result.size());
-
- return result;
-}
-
-bool NANDContentDataFile::GetRange(u32 start, u32 size, u8* buffer)
-{
- EnsureOpen();
- if (!m_file->IsGood())
- return false;
-
- if (!m_file->Seek(start, SEEK_SET))
- return false;
-
- return m_file->ReadBytes(buffer, static_cast<size_t>(size));
-}
-void NANDContentDataFile::Close()
-{
- if (m_file && m_file->IsOpen())
- m_file->Close();
-}
-
-bool NANDContentDataBuffer::GetRange(u32 start, u32 size, u8* buffer)
-{
- if (start + size > m_buffer.size())
- return false;
-
- std::copy_n(&m_buffer[start], size, buffer);
- return true;
-}
-
-NANDContentLoader::NANDContentLoader(const std::string& content_name, Common::FromWhichRoot from)
- : m_root(from)
-{
- m_Valid = Initialize(content_name);
-}
-
-NANDContentLoader::~NANDContentLoader()
-{
-}
-
-bool NANDContentLoader::IsValid() const
-{
- return m_Valid;
-}
-
-const NANDContent* NANDContentLoader::GetContentByID(u32 id) const
-{
- const auto iterator = std::find_if(m_Content.begin(), m_Content.end(), [id](const auto& content) {
- return content.m_metadata.id == id;
- });
- return iterator != m_Content.end() ? &*iterator : nullptr;
-}
-
-const NANDContent* NANDContentLoader::GetContentByIndex(int index) const
-{
- for (auto& Content : m_Content)
- {
- if (Content.m_metadata.index == index)
- {
- return &Content;
- }
- }
- return nullptr;
-}
-
-bool NANDContentLoader::Initialize(const std::string& name)
-{
- if (name.empty())
- return false;
-
- m_Path = name;
-
- WiiWAD wad(name);
- std::vector<u8> data_app;
-
- if (wad.IsValid())
- {
- m_IsWAD = true;
- m_ticket = wad.GetTicket();
- m_tmd = wad.GetTMD();
- data_app = wad.GetDataApp();
- }
- else
- {
- std::string tmd_filename(m_Path);
-
- if (tmd_filename.back() == '/')
- tmd_filename += "title.tmd";
- else
- m_Path = tmd_filename.substr(0, tmd_filename.find("title.tmd"));
-
- File::IOFile tmd_file(tmd_filename, "rb");
- if (!tmd_file)
- {
- WARN_LOG(DISCIO, "CreateFromDirectory: error opening %s", tmd_filename.c_str());
- return false;
- }
-
- std::vector<u8> bytes(tmd_file.GetSize());
- tmd_file.ReadBytes(bytes.data(), bytes.size());
- m_tmd.SetBytes(std::move(bytes));
-
- m_ticket = FindSignedTicket(m_tmd.GetTitleId());
- }
-
- InitializeContentEntries(data_app);
- return true;
-}
-
-void NANDContentLoader::InitializeContentEntries(const std::vector<u8>& data_app)
-{
- if (!m_ticket.IsValid())
- {
- ERROR_LOG(IOS_ES, "No valid ticket for title %016" PRIx64, m_tmd.GetTitleId());
- return;
- }
-
- const std::vector<IOS::ES::Content> contents = m_tmd.GetContents();
- m_Content.resize(contents.size());
-
- u32 data_app_offset = 0;
- const std::array<u8, 16> title_key = m_ticket.GetTitleKey();
- IOS::ES::SharedContentMap shared_content{m_root};
-
- for (size_t i = 0; i < contents.size(); ++i)
- {
- const auto& content = contents.at(i);
-
- if (m_IsWAD)
- {
- // The content index is used as IV (2 bytes); the remaining 14 bytes are zeroes.
- std::array<u8, 16> iv{};
- iv[0] = static_cast<u8>(content.index >> 8) & 0xFF;
- iv[1] = static_cast<u8>(content.index) & 0xFF;
-
- u32 rounded_size = Common::AlignUp(static_cast<u32>(content.size), 0x40);
-
- m_Content[i].m_Data = std::make_unique<NANDContentDataBuffer>(Common::AES::Decrypt(
- title_key.data(), iv.data(), &data_app[data_app_offset], rounded_size));
- data_app_offset += rounded_size;
- }
- else
- {
- std::string filename;
- if (content.IsShared())
- filename = *shared_content.GetFilenameFromSHA1(content.sha1);
- else
- filename = StringFromFormat("%s/%08x.app", m_Path.c_str(), content.id);
-
- m_Content[i].m_Data = std::make_unique<NANDContentDataFile>(filename);
- }
-
- m_Content[i].m_metadata = std::move(content);
- }
-}
-
-NANDContentManager::~NANDContentManager()
-{
-}
-
-const NANDContentLoader& NANDContentManager::GetNANDLoader(const std::string& content_path,
- Common::FromWhichRoot from)
-{
- auto it = m_map.find(content_path);
- if (it != m_map.end())
- return *it->second;
- return *m_map
- .emplace_hint(it, std::make_pair(content_path, std::make_unique<NANDContentLoader>(
- content_path, from)))
- ->second;
-}
-
-const NANDContentLoader& NANDContentManager::GetNANDLoader(u64 title_id, Common::FromWhichRoot from)
-{
- std::string path = Common::GetTitleContentPath(title_id, from);
- return GetNANDLoader(path, from);
-}
-
-void NANDContentManager::ClearCache()
-{
- m_map.clear();
-}
-
-IOS::ES::TicketReader FindSignedTicket(u64 title_id)
-{
- std::string ticket_filename = Common::GetTicketFileName(title_id, Common::FROM_CONFIGURED_ROOT);
- File::IOFile ticket_file(ticket_filename, "rb");
- if (!ticket_file)
- {
- return IOS::ES::TicketReader{};
- }
-
- std::vector<u8> signed_ticket(ticket_file.GetSize());
- if (!ticket_file.ReadBytes(signed_ticket.data(), signed_ticket.size()))
- {
- return IOS::ES::TicketReader{};
- }
-
- return IOS::ES::TicketReader{std::move(signed_ticket)};
-}
-} // namespace end
diff --git a/Source/Core/DiscIO/NANDContentLoader.h b/Source/Core/DiscIO/NANDContentLoader.h
deleted file mode 100644
index aa7d1c168e..0000000000
--- a/Source/Core/DiscIO/NANDContentLoader.h
+++ /dev/null
@@ -1,126 +0,0 @@
-// Copyright 2009 Dolphin Emulator Project
-// Licensed under GPLv2+
-// Refer to the license.txt file included.
-
-#pragma once
-
-#include <cstddef>
-#include <memory>
-#include <string>
-#include <unordered_map>
-#include <vector>
-
-#include "Common/CommonTypes.h"
-#include "Common/NandPaths.h"
-#include "Core/IOS/ES/Formats.h"
-
-namespace File
-{
-class IOFile;
-}
-
-namespace DiscIO
-{
-enum class Region;
-
-// TODO: move some of these to Core/IOS/ES.
-IOS::ES::TicketReader FindSignedTicket(u64 title_id);
-
-class NANDContentData
-{
-public:
- virtual ~NANDContentData() = 0;
- virtual void Open() {}
- virtual std::vector<u8> Get() = 0;
- virtual bool GetRange(u32 start, u32 size, u8* buffer) = 0;
- virtual void Close() {}
-};
-
-class NANDContentDataFile final : public NANDContentData
-{
-public:
- explicit NANDContentDataFile(const std::string& filename);
- ~NANDContentDataFile();
-
- void Open() override;
- std::vector<u8> Get() override;
- bool GetRange(u32 start, u32 size, u8* buffer) override;
- void Close() override;
-
-private:
- void EnsureOpen();
-
- const std::string m_filename;
- std::unique_ptr<File::IOFile> m_file;
-};
-
-class NANDContentDataBuffer final : public NANDContentData
-{
-public:
- explicit NANDContentDataBuffer(const std::vector<u8>& buffer) : m_buffer(buffer) {}
- std::vector<u8> Get() override { return m_buffer; }
- bool GetRange(u32 start, u32 size, u8* buffer) override;
-
-private:
- const std::vector<u8> m_buffer;
-};
-
-struct NANDContent
-{
- IOS::ES::Content m_metadata;
- std::unique_ptr<NANDContentData> m_Data;
-};
-
-// Instances of this class must be created by NANDContentManager
-class NANDContentLoader final
-{
-public:
- explicit NANDContentLoader(const std::string& content_name, Common::FromWhichRoot from);
- ~NANDContentLoader();
-
- bool IsValid() const;
- const NANDContent* GetContentByID(u32 id) const;
- const NANDContent* GetContentByIndex(int index) const;
- const IOS::ES::TMDReader& GetTMD() const { return m_tmd; }
- const IOS::ES::TicketReader& GetTicket() const { return m_ticket; }
- const std::vector<NANDContent>& GetContent() const { return m_Content; }
-private:
- bool Initialize(const std::string& name);
- void InitializeContentEntries(const std::vector<u8>& data_app);
-
- bool m_Valid = false;
- bool m_IsWAD = false;
- Common::FromWhichRoot m_root;
- std::string m_Path;
- IOS::ES::TMDReader m_tmd;
- IOS::ES::TicketReader m_ticket;
-
- std::vector<NANDContent> m_Content;
-};
-
-// we open the NAND Content files too often... let's cache them
-class NANDContentManager
-{
-public:
- static NANDContentManager& Access()
- {
- static NANDContentManager instance;
- return instance;
- }
-
- const NANDContentLoader& GetNANDLoader(const std::string& content_path,
- Common::FromWhichRoot from = Common::FROM_CONFIGURED_ROOT);
- const NANDContentLoader& GetNANDLoader(u64 title_id,
- Common::FromWhichRoot from = Common::FROM_CONFIGURED_ROOT);
- void ClearCache();
-
-private:
- NANDContentManager() {}
- ~NANDContentManager();
-
- NANDContentManager(NANDContentManager const&) = delete;
- void operator=(NANDContentManager const&) = delete;
-
- std::unordered_map<std::string, std::unique_ptr<NANDContentLoader>> m_map;
-};
-}
diff --git a/Source/Core/DiscIO/NANDImporter.cpp b/Source/Core/DiscIO/NANDImporter.cpp
index 220a241390..5a9983ce03 100644
--- a/Source/Core/DiscIO/NANDImporter.cpp
+++ b/Source/Core/DiscIO/NANDImporter.cpp
@@ -17,7 +17,6 @@
#include "Common/StringUtil.h"
#include "Common/Swap.h"
#include "Core/IOS/ES/Formats.h"
-#include "DiscIO/NANDContentLoader.h"
namespace DiscIO
{
@@ -44,9 +43,6 @@ void NANDImporter::ImportNANDBin(const std::string& path_to_bin,
ProcessEntry(0, nand_root);
ExportKeys(nand_root);
ExtractCertificates(nand_root);
-
- // We have to clear the cache so the new NAND takes effect
- DiscIO::NANDContentManager::Access().ClearCache();
}
bool NANDImporter::ReadNANDBin(const std::string& path_to_bin)
diff --git a/Source/Core/DiscIO/VolumeGC.h b/Source/Core/DiscIO/VolumeGC.h
index fc065a8d60..4f878c3bc9 100644
--- a/Source/Core/DiscIO/VolumeGC.h
+++ b/Source/Core/DiscIO/VolumeGC.h
@@ -15,8 +15,6 @@
#include "DiscIO/Filesystem.h"
#include "DiscIO/Volume.h"
-// --- this volume type is used for GC disc images ---
-
namespace DiscIO
{
class BlobReader;
diff --git a/Source/Core/DiscIO/VolumeWad.h b/Source/Core/DiscIO/VolumeWad.h
index a97f2d078e..33bfe4f7a6 100644
--- a/Source/Core/DiscIO/VolumeWad.h
+++ b/Source/Core/DiscIO/VolumeWad.h
@@ -14,10 +14,6 @@
#include "Core/IOS/ES/Formats.h"
#include "DiscIO/Volume.h"
-// --- this volume type is used for Wad files ---
-// Some of this code might look redundant with the NANDContentLoader class, however,
-// We do not do any decryption here, we do raw read, so things are -Faster-
-
namespace DiscIO
{
class BlobReader;
diff --git a/Source/Core/DiscIO/VolumeWii.h b/Source/Core/DiscIO/VolumeWii.h
index 97604887a3..84d58a530c 100644
--- a/Source/Core/DiscIO/VolumeWii.h
+++ b/Source/Core/DiscIO/VolumeWii.h
@@ -17,8 +17,6 @@
#include "DiscIO/Filesystem.h"
#include "DiscIO/Volume.h"
-// --- this volume type is used for Wii disc images ---
-
namespace DiscIO
{
class BlobReader;
diff --git a/Source/Core/DiscIO/WiiWad.h b/Source/Core/DiscIO/WiiWad.h
index 6f3f4a97bc..1bdd40f698 100644
--- a/Source/Core/DiscIO/WiiWad.h
+++ b/Source/Core/DiscIO/WiiWad.h
@@ -20,6 +20,8 @@ class WiiWAD
public:
explicit WiiWAD(const std::string& name);
explicit WiiWAD(std::unique_ptr<BlobReader> blob_reader);
+ WiiWAD(WiiWAD&&) = default;
+ WiiWAD& operator=(WiiWAD&&) = default;
~WiiWAD();
bool IsValid() const { return m_valid; }