summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorJosJuice <josjuice@gmail.com>2015-09-13 14:17:58 +0200
committerJosJuice <josjuice@gmail.com>2015-09-13 14:17:58 +0200
commit210aa774d554bb9818d79030bbc26b8eb2c500b2 (patch)
treeba6b773b5b8111433455a31a8e0b8a883bcdc07d /Source
parent10aafff5b94864c150f4f4f45d4e106afc795342 (diff)
DolphinWX: Only read titles.txt once
titles.txt is read into a map and passed to the GameListItem constructor, making game list scanning a bit more efficient. ISOPropreties's constructor is changed to take a GameListItem as an argument instead of creating one on its own, because ISOPropreties doesn't have the titles.txt map that the GameListItem constructor wants.
Diffstat (limited to 'Source')
-rw-r--r--Source/Core/DolphinWX/Cheats/CreateCodeDialog.cpp2
-rw-r--r--Source/Core/DolphinWX/GameListCtrl.cpp29
-rw-r--r--Source/Core/DolphinWX/ISOFile.cpp41
-rw-r--r--Source/Core/DolphinWX/ISOFile.h5
-rw-r--r--Source/Core/DolphinWX/ISOProperties.cpp28
-rw-r--r--Source/Core/DolphinWX/ISOProperties.h5
6 files changed, 57 insertions, 53 deletions
diff --git a/Source/Core/DolphinWX/Cheats/CreateCodeDialog.cpp b/Source/Core/DolphinWX/Cheats/CreateCodeDialog.cpp
index 5239a1817a..60c600702b 100644
--- a/Source/Core/DolphinWX/Cheats/CreateCodeDialog.cpp
+++ b/Source/Core/DolphinWX/Cheats/CreateCodeDialog.cpp
@@ -87,7 +87,7 @@ void CreateCodeDialog::PressOK(wxCommandEvent& ev)
// pretty hacky - add the code to the gameini
{
- CISOProperties isoprops(SConfig::GetInstance().m_LastFilename, this);
+ CISOProperties isoprops(GameListItem(SConfig::GetInstance().m_LastFilename, std::unordered_map<std::string, std::string>()), this);
// add the code to the isoproperties arcode list
arCodes->push_back(new_cheat);
// save the gameini
diff --git a/Source/Core/DolphinWX/GameListCtrl.cpp b/Source/Core/DolphinWX/GameListCtrl.cpp
index 01aa4afa18..8d5ed1d61a 100644
--- a/Source/Core/DolphinWX/GameListCtrl.cpp
+++ b/Source/Core/DolphinWX/GameListCtrl.cpp
@@ -9,6 +9,7 @@
#include <cstring>
#include <memory>
#include <string>
+#include <unordered_map>
#include <vector>
#include <wx/bitmap.h>
#include <wx/buffer.h>
@@ -439,6 +440,28 @@ void CGameListCtrl::ScanForISOs()
{
ClearIsoFiles();
+ // Load custom game titles from titles.txt
+ // http://www.gametdb.com/Wii/Downloads
+ std::unordered_map<std::string, std::string> custom_title_map;
+ std::ifstream titlestxt;
+ OpenFStream(titlestxt, File::GetUserPath(D_LOAD_IDX) + "titles.txt", std::ios::in);
+
+ if (!titlestxt.is_open())
+ OpenFStream(titlestxt, File::GetUserPath(D_LOAD_IDX) + "wiitdb.txt", std::ios::in);
+
+ if (titlestxt.is_open())
+ {
+ std::string line;
+ while (!titlestxt.eof() && std::getline(titlestxt, line))
+ {
+ const size_t equals_index = line.find('=');
+ if (equals_index != std::string::npos)
+ custom_title_map.emplace(StripSpaces(line.substr(0, equals_index)),
+ StripSpaces(line.substr(equals_index + 1)));
+ }
+ titlestxt.close();
+ }
+
std::vector<std::string> Extensions;
if (SConfig::GetInstance().m_ListGC)
@@ -485,7 +508,7 @@ void CGameListCtrl::ScanForISOs()
if (dialog.WasCancelled())
break;
- auto iso_file = std::make_unique<GameListItem>(rFilenames[i]);
+ auto iso_file = std::make_unique<GameListItem>(rFilenames[i], custom_title_map);
if (iso_file->IsValid())
{
@@ -580,7 +603,7 @@ void CGameListCtrl::ScanForISOs()
for (const auto& drive : drives)
{
- auto gli = std::make_unique<GameListItem>(drive);
+ auto gli = std::make_unique<GameListItem>(drive, custom_title_map);
if (gli->IsValid())
m_ISOFiles.push_back(gli.release());
@@ -991,7 +1014,7 @@ void CGameListCtrl::OnProperties(wxCommandEvent& WXUNUSED (event))
if (!iso)
return;
- CISOProperties* ISOProperties = new CISOProperties(iso->GetFileName(), this);
+ CISOProperties* ISOProperties = new CISOProperties(*iso, this);
ISOProperties->Show();
}
diff --git a/Source/Core/DolphinWX/ISOFile.cpp b/Source/Core/DolphinWX/ISOFile.cpp
index 00f707529b..28051d0fb0 100644
--- a/Source/Core/DolphinWX/ISOFile.cpp
+++ b/Source/Core/DolphinWX/ISOFile.cpp
@@ -8,6 +8,7 @@
#include <cstring>
#include <memory>
#include <string>
+#include <unordered_map>
#include <utility>
#include <vector>
#include <wx/app.h>
@@ -62,7 +63,7 @@ static std::string GetLanguageString(DiscIO::IVolume::ELanguage language, std::m
return "";
}
-GameListItem::GameListItem(const std::string& _rFileName)
+GameListItem::GameListItem(const std::string& _rFileName, const std::unordered_map<std::string, std::string>& custom_titles)
: m_FileName(_rFileName)
, m_emu_state(0)
, m_FileSize(0)
@@ -135,38 +136,18 @@ GameListItem::GameListItem(const std::string& _rFileName)
if (!m_has_custom_name)
{
- // Attempt to load game titles from titles.txt
- // http://www.gametdb.com/Wii/Downloads
- std::ifstream titlestxt;
- OpenFStream(titlestxt, File::GetUserPath(D_LOAD_IDX) + "titles.txt", std::ios::in);
+ std::string game_id = m_UniqueID;
- if (!titlestxt.is_open())
- OpenFStream(titlestxt, File::GetUserPath(D_LOAD_IDX) + "wiitdb.txt", std::ios::in);
+ // Ignore publisher ID for WAD files
+ if (m_Platform == DiscIO::IVolume::WII_WAD)
+ game_id.erase(game_id.size() - 2);
- if (titlestxt.is_open() && GetUniqueID().size() >= 4)
+ auto end = custom_titles.end();
+ auto it = custom_titles.find(game_id);
+ if (it != end)
{
- while (!titlestxt.eof())
- {
- std::string line;
-
- if (!std::getline(titlestxt, line) && titlestxt.eof())
- break;
-
- const size_t equals_index = line.find('=');
- std::string game_id = m_UniqueID;
-
- // Ignore publisher ID for WAD files
- if (m_Platform == DiscIO::IVolume::WII_WAD)
- game_id.erase(game_id.size() - 2);
-
- if (line.substr(0, equals_index - 1) == game_id)
- {
- m_custom_name = StripSpaces(line.substr(equals_index + 1));
- m_has_custom_name = true;
- break;
- }
- }
- titlestxt.close();
+ m_custom_name = it->second;
+ m_has_custom_name = true;
}
}
}
diff --git a/Source/Core/DolphinWX/ISOFile.h b/Source/Core/DolphinWX/ISOFile.h
index da5c80a300..d0e89e7a7e 100644
--- a/Source/Core/DolphinWX/ISOFile.h
+++ b/Source/Core/DolphinWX/ISOFile.h
@@ -5,6 +5,7 @@
#pragma once
#include <string>
+#include <unordered_map>
#include <utility>
#include <vector>
@@ -17,10 +18,10 @@
#endif
class PointerWrap;
-class GameListItem : NonCopyable
+class GameListItem
{
public:
- GameListItem(const std::string& _rFileName);
+ GameListItem(const std::string& _rFileName, const std::unordered_map<std::string, std::string>& custom_titles);
~GameListItem();
bool IsValid() const {return m_Valid;}
diff --git a/Source/Core/DolphinWX/ISOProperties.cpp b/Source/Core/DolphinWX/ISOProperties.cpp
index 3f98d301a6..38487227b6 100644
--- a/Source/Core/DolphinWX/ISOProperties.cpp
+++ b/Source/Core/DolphinWX/ISOProperties.cpp
@@ -99,11 +99,12 @@ BEGIN_EVENT_TABLE(CISOProperties, wxDialog)
EVT_CHOICE(ID_LANG, CISOProperties::OnChangeBannerLang)
END_EVENT_TABLE()
-CISOProperties::CISOProperties(const std::string& fileName, wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& position, const wxSize& size, long style)
+CISOProperties::CISOProperties(const GameListItem& game_list_item, wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& position, const wxSize& size, long style)
: wxDialog(parent, id, title, position, size, style)
+ , OpenGameListItem(game_list_item)
{
// Load ISO data
- OpenISO = DiscIO::CreateVolumeFromFilename(fileName);
+ OpenISO = DiscIO::CreateVolumeFromFilename(OpenGameListItem.GetFileName());
// Is it really necessary to use GetTitleID if GetUniqueID fails?
game_id = OpenISO->GetUniqueID();
@@ -122,8 +123,6 @@ CISOProperties::CISOProperties(const std::string& fileName, wxWindow* parent, wx
GameIniLocal = SConfig::LoadLocalGameIni(game_id, OpenISO->GetRevision());
// Setup GUI
- OpenGameListItem = new GameListItem(fileName);
-
bRefreshList = false;
CreateGUIControls();
@@ -191,7 +190,7 @@ CISOProperties::CISOProperties(const std::string& fileName, wxWindow* parent, wx
bool wii = OpenISO->GetVolumeType() != DiscIO::IVolume::GAMECUBE_DISC;
ChangeBannerDetails(SConfig::GetInstance().GetCurrentLanguage(wii));
- m_Banner->SetBitmap(OpenGameListItem->GetBitmap());
+ m_Banner->SetBitmap(OpenGameListItem.GetBitmap());
m_Banner->Bind(wxEVT_RIGHT_DOWN, &CISOProperties::RightClickOnBanner, this);
// Filesystem browser/dumper
@@ -205,7 +204,7 @@ CISOProperties::CISOProperties(const std::string& fileName, wxWindow* parent, wx
{
for (u32 i = 0; i < 0xFFFFFFFF; i++) // yes, technically there can be OVER NINE THOUSAND partitions...
{
- std::unique_ptr<DiscIO::IVolume> volume(DiscIO::CreateVolumeFromFilename(fileName, group, i));
+ std::unique_ptr<DiscIO::IVolume> volume(DiscIO::CreateVolumeFromFilename(OpenGameListItem.GetFileName(), group, i));
if (volume != nullptr)
{
std::unique_ptr<DiscIO::IFileSystem> file_system(DiscIO::CreateFileSystem(volume.get()));
@@ -247,7 +246,6 @@ CISOProperties::~CISOProperties()
{
if (OpenISO->GetVolumeType() == DiscIO::IVolume::GAMECUBE_DISC && pFileSystem)
delete pFileSystem;
- delete OpenGameListItem;
delete OpenISO;
}
@@ -497,7 +495,7 @@ void CISOProperties::CreateGUIControls()
bool wii = OpenISO->GetVolumeType() != DiscIO::IVolume::GAMECUBE_DISC;
DiscIO::IVolume::ELanguage preferred_language = SConfig::GetInstance().GetCurrentLanguage(wii);
- std::vector<DiscIO::IVolume::ELanguage> languages = OpenGameListItem->GetLanguages();
+ std::vector<DiscIO::IVolume::ELanguage> languages = OpenGameListItem.GetLanguages();
int preferred_language_index = 0;
for (size_t i = 0; i < languages.size(); ++i)
{
@@ -1248,7 +1246,7 @@ void CISOProperties::OnComputeMD5Sum(wxCommandEvent& WXUNUSED (event))
u64 read_offset = 0;
md5_context ctx;
- File::IOFile file(OpenGameListItem->GetFileName(), "rb");
+ File::IOFile file(OpenGameListItem.GetFileName(), "rb");
u64 game_size = file.GetSize();
wxProgressDialog progressDialog(
@@ -1497,14 +1495,14 @@ void CISOProperties::ActionReplayButtonClicked(wxCommandEvent& event)
void CISOProperties::OnChangeBannerLang(wxCommandEvent& event)
{
- ChangeBannerDetails(OpenGameListItem->GetLanguages()[event.GetSelection()]);
+ ChangeBannerDetails(OpenGameListItem.GetLanguages()[event.GetSelection()]);
}
void CISOProperties::ChangeBannerDetails(DiscIO::IVolume::ELanguage language)
{
- wxString const name = StrToWxStr(OpenGameListItem->GetName(language));
- wxString const comment = StrToWxStr(OpenGameListItem->GetDescription(language));
- wxString const maker = StrToWxStr(OpenGameListItem->GetCompany());
+ wxString const name = StrToWxStr(OpenGameListItem.GetName(language));
+ wxString const comment = StrToWxStr(OpenGameListItem.GetDescription(language));
+ wxString const maker = StrToWxStr(OpenGameListItem.GetCompany());
// Updates the information shown in the window
m_Name->SetValue(name);
@@ -1512,8 +1510,8 @@ void CISOProperties::ChangeBannerDetails(DiscIO::IVolume::ELanguage language)
m_Maker->SetValue(maker);//dev too
std::string filename, extension;
- SplitPath(OpenGameListItem->GetFileName(), nullptr, &filename, &extension);
+ SplitPath(OpenGameListItem.GetFileName(), nullptr, &filename, &extension);
// Also sets the window's title
SetTitle(StrToWxStr(StringFromFormat("%s%s: %s - ", filename.c_str(),
- extension.c_str(), OpenGameListItem->GetUniqueID().c_str())) + name);
+ extension.c_str(), OpenGameListItem.GetUniqueID().c_str())) + name);
}
diff --git a/Source/Core/DolphinWX/ISOProperties.h b/Source/Core/DolphinWX/ISOProperties.h
index c325c44572..fd1735830a 100644
--- a/Source/Core/DolphinWX/ISOProperties.h
+++ b/Source/Core/DolphinWX/ISOProperties.h
@@ -19,6 +19,7 @@
#include "DiscIO/Volume.h"
#include "DiscIO/VolumeCreator.h"
#include "DolphinWX/ARCodeAddEdit.h"
+#include "DolphinWX/ISOFile.h"
#include "DolphinWX/PatchAddEdit.h"
class GameListItem;
@@ -58,7 +59,7 @@ struct PHackData
class CISOProperties : public wxDialog
{
public:
- CISOProperties(const std::string& fileName,
+ CISOProperties(const GameListItem& game_list_item,
wxWindow* parent,
wxWindowID id = wxID_ANY,
const wxString& title = _("Properties"),
@@ -215,7 +216,7 @@ private:
void SetRefresh(wxCommandEvent& event);
void OnChangeBannerLang(wxCommandEvent& event);
- GameListItem* OpenGameListItem;
+ const GameListItem OpenGameListItem;
typedef std::vector<const DiscIO::SFileInfo*>::iterator fileIter;