Wrapped fopen/close/read/write functions inside a simple "IOFile" class. Reading, writing, and error checking became simpler in most cases. It should be near impossible to forget to close a file now that the destructor takes care of it. (I hope this fixes Issue 3635) I have tested the functionality of most things, but it is possible I broke something. :p

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@7328 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Jordan Woyak
2011-03-11 10:21:46 +00:00
parent 4f69672b2b
commit 59fd1008ca
68 changed files with 1112 additions and 1154 deletions

View File

@ -52,20 +52,14 @@ std::string CreateTitleContentPath(u64 _titleID)
bool CheckTitleTMD(u64 _titleID)
{
std::string TitlePath;
TitlePath = CreateTitleContentPath(_titleID) + "/title.tmd";
const std::string TitlePath = CreateTitleContentPath(_titleID) + "/title.tmd";
if (File::Exists(TitlePath))
{
FILE* pTMDFile = fopen(TitlePath.c_str(), "rb");
if(pTMDFile)
{
u64 TitleID = 0xDEADBEEFDEADBEEFULL;
fseeko(pTMDFile, 0x18C, SEEK_SET);
fread(&TitleID, 8, 1, pTMDFile);
fclose(pTMDFile);
if (_titleID == Common::swap64(TitleID))
return true;
}
File::IOFile pTMDFile(TitlePath, "rb");
u64 TitleID = 0;
pTMDFile.Seek(0x18C, SEEK_SET);
if (pTMDFile.ReadArray(&TitleID, 1) && _titleID == Common::swap64(TitleID))
return true;
}
INFO_LOG(DISCIO, "Invalid or no tmd for title %08x %08x", (u32)(_titleID >> 32), (u32)(_titleID & 0xFFFFFFFF));
return false;
@ -73,19 +67,14 @@ bool CheckTitleTMD(u64 _titleID)
bool CheckTitleTIK(u64 _titleID)
{
std::string TikPath = Common::CreateTicketFileName(_titleID);
const std::string TikPath = Common::CreateTicketFileName(_titleID);
if (File::Exists(TikPath))
{
FILE* pTIKFile = fopen(TikPath.c_str(), "rb");
if(pTIKFile)
{
u64 TitleID = 0xDEADBEEFDEADBEEFULL;
fseeko(pTIKFile, 0x1dC, SEEK_SET);
fread(&TitleID, 8, 1, pTIKFile);
fclose(pTIKFile);
if (_titleID == Common::swap64(TitleID))
return true;
}
File::IOFile pTIKFile(TikPath, "rb");
u64 TitleID = 0;
pTIKFile.Seek(0x1dC, SEEK_SET);
if (pTIKFile.ReadArray(&TitleID, 1) && _titleID == Common::swap64(TitleID))
return true;
}
INFO_LOG(DISCIO, "Invalid or no tik for title %08x %08x", (u32)(_titleID >> 32), (u32)(_titleID & 0xFFFFFFFF));
return false;