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.
This commit is contained in:
parent
10aafff5b9
commit
210aa774d5
|
@ -87,7 +87,7 @@ void CreateCodeDialog::PressOK(wxCommandEvent& ev)
|
||||||
|
|
||||||
// pretty hacky - add the code to the gameini
|
// 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
|
// add the code to the isoproperties arcode list
|
||||||
arCodes->push_back(new_cheat);
|
arCodes->push_back(new_cheat);
|
||||||
// save the gameini
|
// save the gameini
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <unordered_map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <wx/bitmap.h>
|
#include <wx/bitmap.h>
|
||||||
#include <wx/buffer.h>
|
#include <wx/buffer.h>
|
||||||
|
@ -439,6 +440,28 @@ void CGameListCtrl::ScanForISOs()
|
||||||
{
|
{
|
||||||
ClearIsoFiles();
|
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;
|
std::vector<std::string> Extensions;
|
||||||
|
|
||||||
if (SConfig::GetInstance().m_ListGC)
|
if (SConfig::GetInstance().m_ListGC)
|
||||||
|
@ -485,7 +508,7 @@ void CGameListCtrl::ScanForISOs()
|
||||||
if (dialog.WasCancelled())
|
if (dialog.WasCancelled())
|
||||||
break;
|
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())
|
if (iso_file->IsValid())
|
||||||
{
|
{
|
||||||
|
@ -580,7 +603,7 @@ void CGameListCtrl::ScanForISOs()
|
||||||
|
|
||||||
for (const auto& drive : drives)
|
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())
|
if (gli->IsValid())
|
||||||
m_ISOFiles.push_back(gli.release());
|
m_ISOFiles.push_back(gli.release());
|
||||||
|
@ -991,7 +1014,7 @@ void CGameListCtrl::OnProperties(wxCommandEvent& WXUNUSED (event))
|
||||||
if (!iso)
|
if (!iso)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
CISOProperties* ISOProperties = new CISOProperties(iso->GetFileName(), this);
|
CISOProperties* ISOProperties = new CISOProperties(*iso, this);
|
||||||
ISOProperties->Show();
|
ISOProperties->Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <unordered_map>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <wx/app.h>
|
#include <wx/app.h>
|
||||||
|
@ -62,7 +63,7 @@ static std::string GetLanguageString(DiscIO::IVolume::ELanguage language, std::m
|
||||||
return "";
|
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_FileName(_rFileName)
|
||||||
, m_emu_state(0)
|
, m_emu_state(0)
|
||||||
, m_FileSize(0)
|
, m_FileSize(0)
|
||||||
|
@ -135,38 +136,18 @@ GameListItem::GameListItem(const std::string& _rFileName)
|
||||||
|
|
||||||
if (!m_has_custom_name)
|
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);
|
|
||||||
|
|
||||||
if (!titlestxt.is_open())
|
|
||||||
OpenFStream(titlestxt, File::GetUserPath(D_LOAD_IDX) + "wiitdb.txt", std::ios::in);
|
|
||||||
|
|
||||||
if (titlestxt.is_open() && GetUniqueID().size() >= 4)
|
|
||||||
{
|
|
||||||
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;
|
std::string game_id = m_UniqueID;
|
||||||
|
|
||||||
// Ignore publisher ID for WAD files
|
// Ignore publisher ID for WAD files
|
||||||
if (m_Platform == DiscIO::IVolume::WII_WAD)
|
if (m_Platform == DiscIO::IVolume::WII_WAD)
|
||||||
game_id.erase(game_id.size() - 2);
|
game_id.erase(game_id.size() - 2);
|
||||||
|
|
||||||
if (line.substr(0, equals_index - 1) == game_id)
|
auto end = custom_titles.end();
|
||||||
|
auto it = custom_titles.find(game_id);
|
||||||
|
if (it != end)
|
||||||
{
|
{
|
||||||
m_custom_name = StripSpaces(line.substr(equals_index + 1));
|
m_custom_name = it->second;
|
||||||
m_has_custom_name = true;
|
m_has_custom_name = true;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
titlestxt.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <unordered_map>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
@ -17,10 +18,10 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class PointerWrap;
|
class PointerWrap;
|
||||||
class GameListItem : NonCopyable
|
class GameListItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GameListItem(const std::string& _rFileName);
|
GameListItem(const std::string& _rFileName, const std::unordered_map<std::string, std::string>& custom_titles);
|
||||||
~GameListItem();
|
~GameListItem();
|
||||||
|
|
||||||
bool IsValid() const {return m_Valid;}
|
bool IsValid() const {return m_Valid;}
|
||||||
|
|
|
@ -99,11 +99,12 @@ BEGIN_EVENT_TABLE(CISOProperties, wxDialog)
|
||||||
EVT_CHOICE(ID_LANG, CISOProperties::OnChangeBannerLang)
|
EVT_CHOICE(ID_LANG, CISOProperties::OnChangeBannerLang)
|
||||||
END_EVENT_TABLE()
|
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)
|
: wxDialog(parent, id, title, position, size, style)
|
||||||
|
, OpenGameListItem(game_list_item)
|
||||||
{
|
{
|
||||||
// Load ISO data
|
// Load ISO data
|
||||||
OpenISO = DiscIO::CreateVolumeFromFilename(fileName);
|
OpenISO = DiscIO::CreateVolumeFromFilename(OpenGameListItem.GetFileName());
|
||||||
|
|
||||||
// Is it really necessary to use GetTitleID if GetUniqueID fails?
|
// Is it really necessary to use GetTitleID if GetUniqueID fails?
|
||||||
game_id = OpenISO->GetUniqueID();
|
game_id = OpenISO->GetUniqueID();
|
||||||
|
@ -122,8 +123,6 @@ CISOProperties::CISOProperties(const std::string& fileName, wxWindow* parent, wx
|
||||||
GameIniLocal = SConfig::LoadLocalGameIni(game_id, OpenISO->GetRevision());
|
GameIniLocal = SConfig::LoadLocalGameIni(game_id, OpenISO->GetRevision());
|
||||||
|
|
||||||
// Setup GUI
|
// Setup GUI
|
||||||
OpenGameListItem = new GameListItem(fileName);
|
|
||||||
|
|
||||||
bRefreshList = false;
|
bRefreshList = false;
|
||||||
|
|
||||||
CreateGUIControls();
|
CreateGUIControls();
|
||||||
|
@ -191,7 +190,7 @@ CISOProperties::CISOProperties(const std::string& fileName, wxWindow* parent, wx
|
||||||
bool wii = OpenISO->GetVolumeType() != DiscIO::IVolume::GAMECUBE_DISC;
|
bool wii = OpenISO->GetVolumeType() != DiscIO::IVolume::GAMECUBE_DISC;
|
||||||
ChangeBannerDetails(SConfig::GetInstance().GetCurrentLanguage(wii));
|
ChangeBannerDetails(SConfig::GetInstance().GetCurrentLanguage(wii));
|
||||||
|
|
||||||
m_Banner->SetBitmap(OpenGameListItem->GetBitmap());
|
m_Banner->SetBitmap(OpenGameListItem.GetBitmap());
|
||||||
m_Banner->Bind(wxEVT_RIGHT_DOWN, &CISOProperties::RightClickOnBanner, this);
|
m_Banner->Bind(wxEVT_RIGHT_DOWN, &CISOProperties::RightClickOnBanner, this);
|
||||||
|
|
||||||
// Filesystem browser/dumper
|
// 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...
|
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)
|
if (volume != nullptr)
|
||||||
{
|
{
|
||||||
std::unique_ptr<DiscIO::IFileSystem> file_system(DiscIO::CreateFileSystem(volume.get()));
|
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)
|
if (OpenISO->GetVolumeType() == DiscIO::IVolume::GAMECUBE_DISC && pFileSystem)
|
||||||
delete pFileSystem;
|
delete pFileSystem;
|
||||||
delete OpenGameListItem;
|
|
||||||
delete OpenISO;
|
delete OpenISO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -497,7 +495,7 @@ void CISOProperties::CreateGUIControls()
|
||||||
bool wii = OpenISO->GetVolumeType() != DiscIO::IVolume::GAMECUBE_DISC;
|
bool wii = OpenISO->GetVolumeType() != DiscIO::IVolume::GAMECUBE_DISC;
|
||||||
DiscIO::IVolume::ELanguage preferred_language = SConfig::GetInstance().GetCurrentLanguage(wii);
|
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;
|
int preferred_language_index = 0;
|
||||||
for (size_t i = 0; i < languages.size(); ++i)
|
for (size_t i = 0; i < languages.size(); ++i)
|
||||||
{
|
{
|
||||||
|
@ -1248,7 +1246,7 @@ void CISOProperties::OnComputeMD5Sum(wxCommandEvent& WXUNUSED (event))
|
||||||
u64 read_offset = 0;
|
u64 read_offset = 0;
|
||||||
md5_context ctx;
|
md5_context ctx;
|
||||||
|
|
||||||
File::IOFile file(OpenGameListItem->GetFileName(), "rb");
|
File::IOFile file(OpenGameListItem.GetFileName(), "rb");
|
||||||
u64 game_size = file.GetSize();
|
u64 game_size = file.GetSize();
|
||||||
|
|
||||||
wxProgressDialog progressDialog(
|
wxProgressDialog progressDialog(
|
||||||
|
@ -1497,14 +1495,14 @@ void CISOProperties::ActionReplayButtonClicked(wxCommandEvent& event)
|
||||||
|
|
||||||
void CISOProperties::OnChangeBannerLang(wxCommandEvent& event)
|
void CISOProperties::OnChangeBannerLang(wxCommandEvent& event)
|
||||||
{
|
{
|
||||||
ChangeBannerDetails(OpenGameListItem->GetLanguages()[event.GetSelection()]);
|
ChangeBannerDetails(OpenGameListItem.GetLanguages()[event.GetSelection()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CISOProperties::ChangeBannerDetails(DiscIO::IVolume::ELanguage language)
|
void CISOProperties::ChangeBannerDetails(DiscIO::IVolume::ELanguage language)
|
||||||
{
|
{
|
||||||
wxString const name = StrToWxStr(OpenGameListItem->GetName(language));
|
wxString const name = StrToWxStr(OpenGameListItem.GetName(language));
|
||||||
wxString const comment = StrToWxStr(OpenGameListItem->GetDescription(language));
|
wxString const comment = StrToWxStr(OpenGameListItem.GetDescription(language));
|
||||||
wxString const maker = StrToWxStr(OpenGameListItem->GetCompany());
|
wxString const maker = StrToWxStr(OpenGameListItem.GetCompany());
|
||||||
|
|
||||||
// Updates the information shown in the window
|
// Updates the information shown in the window
|
||||||
m_Name->SetValue(name);
|
m_Name->SetValue(name);
|
||||||
|
@ -1512,8 +1510,8 @@ void CISOProperties::ChangeBannerDetails(DiscIO::IVolume::ELanguage language)
|
||||||
m_Maker->SetValue(maker);//dev too
|
m_Maker->SetValue(maker);//dev too
|
||||||
|
|
||||||
std::string filename, extension;
|
std::string filename, extension;
|
||||||
SplitPath(OpenGameListItem->GetFileName(), nullptr, &filename, &extension);
|
SplitPath(OpenGameListItem.GetFileName(), nullptr, &filename, &extension);
|
||||||
// Also sets the window's title
|
// Also sets the window's title
|
||||||
SetTitle(StrToWxStr(StringFromFormat("%s%s: %s - ", filename.c_str(),
|
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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include "DiscIO/Volume.h"
|
#include "DiscIO/Volume.h"
|
||||||
#include "DiscIO/VolumeCreator.h"
|
#include "DiscIO/VolumeCreator.h"
|
||||||
#include "DolphinWX/ARCodeAddEdit.h"
|
#include "DolphinWX/ARCodeAddEdit.h"
|
||||||
|
#include "DolphinWX/ISOFile.h"
|
||||||
#include "DolphinWX/PatchAddEdit.h"
|
#include "DolphinWX/PatchAddEdit.h"
|
||||||
|
|
||||||
class GameListItem;
|
class GameListItem;
|
||||||
|
@ -58,7 +59,7 @@ struct PHackData
|
||||||
class CISOProperties : public wxDialog
|
class CISOProperties : public wxDialog
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CISOProperties(const std::string& fileName,
|
CISOProperties(const GameListItem& game_list_item,
|
||||||
wxWindow* parent,
|
wxWindow* parent,
|
||||||
wxWindowID id = wxID_ANY,
|
wxWindowID id = wxID_ANY,
|
||||||
const wxString& title = _("Properties"),
|
const wxString& title = _("Properties"),
|
||||||
|
@ -215,7 +216,7 @@ private:
|
||||||
void SetRefresh(wxCommandEvent& event);
|
void SetRefresh(wxCommandEvent& event);
|
||||||
void OnChangeBannerLang(wxCommandEvent& event);
|
void OnChangeBannerLang(wxCommandEvent& event);
|
||||||
|
|
||||||
GameListItem* OpenGameListItem;
|
const GameListItem OpenGameListItem;
|
||||||
|
|
||||||
typedef std::vector<const DiscIO::SFileInfo*>::iterator fileIter;
|
typedef std::vector<const DiscIO::SFileInfo*>::iterator fileIter;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue