CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/UI/GameScreen.cpp
Views: 1401
1
// Copyright (c) 2013- PPSSPP Project.
2
3
// This program is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, version 2.0 or later versions.
6
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
// GNU General Public License 2.0 for more details.
11
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
14
15
// Official git repository and contact information can be found at
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
17
18
#include <algorithm>
19
20
#include "ppsspp_config.h"
21
22
#include "Common/Render/DrawBuffer.h"
23
#include "Common/UI/Context.h"
24
#include "Common/UI/View.h"
25
#include "Common/UI/ViewGroup.h"
26
27
#include "Common/Data/Text/I18n.h"
28
#include "Common/Data/Text/Parsers.h"
29
#include "Common/Data/Encoding/Utf8.h"
30
#include "Common/File/FileUtil.h"
31
#include "Common/StringUtils.h"
32
#include "Common/System/System.h"
33
#include "Common/System/OSD.h"
34
#include "Common/System/Request.h"
35
#include "Common/System/NativeApp.h"
36
#include "Core/Config.h"
37
#include "Core/Reporting.h"
38
#include "Core/System.h"
39
#include "Core/Loaders.h"
40
#include "Core/Util/GameDB.h"
41
#include "Core/HLE/Plugins.h"
42
#include "UI/OnScreenDisplay.h"
43
#include "UI/CwCheatScreen.h"
44
#include "UI/EmuScreen.h"
45
#include "UI/GameScreen.h"
46
#include "UI/GameSettingsScreen.h"
47
#include "UI/GameInfoCache.h"
48
#include "UI/MiscScreens.h"
49
#include "UI/MainScreen.h"
50
#include "UI/BackgroundAudio.h"
51
#include "UI/SavedataScreen.h"
52
#include "Core/Reporting.h"
53
54
GameScreen::GameScreen(const Path &gamePath, bool inGame) : UIDialogScreenWithGameBackground(gamePath), inGame_(inGame) {
55
g_BackgroundAudio.SetGame(gamePath);
56
System_PostUIMessage(UIMessage::GAME_SELECTED, gamePath.ToString());
57
}
58
59
GameScreen::~GameScreen() {
60
if (CRC32string == "...") {
61
Reporting::CancelCRC();
62
}
63
System_PostUIMessage(UIMessage::GAME_SELECTED, "");
64
}
65
66
template <typename I> std::string int2hexstr(I w, size_t hex_len = sizeof(I) << 1) {
67
static const char* digits = "0123456789ABCDEF";
68
std::string rc(hex_len, '0');
69
for (size_t i = 0, j = (hex_len - 1) * 4; i < hex_len; ++i, j -= 4)
70
rc[i] = digits[(w >> j) & 0x0f];
71
return rc;
72
}
73
74
void GameScreen::update() {
75
UIScreen::update();
76
77
// Has the user requested a CRC32?
78
if (CRC32string == "...") {
79
// Wait until the CRC32 is ready. It might take time on some devices.
80
if (Reporting::HasCRC(gamePath_)) {
81
uint32_t crcvalue = Reporting::RetrieveCRC(gamePath_);
82
CRC32string = int2hexstr(crcvalue);
83
tvCRC_->SetVisibility(UI::V_VISIBLE);
84
tvCRC_->SetText(CRC32string);
85
if (tvCRCCopy_) {
86
tvCRCCopy_->SetVisibility(UI::V_VISIBLE);
87
}
88
if (btnCalcCRC_) {
89
btnCalcCRC_->SetVisibility(UI::V_GONE);
90
}
91
}
92
}
93
}
94
95
void GameScreen::CreateViews() {
96
std::shared_ptr<GameInfo> info = g_gameInfoCache->GetInfo(NULL, gamePath_, GameInfoFlags::PARAM_SFO | GameInfoFlags::ICON | GameInfoFlags::BG);
97
98
if (info->Ready(GameInfoFlags::PARAM_SFO)) {
99
saveDirs = info->GetSaveDataDirectories(); // Get's very heavy, let's not do it in update()
100
}
101
102
auto di = GetI18NCategory(I18NCat::DIALOG);
103
auto ga = GetI18NCategory(I18NCat::GAME);
104
105
// Information in the top left.
106
// Back button to the bottom left.
107
// Scrolling action menu to the right.
108
using namespace UI;
109
110
Margins actionMenuMargins(0, 100, 15, 0);
111
112
root_ = new LinearLayout(ORIENT_HORIZONTAL);
113
114
ViewGroup *leftColumn = new AnchorLayout(new LinearLayoutParams(1.0f));
115
root_->Add(leftColumn);
116
117
leftColumn->Add(new Choice(di->T("Back"), "", false, new AnchorLayoutParams(150, WRAP_CONTENT, 10, NONE, NONE, 10)))->OnClick.Handle(this, &GameScreen::OnSwitchBack);
118
if (info->Ready(GameInfoFlags::PARAM_SFO)) {
119
ViewGroup *badgeHolder = new LinearLayout(ORIENT_HORIZONTAL, new AnchorLayoutParams(10, 10, 110, NONE));
120
LinearLayout *mainGameInfo = new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(1.0f));
121
mainGameInfo->SetSpacing(3.0f);
122
123
// Need an explicit size here because homebrew uses screenshots as icons.
124
badgeHolder->Add(new GameIconView(gamePath_, 2.0f, new LinearLayoutParams(144 * 2, 80 * 2, UI::Margins(0))));
125
badgeHolder->Add(mainGameInfo);
126
127
leftColumn->Add(badgeHolder);
128
129
LinearLayout *infoLayout = new LinearLayout(ORIENT_VERTICAL, new AnchorLayoutParams(10, 200, NONE, NONE));
130
leftColumn->Add(infoLayout);
131
132
// TODO: Add non-translated title here if available in gameDB.
133
tvTitle_ = mainGameInfo->Add(new TextView(info->GetTitle(), ALIGN_LEFT | FLAG_WRAP_TEXT, false, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)));
134
tvTitle_->SetShadow(true);
135
tvID_ = mainGameInfo->Add(new TextView("", ALIGN_LEFT | FLAG_WRAP_TEXT, true, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)));
136
tvID_->SetShadow(true);
137
tvRegion_ = mainGameInfo->Add(new TextView("", ALIGN_LEFT, true, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)));
138
tvRegion_->SetShadow(true);
139
tvGameSize_ = mainGameInfo->Add(new TextView("...", ALIGN_LEFT, true, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)));
140
tvGameSize_->SetShadow(true);
141
142
// This one doesn't need to be updated.
143
infoLayout->Add(new TextView(gamePath_.ToVisualString(), ALIGN_LEFT | FLAG_WRAP_TEXT, true, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)))->SetShadow(true);
144
tvSaveDataSize_ = infoLayout->Add(new TextView("...", ALIGN_LEFT, true, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)));
145
tvSaveDataSize_->SetShadow(true);
146
tvInstallDataSize_ = infoLayout->Add(new TextView("", ALIGN_LEFT, true, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)));
147
tvInstallDataSize_->SetShadow(true);
148
tvInstallDataSize_->SetVisibility(V_GONE);
149
tvPlayTime_ = infoLayout->Add(new TextView("", ALIGN_LEFT, true, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)));
150
tvPlayTime_->SetShadow(true);
151
tvPlayTime_->SetVisibility(V_GONE);
152
153
LinearLayout *crcHoriz = infoLayout->Add(new LinearLayout(ORIENT_HORIZONTAL));
154
tvCRC_ = crcHoriz->Add(new TextView("", ALIGN_LEFT, true, new LinearLayoutParams(0.0, G_VCENTER)));
155
tvCRC_->SetShadow(true);
156
Visibility crcVisibility = Reporting::HasCRC(gamePath_) ? V_VISIBLE : V_GONE;
157
tvCRC_->SetVisibility(crcVisibility);
158
if (System_GetPropertyBool(SYSPROP_HAS_TEXT_CLIPBOARD)) {
159
tvCRCCopy_ = crcHoriz->Add(new Button(di->T("Copy to clipboard"), new LinearLayoutParams(0.0, G_VCENTER)));
160
tvCRCCopy_->OnClick.Add([this](UI::EventParams &) {
161
u32 crc = Reporting::RetrieveCRC(gamePath_);
162
char buffer[16];
163
snprintf(buffer, sizeof(buffer), "%08X", crc);
164
System_CopyStringToClipboard(buffer);
165
// Success indication. Not worth a translatable string.
166
g_OSD.Show(OSDType::MESSAGE_SUCCESS, buffer, 1.0f);
167
return UI::EVENT_DONE;
168
});
169
tvCRCCopy_->SetVisibility(crcVisibility);
170
tvCRCCopy_->SetScale(0.82f);
171
} else {
172
tvCRCCopy_ = nullptr;
173
}
174
175
tvVerified_ = infoLayout->Add(new NoticeView(NoticeLevel::INFO, ga->T("Click \"Calculate CRC\" to verify ISO"), "", new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)));
176
tvVerified_->SetVisibility(UI::V_GONE);
177
tvVerified_->SetSquishy(true);
178
179
// Show plugin info, if any. Later might add checkboxes.
180
auto plugins = HLEPlugins::FindPlugins(info->id, g_Config.sLanguageIni);
181
if (!plugins.empty()) {
182
auto sy = GetI18NCategory(I18NCat::SYSTEM);
183
infoLayout->Add(new TextView(sy->T("Plugins"), ALIGN_LEFT, true));
184
for (const auto &plugin : plugins) {
185
infoLayout->Add(new TextView(ApplySafeSubstitutions("* %1", plugin.name), ALIGN_LEFT, true));
186
}
187
}
188
} else {
189
tvTitle_ = nullptr;
190
tvID_ = nullptr;
191
tvGameSize_ = nullptr;
192
tvSaveDataSize_ = nullptr;
193
tvInstallDataSize_ = nullptr;
194
tvRegion_ = nullptr;
195
tvPlayTime_ = nullptr;
196
tvCRC_ = nullptr;
197
tvCRCCopy_ = nullptr;
198
tvVerified_ = nullptr;
199
}
200
201
ViewGroup *rightColumn = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(300, FILL_PARENT, actionMenuMargins));
202
root_->Add(rightColumn);
203
204
LinearLayout *rightColumnItems = new LinearLayout(ORIENT_VERTICAL);
205
rightColumnItems->SetSpacing(0.0f);
206
rightColumn->Add(rightColumnItems);
207
208
if (!inGame_) {
209
rightColumnItems->Add(new Choice(ga->T("Play")))->OnClick.Handle(this, &GameScreen::OnPlay);
210
}
211
212
btnGameSettings_ = rightColumnItems->Add(new Choice(ga->T("Game Settings")));
213
btnGameSettings_->OnClick.Handle(this, &GameScreen::OnGameSettings);
214
215
btnDeleteGameConfig_ = rightColumnItems->Add(new Choice(ga->T("Delete Game Config")));
216
btnDeleteGameConfig_->OnClick.Handle(this, &GameScreen::OnDeleteConfig);
217
if (inGame_)
218
btnDeleteGameConfig_->SetEnabled(false);
219
220
btnCreateGameConfig_ = rightColumnItems->Add(new Choice(ga->T("Create Game Config")));
221
btnCreateGameConfig_->OnClick.Handle(this, &GameScreen::OnCreateConfig);
222
if (inGame_)
223
btnCreateGameConfig_->SetEnabled(false);
224
225
btnGameSettings_->SetVisibility(V_GONE);
226
btnDeleteGameConfig_->SetVisibility(V_GONE);
227
btnCreateGameConfig_->SetVisibility(V_GONE);
228
229
btnDeleteSaveData_ = new Choice(ga->T("Delete Save Data"));
230
rightColumnItems->Add(btnDeleteSaveData_)->OnClick.Handle(this, &GameScreen::OnDeleteSaveData);
231
btnDeleteSaveData_->SetVisibility(V_GONE);
232
233
otherChoices_.clear();
234
235
// Don't want to be able to delete the game while it's running.
236
Choice *deleteChoice = rightColumnItems->Add(AddOtherChoice(new Choice(ga->T("Delete Game"))));
237
deleteChoice->OnClick.Handle(this, &GameScreen::OnDeleteGame);
238
if (inGame_) {
239
deleteChoice->SetEnabled(false);
240
}
241
if (System_GetPropertyBool(SYSPROP_CAN_CREATE_SHORTCUT)) {
242
rightColumnItems->Add(AddOtherChoice(new Choice(ga->T("Create Shortcut"))))->OnClick.Add([=](UI::EventParams &e) {
243
std::shared_ptr<GameInfo> info = g_gameInfoCache->GetInfo(NULL, gamePath_, GameInfoFlags::PARAM_SFO);
244
if (info->Ready(GameInfoFlags::PARAM_SFO)) {
245
// TODO: Should we block on Ready?
246
System_CreateGameShortcut(gamePath_, info->GetTitle());
247
}
248
return UI::EVENT_DONE;
249
});
250
}
251
252
if (isRecentGame(gamePath_)) {
253
Choice *removeButton = rightColumnItems->Add(AddOtherChoice(new Choice(ga->T("Remove From Recent"))));
254
removeButton->OnClick.Handle(this, &GameScreen::OnRemoveFromRecent);
255
if (inGame_) {
256
removeButton->SetEnabled(false);
257
}
258
}
259
260
#if (defined(USING_QT_UI) || PPSSPP_PLATFORM(WINDOWS) || PPSSPP_PLATFORM(MAC)) && !PPSSPP_PLATFORM(UWP)
261
rightColumnItems->Add(AddOtherChoice(new Choice(ga->T("Show In Folder"))))->OnClick.Handle(this, &GameScreen::OnShowInFolder);
262
#endif
263
if (g_Config.bEnableCheats) {
264
auto pa = GetI18NCategory(I18NCat::PAUSE);
265
rightColumnItems->Add(AddOtherChoice(new Choice(pa->T("Cheats"))))->OnClick.Handle(this, &GameScreen::OnCwCheat);
266
}
267
268
btnSetBackground_ = rightColumnItems->Add(new Choice(ga->T("Use UI background")));
269
btnSetBackground_->OnClick.Handle(this, &GameScreen::OnSetBackground);
270
btnSetBackground_->SetVisibility(V_GONE);
271
272
bool fileTypeSupportCRC = false;
273
if (info) {
274
switch (info->fileType) {
275
case IdentifiedFileType::PSP_PBP:
276
case IdentifiedFileType::PSP_PBP_DIRECTORY:
277
case IdentifiedFileType::PSP_ISO_NP:
278
case IdentifiedFileType::PSP_ISO:
279
fileTypeSupportCRC = true;
280
break;
281
282
default:
283
break;
284
}
285
}
286
287
isHomebrew_ = info && info->region > GAMEREGION_MAX;
288
if (fileTypeSupportCRC && !isHomebrew_ && !Reporting::HasCRC(gamePath_) ) {
289
btnCalcCRC_ = rightColumnItems->Add(new ChoiceWithValueDisplay(&CRC32string, ga->T("Calculate CRC"), I18NCat::NONE));
290
btnCalcCRC_->OnClick.Handle(this, &GameScreen::OnDoCRC32);
291
} else {
292
btnCalcCRC_ = nullptr;
293
}
294
}
295
296
UI::Choice *GameScreen::AddOtherChoice(UI::Choice *choice) {
297
otherChoices_.push_back(choice);
298
// While loading.
299
choice->SetVisibility(UI::V_GONE);
300
return choice;
301
}
302
303
UI::EventReturn GameScreen::OnCreateConfig(UI::EventParams &e) {
304
std::shared_ptr<GameInfo> info = g_gameInfoCache->GetInfo(nullptr, gamePath_, GameInfoFlags::PARAM_SFO);
305
if (!info->Ready(GameInfoFlags::PARAM_SFO)) {
306
return UI::EVENT_SKIPPED;
307
}
308
g_Config.createGameConfig(info->id);
309
g_Config.saveGameConfig(info->id, info->GetTitle());
310
info->hasConfig = true;
311
312
screenManager()->topScreen()->RecreateViews();
313
return UI::EVENT_DONE;
314
}
315
316
void GameScreen::CallbackDeleteConfig(bool yes) {
317
if (yes) {
318
std::shared_ptr<GameInfo> info = g_gameInfoCache->GetInfo(nullptr, gamePath_, GameInfoFlags::PARAM_SFO);
319
if (!info->Ready(GameInfoFlags::PARAM_SFO)) {
320
return;
321
}
322
g_Config.deleteGameConfig(info->id);
323
info->hasConfig = false;
324
screenManager()->RecreateAllViews();
325
}
326
}
327
328
UI::EventReturn GameScreen::OnDeleteConfig(UI::EventParams &e)
329
{
330
auto di = GetI18NCategory(I18NCat::DIALOG);
331
auto ga = GetI18NCategory(I18NCat::GAME);
332
screenManager()->push(
333
new PromptScreen(gamePath_, di->T("DeleteConfirmGameConfig", "Do you really want to delete the settings for this game?"), ga->T("ConfirmDelete"), di->T("Cancel"),
334
std::bind(&GameScreen::CallbackDeleteConfig, this, std::placeholders::_1)));
335
336
return UI::EVENT_DONE;
337
}
338
339
ScreenRenderFlags GameScreen::render(ScreenRenderMode mode) {
340
ScreenRenderFlags flags = UIScreen::render(mode);
341
342
auto ga = GetI18NCategory(I18NCat::GAME);
343
344
Draw::DrawContext *draw = screenManager()->getDrawContext();
345
346
std::shared_ptr<GameInfo> info = g_gameInfoCache->GetInfo(draw, gamePath_, GameInfoFlags::BG | GameInfoFlags::SIZE | GameInfoFlags::UNCOMPRESSED_SIZE);
347
348
if (tvTitle_) {
349
tvTitle_->SetText(info->GetTitle());
350
}
351
352
if (info->Ready(GameInfoFlags::SIZE | GameInfoFlags::UNCOMPRESSED_SIZE)) {
353
char temp[256];
354
if (tvGameSize_) {
355
snprintf(temp, sizeof(temp), "%s: %s", ga->T_cstr("Game"), NiceSizeFormat(info->gameSizeOnDisk).c_str());
356
if (info->gameSizeUncompressed != info->gameSizeOnDisk) {
357
size_t len = strlen(temp);
358
snprintf(temp + len, sizeof(temp) - len, " (%s: %s)", ga->T_cstr("Uncompressed"), NiceSizeFormat(info->gameSizeUncompressed).c_str());
359
}
360
tvGameSize_->SetText(temp);
361
}
362
if (tvSaveDataSize_) {
363
if (info->saveDataSize > 0) {
364
snprintf(temp, sizeof(temp), "%s: %s", ga->T_cstr("SaveData"), NiceSizeFormat(info->saveDataSize).c_str());
365
tvSaveDataSize_->SetText(temp);
366
} else {
367
tvSaveDataSize_->SetVisibility(UI::V_GONE);
368
}
369
}
370
if (info->installDataSize > 0 && tvInstallDataSize_) {
371
snprintf(temp, sizeof(temp), "%s: %1.2f %s", ga->T_cstr("InstallData"), (float) (info->installDataSize) / 1024.f / 1024.f, ga->T_cstr("MB"));
372
tvInstallDataSize_->SetText(temp);
373
tvInstallDataSize_->SetVisibility(UI::V_VISIBLE);
374
}
375
}
376
377
if (tvRegion_) {
378
if (info->region >= 0 && info->region < GAMEREGION_MAX && info->region != GAMEREGION_OTHER) {
379
static const char *regionNames[GAMEREGION_MAX] = {
380
"Japan",
381
"USA",
382
"Europe",
383
"Hong Kong",
384
"Asia",
385
"Korea"
386
};
387
tvRegion_->SetText(ga->T(regionNames[info->region]));
388
} else if (info->region > GAMEREGION_MAX) {
389
tvRegion_->SetText(ga->T("Homebrew"));
390
}
391
}
392
393
if (tvPlayTime_) {
394
std::string str;
395
if (g_Config.TimeTracker().GetPlayedTimeString(info->id, &str)) {
396
tvPlayTime_->SetText(str);
397
tvPlayTime_->SetVisibility(UI::V_VISIBLE);
398
}
399
}
400
401
if (tvCRC_ && Reporting::HasCRC(gamePath_)) {
402
auto rp = GetI18NCategory(I18NCat::REPORTING);
403
uint32_t crcVal = Reporting::RetrieveCRC(gamePath_);
404
std::string crc = StringFromFormat("%08X", crcVal);
405
tvCRC_->SetText(ReplaceAll(rp->T("FeedbackCRCValue", "Disc CRC: %1"), "%1", crc));
406
tvCRC_->SetVisibility(UI::V_VISIBLE);
407
if (tvCRCCopy_) {
408
tvCRCCopy_->SetVisibility(UI::V_VISIBLE);
409
}
410
411
// Let's check the CRC in the game database, looking up the ID and also matching the crc.
412
std::vector<GameDBInfo> dbInfos;
413
if (tvVerified_ && info->Ready(GameInfoFlags::PARAM_SFO) && g_gameDB.GetGameInfos(info->id_version, &dbInfos)) {
414
bool found = false;
415
for (auto &dbInfo : dbInfos) {
416
if (dbInfo.crc == crcVal) {
417
found = true;
418
}
419
}
420
if (found) {
421
tvVerified_->SetText(ga->T("ISO OK according to the ReDump project"));
422
tvVerified_->SetLevel(NoticeLevel::SUCCESS);
423
tvVerified_->SetVisibility(UI::V_VISIBLE);
424
} else {
425
// Like the other messages below, disabled until we have a database we have confidence in.
426
// tvVerified_->SetText(ga->T("CRC checksum does not match, bad or modified ISO"));
427
// tvVerified_->SetLevel(NoticeLevel::ERROR);
428
tvVerified_->SetVisibility(UI::V_GONE);
429
}
430
} else if (tvVerified_) {
431
// tvVerified_->SetText(ga->T("Game ID unknown - not in the ReDump database"));
432
// tvVerified_->SetVisibility(UI::V_VISIBLE);
433
// tvVerified_->SetLevel(NoticeLevel::WARN);
434
tvVerified_->SetVisibility(UI::V_GONE);
435
}
436
} else if (!isHomebrew_) {
437
GameDBInfo dbInfo;
438
if (tvVerified_) {
439
std::vector<GameDBInfo> dbInfos;
440
if (info->Ready(GameInfoFlags::PARAM_SFO) && !g_gameDB.GetGameInfos(info->id_version, &dbInfos)) {
441
// tvVerified_->SetText(ga->T("Game ID unknown - not in the ReDump database"));
442
// tvVerified_->SetVisibility(UI::V_VISIBLE);
443
// tvVerified_->SetLevel(NoticeLevel::WARN);
444
} else if (info->Ready(GameInfoFlags::UNCOMPRESSED_SIZE) && info->gameSizeUncompressed != 0) { // don't do this check if info still pending
445
bool found = false;
446
for (auto &dbInfo : dbInfos) {
447
// TODO: Doesn't take CSO/CHD into account.
448
if (info->gameSizeUncompressed == dbInfo.size) {
449
found = true;
450
}
451
}
452
if (!found) {
453
// tvVerified_->SetText(ga->T("File size incorrect, bad or modified ISO"));
454
// tvVerified_->SetVisibility(UI::V_VISIBLE);
455
// tvVerified_->SetLevel(NoticeLevel::ERROR);
456
// INFO_LOG(Log::Loader, "File size %d not matching game DB", (int)info->gameSizeUncompressed);
457
} else {
458
tvVerified_->SetText(ga->T("Click \"Calculate CRC\" to verify ISO"));
459
tvVerified_->SetVisibility(UI::V_VISIBLE);
460
tvVerified_->SetLevel(NoticeLevel::INFO);
461
}
462
}
463
}
464
}
465
466
if (tvID_) {
467
tvID_->SetText(ReplaceAll(info->id_version, "_", " v"));
468
}
469
470
if (!info->id.empty()) {
471
btnGameSettings_->SetVisibility(info->hasConfig ? UI::V_VISIBLE : UI::V_GONE);
472
btnDeleteGameConfig_->SetVisibility(info->hasConfig ? UI::V_VISIBLE : UI::V_GONE);
473
btnCreateGameConfig_->SetVisibility(info->hasConfig ? UI::V_GONE : UI::V_VISIBLE);
474
475
if (saveDirs.size()) {
476
btnDeleteSaveData_->SetVisibility(UI::V_VISIBLE);
477
}
478
if (info->pic0.texture || info->pic1.texture) {
479
btnSetBackground_->SetVisibility(UI::V_VISIBLE);
480
}
481
}
482
483
if (info->Ready(GameInfoFlags::PARAM_SFO)) {
484
// At this point, the above buttons won't become visible. We can show these now.
485
for (UI::Choice *choice : otherChoices_) {
486
choice->SetVisibility(UI::V_VISIBLE);
487
}
488
}
489
return flags;
490
}
491
492
UI::EventReturn GameScreen::OnShowInFolder(UI::EventParams &e) {
493
System_ShowFileInFolder(gamePath_);
494
return UI::EVENT_DONE;
495
}
496
497
UI::EventReturn GameScreen::OnCwCheat(UI::EventParams &e) {
498
screenManager()->push(new CwCheatScreen(gamePath_));
499
return UI::EVENT_DONE;
500
}
501
502
UI::EventReturn GameScreen::OnDoCRC32(UI::EventParams& e) {
503
CRC32string = "...";
504
Reporting::QueueCRC(gamePath_);
505
if (btnCalcCRC_) {
506
btnCalcCRC_->SetEnabled(false);
507
}
508
return UI::EVENT_DONE;
509
}
510
511
512
UI::EventReturn GameScreen::OnSwitchBack(UI::EventParams &e) {
513
TriggerFinish(DR_OK);
514
return UI::EVENT_DONE;
515
}
516
517
UI::EventReturn GameScreen::OnPlay(UI::EventParams &e) {
518
screenManager()->switchScreen(new EmuScreen(gamePath_));
519
return UI::EVENT_DONE;
520
}
521
522
UI::EventReturn GameScreen::OnGameSettings(UI::EventParams &e) {
523
std::shared_ptr<GameInfo> info = g_gameInfoCache->GetInfo(NULL, gamePath_, GameInfoFlags::PARAM_SFO);
524
if (info && info->Ready(GameInfoFlags::PARAM_SFO)) {
525
std::string discID = info->GetParamSFO().GetValueString("DISC_ID");
526
if ((discID.empty() || !info->disc_total) && gamePath_.FilePathContainsNoCase("PSP/GAME/"))
527
discID = g_paramSFO.GenerateFakeID(gamePath_);
528
screenManager()->push(new GameSettingsScreen(gamePath_, discID, true));
529
}
530
return UI::EVENT_DONE;
531
}
532
533
UI::EventReturn GameScreen::OnDeleteSaveData(UI::EventParams &e) {
534
std::shared_ptr<GameInfo> info = g_gameInfoCache->GetInfo(NULL, gamePath_, GameInfoFlags::PARAM_SFO);
535
if (info) {
536
// Check that there's any savedata to delete
537
if (saveDirs.size()) {
538
auto di = GetI18NCategory(I18NCat::DIALOG);
539
auto ga = GetI18NCategory(I18NCat::GAME);
540
screenManager()->push(
541
new PromptScreen(gamePath_, di->T("DeleteConfirmAll", "Do you really want to delete all\nyour save data for this game?"), ga->T("ConfirmDelete"), di->T("Cancel"),
542
std::bind(&GameScreen::CallbackDeleteSaveData, this, std::placeholders::_1)));
543
}
544
}
545
RecreateViews();
546
return UI::EVENT_DONE;
547
}
548
549
void GameScreen::CallbackDeleteSaveData(bool yes) {
550
if (yes) {
551
std::shared_ptr<GameInfo> info = g_gameInfoCache->GetInfo(NULL, gamePath_, GameInfoFlags::PARAM_SFO);
552
info->DeleteAllSaveData();
553
info->saveDataSize = 0;
554
info->installDataSize = 0;
555
}
556
}
557
558
UI::EventReturn GameScreen::OnDeleteGame(UI::EventParams &e) {
559
std::shared_ptr<GameInfo> info = g_gameInfoCache->GetInfo(NULL, gamePath_, GameInfoFlags::PARAM_SFO);
560
if (info->Ready(GameInfoFlags::PARAM_SFO)) {
561
auto di = GetI18NCategory(I18NCat::DIALOG);
562
auto ga = GetI18NCategory(I18NCat::GAME);
563
std::string prompt;
564
prompt = di->T("DeleteConfirmGame", "Do you really want to delete this game\nfrom your device? You can't undo this.");
565
prompt += "\n\n" + gamePath_.ToVisualString(g_Config.memStickDirectory.c_str());
566
screenManager()->push(
567
new PromptScreen(gamePath_, prompt, ga->T("ConfirmDelete"), di->T("Cancel"),
568
std::bind(&GameScreen::CallbackDeleteGame, this, std::placeholders::_1)));
569
}
570
return UI::EVENT_DONE;
571
}
572
573
void GameScreen::CallbackDeleteGame(bool yes) {
574
if (yes) {
575
std::shared_ptr<GameInfo> info = g_gameInfoCache->GetInfo(NULL, gamePath_, GameInfoFlags::PARAM_SFO);
576
info->Delete();
577
g_gameInfoCache->Clear();
578
screenManager()->switchScreen(new MainScreen());
579
}
580
}
581
582
bool GameScreen::isRecentGame(const Path &gamePath) {
583
if (g_Config.iMaxRecent <= 0)
584
return false;
585
586
const std::string resolved = File::ResolvePath(gamePath.ToString());
587
for (const auto &iso : g_Config.RecentIsos()) {
588
const std::string recent = File::ResolvePath(iso);
589
if (resolved == recent)
590
return true;
591
}
592
return false;
593
}
594
595
UI::EventReturn GameScreen::OnRemoveFromRecent(UI::EventParams &e) {
596
g_Config.RemoveRecent(gamePath_.ToString());
597
screenManager()->switchScreen(new MainScreen());
598
return UI::EVENT_DONE;
599
}
600
601
class SetBackgroundPopupScreen : public PopupScreen {
602
public:
603
SetBackgroundPopupScreen(std::string_view title, const Path &gamePath)
604
: PopupScreen(title), gamePath_(gamePath) {
605
timeStart_ = time_now_d();
606
}
607
const char *tag() const override { return "SetBackgroundPopup"; }
608
609
protected:
610
bool FillVertical() const override { return false; }
611
bool ShowButtons() const override { return false; }
612
void CreatePopupContents(UI::ViewGroup *parent) override;
613
void update() override;
614
615
private:
616
Path gamePath_;
617
double timeStart_;
618
double timeDone_ = 0.0;
619
620
enum class Status {
621
PENDING,
622
DELAY,
623
DONE,
624
};
625
Status status_ = Status::PENDING;
626
};
627
628
void SetBackgroundPopupScreen::CreatePopupContents(UI::ViewGroup *parent) {
629
auto ga = GetI18NCategory(I18NCat::GAME);
630
parent->Add(new UI::TextView(ga->T("One moment please..."), ALIGN_LEFT | ALIGN_VCENTER, false, new UI::LinearLayoutParams(UI::Margins(10, 0, 10, 10))));
631
}
632
633
void SetBackgroundPopupScreen::update() {
634
PopupScreen::update();
635
636
std::shared_ptr<GameInfo> info = g_gameInfoCache->GetInfo(nullptr, gamePath_, GameInfoFlags::BG);
637
if (status_ == Status::PENDING && info->Ready(GameInfoFlags::BG)) {
638
GameInfoTex *pic = nullptr;
639
if (info->pic1.dataLoaded && info->pic1.data.size()) {
640
pic = &info->pic1;
641
} else if (info->pic0.dataLoaded && info->pic0.data.size()) {
642
pic = &info->pic0;
643
}
644
645
if (pic) {
646
const Path bgPng = GetSysDirectory(DIRECTORY_SYSTEM) / "background.png";
647
File::WriteStringToFile(false, pic->data, bgPng);
648
}
649
650
UIBackgroundShutdown();
651
652
// It's worse if it flickers, stay open for at least 1s.
653
timeDone_ = timeStart_ + 1.0;
654
status_ = Status::DELAY;
655
}
656
657
if (status_ == Status::DELAY && timeDone_ <= time_now_d()) {
658
TriggerFinish(DR_OK);
659
status_ = Status::DONE;
660
}
661
}
662
663
UI::EventReturn GameScreen::OnSetBackground(UI::EventParams &e) {
664
auto ga = GetI18NCategory(I18NCat::GAME);
665
// This popup is used to prevent any race condition:
666
// g_gameInfoCache may take time to load the data, and a crash could happen if they exit before then.
667
SetBackgroundPopupScreen *pop = new SetBackgroundPopupScreen(ga->T("Setting Background"), gamePath_);
668
if (e.v)
669
pop->SetPopupOrigin(e.v);
670
screenManager()->push(pop);
671
return UI::EVENT_DONE;
672
}
673
674