2013-04-18 06:09:55 +03:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2010-09-06 07:36:58 +03:00
|
|
|
|
2014-02-20 05:11:52 +02:00
|
|
|
#include <cstdio>
|
2010-12-22 02:48:59 +02:00
|
|
|
#include <fstream>
|
2014-02-20 05:11:52 +02:00
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
2010-09-06 15:14:18 +03:00
|
|
|
|
2014-09-08 04:06:58 +03:00
|
|
|
#include "Common/CommonTypes.h"
|
2014-02-17 12:18:15 +02:00
|
|
|
#include "Common/FileUtil.h"
|
|
|
|
#include "Common/NandPaths.h"
|
2014-02-20 05:11:52 +02:00
|
|
|
#include "Common/StringUtil.h"
|
2014-02-17 12:18:15 +02:00
|
|
|
|
2010-09-06 07:36:58 +03:00
|
|
|
namespace Common
|
|
|
|
{
|
2010-10-01 15:38:31 +03:00
|
|
|
|
2011-05-09 08:47:29 +03:00
|
|
|
std::string GetTicketFileName(u64 _titleID)
|
2010-09-06 07:36:58 +03:00
|
|
|
{
|
2014-02-08 03:23:34 +02:00
|
|
|
return StringFromFormat("%sticket/%08x/%08x.tik",
|
2014-03-29 12:05:44 +02:00
|
|
|
File::GetUserPath(D_WIIUSER_IDX).c_str(),
|
2014-02-08 03:23:34 +02:00
|
|
|
(u32)(_titleID >> 32), (u32)_titleID);
|
2010-09-06 07:36:58 +03:00
|
|
|
}
|
|
|
|
|
2011-05-09 08:47:29 +03:00
|
|
|
std::string GetTitleDataPath(u64 _titleID)
|
2010-09-07 09:06:08 +03:00
|
|
|
{
|
2014-02-08 03:23:34 +02:00
|
|
|
return StringFromFormat("%stitle/%08x/%08x/data/",
|
|
|
|
File::GetUserPath(D_WIIUSER_IDX).c_str(),
|
|
|
|
(u32)(_titleID >> 32), (u32)_titleID);
|
2010-09-07 09:06:08 +03:00
|
|
|
}
|
|
|
|
|
2011-05-09 08:47:29 +03:00
|
|
|
std::string GetTMDFileName(u64 _titleID)
|
|
|
|
{
|
|
|
|
return GetTitleContentPath(_titleID) + "title.tmd";
|
|
|
|
}
|
|
|
|
std::string GetTitleContentPath(u64 _titleID)
|
2010-09-06 07:36:58 +03:00
|
|
|
{
|
2014-02-08 03:23:34 +02:00
|
|
|
return StringFromFormat("%stitle/%08x/%08x/content/",
|
2014-03-29 12:05:44 +02:00
|
|
|
File::GetUserPath(D_WIIUSER_IDX).c_str(),
|
2014-02-08 03:23:34 +02:00
|
|
|
(u32)(_titleID >> 32), (u32)_titleID);
|
2010-09-06 07:36:58 +03:00
|
|
|
}
|
|
|
|
|
2010-09-07 09:06:08 +03:00
|
|
|
bool CheckTitleTMD(u64 _titleID)
|
|
|
|
{
|
2011-05-09 08:47:29 +03:00
|
|
|
const std::string TitlePath = GetTMDFileName(_titleID);
|
2011-03-01 05:06:14 +02:00
|
|
|
if (File::Exists(TitlePath))
|
2010-09-07 09:06:08 +03:00
|
|
|
{
|
2011-03-11 12:21:46 +02:00
|
|
|
File::IOFile pTMDFile(TitlePath, "rb");
|
|
|
|
u64 TitleID = 0;
|
|
|
|
pTMDFile.Seek(0x18C, SEEK_SET);
|
|
|
|
if (pTMDFile.ReadArray(&TitleID, 1) && _titleID == Common::swap64(TitleID))
|
|
|
|
return true;
|
2010-09-07 09:06:08 +03:00
|
|
|
}
|
|
|
|
INFO_LOG(DISCIO, "Invalid or no tmd for title %08x %08x", (u32)(_titleID >> 32), (u32)(_titleID & 0xFFFFFFFF));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CheckTitleTIK(u64 _titleID)
|
|
|
|
{
|
2013-10-29 07:23:17 +02:00
|
|
|
const std::string ticketFileName = Common::GetTicketFileName(_titleID);
|
2011-05-09 08:47:29 +03:00
|
|
|
if (File::Exists(ticketFileName))
|
2010-09-07 09:06:08 +03:00
|
|
|
{
|
2011-05-09 08:47:29 +03:00
|
|
|
File::IOFile pTIKFile(ticketFileName, "rb");
|
2011-03-11 12:21:46 +02:00
|
|
|
u64 TitleID = 0;
|
|
|
|
pTIKFile.Seek(0x1dC, SEEK_SET);
|
|
|
|
if (pTIKFile.ReadArray(&TitleID, 1) && _titleID == Common::swap64(TitleID))
|
|
|
|
return true;
|
2010-09-07 09:06:08 +03:00
|
|
|
}
|
|
|
|
INFO_LOG(DISCIO, "Invalid or no tik for title %08x %08x", (u32)(_titleID >> 32), (u32)(_titleID & 0xFFFFFFFF));
|
|
|
|
return false;
|
|
|
|
}
|
2010-10-01 15:38:31 +03:00
|
|
|
|
2010-12-22 02:48:59 +02:00
|
|
|
static void CreateReplacementFile(std::string &filename)
|
|
|
|
{
|
2013-03-01 03:33:39 +02:00
|
|
|
std::ofstream replace;
|
|
|
|
OpenFStream(replace, filename, std::ios_base::out);
|
2010-12-22 02:48:59 +02:00
|
|
|
replace <<"\" __22__\n";
|
|
|
|
replace << "* __2a__\n";
|
|
|
|
//replace << "/ __2f__\n";
|
|
|
|
replace << ": __3a__\n";
|
|
|
|
replace << "< __3c__\n";
|
|
|
|
replace << "> __3e__\n";
|
|
|
|
replace << "? __3f__\n";
|
|
|
|
//replace <<"\\ __5c__\n";
|
|
|
|
replace << "| __7c__\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReadReplacements(replace_v& replacements)
|
|
|
|
{
|
|
|
|
replacements.clear();
|
|
|
|
const std::string replace_fname = "/sys/replace";
|
|
|
|
std::string filename(File::GetUserPath(D_WIIROOT_IDX));
|
|
|
|
filename += replace_fname;
|
|
|
|
|
2011-03-01 05:06:14 +02:00
|
|
|
if (!File::Exists(filename))
|
2010-12-22 02:48:59 +02:00
|
|
|
CreateReplacementFile(filename);
|
|
|
|
|
2013-03-01 03:33:39 +02:00
|
|
|
std::ifstream f;
|
|
|
|
OpenFStream(f, filename, std::ios_base::in);
|
2010-12-22 02:48:59 +02:00
|
|
|
char letter;
|
|
|
|
std::string replacement;
|
|
|
|
|
|
|
|
while (f >> letter >> replacement && replacement.size())
|
|
|
|
replacements.push_back(std::make_pair(letter, replacement));
|
|
|
|
}
|
|
|
|
|
2014-09-11 20:00:40 +03:00
|
|
|
}
|