diff options
| author | Jordan Woyak <jordan.woyak@gmail.com> | 2011-03-11 10:21:46 +0000 |
|---|---|---|
| committer | Jordan Woyak <jordan.woyak@gmail.com> | 2011-03-11 10:21:46 +0000 |
| commit | 59fd1008ca9cf4e9f75fdd6ee8ec53a2c7d7a13b (patch) | |
| tree | 1de127fb452967ccc052324d9aff0775ea1b76cf /Source/Core/Common/Src/NandPaths.cpp | |
| parent | 4f69672b2b31581746aae907e7757981fc48db77 (diff) | |
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
Diffstat (limited to 'Source/Core/Common/Src/NandPaths.cpp')
| -rw-r--r-- | Source/Core/Common/Src/NandPaths.cpp | 35 |
1 files changed, 12 insertions, 23 deletions
diff --git a/Source/Core/Common/Src/NandPaths.cpp b/Source/Core/Common/Src/NandPaths.cpp index 3b2587520d..209bb25500 100644 --- a/Source/Core/Common/Src/NandPaths.cpp +++ b/Source/Core/Common/Src/NandPaths.cpp @@ -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; |
