From e73de25a9e86df7d98b62267b3441ddbd5b5ce8b Mon Sep 17 00:00:00 2001 From: JosJuice Date: Tue, 27 Jun 2017 11:27:36 +0200 Subject: [PATCH 1/7] GameListCtrl: Put CACHE_REVISION in .cpp file Reduces the number of files that have to be recompiled when changing the cache revision. --- Source/Core/DolphinWX/GameListCtrl.cpp | 2 ++ Source/Core/DolphinWX/GameListCtrl.h | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/Core/DolphinWX/GameListCtrl.cpp b/Source/Core/DolphinWX/GameListCtrl.cpp index 83fd250d62..be80107790 100644 --- a/Source/Core/DolphinWX/GameListCtrl.cpp +++ b/Source/Core/DolphinWX/GameListCtrl.cpp @@ -80,6 +80,8 @@ public: wxProgressDialog* dialog; }; +static constexpr u32 CACHE_REVISION = 2; // Last changed in PR 5687 + static bool sorted = false; static int CompareGameListItems(const GameListItem* iso1, const GameListItem* iso2, diff --git a/Source/Core/DolphinWX/GameListCtrl.h b/Source/Core/DolphinWX/GameListCtrl.h index 6dbcf8aa3e..3004ce2e8a 100644 --- a/Source/Core/DolphinWX/GameListCtrl.h +++ b/Source/Core/DolphinWX/GameListCtrl.h @@ -125,7 +125,6 @@ private: } m_image_indexes; // Actual backing GameListItems are maintained in a background thread and cached to file - static constexpr u32 CACHE_REVISION = 2; // Last changed in PR 5687 std::list> m_cached_files; // Locks the list, not the contents std::mutex m_cache_mutex; From 691b676145d40ba7bbdf2deb1b8eba31aa3ddda2 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Tue, 27 Jun 2017 11:28:55 +0200 Subject: [PATCH 2/7] GameListItem: Fix minor naming style violation --- Source/Core/DolphinWX/ISOFile.cpp | 6 +++--- Source/Core/DolphinWX/ISOFile.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/Core/DolphinWX/ISOFile.cpp b/Source/Core/DolphinWX/ISOFile.cpp index 3b607e8cf2..9f20f65ef5 100644 --- a/Source/Core/DolphinWX/ISOFile.cpp +++ b/Source/Core/DolphinWX/ISOFile.cpp @@ -113,12 +113,12 @@ GameListItem::GameListItem(const std::string& filename) // A bit like the Homebrew Channel icon, except there can be multiple files // in a folder with their own icons. Useful for those who don't want to have // a Homebrew Channel-style folder structure. - if (SetWxBannerFromPngFile(path + name + ".png")) + if (SetWxBannerFromPNGFile(path + name + ".png")) return; // Homebrew Channel icon. Typical for DOLs and ELFs, // but can be also used with volumes. - if (SetWxBannerFromPngFile(path + "icon.png")) + if (SetWxBannerFromPNGFile(path + "icon.png")) return; } else @@ -227,7 +227,7 @@ void GameListItem::ReadVolumeBanner(std::vector* image, const std::vector* image, const std::vector& buffer, int width, int height); // Outputs to m_banner_wx - bool SetWxBannerFromPngFile(const std::string& path); + bool SetWxBannerFromPNGFile(const std::string& path); void SetWxBannerFromRaw(const Banner& banner); // IMPORTANT: Nearly all data members must be save/restored in DoState. From b9499441ee9f470ae586b0412c1e961c67b27941 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Tue, 27 Jun 2017 11:30:27 +0200 Subject: [PATCH 3/7] GameListItem: Fix comment about PNG banners for volumes f16599f quietly dropped the ability to set custom banners for volumes. --- Source/Core/DolphinWX/ISOFile.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Source/Core/DolphinWX/ISOFile.cpp b/Source/Core/DolphinWX/ISOFile.cpp index 9f20f65ef5..86712ae28f 100644 --- a/Source/Core/DolphinWX/ISOFile.cpp +++ b/Source/Core/DolphinWX/ISOFile.cpp @@ -116,8 +116,7 @@ GameListItem::GameListItem(const std::string& filename) if (SetWxBannerFromPNGFile(path + name + ".png")) return; - // Homebrew Channel icon. Typical for DOLs and ELFs, - // but can be also used with volumes. + // Homebrew Channel icon. The most typical icon format for DOLs and ELFs. if (SetWxBannerFromPNGFile(path + "icon.png")) return; } From 89716025daf90a18aac0433b1f6f543d6c2d0233 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Tue, 27 Jun 2017 11:33:47 +0200 Subject: [PATCH 4/7] GameListItem: Reduce levels of indentation --- Source/Core/DolphinWX/ISOFile.cpp | 40 +++++++++++++++---------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/Source/Core/DolphinWX/ISOFile.cpp b/Source/Core/DolphinWX/ISOFile.cpp index 86712ae28f..a7d70fd81c 100644 --- a/Source/Core/DolphinWX/ISOFile.cpp +++ b/Source/Core/DolphinWX/ISOFile.cpp @@ -241,13 +241,13 @@ bool GameListItem::SetWxBannerFromPNGFile(const std::string& path) void GameListItem::SetWxBannerFromRaw(const Banner& banner) { + if (banner.empty()) + return; + // Need to make explicit copy as wxImage uses reference counting for copies combined with only // taking a pointer, not the content, when given a buffer to its constructor. - if (!banner.empty()) - { - m_banner_wx.Create(banner.width, banner.height, false); - std::memcpy(m_banner_wx.GetData(), banner.buffer.data(), banner.buffer.size()); - } + m_banner_wx.Create(banner.width, banner.height, false); + std::memcpy(m_banner_wx.GetData(), banner.buffer.data(), banner.buffer.size()); } bool GameListItem::BannerChanged() @@ -255,21 +255,21 @@ bool GameListItem::BannerChanged() // Wii banners can only be read if there is a savefile, // so sometimes caches don't contain banners. Let's check // if a banner has become available after the cache was made. - if ((m_platform == DiscIO::Platform::WII_DISC || m_platform == DiscIO::Platform::WII_WAD) && - m_banner.empty()) - { - auto& banner = m_pending.banner; - std::vector buffer = - DiscIO::Volume::GetWiiBanner(&banner.width, &banner.height, m_title_id); - if (buffer.size()) - { - ReadVolumeBanner(&banner.buffer, buffer, banner.width, banner.height); - // Only reach here if m_banner was empty, so don't need to explicitly compare to see if - // different - return true; - } - } - return false; + + if (!m_banner.empty()) + return false; + if (m_platform != DiscIO::Platform::WII_DISC && m_platform != DiscIO::Platform::WII_WAD) + return false; + + auto& banner = m_pending.banner; + std::vector buffer = DiscIO::Volume::GetWiiBanner(&banner.width, &banner.height, m_title_id); + if (!buffer.size()) + return false; + + ReadVolumeBanner(&banner.buffer, buffer, banner.width, banner.height); + // We only reach here if m_banner was empty, so we don't need to explicitly + // compare to see if they are different + return true; } void GameListItem::BannerCommit() From caf60877663df273cf858d6f913ba5aaf24414be Mon Sep 17 00:00:00 2001 From: JosJuice Date: Tue, 27 Jun 2017 11:36:50 +0200 Subject: [PATCH 5/7] GameListItem: Rename m_banner to m_volume_banner I want to clarify that it isn't used for PNG banners. --- Source/Core/DolphinWX/ISOFile.cpp | 21 +++++++++++---------- Source/Core/DolphinWX/ISOFile.h | 5 +++-- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/Source/Core/DolphinWX/ISOFile.cpp b/Source/Core/DolphinWX/ISOFile.cpp index a7d70fd81c..7a35cdb10a 100644 --- a/Source/Core/DolphinWX/ISOFile.cpp +++ b/Source/Core/DolphinWX/ISOFile.cpp @@ -90,8 +90,9 @@ GameListItem::GameListItem(const std::string& filename) m_disc_number = volume->GetDiscNumber().value_or(0); m_revision = volume->GetRevision().value_or(0); - std::vector buffer = volume->GetBanner(&m_banner.width, &m_banner.height); - ReadVolumeBanner(&m_banner.buffer, buffer, m_banner.width, m_banner.height); + auto& banner = m_volume_banner; + std::vector buffer = volume->GetBanner(&banner.width, &banner.height); + ReadVolumeBanner(&banner.buffer, buffer, banner.width, banner.height); m_valid = true; } @@ -123,7 +124,7 @@ GameListItem::GameListItem(const std::string& filename) else { // Volume banner. Typical for everything that isn't a DOL or ELF. - SetWxBannerFromRaw(m_banner); + SetWxBannerFromRaw(m_volume_banner); } } @@ -195,12 +196,12 @@ void GameListItem::DoState(PointerWrap& p) p.Do(m_blob_type); p.Do(m_revision); p.Do(m_disc_number); - m_banner.DoState(p); + m_volume_banner.DoState(p); m_emu_state.DoState(p); p.Do(m_custom_name); if (p.GetMode() == PointerWrap::MODE_READ) { - SetWxBannerFromRaw(m_banner); + SetWxBannerFromRaw(m_volume_banner); } } @@ -256,26 +257,26 @@ bool GameListItem::BannerChanged() // so sometimes caches don't contain banners. Let's check // if a banner has become available after the cache was made. - if (!m_banner.empty()) + if (!m_volume_banner.empty()) return false; if (m_platform != DiscIO::Platform::WII_DISC && m_platform != DiscIO::Platform::WII_WAD) return false; - auto& banner = m_pending.banner; + auto& banner = m_pending.volume_banner; std::vector buffer = DiscIO::Volume::GetWiiBanner(&banner.width, &banner.height, m_title_id); if (!buffer.size()) return false; ReadVolumeBanner(&banner.buffer, buffer, banner.width, banner.height); - // We only reach here if m_banner was empty, so we don't need to explicitly + // We only reach here if m_volume_banner was empty, so we don't need to explicitly // compare to see if they are different return true; } void GameListItem::BannerCommit() { - m_banner = std::move(m_pending.banner); - SetWxBannerFromRaw(m_banner); + m_volume_banner = std::move(m_pending.volume_banner); + SetWxBannerFromRaw(m_volume_banner); } std::string GameListItem::GetDescription(DiscIO::Language language) const diff --git a/Source/Core/DolphinWX/ISOFile.h b/Source/Core/DolphinWX/ISOFile.h index 4320118b2b..aa9893eaf3 100644 --- a/Source/Core/DolphinWX/ISOFile.h +++ b/Source/Core/DolphinWX/ISOFile.h @@ -95,6 +95,7 @@ private: int height); // Outputs to m_banner_wx bool SetWxBannerFromPNGFile(const std::string& path); + // Outputs to m_banner_wx void SetWxBannerFromRaw(const Banner& banner); // IMPORTANT: Nearly all data members must be save/restored in DoState. @@ -120,7 +121,7 @@ private: u16 m_revision{}; u8 m_disc_number{}; - Banner m_banner{}; + Banner m_volume_banner{}; EmuState m_emu_state{}; // Overridden name from TitleDatabase std::string m_custom_name{}; @@ -133,7 +134,7 @@ private: struct { EmuState emu_state; - Banner banner; + Banner volume_banner; std::string custom_name; } m_pending{}; }; From a6471234a22e15176424d24cb31be56fd8e73061 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Tue, 27 Jun 2017 12:45:02 +0200 Subject: [PATCH 6/7] FileSearch: Use strcasecmp in non-std code Because why should only Windows get in on the FileSearch speedup fun? (Not that this fixes the slowness of File::ScanDirectoryTree...) --- Source/Core/Common/FileSearch.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Source/Core/Common/FileSearch.cpp b/Source/Core/Common/FileSearch.cpp index 4b3b0820d2..cca5c095f7 100644 --- a/Source/Core/Common/FileSearch.cpp +++ b/Source/Core/Common/FileSearch.cpp @@ -14,6 +14,8 @@ namespace fs = std::experimental::filesystem; #define HAS_STD_FILESYSTEM #else +#include +#include "Common/CommonFuncs.h" #include "Common/FileUtil.h" #endif @@ -55,11 +57,10 @@ std::vector DoFileSearch(const std::vector& directorie return true; if (entry.isDirectory) return false; - std::string name = entry.virtualName; - std::transform(name.begin(), name.end(), name.begin(), ::tolower); return std::any_of(exts.begin(), exts.end(), [&](const std::string& ext) { + const std::string& name = entry.virtualName; return name.length() >= ext.length() && - name.compare(name.length() - ext.length(), ext.length(), ext) == 0; + strcasecmp(name.c_str() + name.length() - ext.length(), ext.c_str()) == 0; }); }); } From 7992c786b9de692bc71e00996f55153320aea1e5 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Tue, 27 Jun 2017 13:09:33 +0200 Subject: [PATCH 7/7] Fix references to CACHE_REVISION in DiscIO comments The ISOFile.cpp one has been moved, and the GameFile.cpp one isn't used for anything because DolphinQt2 doesn't support caching yet. --- Source/Core/DiscIO/Blob.h | 2 +- Source/Core/DiscIO/Enums.cpp | 2 +- Source/Core/DiscIO/Enums.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/Core/DiscIO/Blob.h b/Source/Core/DiscIO/Blob.h index 9e92b08ae4..686605ed80 100644 --- a/Source/Core/DiscIO/Blob.h +++ b/Source/Core/DiscIO/Blob.h @@ -25,7 +25,7 @@ namespace DiscIO { -// Increment CACHE_REVISION (ISOFile.cpp & GameFile.cpp) if the enum below is modified +// Increment CACHE_REVISION (GameListCtrl.cpp) if the enum below is modified enum class BlobType { PLAIN, diff --git a/Source/Core/DiscIO/Enums.cpp b/Source/Core/DiscIO/Enums.cpp index bfd9da0254..eae90b34ab 100644 --- a/Source/Core/DiscIO/Enums.cpp +++ b/Source/Core/DiscIO/Enums.cpp @@ -16,7 +16,7 @@ bool IsNTSC(Region region) return region == Region::NTSC_J || region == Region::NTSC_U || region == Region::NTSC_K; } -// Increment CACHE_REVISION (ISOFile.cpp & GameFile.cpp) if the code below is modified +// Increment CACHE_REVISION (GameListCtrl.cpp) if the code below is modified Country TypicalCountryForRegion(Region region) { diff --git a/Source/Core/DiscIO/Enums.h b/Source/Core/DiscIO/Enums.h index b06576c685..fb604fd3be 100644 --- a/Source/Core/DiscIO/Enums.h +++ b/Source/Core/DiscIO/Enums.h @@ -10,7 +10,7 @@ namespace DiscIO { -// Increment CACHE_REVISION (ISOFile.cpp & GameFile.cpp) if these enums are modified +// Increment CACHE_REVISION (GameListCtrl.cpp) if these enums are modified enum class Platform {