From 34692ab826abc8f8faa61bdb2280b742424528f1 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Sat, 7 Dec 2013 15:14:29 -0500 Subject: Remove unnecessary Src/ folders --- Source/Core/DiscIO/VolumeGC.cpp | 166 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) create mode 100644 Source/Core/DiscIO/VolumeGC.cpp (limited to 'Source/Core/DiscIO/VolumeGC.cpp') diff --git a/Source/Core/DiscIO/VolumeGC.cpp b/Source/Core/DiscIO/VolumeGC.cpp new file mode 100644 index 0000000000..325e200a34 --- /dev/null +++ b/Source/Core/DiscIO/VolumeGC.cpp @@ -0,0 +1,166 @@ +// Copyright 2013 Dolphin Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#include "VolumeGC.h" +#include "StringUtil.h" +#include "FileMonitor.h" + +namespace DiscIO +{ +CVolumeGC::CVolumeGC(IBlobReader* _pReader) + : m_pReader(_pReader) +{} + +CVolumeGC::~CVolumeGC() +{ + delete m_pReader; + m_pReader = NULL; // I don't think this makes any difference, but anyway +} + +bool CVolumeGC::Read(u64 _Offset, u64 _Length, u8* _pBuffer) const +{ + if (m_pReader == NULL) + return false; + + FileMon::FindFilename(_Offset); + + return m_pReader->Read(_Offset, _Length, _pBuffer); +} + +bool CVolumeGC::RAWRead(u64 _Offset, u64 _Length, u8* _pBuffer) const +{ + return Read(_Offset, _Length, _pBuffer); +} + +std::string CVolumeGC::GetUniqueID() const +{ + static const std::string NO_UID("NO_UID"); + if (m_pReader == NULL) + return NO_UID; + + char ID[7]; + + if (!Read(0, sizeof(ID), reinterpret_cast(ID))) + { + PanicAlertT("Failed to read unique ID from disc image"); + return NO_UID; + } + + ID[6] = '\0'; + + return ID; +} + +std::string CVolumeGC::GetRevisionSpecificUniqueID() const +{ + char rev[16]; + sprintf(rev, "r%d", GetRevision()); + return GetUniqueID() + rev; +} + +IVolume::ECountry CVolumeGC::GetCountry() const +{ + if (!m_pReader) + return COUNTRY_UNKNOWN; + + u8 CountryCode; + m_pReader->Read(3, 1, &CountryCode); + + return CountrySwitch(CountryCode); +} + +std::string CVolumeGC::GetMakerID() const +{ + if (m_pReader == NULL) + return std::string(); + + char makerID[3]; + if (!Read(0x4, 0x2, (u8*)&makerID)) + return std::string(); + makerID[2] = '\0'; + + return makerID; +} + +int CVolumeGC::GetRevision() const +{ + if (!m_pReader) + return 0; + + u8 Revision; + if (!Read(7, 1, &Revision)) + return 0; + + return Revision; +} + +std::vector CVolumeGC::GetNames() const +{ + std::vector names; + + auto const string_decoder = GetStringDecoder(GetCountry()); + + char name[0x60 + 1] = {}; + if (m_pReader != NULL && Read(0x20, 0x60, (u8*)name)) + names.push_back(string_decoder(name)); + + return names; +} + +u32 CVolumeGC::GetFSTSize() const +{ + if (m_pReader == NULL) + return 0; + + u32 size; + if (!Read(0x428, 0x4, (u8*)&size)) + return 0; + + return Common::swap32(size); +} + +std::string CVolumeGC::GetApploaderDate() const +{ + if (m_pReader == NULL) + return std::string(); + + char date[16]; + if (!Read(0x2440, 0x10, (u8*)&date)) + return std::string(); + // Should be 0 already, but just in case + date[10] = '\0'; + + return date; +} + +u64 CVolumeGC::GetSize() const +{ + if (m_pReader) + return m_pReader->GetDataSize(); + else + return 0; +} + +u64 CVolumeGC::GetRawSize() const +{ + if (m_pReader) + return m_pReader->GetRawSize(); + else + return 0; +} + +bool CVolumeGC::IsDiscTwo() const +{ + bool discTwo; + Read(6,1, (u8*) &discTwo); + return discTwo; +} + +auto CVolumeGC::GetStringDecoder(ECountry country) -> StringDecoder +{ + return (COUNTRY_JAPAN == country || COUNTRY_TAIWAN == country) ? + SHIFTJISToUTF8 : CP1252ToUTF8; +} + +} // namespace -- cgit v1.2.3 From ebff7974c3373cb96516cac0aa944e48b54e1d6b Mon Sep 17 00:00:00 2001 From: Matthew Parlane Date: Sat, 8 Feb 2014 14:23:34 +1300 Subject: Some tidy up of sprintf to StringFromFormat --- Source/Core/DiscIO/VolumeGC.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'Source/Core/DiscIO/VolumeGC.cpp') diff --git a/Source/Core/DiscIO/VolumeGC.cpp b/Source/Core/DiscIO/VolumeGC.cpp index 325e200a34..f2d97462e9 100644 --- a/Source/Core/DiscIO/VolumeGC.cpp +++ b/Source/Core/DiscIO/VolumeGC.cpp @@ -54,9 +54,7 @@ std::string CVolumeGC::GetUniqueID() const std::string CVolumeGC::GetRevisionSpecificUniqueID() const { - char rev[16]; - sprintf(rev, "r%d", GetRevision()); - return GetUniqueID() + rev; + return GetUniqueID() + StringFromFormat("r%d", GetRevision()); } IVolume::ECountry CVolumeGC::GetCountry() const -- cgit v1.2.3 From e59f770ccbf61f012d148a390e7f76775ab2a02e Mon Sep 17 00:00:00 2001 From: Pierre Bourdon Date: Sun, 9 Feb 2014 16:12:59 +0100 Subject: Revert "Merge pull request #49 from Parlane/sprintf_tidy" Change broke the build on Debian stable. This reverts commit 28755439b36ac8e875d764da5db31ad693459ace, reversing changes made to 64e01ec763d21915e7166e625f8a3e85b46fbcbb. --- Source/Core/DiscIO/VolumeGC.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'Source/Core/DiscIO/VolumeGC.cpp') diff --git a/Source/Core/DiscIO/VolumeGC.cpp b/Source/Core/DiscIO/VolumeGC.cpp index f2d97462e9..325e200a34 100644 --- a/Source/Core/DiscIO/VolumeGC.cpp +++ b/Source/Core/DiscIO/VolumeGC.cpp @@ -54,7 +54,9 @@ std::string CVolumeGC::GetUniqueID() const std::string CVolumeGC::GetRevisionSpecificUniqueID() const { - return GetUniqueID() + StringFromFormat("r%d", GetRevision()); + char rev[16]; + sprintf(rev, "r%d", GetRevision()); + return GetUniqueID() + rev; } IVolume::ECountry CVolumeGC::GetCountry() const -- cgit v1.2.3 From 32bfcc034f41276f0fad036dece8a8f632913dff Mon Sep 17 00:00:00 2001 From: Matthew Parlane Date: Sat, 8 Feb 2014 14:23:34 +1300 Subject: Some tidy up of sprintf to StringFromFormat Includes a small fix to SetupWiiMemory --- Source/Core/DiscIO/VolumeGC.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'Source/Core/DiscIO/VolumeGC.cpp') diff --git a/Source/Core/DiscIO/VolumeGC.cpp b/Source/Core/DiscIO/VolumeGC.cpp index 325e200a34..f2d97462e9 100644 --- a/Source/Core/DiscIO/VolumeGC.cpp +++ b/Source/Core/DiscIO/VolumeGC.cpp @@ -54,9 +54,7 @@ std::string CVolumeGC::GetUniqueID() const std::string CVolumeGC::GetRevisionSpecificUniqueID() const { - char rev[16]; - sprintf(rev, "r%d", GetRevision()); - return GetUniqueID() + rev; + return GetUniqueID() + StringFromFormat("r%d", GetRevision()); } IVolume::ECountry CVolumeGC::GetCountry() const -- cgit v1.2.3 From 2afe2152712981e21d6bda6f029292ed2b1cf91e Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 17 Feb 2014 05:18:15 -0500 Subject: Convert all includes to relative paths. --- Source/Core/DiscIO/VolumeGC.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Source/Core/DiscIO/VolumeGC.cpp') diff --git a/Source/Core/DiscIO/VolumeGC.cpp b/Source/Core/DiscIO/VolumeGC.cpp index f2d97462e9..8039d56922 100644 --- a/Source/Core/DiscIO/VolumeGC.cpp +++ b/Source/Core/DiscIO/VolumeGC.cpp @@ -2,9 +2,9 @@ // Licensed under GPLv2 // Refer to the license.txt file included. -#include "VolumeGC.h" -#include "StringUtil.h" -#include "FileMonitor.h" +#include "Common/StringUtil.h" +#include "DiscIO/FileMonitor.h" +#include "DiscIO/VolumeGC.h" namespace DiscIO { -- cgit v1.2.3 From c698c07755fb95990f7b74ac525a65b2c725bfbf Mon Sep 17 00:00:00 2001 From: Pierre Bourdon Date: Fri, 21 Feb 2014 01:47:53 +0100 Subject: Make DiscIO/ mostly IWYU clean (and fix errors in rest of the project detected by this change). --- Source/Core/DiscIO/VolumeGC.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'Source/Core/DiscIO/VolumeGC.cpp') diff --git a/Source/Core/DiscIO/VolumeGC.cpp b/Source/Core/DiscIO/VolumeGC.cpp index 8039d56922..4e057df78c 100644 --- a/Source/Core/DiscIO/VolumeGC.cpp +++ b/Source/Core/DiscIO/VolumeGC.cpp @@ -2,8 +2,15 @@ // Licensed under GPLv2 // Refer to the license.txt file included. +#include +#include +#include + +#include "Common/Common.h" #include "Common/StringUtil.h" +#include "DiscIO/Blob.h" #include "DiscIO/FileMonitor.h" +#include "DiscIO/Volume.h" #include "DiscIO/VolumeGC.h" namespace DiscIO -- cgit v1.2.3 From d802d392811be44d34ae9cd23f616db93e54c50f Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Sun, 9 Mar 2014 21:14:26 +0100 Subject: clang-modernize -use-nullptr and s/\bNULL\b/nullptr/g for *.cpp/h/mm files not compiled on my machine --- Source/Core/DiscIO/VolumeGC.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'Source/Core/DiscIO/VolumeGC.cpp') diff --git a/Source/Core/DiscIO/VolumeGC.cpp b/Source/Core/DiscIO/VolumeGC.cpp index 4e057df78c..63c60a9846 100644 --- a/Source/Core/DiscIO/VolumeGC.cpp +++ b/Source/Core/DiscIO/VolumeGC.cpp @@ -22,12 +22,12 @@ CVolumeGC::CVolumeGC(IBlobReader* _pReader) CVolumeGC::~CVolumeGC() { delete m_pReader; - m_pReader = NULL; // I don't think this makes any difference, but anyway + m_pReader = nullptr; // I don't think this makes any difference, but anyway } bool CVolumeGC::Read(u64 _Offset, u64 _Length, u8* _pBuffer) const { - if (m_pReader == NULL) + if (m_pReader == nullptr) return false; FileMon::FindFilename(_Offset); @@ -43,7 +43,7 @@ bool CVolumeGC::RAWRead(u64 _Offset, u64 _Length, u8* _pBuffer) const std::string CVolumeGC::GetUniqueID() const { static const std::string NO_UID("NO_UID"); - if (m_pReader == NULL) + if (m_pReader == nullptr) return NO_UID; char ID[7]; @@ -77,7 +77,7 @@ IVolume::ECountry CVolumeGC::GetCountry() const std::string CVolumeGC::GetMakerID() const { - if (m_pReader == NULL) + if (m_pReader == nullptr) return std::string(); char makerID[3]; @@ -107,7 +107,7 @@ std::vector CVolumeGC::GetNames() const auto const string_decoder = GetStringDecoder(GetCountry()); char name[0x60 + 1] = {}; - if (m_pReader != NULL && Read(0x20, 0x60, (u8*)name)) + if (m_pReader != nullptr && Read(0x20, 0x60, (u8*)name)) names.push_back(string_decoder(name)); return names; @@ -115,7 +115,7 @@ std::vector CVolumeGC::GetNames() const u32 CVolumeGC::GetFSTSize() const { - if (m_pReader == NULL) + if (m_pReader == nullptr) return 0; u32 size; @@ -127,7 +127,7 @@ u32 CVolumeGC::GetFSTSize() const std::string CVolumeGC::GetApploaderDate() const { - if (m_pReader == NULL) + if (m_pReader == nullptr) return std::string(); char date[16]; -- cgit v1.2.3 From 9e340b1c818b95454656ac3e5210fdd8235a6ab1 Mon Sep 17 00:00:00 2001 From: Rohit Nirmal Date: Wed, 27 Aug 2014 20:35:20 -0500 Subject: Initialize variables to silence garbage return warning from scan-build. --- Source/Core/DiscIO/VolumeGC.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/DiscIO/VolumeGC.cpp') diff --git a/Source/Core/DiscIO/VolumeGC.cpp b/Source/Core/DiscIO/VolumeGC.cpp index 63c60a9846..f0f3d4ee25 100644 --- a/Source/Core/DiscIO/VolumeGC.cpp +++ b/Source/Core/DiscIO/VolumeGC.cpp @@ -157,7 +157,7 @@ u64 CVolumeGC::GetRawSize() const bool CVolumeGC::IsDiscTwo() const { - bool discTwo; + bool discTwo = false; Read(6,1, (u8*) &discTwo); return discTwo; } -- cgit v1.2.3 From 4cb46879bc2fb517d0db70d5bcb53685a9ab0102 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 31 Aug 2014 09:34:58 -0400 Subject: DiscIO: Move some raw pointers over to unique_ptr --- Source/Core/DiscIO/VolumeGC.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'Source/Core/DiscIO/VolumeGC.cpp') diff --git a/Source/Core/DiscIO/VolumeGC.cpp b/Source/Core/DiscIO/VolumeGC.cpp index 63c60a9846..9c3dfadf17 100644 --- a/Source/Core/DiscIO/VolumeGC.cpp +++ b/Source/Core/DiscIO/VolumeGC.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include +#include #include #include @@ -21,8 +22,6 @@ CVolumeGC::CVolumeGC(IBlobReader* _pReader) CVolumeGC::~CVolumeGC() { - delete m_pReader; - m_pReader = nullptr; // I don't think this makes any difference, but anyway } bool CVolumeGC::Read(u64 _Offset, u64 _Length, u8* _pBuffer) const -- cgit v1.2.3 From fbc64984ca7de7db10b1a8a4f49002f260c93569 Mon Sep 17 00:00:00 2001 From: Rohit Nirmal Date: Sun, 7 Sep 2014 20:06:58 -0500 Subject: Include CommonTypes.h instead of Common.h. --- Source/Core/DiscIO/VolumeGC.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/DiscIO/VolumeGC.cpp') diff --git a/Source/Core/DiscIO/VolumeGC.cpp b/Source/Core/DiscIO/VolumeGC.cpp index 77d50da2ed..05ccd4264c 100644 --- a/Source/Core/DiscIO/VolumeGC.cpp +++ b/Source/Core/DiscIO/VolumeGC.cpp @@ -7,7 +7,7 @@ #include #include -#include "Common/Common.h" +#include "Common/CommonTypes.h" #include "Common/StringUtil.h" #include "DiscIO/Blob.h" #include "DiscIO/FileMonitor.h" -- cgit v1.2.3 From 6cfa5798703369dfa385ed1ade7b8f4d9a5918ba Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 7 Oct 2014 21:15:14 -0400 Subject: VolumeGC: Use regular return type declaration for GetStringDecoder --- Source/Core/DiscIO/VolumeGC.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/DiscIO/VolumeGC.cpp') diff --git a/Source/Core/DiscIO/VolumeGC.cpp b/Source/Core/DiscIO/VolumeGC.cpp index 05ccd4264c..ef0e56a21d 100644 --- a/Source/Core/DiscIO/VolumeGC.cpp +++ b/Source/Core/DiscIO/VolumeGC.cpp @@ -161,7 +161,7 @@ bool CVolumeGC::IsDiscTwo() const return discTwo; } -auto CVolumeGC::GetStringDecoder(ECountry country) -> StringDecoder +CVolumeGC::StringDecoder CVolumeGC::GetStringDecoder(ECountry country) { return (COUNTRY_JAPAN == country || COUNTRY_TAIWAN == country) ? SHIFTJISToUTF8 : CP1252ToUTF8; -- cgit v1.2.3 From fa5e3ec29244186a67aeaf68da9a8bb35eb8c4fb Mon Sep 17 00:00:00 2001 From: Rachel Bryk Date: Fri, 14 Nov 2014 20:59:39 -0500 Subject: Implement GetRevision() for wii disks. --- Source/Core/DiscIO/VolumeGC.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Source/Core/DiscIO/VolumeGC.cpp') diff --git a/Source/Core/DiscIO/VolumeGC.cpp b/Source/Core/DiscIO/VolumeGC.cpp index ef0e56a21d..57303b13e7 100644 --- a/Source/Core/DiscIO/VolumeGC.cpp +++ b/Source/Core/DiscIO/VolumeGC.cpp @@ -92,11 +92,11 @@ int CVolumeGC::GetRevision() const if (!m_pReader) return 0; - u8 Revision; - if (!Read(7, 1, &Revision)) + u8 revision; + if (!Read(7, 1, &revision)) return 0; - return Revision; + return revision; } std::vector CVolumeGC::GetNames() const -- cgit v1.2.3 From bb93336ecf9f74c59cab21a582704cba189e813f Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sun, 28 Dec 2014 10:35:48 +0100 Subject: DiscIO: Replace "raw" functions with "decrypt" parameters This is intended to make decryption look less implicit in the code. --- Source/Core/DiscIO/VolumeGC.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'Source/Core/DiscIO/VolumeGC.cpp') diff --git a/Source/Core/DiscIO/VolumeGC.cpp b/Source/Core/DiscIO/VolumeGC.cpp index 57303b13e7..984a82ce3b 100644 --- a/Source/Core/DiscIO/VolumeGC.cpp +++ b/Source/Core/DiscIO/VolumeGC.cpp @@ -24,8 +24,11 @@ CVolumeGC::~CVolumeGC() { } -bool CVolumeGC::Read(u64 _Offset, u64 _Length, u8* _pBuffer) const +bool CVolumeGC::Read(u64 _Offset, u64 _Length, u8* _pBuffer, bool decrypt) const { + if (decrypt) + PanicAlertT("Tried to decrypt data from a non-Wii volume"); + if (m_pReader == nullptr) return false; @@ -34,11 +37,6 @@ bool CVolumeGC::Read(u64 _Offset, u64 _Length, u8* _pBuffer) const return m_pReader->Read(_Offset, _Length, _pBuffer); } -bool CVolumeGC::RAWRead(u64 _Offset, u64 _Length, u8* _pBuffer) const -{ - return Read(_Offset, _Length, _pBuffer); -} - std::string CVolumeGC::GetUniqueID() const { static const std::string NO_UID("NO_UID"); -- cgit v1.2.3 From e186104960ce11bb52b30cebfb8ab08d036c8816 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sat, 7 Feb 2015 09:49:26 +0100 Subject: Don't use revision-specific unique ID strings outside of CoreParameter --- Source/Core/DiscIO/VolumeGC.cpp | 5 ----- 1 file changed, 5 deletions(-) (limited to 'Source/Core/DiscIO/VolumeGC.cpp') diff --git a/Source/Core/DiscIO/VolumeGC.cpp b/Source/Core/DiscIO/VolumeGC.cpp index 984a82ce3b..7d09fc234e 100644 --- a/Source/Core/DiscIO/VolumeGC.cpp +++ b/Source/Core/DiscIO/VolumeGC.cpp @@ -56,11 +56,6 @@ std::string CVolumeGC::GetUniqueID() const return ID; } -std::string CVolumeGC::GetRevisionSpecificUniqueID() const -{ - return GetUniqueID() + StringFromFormat("r%d", GetRevision()); -} - IVolume::ECountry CVolumeGC::GetCountry() const { if (!m_pReader) -- cgit v1.2.3 From 06cb85991e7abbbaf50479eb902ee5c43c7415a9 Mon Sep 17 00:00:00 2001 From: Stevoisiak Date: Mon, 23 Feb 2015 20:43:29 -0500 Subject: De-capitalized CountryCode --- Source/Core/DiscIO/VolumeGC.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Source/Core/DiscIO/VolumeGC.cpp') diff --git a/Source/Core/DiscIO/VolumeGC.cpp b/Source/Core/DiscIO/VolumeGC.cpp index 7d09fc234e..5f6e91b847 100644 --- a/Source/Core/DiscIO/VolumeGC.cpp +++ b/Source/Core/DiscIO/VolumeGC.cpp @@ -61,10 +61,10 @@ IVolume::ECountry CVolumeGC::GetCountry() const if (!m_pReader) return COUNTRY_UNKNOWN; - u8 CountryCode; - m_pReader->Read(3, 1, &CountryCode); + u8 country_code; + m_pReader->Read(3, 1, &country_code); - return CountrySwitch(CountryCode); + return CountrySwitch(country_code); } std::string CVolumeGC::GetMakerID() const -- cgit v1.2.3 From 492aa5c3915f38be7ea90f5dddd99f3244cf8914 Mon Sep 17 00:00:00 2001 From: Stevoisiak Date: Sat, 28 Feb 2015 22:03:53 -0500 Subject: DiscIO: Get rid of unsafe cast --- Source/Core/DiscIO/VolumeGC.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Source/Core/DiscIO/VolumeGC.cpp') diff --git a/Source/Core/DiscIO/VolumeGC.cpp b/Source/Core/DiscIO/VolumeGC.cpp index 5f6e91b847..132a630cf0 100644 --- a/Source/Core/DiscIO/VolumeGC.cpp +++ b/Source/Core/DiscIO/VolumeGC.cpp @@ -149,9 +149,9 @@ u64 CVolumeGC::GetRawSize() const bool CVolumeGC::IsDiscTwo() const { - bool discTwo = false; - Read(6,1, (u8*) &discTwo); - return discTwo; + u8 disc_two_check; + Read(6, 1, &disc_two_check); + return (disc_two_check == 1); } CVolumeGC::StringDecoder CVolumeGC::GetStringDecoder(ECountry country) -- cgit v1.2.3 From 235ecfbed71986f0be2ecf469a10e1105dcb3c96 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Thu, 9 Apr 2015 17:44:53 +0200 Subject: Return GetNames languages, to avoid hardcoded language lists in callers This makes the code cleaner and also leads to some user-visible changes: The wx game properties will no longer let the user select WAD languages that don't have any names. The Qt game list will now display names using the languages set in the configuration instead of always using English for PAL GC games and Japanese for WADs. If a WAD doesn't have a name in the user's preferred language, English is now selected as a fallback before Japanese. --- Source/Core/DiscIO/VolumeGC.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'Source/Core/DiscIO/VolumeGC.cpp') diff --git a/Source/Core/DiscIO/VolumeGC.cpp b/Source/Core/DiscIO/VolumeGC.cpp index 132a630cf0..272408011e 100644 --- a/Source/Core/DiscIO/VolumeGC.cpp +++ b/Source/Core/DiscIO/VolumeGC.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include +#include #include #include #include @@ -92,15 +93,15 @@ int CVolumeGC::GetRevision() const return revision; } -std::vector CVolumeGC::GetNames() const +std::map CVolumeGC::GetNames() const { - std::vector names; + std::map names; auto const string_decoder = GetStringDecoder(GetCountry()); char name[0x60 + 1] = {}; if (m_pReader != nullptr && Read(0x20, 0x60, (u8*)name)) - names.push_back(string_decoder(name)); + names[IVolume::ELanguage::LANGUAGE_UNKNOWN] = string_decoder(name); return names; } -- cgit v1.2.3 From ee694e327ada8c42949a3907d6fa222f73f276b0 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Fri, 10 Apr 2015 22:10:49 +0200 Subject: Get rid of banner loaders and move their functionality to volumes Having some data available in banner loaders and some other data data available in volumes gets messy, especially with GetNames(), which is available in both but returns different results depending on which one is used. This change drops support for reading names and descriptions from Wii save data. --- Source/Core/DiscIO/VolumeGC.cpp | 167 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 160 insertions(+), 7 deletions(-) (limited to 'Source/Core/DiscIO/VolumeGC.cpp') diff --git a/Source/Core/DiscIO/VolumeGC.cpp b/Source/Core/DiscIO/VolumeGC.cpp index 272408011e..dd18338f63 100644 --- a/Source/Core/DiscIO/VolumeGC.cpp +++ b/Source/Core/DiscIO/VolumeGC.cpp @@ -8,10 +8,13 @@ #include #include +#include "Common/ColorUtil.h" #include "Common/CommonTypes.h" #include "Common/StringUtil.h" +#include "Common/Logging/Log.h" #include "DiscIO/Blob.h" #include "DiscIO/FileMonitor.h" +#include "DiscIO/Filesystem.h" #include "DiscIO/Volume.h" #include "DiscIO/VolumeGC.h" @@ -93,19 +96,133 @@ int CVolumeGC::GetRevision() const return revision; } +std::string CVolumeGC::GetName() const +{ + char name[0x60]; + if (m_pReader != nullptr && Read(0x20, 0x60, (u8*)name)) + return DecodeString(name); + else + return ""; +} + std::map CVolumeGC::GetNames() const { std::map names; - auto const string_decoder = GetStringDecoder(GetCountry()); + if (!LoadBannerFile()) + return names; - char name[0x60 + 1] = {}; - if (m_pReader != nullptr && Read(0x20, 0x60, (u8*)name)) - names[IVolume::ELanguage::LANGUAGE_UNKNOWN] = string_decoder(name); + u32 name_count = 0; + IVolume::ELanguage language; + bool is_japanese = GetCountry() == IVolume::ECountry::COUNTRY_JAPAN; + + switch (m_banner_file_type) + { + case BANNER_BNR1: + name_count = 1; + language = is_japanese ? IVolume::ELanguage::LANGUAGE_JAPANESE : IVolume::ELanguage::LANGUAGE_ENGLISH; + break; + + case BANNER_BNR2: + name_count = 6; + language = IVolume::ELanguage::LANGUAGE_ENGLISH; + break; + + case BANNER_INVALID: + case BANNER_NOT_LOADED: + break; + } + + auto const banner = reinterpret_cast(m_banner_file.data()); + + for (u32 i = 0; i < name_count; ++i) + { + auto& comment = banner->comment[i]; + std::string name = DecodeString(comment.longTitle); + + if (name.empty()) + name = DecodeString(comment.shortTitle); + + if (!name.empty()) + names[(IVolume::ELanguage)(language + i)] = name; + } return names; } +std::map CVolumeGC::GetDescriptions() const +{ + std::map descriptions; + + if (!LoadBannerFile()) + return descriptions; + + u32 desc_count = 0; + IVolume::ELanguage language; + bool is_japanese = GetCountry() == IVolume::ECountry::COUNTRY_JAPAN; + + switch (m_banner_file_type) + { + case BANNER_BNR1: + desc_count = 1; + language = is_japanese ? IVolume::ELanguage::LANGUAGE_JAPANESE : IVolume::ELanguage::LANGUAGE_ENGLISH; + break; + + case BANNER_BNR2: + language = IVolume::ELanguage::LANGUAGE_ENGLISH; + desc_count = 6; + break; + + case BANNER_INVALID: + case BANNER_NOT_LOADED: + break; + } + + auto banner = reinterpret_cast(m_banner_file.data()); + + for (u32 i = 0; i < desc_count; ++i) + { + auto& data = banner->comment[i].comment; + std::string description = DecodeString(data); + + if (!description.empty()) + descriptions[(IVolume::ELanguage)(language + i)] = description; + } + + return descriptions; +} + +std::string CVolumeGC::GetCompany() const +{ + if (!LoadBannerFile()) + return ""; + + auto const pBanner = (GCBanner*)m_banner_file.data(); + std::string company = DecodeString(pBanner->comment[0].longMaker); + + if (company.empty()) + company = DecodeString(pBanner->comment[0].shortMaker); + + return company; +} + +std::vector CVolumeGC::GetBanner(int* width, int* height) const +{ + if (!LoadBannerFile()) + { + *width = 0; + *height = 0; + return std::vector(); + } + + std::vector image_buffer(GC_BANNER_WIDTH * GC_BANNER_HEIGHT); + auto const pBanner = (GCBanner*)m_banner_file.data(); + ColorUtil::decode5A3image(image_buffer.data(), pBanner->image, GC_BANNER_WIDTH, GC_BANNER_HEIGHT); + *width = GC_BANNER_WIDTH; + *height = GC_BANNER_HEIGHT; + return image_buffer; +} + u32 CVolumeGC::GetFSTSize() const { if (m_pReader == nullptr) @@ -155,10 +272,46 @@ bool CVolumeGC::IsDiscTwo() const return (disc_two_check == 1); } -CVolumeGC::StringDecoder CVolumeGC::GetStringDecoder(ECountry country) +bool CVolumeGC::LoadBannerFile() const { - return (COUNTRY_JAPAN == country || COUNTRY_TAIWAN == country) ? - SHIFTJISToUTF8 : CP1252ToUTF8; + // The methods GetNames, GetDescriptions, GetCompany and GetBanner + // all need to access the opening.bnr file. These four methods are + // typically called after each other, so we store the file in RAM + // to avoid reading it from the disc several times. However, + // if none of these methods are called, the file is never loaded. + + if (m_banner_file_type != BANNER_NOT_LOADED) + return m_banner_file_type != BANNER_INVALID; + + std::unique_ptr file_system(CreateFileSystem(this)); + size_t file_size = (size_t)file_system->GetFileSize("opening.bnr"); + if (file_size == BNR1_SIZE || file_size == BNR2_SIZE) + { + m_banner_file.resize(file_size); + file_system->ReadFile("opening.bnr", m_banner_file.data(), m_banner_file.size()); + + u32 bannerSignature = *(u32*)m_banner_file.data(); + switch (bannerSignature) + { + case 0x31524e42: // "BNR1" + m_banner_file_type = BANNER_BNR1; + break; + case 0x32524e42: // "BNR2" + m_banner_file_type = BANNER_BNR2; + break; + default: + m_banner_file_type = BANNER_INVALID; + WARN_LOG(DISCIO, "Invalid opening.bnr type"); + break; + } + } + else + { + m_banner_file_type = BANNER_INVALID; + WARN_LOG(DISCIO, "Invalid opening.bnr size: %0lx", (unsigned long)file_size); + } + + return m_banner_file_type != BANNER_INVALID; } } // namespace -- cgit v1.2.3 From bad09fc35820c02b664ada9359867f1326249c92 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Mon, 11 May 2015 11:19:30 +0200 Subject: Volume: Rename GetName to GetInternalName This is intended to better separate it from GetNames and to clarify that this name originally wasn't meant to be shown to users. The ISOProperties GUI is also updated, mainly because labeling the long banner name "short name" was confusing. --- Source/Core/DiscIO/VolumeGC.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/DiscIO/VolumeGC.cpp') diff --git a/Source/Core/DiscIO/VolumeGC.cpp b/Source/Core/DiscIO/VolumeGC.cpp index dd18338f63..efac5e8dfe 100644 --- a/Source/Core/DiscIO/VolumeGC.cpp +++ b/Source/Core/DiscIO/VolumeGC.cpp @@ -96,7 +96,7 @@ int CVolumeGC::GetRevision() const return revision; } -std::string CVolumeGC::GetName() const +std::string CVolumeGC::GetInternalName() const { char name[0x60]; if (m_pReader != nullptr && Read(0x20, 0x60, (u8*)name)) -- cgit v1.2.3 From cefcb0ace9d363b3679b4e93bcc9ec05f1e5f4f8 Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Mon, 18 May 2015 01:08:10 +0200 Subject: Update license headers to GPLv2+ --- Source/Core/DiscIO/VolumeGC.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/DiscIO/VolumeGC.cpp') diff --git a/Source/Core/DiscIO/VolumeGC.cpp b/Source/Core/DiscIO/VolumeGC.cpp index efac5e8dfe..3cb00317ad 100644 --- a/Source/Core/DiscIO/VolumeGC.cpp +++ b/Source/Core/DiscIO/VolumeGC.cpp @@ -1,5 +1,5 @@ // Copyright 2013 Dolphin Emulator Project -// Licensed under GPLv2 +// Licensed under GPLv2+ // Refer to the license.txt file included. #include -- cgit v1.2.3 From 30ebb2459eb97ba544547183854775df8460b475 Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Sun, 24 May 2015 06:55:12 +0200 Subject: Set copyright year to when a file was created --- Source/Core/DiscIO/VolumeGC.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/DiscIO/VolumeGC.cpp') diff --git a/Source/Core/DiscIO/VolumeGC.cpp b/Source/Core/DiscIO/VolumeGC.cpp index 3cb00317ad..9e1de926e2 100644 --- a/Source/Core/DiscIO/VolumeGC.cpp +++ b/Source/Core/DiscIO/VolumeGC.cpp @@ -1,4 +1,4 @@ -// Copyright 2013 Dolphin Emulator Project +// Copyright 2008 Dolphin Emulator Project // Licensed under GPLv2+ // Refer to the license.txt file included. -- cgit v1.2.3 From 301218a1039a651067a524bceccbd970f965235c Mon Sep 17 00:00:00 2001 From: JosJuice Date: Fri, 29 May 2015 21:14:02 +0200 Subject: Volume: Use more appropriate types for some returned values Disc number is changed from bool to u8, and revision is changed from int to u16 (WADs can use all 16 bits, but discs can only use 8 bits). --- Source/Core/DiscIO/VolumeGC.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'Source/Core/DiscIO/VolumeGC.cpp') diff --git a/Source/Core/DiscIO/VolumeGC.cpp b/Source/Core/DiscIO/VolumeGC.cpp index 9e1de926e2..d4883645c9 100644 --- a/Source/Core/DiscIO/VolumeGC.cpp +++ b/Source/Core/DiscIO/VolumeGC.cpp @@ -84,7 +84,7 @@ std::string CVolumeGC::GetMakerID() const return makerID; } -int CVolumeGC::GetRevision() const +u16 CVolumeGC::GetRevision() const { if (!m_pReader) return 0; @@ -265,11 +265,11 @@ u64 CVolumeGC::GetRawSize() const return 0; } -bool CVolumeGC::IsDiscTwo() const +u8 CVolumeGC::GetDiscNumber() const { - u8 disc_two_check; - Read(6, 1, &disc_two_check); - return (disc_two_check == 1); + u8 disc_number; + Read(6, 1, &disc_number); + return disc_number; } bool CVolumeGC::LoadBannerFile() const -- cgit v1.2.3 From 78b6ed0218da61bf75f3179850d780ed8f02f3bf Mon Sep 17 00:00:00 2001 From: JosJuice Date: Wed, 3 Jun 2015 11:35:05 +0200 Subject: VolumeGC: Check that opening.bnr size matches type The old code would accept files with BNR1 length and BNR2 type, which can be a problem when GetNames tries to read the extra BNR2 strings. --- Source/Core/DiscIO/VolumeGC.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'Source/Core/DiscIO/VolumeGC.cpp') diff --git a/Source/Core/DiscIO/VolumeGC.cpp b/Source/Core/DiscIO/VolumeGC.cpp index d4883645c9..fca22949ac 100644 --- a/Source/Core/DiscIO/VolumeGC.cpp +++ b/Source/Core/DiscIO/VolumeGC.cpp @@ -291,24 +291,24 @@ bool CVolumeGC::LoadBannerFile() const file_system->ReadFile("opening.bnr", m_banner_file.data(), m_banner_file.size()); u32 bannerSignature = *(u32*)m_banner_file.data(); - switch (bannerSignature) + if (file_size == BNR1_SIZE && bannerSignature == 0x31524e42) // "BNR1" { - case 0x31524e42: // "BNR1" m_banner_file_type = BANNER_BNR1; - break; - case 0x32524e42: // "BNR2" + } + else if (file_size == BNR2_SIZE && bannerSignature == 0x32524e42) // "BNR2" + { m_banner_file_type = BANNER_BNR2; - break; - default: + } + else + { m_banner_file_type = BANNER_INVALID; - WARN_LOG(DISCIO, "Invalid opening.bnr type"); - break; + WARN_LOG(DISCIO, "Invalid opening.bnr. Type: %0x Size: %0lx", bannerSignature, (unsigned long)file_size); } } else { m_banner_file_type = BANNER_INVALID; - WARN_LOG(DISCIO, "Invalid opening.bnr size: %0lx", (unsigned long)file_size); + WARN_LOG(DISCIO, "Invalid opening.bnr. Size: %0lx", (unsigned long)file_size); } return m_banner_file_type != BANNER_INVALID; -- cgit v1.2.3 From 0ed31181411a9aa98dc194c6179681e670f186cb Mon Sep 17 00:00:00 2001 From: JosJuice Date: Thu, 4 Jun 2015 16:26:36 +0200 Subject: Volume: Return volume type as an enum ISOFile and GameFile were using IsWiiDisc() and IsWadFile() to set an enum value. The volume might as well return an enum directly. I increased the Qt CACHE_REVISION because m_platform now is saved as u32 instead of int, but increasing the wx CACHE_REVISION is not necessary. --- Source/Core/DiscIO/VolumeGC.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'Source/Core/DiscIO/VolumeGC.cpp') diff --git a/Source/Core/DiscIO/VolumeGC.cpp b/Source/Core/DiscIO/VolumeGC.cpp index d4883645c9..8a396cff00 100644 --- a/Source/Core/DiscIO/VolumeGC.cpp +++ b/Source/Core/DiscIO/VolumeGC.cpp @@ -272,6 +272,11 @@ u8 CVolumeGC::GetDiscNumber() const return disc_number; } +IVolume::EPlatform CVolumeGC::GetVolumeType() const +{ + return GAMECUBE_DISC; +} + bool CVolumeGC::LoadBannerFile() const { // The methods GetNames, GetDescriptions, GetCompany and GetBanner -- cgit v1.2.3 From ec0370d2d1b533516964ae1982ac25f8ae33acb3 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sun, 10 May 2015 19:09:11 +0200 Subject: Volume: Add prefer_long parameter to GetNames GC games with long names store two variations of the name in opening.bnr. This makes the shorter of those names available. For volumes other than GC discs, prefer_long is ignored. --- Source/Core/DiscIO/VolumeGC.cpp | 150 ++++++++++++++++++---------------------- 1 file changed, 66 insertions(+), 84 deletions(-) (limited to 'Source/Core/DiscIO/VolumeGC.cpp') diff --git a/Source/Core/DiscIO/VolumeGC.cpp b/Source/Core/DiscIO/VolumeGC.cpp index 07682e7a65..6160c65b24 100644 --- a/Source/Core/DiscIO/VolumeGC.cpp +++ b/Source/Core/DiscIO/VolumeGC.cpp @@ -105,91 +105,14 @@ std::string CVolumeGC::GetInternalName() const return ""; } -std::map CVolumeGC::GetNames() const +std::map CVolumeGC::GetNames(bool prefer_long) const { - std::map names; - - if (!LoadBannerFile()) - return names; - - u32 name_count = 0; - IVolume::ELanguage language; - bool is_japanese = GetCountry() == IVolume::ECountry::COUNTRY_JAPAN; - - switch (m_banner_file_type) - { - case BANNER_BNR1: - name_count = 1; - language = is_japanese ? IVolume::ELanguage::LANGUAGE_JAPANESE : IVolume::ELanguage::LANGUAGE_ENGLISH; - break; - - case BANNER_BNR2: - name_count = 6; - language = IVolume::ELanguage::LANGUAGE_ENGLISH; - break; - - case BANNER_INVALID: - case BANNER_NOT_LOADED: - break; - } - - auto const banner = reinterpret_cast(m_banner_file.data()); - - for (u32 i = 0; i < name_count; ++i) - { - auto& comment = banner->comment[i]; - std::string name = DecodeString(comment.longTitle); - - if (name.empty()) - name = DecodeString(comment.shortTitle); - - if (!name.empty()) - names[(IVolume::ELanguage)(language + i)] = name; - } - - return names; + return ReadMultiLanguageStrings(false, prefer_long); } std::map CVolumeGC::GetDescriptions() const { - std::map descriptions; - - if (!LoadBannerFile()) - return descriptions; - - u32 desc_count = 0; - IVolume::ELanguage language; - bool is_japanese = GetCountry() == IVolume::ECountry::COUNTRY_JAPAN; - - switch (m_banner_file_type) - { - case BANNER_BNR1: - desc_count = 1; - language = is_japanese ? IVolume::ELanguage::LANGUAGE_JAPANESE : IVolume::ELanguage::LANGUAGE_ENGLISH; - break; - - case BANNER_BNR2: - language = IVolume::ELanguage::LANGUAGE_ENGLISH; - desc_count = 6; - break; - - case BANNER_INVALID: - case BANNER_NOT_LOADED: - break; - } - - auto banner = reinterpret_cast(m_banner_file.data()); - - for (u32 i = 0; i < desc_count; ++i) - { - auto& data = banner->comment[i].comment; - std::string description = DecodeString(data); - - if (!description.empty()) - descriptions[(IVolume::ELanguage)(language + i)] = description; - } - - return descriptions; + return ReadMultiLanguageStrings(true); } std::string CVolumeGC::GetCompany() const @@ -277,14 +200,17 @@ IVolume::EPlatform CVolumeGC::GetVolumeType() const return GAMECUBE_DISC; } +// Returns true if the loaded banner file is valid, +// regardless of whether it was loaded by the current call bool CVolumeGC::LoadBannerFile() const { - // The methods GetNames, GetDescriptions, GetCompany and GetBanner - // all need to access the opening.bnr file. These four methods are - // typically called after each other, so we store the file in RAM - // to avoid reading it from the disc several times. However, + // The methods ReadMultiLanguageStrings, GetCompany and GetBanner + // need to access the opening.bnr file. These methods are + // usually called one after another. The file is cached in + // RAM to avoid reading it from the disc several times, but // if none of these methods are called, the file is never loaded. + // If opening.bnr has been loaded already, return immediately if (m_banner_file_type != BANNER_NOT_LOADED) return m_banner_file_type != BANNER_INVALID; @@ -319,4 +245,60 @@ bool CVolumeGC::LoadBannerFile() const return m_banner_file_type != BANNER_INVALID; } +std::map CVolumeGC::ReadMultiLanguageStrings(bool description, bool prefer_long) const +{ + std::map strings; + + if (!LoadBannerFile()) + return strings; + + u32 number_of_languages = 0; + ELanguage start_language; + bool is_japanese = GetCountry() == ECountry::COUNTRY_JAPAN; + + switch (m_banner_file_type) + { + case BANNER_BNR1: // NTSC + number_of_languages = 1; + start_language = is_japanese ? ELanguage::LANGUAGE_JAPANESE : ELanguage::LANGUAGE_ENGLISH; + break; + + case BANNER_BNR2: // PAL + number_of_languages = 6; + start_language = ELanguage::LANGUAGE_ENGLISH; + break; + + // Shouldn't happen + case BANNER_INVALID: + case BANNER_NOT_LOADED: + break; + } + + auto const banner = reinterpret_cast(m_banner_file.data()); + + for (u32 i = 0; i < number_of_languages; ++i) + { + GCBannerComment comment = banner->comment[i]; + std::string string; + + if (description) + { + string = DecodeString(comment.comment); + } + else // Title + { + if (prefer_long) + string = DecodeString(comment.longTitle); + + if (string.empty()) + string = DecodeString(comment.shortTitle); + } + + if (!string.empty()) + strings[(ELanguage)(start_language + i)] = string; + } + + return strings; +} + } // namespace -- cgit v1.2.3