1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
|
// Copyright 2008 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include <algorithm>
#include <cinttypes>
#include <cstdio>
#include <cstring>
#include <memory>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#include <wx/app.h>
#include <wx/bitmap.h>
#include <wx/filefn.h>
#include <wx/image.h>
#include <wx/toplevel.h>
#include "Common/ChunkFile.h"
#include "Common/CommonPaths.h"
#include "Common/CommonTypes.h"
#include "Common/FileUtil.h"
#include "Common/Hash.h"
#include "Common/IniFile.h"
#include "Common/NandPaths.h"
#include "Common/StringUtil.h"
#include "Core/Boot/Boot.h"
#include "Core/ConfigManager.h"
#include "Core/IOS/ES/Formats.h"
#include "Core/TitleDatabase.h"
#include "DiscIO/Blob.h"
#include "DiscIO/Enums.h"
#include "DiscIO/Volume.h"
#include "DolphinWX/ISOFile.h"
#include "DolphinWX/WxUtils.h"
static std::string GetLanguageString(DiscIO::Language language,
std::map<DiscIO::Language, std::string> strings)
{
auto end = strings.end();
auto it = strings.find(language);
if (it != end)
return it->second;
// English tends to be a good fallback when the requested language isn't available
if (language != DiscIO::Language::LANGUAGE_ENGLISH)
{
it = strings.find(DiscIO::Language::LANGUAGE_ENGLISH);
if (it != end)
return it->second;
}
// If English isn't available either, just pick something
if (!strings.empty())
return strings.cbegin()->second;
return "";
}
GameListItem::GameListItem(const std::string& filename, const Core::TitleDatabase& title_database)
: m_file_name(filename), m_region(DiscIO::Region::UNKNOWN_REGION),
m_country(DiscIO::Country::COUNTRY_UNKNOWN)
{
{
std::unique_ptr<DiscIO::Volume> volume(DiscIO::CreateVolumeFromFilename(m_file_name));
if (volume != nullptr)
{
m_platform = volume->GetVolumeType();
m_descriptions = volume->GetDescriptions();
m_names = volume->GetLongNames();
if (m_names.empty())
m_names = volume->GetShortNames();
m_company = GetLanguageString(DiscIO::Language::LANGUAGE_ENGLISH, volume->GetLongMakers());
if (m_company.empty())
m_company = GetLanguageString(DiscIO::Language::LANGUAGE_ENGLISH, volume->GetShortMakers());
m_region = volume->GetRegion();
m_country = volume->GetCountry();
m_blob_type = volume->GetBlobType();
m_file_size = volume->GetRawSize();
m_volume_size = volume->GetSize();
m_game_id = volume->GetGameID();
m_title_id = volume->GetTitleID().value_or(0);
m_disc_number = volume->GetDiscNumber().value_or(0);
m_revision = volume->GetRevision().value_or(0);
std::vector<u32> buffer = volume->GetBanner(&m_banner.width, &m_banner.height);
ReadVolumeBanner(&m_banner.buffer, buffer, m_banner.width, m_banner.height);
m_valid = true;
}
}
if (m_company.empty() && m_game_id.size() >= 6)
m_company = DiscIO::GetCompanyFromID(m_game_id.substr(4, 2));
if (IsValid())
{
const auto type = m_platform == DiscIO::Platform::WII_WAD ?
Core::TitleDatabase::TitleType::Channel :
Core::TitleDatabase::TitleType::Other;
m_custom_name = title_database.GetTitleName(m_game_id, type);
}
if (!IsValid() && IsElfOrDol())
{
m_valid = true;
m_file_size = File::GetSize(m_file_name);
m_platform = DiscIO::Platform::ELF_DOL;
m_blob_type = DiscIO::BlobType::DIRECTORY;
std::string path, name;
SplitPath(m_file_name, &path, &name, nullptr);
// 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"))
return;
// Homebrew Channel icon. Typical for DOLs and ELFs,
// but can be also used with volumes.
if (SetWxBannerFromPngFile(path + "icon.png"))
return;
}
else
{
// Volume banner. Typical for everything that isn't a DOL or ELF.
SetWxBannerFromRaw(m_banner);
}
}
bool GameListItem::IsValid() const
{
if (!m_valid)
return false;
if (m_platform == DiscIO::Platform::WII_WAD && !IOS::ES::IsChannel(m_title_id))
return false;
return true;
}
bool GameListItem::EmuStateChanged()
{
IniFile ini = SConfig::LoadGameIni(m_game_id, m_revision);
ini.GetIfExists("EmuState", "EmulationStateId", &m_pending.emu_state.rating, 0);
ini.GetIfExists("EmuState", "EmulationIssues", &m_pending.emu_state.issues, std::string());
return m_emu_state != m_pending.emu_state;
}
void GameListItem::EmuStateCommit()
{
m_emu_state = m_pending.emu_state;
}
void GameListItem::EmuState::DoState(PointerWrap& p)
{
p.Do(rating);
p.Do(issues);
}
void GameListItem::Banner::DoState(PointerWrap& p)
{
p.Do(buffer);
p.Do(width);
p.Do(height);
}
void GameListItem::DoState(PointerWrap& p)
{
p.Do(m_valid);
p.Do(m_file_name);
p.Do(m_file_size);
p.Do(m_volume_size);
p.Do(m_names);
p.Do(m_descriptions);
p.Do(m_company);
p.Do(m_game_id);
p.Do(m_title_id);
p.Do(m_region);
p.Do(m_country);
p.Do(m_platform);
p.Do(m_blob_type);
p.Do(m_revision);
p.Do(m_disc_number);
m_banner.DoState(p);
m_emu_state.DoState(p);
p.Do(m_custom_name);
if (p.GetMode() == PointerWrap::MODE_READ)
{
SetWxBannerFromRaw(m_banner);
}
}
bool GameListItem::IsElfOrDol() const
{
if (m_file_name.size() < 4)
return false;
std::string name_end = m_file_name.substr(m_file_name.size() - 4);
std::transform(name_end.begin(), name_end.end(), name_end.begin(), ::tolower);
return name_end == ".elf" || name_end == ".dol";
}
void GameListItem::ReadVolumeBanner(std::vector<u8>* image, const std::vector<u32>& buffer,
int width, int height)
{
image->resize(width * height * 3);
for (int i = 0; i < width * height; i++)
{
(*image)[i * 3 + 0] = (buffer[i] & 0xFF0000) >> 16;
(*image)[i * 3 + 1] = (buffer[i] & 0x00FF00) >> 8;
(*image)[i * 3 + 2] = (buffer[i] & 0x0000FF) >> 0;
}
}
bool GameListItem::SetWxBannerFromPngFile(const std::string& path)
{
if (!File::Exists(path))
return false;
wxImage image(StrToWxStr(path), wxBITMAP_TYPE_PNG);
if (!image.IsOk())
return false;
m_banner_wx = image;
return true;
}
void GameListItem::SetWxBannerFromRaw(const Banner& banner)
{
// 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());
}
}
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<u32> 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;
}
void GameListItem::BannerCommit()
{
m_banner = std::move(m_pending.banner);
SetWxBannerFromRaw(m_banner);
}
std::string GameListItem::GetDescription(DiscIO::Language language) const
{
return GetLanguageString(language, m_descriptions);
}
std::string GameListItem::GetDescription() const
{
bool wii = m_platform != DiscIO::Platform::GAMECUBE_DISC;
return GetDescription(SConfig::GetInstance().GetCurrentLanguage(wii));
}
std::string GameListItem::GetName(DiscIO::Language language) const
{
return GetLanguageString(language, m_names);
}
std::string GameListItem::GetName() const
{
if (!m_custom_name.empty())
return m_custom_name;
bool wii = m_platform != DiscIO::Platform::GAMECUBE_DISC;
std::string name = GetName(SConfig::GetInstance().GetCurrentLanguage(wii));
if (!name.empty())
return name;
// No usable name, return filename (better than nothing)
std::string ext;
SplitPath(GetFileName(), nullptr, &name, &ext);
return name + ext;
}
std::string GameListItem::GetUniqueIdentifier() const
{
const DiscIO::Language lang = DiscIO::Language::LANGUAGE_ENGLISH;
std::vector<std::string> info;
if (!GetGameID().empty())
info.push_back(GetGameID());
if (GetRevision() != 0)
{
std::string rev_str = "Revision ";
info.push_back(rev_str + std::to_string((long long)GetRevision()));
}
std::string name(GetName(lang));
if (name.empty())
name = GetName();
int disc_number = GetDiscNumber() + 1;
std::string lower_name = name;
std::transform(lower_name.begin(), lower_name.end(), lower_name.begin(), ::tolower);
if (disc_number > 1 &&
lower_name.find(std::string(wxString::Format("disc %i", disc_number))) == std::string::npos &&
lower_name.find(std::string(wxString::Format("disc%i", disc_number))) == std::string::npos)
{
std::string disc_text = "Disc ";
info.push_back(disc_text + std::to_string(disc_number));
}
if (info.empty())
return name;
std::ostringstream ss;
std::copy(info.begin(), info.end() - 1, std::ostream_iterator<std::string>(ss, ", "));
ss << info.back();
return name + " (" + ss.str() + ")";
}
std::vector<DiscIO::Language> GameListItem::GetLanguages() const
{
std::vector<DiscIO::Language> languages;
for (std::pair<DiscIO::Language, std::string> name : m_names)
languages.push_back(name.first);
return languages;
}
const std::string GameListItem::GetWiiFSPath() const
{
if (m_platform != DiscIO::Platform::WII_DISC && m_platform != DiscIO::Platform::WII_WAD)
return "";
const std::string path = Common::GetTitleDataPath(m_title_id, Common::FROM_CONFIGURED_ROOT);
if (path[0] == '.')
return WxStrToStr(wxGetCwd()) + path.substr(strlen(ROOT_DIR));
return path;
}
|