-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
main_window.cpp
2731 lines (2287 loc) · 79.5 KB
/
main_window.cpp
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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "main_window.h"
#include "qt_utils.h"
#include "vfs_dialog.h"
#include "save_manager_dialog.h"
#include "trophy_manager_dialog.h"
#include "user_manager_dialog.h"
#include "screenshot_manager_dialog.h"
#include "kernel_explorer.h"
#include "game_list_frame.h"
#include "debugger_frame.h"
#include "log_frame.h"
#include "settings_dialog.h"
#include "rpcn_settings_dialog.h"
#include "auto_pause_settings_dialog.h"
#include "cg_disasm_window.h"
#include "log_viewer.h"
#include "memory_string_searcher.h"
#include "memory_viewer_panel.h"
#include "rsx_debugger.h"
#include "about_dialog.h"
#include "pad_settings_dialog.h"
#include "progress_dialog.h"
#include "skylander_dialog.h"
#include "cheat_manager.h"
#include "patch_manager_dialog.h"
#include "pkg_install_dialog.h"
#include "category.h"
#include "gui_settings.h"
#include "input_dialog.h"
#include <thread>
#include <charconv>
#include <QScreen>
#include <QDirIterator>
#include <QMimeData>
#include <QMessageBox>
#include <QFileDialog>
#include <QFontDatabase>
#include "rpcs3_version.h"
#include "Emu/System.h"
#include "Emu/IdManager.h"
#include "Emu/VFS.h"
#include "Emu/system_config.h"
#include "Crypto/unpkg.h"
#include "Crypto/unself.h"
#include "Crypto/unedat.h"
#include "Loader/PUP.h"
#include "Loader/TAR.h"
#include "Loader/mself.hpp"
#include "Utilities/Thread.h"
#include "util/sysinfo.hpp"
#include "ui_main_window.h"
LOG_CHANNEL(gui_log, "GUI");
extern atomic_t<bool> g_user_asked_for_frame_capture;
inline std::string sstr(const QString& _in) { return _in.toStdString(); }
main_window::main_window(std::shared_ptr<gui_settings> gui_settings, std::shared_ptr<emu_settings> emu_settings, std::shared_ptr<persistent_settings> persistent_settings, QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::main_window)
, m_gui_settings(gui_settings)
, m_emu_settings(emu_settings)
, m_persistent_settings(persistent_settings)
{
Q_INIT_RESOURCE(resources);
// We have to setup the ui before using a translation
ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);
}
main_window::~main_window()
{
SaveWindowState();
delete ui;
}
/* An init method is used so that RPCS3App can create the necessary connects before calling init (specifically the stylesheet connect).
* Simplifies logic a bit.
*/
bool main_window::Init()
{
setAcceptDrops(true);
// add toolbar widgets (crappy Qt designer is not able to)
ui->toolBar->setObjectName("mw_toolbar");
ui->sizeSlider->setRange(0, gui::gl_max_slider_pos);
ui->toolBar->addWidget(ui->sizeSliderContainer);
ui->toolBar->addWidget(ui->mw_searchbar);
CreateActions();
CreateDockWindows();
CreateConnects();
setMinimumSize(350, minimumSizeHint().height()); // seems fine on win 10
setWindowTitle(QString::fromStdString("RPCS3 " + rpcs3::get_version().to_string()));
Q_EMIT RequestGlobalStylesheetChange();
ConfigureGuiFromSettings(true);
if (const std::string_view branch_name = rpcs3::get_full_branch(); branch_name != "RPCS3/rpcs3/master" && branch_name != "local_build")
{
gui_log.warning("Experimental Build Warning! Build origin: %s", branch_name);
QMessageBox msg;
msg.setWindowTitle(tr("Experimental Build Warning"));
msg.setIcon(QMessageBox::Critical);
msg.setTextFormat(Qt::RichText);
msg.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
msg.setDefaultButton(QMessageBox::No);
msg.setText(QString(tr(
R"(
<p style="white-space: nowrap;">
Please understand that this build is not an official RPCS3 release.<br>
This build contains changes that may break games, or even <b>damage</b> your data.<br>
We recommend to download and use the official build from the <a href='https://rpcs3.net/download'>RPCS3 website</a>.<br><br>
Build origin: %1<br>
Do you wish to use this build anyway?
</p>
)"
)).arg(Qt::convertFromPlainText(branch_name.data())));
msg.layout()->setSizeConstraint(QLayout::SetFixedSize);
if (msg.exec() == QMessageBox::No)
{
return false;
}
}
show(); // needs to be done before creating the thumbnail toolbar
// enable play options if a recent game exists
const bool enable_play_last = !m_recent_game_acts.isEmpty() && m_recent_game_acts.first();
const QString start_tooltip = enable_play_last ? tr("Play %0").arg(m_recent_game_acts.first()->text()) : tr("Play");
if (enable_play_last)
{
ui->sysPauseAct->setText(tr("&Play last played game\tCtrl+E"));
ui->sysPauseAct->setIcon(m_icon_play);
ui->toolbar_start->setToolTip(start_tooltip);
}
ui->sysPauseAct->setEnabled(enable_play_last);
ui->toolbar_start->setEnabled(enable_play_last);
// create tool buttons for the taskbar thumbnail
#ifdef _WIN32
m_thumb_bar = new QWinThumbnailToolBar(this);
m_thumb_bar->setWindow(windowHandle());
m_thumb_playPause = new QWinThumbnailToolButton(m_thumb_bar);
m_thumb_playPause->setToolTip(start_tooltip);
m_thumb_playPause->setIcon(m_icon_thumb_play);
m_thumb_playPause->setEnabled(enable_play_last);
m_thumb_stop = new QWinThumbnailToolButton(m_thumb_bar);
m_thumb_stop->setToolTip(tr("Stop"));
m_thumb_stop->setIcon(m_icon_thumb_stop);
m_thumb_stop->setEnabled(false);
m_thumb_restart = new QWinThumbnailToolButton(m_thumb_bar);
m_thumb_restart->setToolTip(tr("Restart"));
m_thumb_restart->setIcon(m_icon_thumb_restart);
m_thumb_restart->setEnabled(false);
m_thumb_bar->addButton(m_thumb_playPause);
m_thumb_bar->addButton(m_thumb_stop);
m_thumb_bar->addButton(m_thumb_restart);
RepaintThumbnailIcons();
connect(m_thumb_stop, &QWinThumbnailToolButton::clicked, this, []() { Emu.Stop(); });
connect(m_thumb_restart, &QWinThumbnailToolButton::clicked, this, []() { Emu.Restart(); });
connect(m_thumb_playPause, &QWinThumbnailToolButton::clicked, this, &main_window::OnPlayOrPause);
#endif
// Fix possible hidden game list columns. The game list has to be visible already. Use this after show()
m_game_list_frame->FixNarrowColumns();
// RPCS3 Updater
QMenu* download_menu = new QMenu(tr("Update Available!"));
QAction *download_action = new QAction(tr("Download Update"), download_menu);
connect(download_action, &QAction::triggered, this, [this]
{
m_updater.update();
});
download_menu->addAction(download_action);
#ifdef _WIN32
// Use a menu at the top right corner to indicate the new version.
QMenuBar *corner_bar = new QMenuBar(ui->menuBar);
m_download_menu_action = corner_bar->addMenu(download_menu);
ui->menuBar->setCornerWidget(corner_bar);
ui->menuBar->cornerWidget()->setVisible(false);
#else
// Append a menu to the right of the regular menus to indicate the new version.
// Some distros just can't handle corner widgets at the moment.
m_download_menu_action = ui->menuBar->addMenu(download_menu);
#endif
ensure(m_download_menu_action);
m_download_menu_action->setVisible(false);
connect(&m_updater, &update_manager::signal_update_available, this, [this](bool update_available)
{
if (m_download_menu_action)
{
m_download_menu_action->setVisible(update_available);
}
if (ui->menuBar && ui->menuBar->cornerWidget())
{
ui->menuBar->cornerWidget()->setVisible(update_available);
}
});
#if defined(_WIN32) || defined(__linux__)
if (const auto update_value = m_gui_settings->GetValue(gui::m_check_upd_start).toString(); update_value != "false")
{
m_updater.check_for_updates(true, update_value != "true", this);
}
#endif
return true;
}
QString main_window::GetCurrentTitle()
{
QString title = qstr(Emu.GetTitleAndTitleID());
if (title.isEmpty())
{
title = qstr(Emu.GetBoot());
}
return title;
}
// returns appIcon
QIcon main_window::GetAppIcon()
{
return m_app_icon;
}
bool main_window::OnMissingFw()
{
const QString title = tr("Missing Firmware Detected!");
const QString message = tr("Commercial games require the firmware (PS3UPDAT.PUP file) to be installed."
"\n<br>For information about how to obtain the required firmware read the <a href=\"https://rpcs3.net/quickstart\">quickstart guide</a>.");
QMessageBox* mb = new QMessageBox(QMessageBox::Question, title, message, QMessageBox::Ok | QMessageBox::Cancel, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint | Qt::WindowStaysOnTopHint);
mb->deleteLater();
mb->setTextFormat(Qt::RichText);
mb->button(QMessageBox::Ok)->setText(tr("Locate PS3UPDAT.PUP"));
if (mb->exec() == QMessageBox::Ok)
{
InstallPup();
return true;
}
return false;
}
void main_window::ResizeIcons(int index)
{
if (ui->sizeSlider->value() != index)
{
ui->sizeSlider->setSliderPosition(index);
return; // ResizeIcons will be triggered again by setSliderPosition, so return here
}
if (m_save_slider_pos)
{
m_save_slider_pos = false;
m_gui_settings->SetValue(m_is_list_mode ? gui::gl_iconSize : gui::gl_iconSizeGrid, index);
// this will also fire when we used the actions, but i didn't want to add another boolean member
SetIconSizeActions(index);
}
m_game_list_frame->ResizeIcons(index);
}
void main_window::OnPlayOrPause()
{
if (Emu.IsReady())
{
Emu.Run(true);
}
else if (Emu.IsPaused())
{
Emu.Resume();
}
else if (Emu.IsRunning())
{
Emu.Pause();
}
else if (Emu.IsStopped())
{
if (m_selected_game)
{
Boot(m_selected_game->info.path, m_selected_game->info.serial, false, false, false);
}
else if (const auto path = Emu.GetBoot(); !path.empty())
{
if (const auto error = Emu.Load(); error != game_boot_result::no_errors)
{
gui_log.error("Boot failed: reason: %s, path: %s", error, path);
show_boot_error(error);
}
}
else if (!m_recent_game_acts.isEmpty())
{
BootRecentAction(m_recent_game_acts.first());
}
}
}
void main_window::show_boot_error(game_boot_result status)
{
QString message;
switch (status)
{
case game_boot_result::nothing_to_boot:
message = tr("No bootable content was found.");
break;
case game_boot_result::wrong_disc_location:
message = tr("Disc could not be mounted properly. Make sure the disc is not in the dev_hdd0/game folder.");
break;
case game_boot_result::invalid_file_or_folder:
message = tr("The selected file or folder is invalid or corrupted.");
break;
case game_boot_result::install_failed:
message = tr("Additional content could not be installed.");
break;
case game_boot_result::decryption_error:
message = tr("Digital content could not be decrypted. This is usually caused by a missing or invalid license (RAP) file.");
break;
case game_boot_result::file_creation_error:
message = tr("The emulator could not create files required for booting.");
break;
case game_boot_result::firmware_missing: // Handled elsewhere
case game_boot_result::no_errors:
return;
case game_boot_result::generic_error:
default:
message = tr("Unknown error.");
break;
}
const QString link = tr("<br /><br />For information on setting up the emulator and dumping your PS3 games, read the <a href=\"https://rpcs3.net/quickstart\">quickstart guide</a>.");
QMessageBox msg;
msg.setWindowTitle(tr("Boot Failed"));
msg.setIcon(QMessageBox::Critical);
msg.setTextFormat(Qt::RichText);
msg.setStandardButtons(QMessageBox::Ok);
msg.setText(tr("Booting failed: %1 %2").arg(message).arg(link));
msg.exec();
}
void main_window::Boot(const std::string& path, const std::string& title_id, bool direct, bool add_only, bool force_global_config)
{
if (!m_gui_settings->GetBootConfirmation(this, gui::ib_confirm_boot))
{
return;
}
m_app_icon = gui::utils::get_app_icon_from_path(path, title_id);
Emu.SetForceBoot(true);
Emu.Stop();
if (const auto error = Emu.BootGame(path, title_id, direct, add_only, force_global_config); error != game_boot_result::no_errors)
{
gui_log.error("Boot failed: reason: %s, path: %s", error, path);
show_boot_error(error);
}
else
{
gui_log.success("Boot successful.");
if (!add_only)
{
AddRecentAction(gui::Recent_Game(qstr(Emu.GetBoot()), qstr(Emu.GetTitleAndTitleID())));
}
}
m_game_list_frame->Refresh(true);
}
void main_window::BootElf()
{
bool stopped = false;
if (Emu.IsRunning())
{
Emu.Pause();
stopped = true;
}
const QString path_last_elf = m_gui_settings->GetValue(gui::fd_boot_elf).toString();
const QString file_path = QFileDialog::getOpenFileName(this, tr("Select (S)ELF To Boot"), path_last_elf, tr(
"(S)ELF files (*BOOT.BIN *.elf *.self);;"
"ELF files (BOOT.BIN *.elf);;"
"SELF files (EBOOT.BIN *.self);;"
"BOOT files (*BOOT.BIN);;"
"BIN files (*.bin);;"
"All files (*.*)"),
Q_NULLPTR, QFileDialog::DontResolveSymlinks);
if (file_path.isEmpty())
{
if (stopped)
{
Emu.Resume();
}
return;
}
// If we resolved the filepath earlier we would end up setting the last opened dir to the unwanted
// game folder in case of having e.g. a Game Folder with collected links to elf files.
// Don't set last path earlier in case of cancelled dialog
m_gui_settings->SetValue(gui::fd_boot_elf, file_path);
const std::string path = sstr(QFileInfo(file_path).absoluteFilePath());
gui_log.notice("Booting from BootElf...");
Boot(path, "", true);
}
void main_window::BootGame()
{
bool stopped = false;
if (Emu.IsRunning())
{
Emu.Pause();
stopped = true;
}
const QString path_last_game = m_gui_settings->GetValue(gui::fd_boot_game).toString();
const QString dir_path = QFileDialog::getExistingDirectory(this, tr("Select Game Folder"), path_last_game, QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
if (dir_path.isEmpty())
{
if (stopped)
{
Emu.Resume();
}
return;
}
m_gui_settings->SetValue(gui::fd_boot_game, QFileInfo(dir_path).path());
gui_log.notice("Booting from BootGame...");
Boot(sstr(dir_path));
}
void main_window::BootRsxCapture(std::string path)
{
if (path.empty())
{
bool is_stopped = false;
if (Emu.IsRunning())
{
Emu.Pause();
is_stopped = true;
}
const QString file_path = QFileDialog::getOpenFileName(this, tr("Select RSX Capture"), qstr(fs::get_config_dir() + "captures/"), tr("RRC files (*.rrc);;All files (*.*)"));
if (file_path.isEmpty())
{
if (is_stopped)
{
Emu.Resume();
}
return;
}
path = sstr(file_path);
}
if (!m_gui_settings->GetBootConfirmation(this))
{
return;
}
Emu.SetForceBoot(true);
Emu.Stop();
if (!Emu.BootRsxCapture(path))
{
gui_log.error("Capture Boot Failed. path: %s", path);
}
else
{
gui_log.success("Capture Boot Success. path: %s", path);
}
}
bool main_window::InstallRapFile(const QString& path, const std::string& filename)
{
if (path.isEmpty() || filename.empty())
{
return false;
}
// Copy file atomically with thread/process-safe error checking for file size
fs::pending_file to(Emulator::GetHddDir() + "/home/" + Emu.GetUsr() + "/exdata/" + filename.substr(0, filename.find_last_of('.')) + ".rap");
fs::file from(sstr(path));
if (!to.file || !from)
{
return false;
}
to.file.write(from.to_vector<u8>());
if (to.file.size() < 0x10)
{
// Not a RAP file
return false;
}
return to.commit();
}
void main_window::InstallPackages(QStringList file_paths)
{
if (file_paths.isEmpty())
{
// If this function was called without a path, ask the user for files to install.
const QString path_last_pkg = m_gui_settings->GetValue(gui::fd_install_pkg).toString();
const QStringList paths = QFileDialog::getOpenFileNames(this, tr("Select packages and/or rap files to install"),
path_last_pkg, tr("All relevant (*.pkg *.rap);;Package files (*.pkg);;Rap files (*.rap);;All files (*.*)"));
if (paths.isEmpty())
{
return;
}
file_paths.append(paths);
const QFileInfo file_info(file_paths[0]);
m_gui_settings->SetValue(gui::fd_install_pkg, file_info.path());
}
else if (file_paths.count() == 1)
{
// This can currently only happen by drag and drop.
const QString file_path = file_paths.front();
const QFileInfo file_info(file_path);
compat::package_info info = game_compatibility::GetPkgInfo(file_path, m_game_list_frame ? m_game_list_frame->GetGameCompatibility() : nullptr);
if (info.type != compat::package_type::other)
{
if (info.type == compat::package_type::dlc)
{
info.local_cat = tr("\nDLC", "Block for package type (DLC)");
}
else
{
info.local_cat = tr("\nUpdate", "Block for package type (Update)");
}
}
else if (!info.local_cat.isEmpty())
{
info.local_cat = tr("\n%0", "Block for package type").arg(info.local_cat);
}
if (!info.title_id.isEmpty())
{
info.title_id = tr("\n%0", "Block for Title ID").arg(info.title_id);
}
if (!info.version.isEmpty())
{
info.version = tr("\nVersion %0", "Block for Version").arg(info.version);
}
if (!info.changelog.isEmpty())
{
info.changelog = tr("\n\nChangelog:\n%0", "Block for Changelog").arg(info.changelog);
}
if (QMessageBox::question(this, tr("PKG Decrypter / Installer"), tr("Do you want to install this package?\n\n%0\n\n%1%2%3%4%5")
.arg(file_info.fileName()).arg(info.title).arg(info.local_cat).arg(info.title_id).arg(info.version).arg(info.changelog),
QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::Yes)
{
gui_log.notice("PKG: Cancelled installation from drop. File: %s", sstr(file_paths.front()));
return;
}
}
// Install rap files if available
for (const auto& rap : file_paths.filter(QRegExp(".*\\.rap", Qt::CaseInsensitive)))
{
const QFileInfo file_info(rap);
const std::string rapname = sstr(file_info.fileName());
if (InstallRapFile(rap, rapname))
{
gui_log.success("Successfully copied rap file: %s", rapname);
}
else
{
gui_log.error("Could not copy rap file: %s", rapname);
}
}
// Find remaining package files
file_paths = file_paths.filter(QRegExp(".*\\.pkg", Qt::CaseInsensitive));
if (!file_paths.isEmpty())
{
// Handle further installations with a timeout. Otherwise the source explorer instance is not usable during the following file processing.
QTimer::singleShot(0, [this, paths = std::move(file_paths)]()
{
HandlePackageInstallation(paths);
});
}
}
void main_window::HandlePackageInstallation(QStringList file_paths)
{
std::vector<compat::package_info> packages;
game_compatibility* compat = m_game_list_frame ? m_game_list_frame->GetGameCompatibility() : nullptr;
if (file_paths.size() > 1)
{
// Let the user choose the packages to install and select the order in which they shall be installed.
pkg_install_dialog dlg(file_paths, compat, this);
connect(&dlg, &QDialog::accepted, this, [&packages, &dlg]()
{
packages = dlg.GetPathsToInstall();
});
dlg.exec();
}
else
{
packages.push_back(game_compatibility::GetPkgInfo(file_paths.front(), compat));
}
if (packages.empty())
{
return;
}
if (!m_gui_settings->GetBootConfirmation(this))
{
return;
}
progress_dialog pdlg(tr("RPCS3 Package Installer"), tr("Installing package, please wait..."), tr("Cancel"), 0, 1000, false, this);
pdlg.setAutoClose(false);
pdlg.show();
// Synchronization variable
atomic_t<double> progress(0.);
package_error error = package_error::no_error;
bool cancelled = false;
for (size_t i = 0, count = packages.size(); i < count; i++)
{
progress = 0.;
const compat::package_info& package = packages.at(i);
QString app_info = package.title; // This should always be non-empty
if (!package.title_id.isEmpty() || !package.version.isEmpty())
{
app_info += QStringLiteral("\n");
if (!package.title_id.isEmpty())
{
app_info += package.title_id;
}
if (!package.version.isEmpty())
{
if (!package.title_id.isEmpty())
{
app_info += " ";
}
app_info += tr("v.%0", "Package version for install progress dialog").arg(package.version);
}
}
pdlg.SetValue(0);
pdlg.setLabelText(tr("Installing package (%0/%1), please wait...\n\n%2").arg(i + 1).arg(count).arg(app_info));
pdlg.show();
Emu.SetForceBoot(true);
Emu.Stop();
const QFileInfo file_info(package.path);
const std::string path = sstr(package.path);
const std::string file_name = sstr(file_info.fileName());
// Run PKG unpacking asynchronously
named_thread worker("PKG Installer", [path, &progress, &error]
{
package_reader reader(path);
error = reader.check_target_app_version();
if (error == package_error::no_error)
{
return reader.extract_data(progress);
}
return false;
});
// Wait for the completion
while (std::this_thread::sleep_for(5ms), worker <= thread_state::aborting)
{
if (pdlg.wasCanceled())
{
cancelled = true;
progress -= 1.;
break;
}
// Update progress window
double pval = progress;
if (pval < 0.) pval += 1.;
pdlg.SetValue(static_cast<int>(pval * pdlg.maximum()));
QCoreApplication::processEvents();
}
if (worker())
{
pdlg.SetValue(pdlg.maximum());
std::this_thread::sleep_for(100ms);
}
else
{
pdlg.setHidden(true);
pdlg.SignalFailure();
}
if (worker())
{
m_game_list_frame->Refresh(true);
gui_log.success("Successfully installed %s (title_id=%s, title=%s, version=%s).", file_name, sstr(package.title_id), sstr(package.title), sstr(package.version));
if (i == (count - 1))
{
m_gui_settings->ShowInfoBox(tr("Success!"), tr("Successfully installed software from package(s)!"), gui::ib_pkg_success, this);
}
}
else
{
if (!cancelled)
{
if (error == package_error::app_version)
{
gui_log.error("Cannot install %s.", file_name);
QMessageBox::warning(this, tr("Warning!"), tr("The following package cannot be installed on top of the current data:\n%1!").arg(package.path));
}
else
{
gui_log.error("Failed to install %s.", file_name);
QMessageBox::critical(this, tr("Failure!"), tr("Failed to install software from package:\n%1!").arg(package.path));
}
}
return;
}
// return if the thread was still running after cancel
if (cancelled)
{
return;
}
}
}
void main_window::ExtractMSELF()
{
const QString path_last_mself = m_gui_settings->GetValue(gui::fd_ext_mself).toString();
QString file_path = QFileDialog::getOpenFileName(this, tr("Select MSELF To extract"), path_last_mself, tr("All mself files (*.mself);;All files (*.*)"));
if (file_path.isEmpty())
{
return;
}
QString dir = QFileDialog::getExistingDirectory(this, tr("Extraction Directory"), QString{}, QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
if (!dir.isEmpty())
{
m_gui_settings->SetValue(gui::fd_ext_mself, QFileInfo(file_path).path());
extract_mself(sstr(file_path), sstr(dir) + '/');
}
}
void main_window::InstallPup(QString file_path)
{
if (file_path.isEmpty())
{
const QString path_last_pup = m_gui_settings->GetValue(gui::fd_install_pup).toString();
file_path = QFileDialog::getOpenFileName(this, tr("Select PS3UPDAT.PUP To Install"), path_last_pup, tr("PS3 update file (PS3UPDAT.PUP);;All pup files (*.pup);;All files (*.*)"));
}
else
{
if (QMessageBox::question(this, tr("RPCS3 Firmware Installer"), tr("Install firmware: %1?").arg(file_path),
QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::Yes)
{
gui_log.notice("Firmware: Cancelled installation from drop. File: %s", sstr(file_path));
return;
}
}
if (!file_path.isEmpty())
{
// Handle the actual installation with a timeout. Otherwise the source explorer instance is not usable during the following file processing.
QTimer::singleShot(0, [this, file_path]()
{
HandlePupInstallation(file_path);
});
}
}
void main_window::HandlePupInstallation(QString file_path)
{
if (file_path.isEmpty())
{
return;
}
if (!m_gui_settings->GetBootConfirmation(this))
{
return;
}
Emu.SetForceBoot(true);
Emu.Stop();
m_gui_settings->SetValue(gui::fd_install_pup, QFileInfo(file_path).path());
const std::string path = sstr(file_path);
auto critical = [this](QString str)
{
Emu.CallAfter([this, str = std::move(str)]()
{
QMessageBox::critical(this, tr("Firmware Installation Failed"), str);
}, false);
};
fs::file pup_f(path);
if (!pup_f)
{
gui_log.error("Error opening PUP file %s", path);
critical(tr("Firmware installation failed: The selected firmware file couldn't be opened."));
return;
}
if (pup_f.size() < sizeof(PUPHeader))
{
gui_log.error("Too small PUP file: %llu", pup_f.size());
critical(tr("Firmware installation failed: The provided file is empty."));
return;
}
struct PUPHeader header = {};
pup_f.seek(0);
pup_f.read(header);
if (header.header_length + header.data_length != pup_f.size())
{
gui_log.error("Firmware size mismatch, expected: %llu + %llu, actual: %llu", header.header_length, header.data_length, pup_f.size());
critical(tr("Firmware installation failed: The provided file is incomplete. Try redownloading it."));
return;
}
pup_object pup(pup_f);
if (!pup)
{
gui_log.error("Error while installing firmware: PUP file is invalid.");
critical(tr("Firmware installation failed: The provided file is corrupted."));
return;
}
if (!pup.validate_hashes())
{
gui_log.error("Error while installing firmware: Hash check failed.");
critical(tr("Firmware installation failed: The provided file's contents are corrupted."));
return;
}
fs::file update_files_f = pup.get_file(0x300);
tar_object update_files(update_files_f);
auto update_filenames = update_files.get_filenames();
update_filenames.erase(std::remove_if(
update_filenames.begin(), update_filenames.end(), [](std::string s) { return s.find("dev_flash_") == umax; }),
update_filenames.end());
std::string version_string = pup.get_file(0x100).to_string();
if (const usz version_pos = version_string.find('\n'); version_pos != umax)
{
version_string.erase(version_pos);
}
const std::string cur_version = "4.87";
if (version_string < cur_version &&
QMessageBox::question(this, tr("RPCS3 Firmware Installer"), tr("Old firmware detected.\nThe newest firmware version is %1 and you are trying to install version %2\nContinue installation?").arg(qstr(cur_version), qstr(version_string)),
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes) == QMessageBox::No)
{
return;
}
if (std::string installed = utils::get_firmware_version(); !installed.empty())
{
gui_log.warning("Reinstalling firmware: old=%s, new=%s", installed, version_string);
if (QMessageBox::question(this, tr("RPCS3 Firmware Installer"), tr("Firmware of version %1 has already been installed.\nOverwrite current installation with version %2?").arg(qstr(installed), qstr(version_string)),
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes) == QMessageBox::No)
{
gui_log.warning("Reinstallation of firmware aborted.");
return;
}
}
// Remove possibly PS3 fonts from database
QFontDatabase::removeAllApplicationFonts();
progress_dialog pdlg(tr("RPCS3 Firmware Installer"), tr("Installing firmware version %1\nPlease wait...").arg(qstr(version_string)), tr("Cancel"), 0, static_cast<int>(update_filenames.size()), false, this);
pdlg.show();
// Synchronization variable
atomic_t<uint> progress(0);
{
// Run asynchronously
named_thread worker("Firmware Installer", [&]
{
for (const auto& update_filename : update_filenames)
{
fs::file update_file = update_files.get_file(update_filename);
SCEDecrypter self_dec(update_file);
self_dec.LoadHeaders();
self_dec.LoadMetadata(SCEPKG_ERK, SCEPKG_RIV);
self_dec.DecryptData();
auto dev_flash_tar_f = self_dec.MakeFile();
if (dev_flash_tar_f.size() < 3)
{
gui_log.error("Error while installing firmware: PUP contents are invalid.");
critical(tr("Firmware installation failed: Firmware could not be decompressed"));
progress = -1;
return;
}
tar_object dev_flash_tar(dev_flash_tar_f[2]);
if (!dev_flash_tar.extract(g_cfg.vfs.get_dev_flash(), "dev_flash/"))
{
gui_log.error("Error while installing firmware: TAR contents are invalid.");
critical(tr("Firmware installation failed: Firmware contents could not be extracted."));
progress = -1;
return;
}
if (!progress.try_inc(::narrow<uint>(update_filenames.size())))
{
// Installation was cancelled
return;
}
}
});
// Wait for the completion
for (uint value = progress.load(); value < update_filenames.size(); std::this_thread::sleep_for(5ms), value = progress)
{
if (pdlg.wasCanceled())
{
progress = -1;
break;
}
// Update progress window
pdlg.SetValue(static_cast<int>(value));
QCoreApplication::processEvents();