Warning fixes and some cleanups.
[dolphin.git] / Source / Core / DiscIO / Src / VolumeGC.cpp
blobe329b5d35feaedd0d222e7cd896cd79d6915430c
1 // Copyright (C) 2003 Dolphin Project.
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, version 2.0.
7 // This program is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 // GNU General Public License 2.0 for more details.
12 // A copy of the GPL 2.0 should have been included with the program.
13 // If not, see http://www.gnu.org/licenses/
15 // Official SVN repository and contact information can be found at
16 // http://code.google.com/p/dolphin-emu/
18 #include "stdafx.h"
20 #include "VolumeGC.h"
21 #include "StringUtil.h"
22 #include "FileMonitor.h"
24 namespace DiscIO
26 CVolumeGC::CVolumeGC(IBlobReader* _pReader)
27 : m_pReader(_pReader)
30 CVolumeGC::~CVolumeGC()
32 delete m_pReader;
33 m_pReader = NULL; // I don't think this makes any difference, but anyway
36 bool CVolumeGC::Read(u64 _Offset, u64 _Length, u8* _pBuffer) const
38 if (m_pReader == NULL)
39 return false;
41 FileMon::FindFilename(_Offset);
43 return m_pReader->Read(_Offset, _Length, _pBuffer);
46 bool CVolumeGC::RAWRead( u64 _Offset, u64 _Length, u8* _pBuffer ) const
48 return false;
51 std::string CVolumeGC::GetUniqueID() const
53 static const std::string NO_UID("NO_UID");
54 if (m_pReader == NULL)
55 return NO_UID;
57 char id[6];
58 if (!Read(0, sizeof(id), reinterpret_cast<u8*>(id)))
60 PanicAlert("Failed to read unique ID from disc image");
61 return NO_UID;
64 return std::string(id, sizeof(id));
67 IVolume::ECountry CVolumeGC::GetCountry() const
69 if (!m_pReader)
70 return COUNTRY_UNKNOWN;
72 u8 CountryCode;
73 m_pReader->Read(3, 1, &CountryCode);
75 return CountrySwitch(CountryCode);
78 std::string CVolumeGC::GetMakerID() const
80 if (m_pReader == NULL)
81 return std::string();
83 char makerID[3];
84 if (!Read(0x4, 0x2, (u8*)&makerID))
85 return std::string();
86 makerID[2] = '\0';
88 return makerID;
91 std::string CVolumeGC::GetName() const
93 if (m_pReader == NULL)
94 return "";
96 char name[128];
97 if (!Read(0x20, 0x60, (u8*)&name))
98 return "";
100 return name;
103 u32 CVolumeGC::GetFSTSize() const
105 if (m_pReader == NULL)
106 return 0;
108 u32 size;
109 if (!Read(0x428, 0x4, (u8*)&size))
110 return 0;
112 return Common::swap32(size);
115 std::string CVolumeGC::GetApploaderDate() const
117 if (m_pReader == NULL)
118 return std::string();
120 char date[16];
121 if (!Read(0x2440, 0x10, (u8*)&date))
122 return std::string();
123 // Should be 0 already, but just in case
124 date[10] = '\0';
126 return date;
129 u64 CVolumeGC::GetSize() const
131 if (m_pReader)
132 return (size_t)m_pReader->GetDataSize();
133 else
134 return 0;
137 } // namespace