Merge pull request #3139 from JosJuice/fix-wii-root

Mark which Wii root to use in the NAND path code
This commit is contained in:
flacs
2015-10-16 16:49:34 +02:00
17 changed files with 171 additions and 188 deletions

View File

@ -89,58 +89,6 @@ std::string CSharedContent::AddSharedContent(const u8* _pHash)
}
// this classes must be created by the CNANDContentManager
class CNANDContentLoader : public INANDContentLoader
{
public:
CNANDContentLoader(const std::string& _rName);
virtual ~CNANDContentLoader();
bool IsValid() const override { return m_Valid; }
void RemoveTitle() const override;
u64 GetTitleID() const override { return m_TitleID; }
u16 GetIosVersion() const override { return m_IosVersion; }
u32 GetBootIndex() const override { return m_BootIndex; }
size_t GetContentSize() const override { return m_Content.size(); }
const SNANDContent* GetContentByIndex(int _Index) const override;
const u8* GetTMDView() const override { return m_TMDView; }
const u8* GetTMDHeader() const override { return m_TMDHeader; }
u32 GetTIKSize() const override { return m_TIKSize; }
const u8* GetTIK() const override { return m_TIK; }
const std::vector<SNANDContent>& GetContent() const override { return m_Content; }
u16 GetTitleVersion() const override {return m_TitleVersion;}
u16 GetNumEntries() const override {return m_numEntries;}
DiscIO::IVolume::ECountry GetCountry() const override;
u8 GetCountryChar() const override {return m_Country; }
private:
bool m_Valid;
bool m_isWAD;
std::string m_Path;
u64 m_TitleID;
u16 m_IosVersion;
u32 m_BootIndex;
u16 m_numEntries;
u16 m_TitleVersion;
u8 m_TMDView[TMD_VIEW_SIZE];
u8 m_TMDHeader[TMD_HEADER_SIZE];
u32 m_TIKSize;
u8* m_TIK;
u8 m_Country;
std::vector<SNANDContent> m_Content;
bool Initialize(const std::string& _rName);
void AESDecode(u8* _pKey, u8* _IV, u8* _pSrc, u32 _Size, u8* _pDest);
void GetKeyFromTicket(u8* pTicket, u8* pTicketKey);
};
CNANDContentLoader::CNANDContentLoader(const std::string& _rName)
: m_Valid(false)
, m_isWAD(false)
@ -306,43 +254,34 @@ DiscIO::IVolume::ECountry CNANDContentLoader::GetCountry() const
CNANDContentManager::~CNANDContentManager()
{
for (auto& entry : m_Map)
{
delete entry.second;
}
m_Map.clear();
}
const INANDContentLoader& CNANDContentManager::GetNANDLoader(const std::string& _rName, bool forceReload)
const CNANDContentLoader& CNANDContentManager::GetNANDLoader(const std::string& content_path)
{
CNANDContentMap::iterator lb = m_Map.lower_bound(_rName);
if (lb == m_Map.end() || (m_Map.key_comp()(_rName, lb->first)))
{
m_Map.insert(lb, CNANDContentMap::value_type(_rName, new CNANDContentLoader(_rName)));
}
else
{
if (!lb->second->IsValid() || forceReload)
{
delete lb->second;
lb->second = new CNANDContentLoader(_rName);
}
}
return *m_Map[_rName];
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<CNANDContentLoader>(content_path)))->second;
}
const INANDContentLoader& CNANDContentManager::GetNANDLoader(u64 _titleId, bool forceReload)
const CNANDContentLoader& CNANDContentManager::GetNANDLoader(u64 title_id, Common::FromWhichRoot from)
{
std::string _rName = Common::GetTitleContentPath(_titleId);
return GetNANDLoader(_rName, forceReload);
std::string path = Common::GetTitleContentPath(title_id, from);
return GetNANDLoader(path);
}
bool CNANDContentManager::RemoveTitle(u64 _titleID)
bool CNANDContentManager::RemoveTitle(u64 title_id, Common::FromWhichRoot from)
{
if (!GetNANDLoader(_titleID).IsValid())
auto& loader = GetNANDLoader(title_id, from);
if (!loader.IsValid())
return false;
GetNANDLoader(_titleID).RemoveTitle();
return GetNANDLoader(_titleID, true).IsValid();
loader.RemoveTitle();
return GetNANDLoader(title_id, from).IsValid();
}
void CNANDContentManager::ClearCache()
{
m_map.clear();
}
void CNANDContentLoader::RemoveTitle() const
@ -355,11 +294,12 @@ void CNANDContentLoader::RemoveTitle() const
{
if (!(m_Content[i].m_Type & 0x8000)) // skip shared apps
{
std::string filename = StringFromFormat("%s%08x.app", Common::GetTitleContentPath(m_TitleID).c_str(), m_Content[i].m_ContentID);
std::string filename = StringFromFormat("%s/%08x.app", m_Path.c_str(), m_Content[i].m_ContentID);
INFO_LOG(DISCIO, "Delete %s", filename.c_str());
File::Delete(filename);
}
}
CNANDContentManager::Access().ClearCache(); // deletes 'this'
}
}
@ -434,8 +374,8 @@ void cUIDsys::GetTitleIDs(std::vector<u64>& _TitleIDs, bool _owned)
{
for (auto& Element : m_Elements)
{
if ((_owned && Common::CheckTitleTIK(Common::swap64(Element.titleID))) ||
(!_owned && Common::CheckTitleTMD(Common::swap64(Element.titleID))))
if ((_owned && Common::CheckTitleTIK(Common::swap64(Element.titleID), Common::FROM_SESSION_ROOT)) ||
(!_owned && Common::CheckTitleTMD(Common::swap64(Element.titleID), Common::FROM_SESSION_ROOT)))
_TitleIDs.push_back(Common::swap64(Element.titleID));
}
}
@ -444,7 +384,7 @@ u64 CNANDContentManager::Install_WiiWAD(const std::string& fileName)
{
if (fileName.find(".wad") == std::string::npos)
return 0;
const INANDContentLoader& ContentLoader = GetNANDLoader(fileName);
const CNANDContentLoader& ContentLoader = GetNANDLoader(fileName);
if (ContentLoader.IsValid() == false)
return 0;
@ -452,8 +392,8 @@ u64 CNANDContentManager::Install_WiiWAD(const std::string& fileName)
//copy WAD's TMD header and contents to content directory
std::string ContentPath(Common::GetTitleContentPath(TitleID));
std::string TMDFileName(Common::GetTMDFileName(TitleID));
std::string ContentPath(Common::GetTitleContentPath(TitleID, Common::FROM_CONFIGURED_ROOT));
std::string TMDFileName(Common::GetTMDFileName(TitleID, Common::FROM_CONFIGURED_ROOT));
File::CreateFullPath(TMDFileName);
File::IOFile pTMDFile(TMDFileName, "wb");
@ -463,13 +403,13 @@ u64 CNANDContentManager::Install_WiiWAD(const std::string& fileName)
return 0;
}
pTMDFile.WriteBytes(ContentLoader.GetTMDHeader(), INANDContentLoader::TMD_HEADER_SIZE);
pTMDFile.WriteBytes(ContentLoader.GetTMDHeader(), CNANDContentLoader::TMD_HEADER_SIZE);
for (u32 i = 0; i < ContentLoader.GetContentSize(); i++)
{
const SNANDContent& Content = ContentLoader.GetContent()[i];
pTMDFile.WriteBytes(Content.m_Header, INANDContentLoader::CONTENT_HEADER_SIZE);
pTMDFile.WriteBytes(Content.m_Header, CNANDContentLoader::CONTENT_HEADER_SIZE);
std::string APPFileName;
if (Content.m_Type & 0x8000) //shared
@ -504,12 +444,14 @@ u64 CNANDContentManager::Install_WiiWAD(const std::string& fileName)
cUIDsys::AccessInstance().AddTitle(TitleID);
ClearCache();
return TitleID;
}
bool Add_Ticket(u64 TitleID, const u8* p_tik, u32 tikSize)
{
std::string TicketFileName = Common::GetTicketFileName(TitleID);
std::string TicketFileName = Common::GetTicketFileName(TitleID, Common::FROM_CONFIGURED_ROOT);
File::CreateFullPath(TicketFileName);
File::IOFile pTicketFile(TicketFileName, "wb");
if (!pTicketFile || !p_tik)

View File

@ -5,11 +5,12 @@
#pragma once
#include <cstddef>
#include <map>
#include <string>
#include <unordered_map>
#include <vector>
#include "Common/CommonTypes.h"
#include "Common/NandPaths.h"
#include "DiscIO/Volume.h"
namespace DiscIO
@ -28,31 +29,31 @@ struct SNANDContent
u8* m_pData;
};
// pure virtual interface so just the NANDContentManager can create these files only
class INANDContentLoader
// Instances of this class must be created by CNANDContentManager
class CNANDContentLoader final
{
public:
CNANDContentLoader(const std::string& _rName);
virtual ~CNANDContentLoader();
INANDContentLoader() {}
bool IsValid() const { return m_Valid; }
void RemoveTitle() const;
u64 GetTitleID() const { return m_TitleID; }
u16 GetIosVersion() const { return m_IosVersion; }
u32 GetBootIndex() const { return m_BootIndex; }
size_t GetContentSize() const { return m_Content.size(); }
const SNANDContent* GetContentByIndex(int _Index) const;
const u8* GetTMDView() const { return m_TMDView; }
const u8* GetTMDHeader() const { return m_TMDHeader; }
u32 GetTIKSize() const { return m_TIKSize; }
const u8* GetTIK() const { return m_TIK; }
virtual ~INANDContentLoader() {}
const std::vector<SNANDContent>& GetContent() const { return m_Content; }
virtual bool IsValid() const = 0;
virtual void RemoveTitle() const = 0;
virtual u64 GetTitleID() const = 0;
virtual u16 GetIosVersion() const = 0;
virtual u32 GetBootIndex() const = 0;
virtual size_t GetContentSize() const = 0;
virtual const SNANDContent* GetContentByIndex(int _Index) const = 0;
virtual const u8* GetTMDView() const = 0;
virtual const u8* GetTMDHeader() const = 0;
virtual u32 GetTIKSize() const = 0;
virtual const u8* GetTIK() const = 0;
virtual const std::vector<SNANDContent>& GetContent() const = 0;
virtual u16 GetTitleVersion() const = 0;
virtual u16 GetNumEntries() const = 0;
virtual DiscIO::IVolume::ECountry GetCountry() const = 0;
virtual u8 GetCountryChar() const = 0;
u16 GetTitleVersion() const {return m_TitleVersion;}
u16 GetNumEntries() const {return m_numEntries;}
DiscIO::IVolume::ECountry GetCountry() const;
u8 GetCountryChar() const {return m_Country; }
enum
{
@ -61,6 +62,30 @@ public:
CONTENT_HEADER_SIZE = 0x24,
TICKET_SIZE = 0x2A4
};
private:
bool m_Valid;
bool m_isWAD;
std::string m_Path;
u64 m_TitleID;
u16 m_IosVersion;
u32 m_BootIndex;
u16 m_numEntries;
u16 m_TitleVersion;
u8 m_TMDView[TMD_VIEW_SIZE];
u8 m_TMDHeader[TMD_HEADER_SIZE];
u32 m_TIKSize;
u8* m_TIK;
u8 m_Country;
std::vector<SNANDContent> m_Content;
bool Initialize(const std::string& _rName);
void AESDecode(u8* _pKey, u8* _IV, u8* _pSrc, u32 _Size, u8* _pDest);
void GetKeyFromTicket(u8* pTicket, u8* pTicketKey);
};
@ -71,9 +96,10 @@ public:
static CNANDContentManager& Access() { static CNANDContentManager instance; return instance; }
u64 Install_WiiWAD(const std::string& fileName);
const INANDContentLoader& GetNANDLoader(const std::string& _rName, bool forceReload = false);
const INANDContentLoader& GetNANDLoader(u64 _titleId, bool forceReload = false);
bool RemoveTitle(u64 _titleID);
const CNANDContentLoader& GetNANDLoader(const std::string& content_path);
const CNANDContentLoader& GetNANDLoader(u64 title_id, Common::FromWhichRoot from);
bool RemoveTitle(u64 titl_id, Common::FromWhichRoot from);
void ClearCache();
private:
CNANDContentManager() {}
@ -82,8 +108,7 @@ private:
CNANDContentManager(CNANDContentManager const&) = delete;
void operator=(CNANDContentManager const&) = delete;
typedef std::map<std::string, INANDContentLoader*> CNANDContentMap;
CNANDContentMap m_Map;
std::unordered_map<std::string, std::unique_ptr<CNANDContentLoader>> m_map;
};
class CSharedContent