-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
main_window.cpp
3423 lines (2855 loc) · 101 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_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 "infinity_dialog.h"
#include "cheat_manager.h"
#include "patch_manager_dialog.h"
#include "patch_creator_dialog.h"
#include "pkg_install_dialog.h"
#include "category.h"
#include "gui_settings.h"
#include "input_dialog.h"
#include "camera_settings_dialog.h"
#include "ipc_settings_dialog.h"
#include "shortcut_utils.h"
#include "config_checker.h"
#include "shortcut_dialog.h"
#include "system_cmd_dialog.h"
#include "emulated_pad_settings_dialog.h"
#include "welcome_dialog.h"
#include <thread>
#include <charconv>
#include <QScreen>
#include <QDirIterator>
#include <QMimeData>
#include <QMessageBox>
#include <QFileDialog>
#include <QFontDatabase>
#include <QBuffer>
#include <QTemporaryFile>
#include "rpcs3_version.h"
#include "Emu/IdManager.h"
#include "Emu/VFS.h"
#include "Emu/vfs_config.h"
#include "Emu/System.h"
#include "Emu/system_utils.hpp"
#include "Crypto/unpkg.h"
#include "Crypto/unself.h"
#include "Crypto/decrypt_binaries.h"
#include "Loader/PUP.h"
#include "Loader/TAR.h"
#include "Loader/PSF.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;
class CPUDisAsm;
std::shared_ptr<CPUDisAsm> make_basic_ppu_disasm();
inline std::string sstr(const QString& _in) { return _in.toStdString(); }
extern void process_qt_events()
{
if (thread_ctrl::is_main())
{
// NOTE:
// I noticed that calling this from an Emu callback can cause the
// caller to get stuck for a while during newly opened Qt dialogs.
// Adding a timeout here doesn't seem to do anything in that case.
QApplication::processEvents();
}
}
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(std::move(emu_settings))
, m_persistent_settings(std::move(persistent_settings))
, m_updater(nullptr, gui_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()
{
}
/* 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([[maybe_unused]] bool with_cli_boot)
{
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_verbose_version()));
Q_EMIT RequestGlobalStylesheetChange();
ConfigureGuiFromSettings();
m_shortcut_handler = new shortcut_handler(gui::shortcuts::shortcut_handler_id::main_window, this, m_gui_settings);
connect(m_shortcut_handler, &shortcut_handler::shortcut_activated, this, &main_window::handle_shortcut);
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"));
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, []()
{
gui_log.notice("User clicked stop button on thumbnail toolbar");
Emu.GracefulShutdown(false, true);
});
connect(m_thumb_restart, &QWinThumbnailToolButton::clicked, this, []()
{
gui_log.notice("User clicked restart button on thumbnail toolbar");
Emu.Restart();
});
connect(m_thumb_playPause, &QWinThumbnailToolButton::clicked, this, &main_window::OnPlayOrPause);
#endif
// 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(false);
});
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 != gui::update_off)
{
const bool in_background = with_cli_boot || update_value == gui::update_bkg;
const bool auto_accept = !in_background && update_value == gui::update_auto;
m_updater.check_for_updates(true, in_background, auto_accept, this);
}
#endif
// Disable vsh if not present.
ui->bootVSHAct->setEnabled(fs::is_file(g_cfg_vfs.get_dev_flash() + "vsh/module/vsh.self"));
// Focus to search bar by default
ui->mw_searchbar->setFocus();
// Refresh gamelist last
m_game_list_frame->Refresh(true);
return true;
}
QString main_window::GetCurrentTitle()
{
QString title = qstr(Emu.GetTitleAndTitleID());
if (title.isEmpty())
{
title = qstr(Emu.GetLastBoot());
}
return title;
}
// returns appIcon
QIcon main_window::GetAppIcon() const
{
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 %0 href=\"https://rpcs3.net/quickstart\">quickstart guide</a>.").arg(gui::utils::get_link_style());
QMessageBox mb(QMessageBox::Question, title, message, QMessageBox::Ok | QMessageBox::Cancel, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint | Qt::WindowStaysOnTopHint);
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::handle_shortcut(gui::shortcuts::shortcut shortcut_key, const QKeySequence& key_sequence)
{
gui_log.notice("Main window registered shortcut: %s (%s)", shortcut_key, key_sequence.toString());
const system_state status = Emu.GetStatus();
switch (shortcut_key)
{
case gui::shortcuts::shortcut::mw_welcome_dialog:
{
welcome_dialog* welcome = new welcome_dialog(m_gui_settings, true, this);
welcome->open();
break;
}
case gui::shortcuts::shortcut::mw_toggle_fullscreen:
{
ui->toolbar_fullscreen->trigger();
break;
}
case gui::shortcuts::shortcut::mw_exit_fullscreen:
{
if (isFullScreen())
ui->toolbar_fullscreen->trigger();
break;
}
case gui::shortcuts::shortcut::mw_refresh:
{
m_game_list_frame->Refresh(true);
break;
}
case gui::shortcuts::shortcut::mw_pause:
{
if (status == system_state::running)
Emu.Pause();
break;
}
case gui::shortcuts::shortcut::mw_start:
{
if (status == system_state::paused)
Emu.Resume();
else if (status == system_state::ready)
Emu.Run(true);
break;
}
case gui::shortcuts::shortcut::mw_restart:
{
if (!Emu.GetBoot().empty())
Emu.Restart();
break;
}
case gui::shortcuts::shortcut::mw_stop:
{
if (status != system_state::stopped)
Emu.GracefulShutdown(false, true);
break;
}
default:
{
break;
}
}
}
void main_window::OnPlayOrPause()
{
gui_log.notice("User triggered OnPlayOrPause");
switch (Emu.GetStatus())
{
case system_state::ready: Emu.Run(true); return;
case system_state::paused: Emu.Resume(); return;
case system_state::running: Emu.Pause(); return;
case system_state::stopped:
{
if (m_selected_game)
{
gui_log.notice("Booting from OnPlayOrPause...");
Boot(m_selected_game->info.path, m_selected_game->info.serial);
}
else if (const std::string path = Emu.GetLastBoot(); !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());
}
return;
}
case system_state::starting: break;
default: fmt::throw_exception("Unreachable");
}
}
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::invalid_bdvd_folder:
message = tr("The virtual dev_bdvd folder does not exist or is not empty.");
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::unsupported_disc_type:
message = tr("This disc type is not supported yet.");
break;
case game_boot_result::savestate_corrupted:
message = tr("Savestate data is corrupted or it's not an RPCS3 savestate.");
break;
case game_boot_result::savestate_version_unsupported:
message = tr("Savestate versioning data differes from your RPCS3 build.");
break;
case game_boot_result::still_running:
message = tr("A game or PS3 application is still running or has yet to be fully stopped.");
break;
case game_boot_result::firmware_missing: // Handled elsewhere
case game_boot_result::no_errors:
return;
case game_boot_result::generic_error:
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 %0 href=\"https://rpcs3.net/quickstart\">quickstart guide</a>.").arg(gui::utils::get_link_style());
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 refresh_list, cfg_mode config_mode, const std::string& config_path)
{
if (!m_gui_settings->GetBootConfirmation(this, gui::ib_confirm_boot))
{
return;
}
Emu.GracefulShutdown(false);
m_app_icon = gui::utils::get_app_icon_from_path(path, title_id);
if (const auto error = Emu.BootGame(path, title_id, direct, config_mode, config_path); 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.");
AddRecentAction(gui::Recent_Game(qstr(Emu.GetBoot()), qstr(Emu.GetTitleAndTitleID())));
if (refresh_list)
{
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, true);
}
void main_window::BootTest()
{
bool stopped = false;
if (Emu.IsRunning())
{
Emu.Pause();
stopped = true;
}
#ifdef _WIN32
const QString path_tests = QString::fromStdString(fs::get_config_dir()) + "/test/";
#elif defined(__linux__)
const QString path_tests = QCoreApplication::applicationDirPath() + "/../share/rpcs3/test/";
#else
const QString path_tests = QCoreApplication::applicationDirPath() + "/../Resources/test/";
#endif
const QString file_path = QFileDialog::getOpenFileName(this, tr("Select (S)ELF To Boot"), path_tests, tr(
"(S)ELF files (*.elf *.self);;"
"ELF files (*.elf);;"
"SELF files (*.self);;"
"All files (*.*)"),
Q_NULLPTR, QFileDialog::DontResolveSymlinks);
if (file_path.isEmpty())
{
if (stopped)
{
Emu.Resume();
}
return;
}
const std::string path = sstr(QFileInfo(file_path).absoluteFilePath());
gui_log.notice("Booting from BootTest...");
Boot(path, "", true);
}
void main_window::BootSavestate()
{
bool stopped = false;
if (Emu.IsRunning())
{
Emu.Pause();
stopped = true;
}
const QString file_path = QFileDialog::getOpenFileName(this, tr("Select Savestate To Boot"), qstr(fs::get_cache_dir() + "/savestates/"), tr(
"Savestate files (*.SAVESTAT);;"
"All files (*.*)"),
Q_NULLPTR, QFileDialog::DontResolveSymlinks);
if (file_path.isEmpty())
{
if (stopped)
{
Emu.Resume();
}
return;
}
const std::string path = sstr(QFileInfo(file_path).absoluteFilePath());
gui_log.notice("Booting from BootSavestate...");
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), "", false, true);
}
void main_window::BootVSH()
{
gui_log.notice("Booting from BootVSH...");
Boot(g_cfg_vfs.get_dev_flash() + "/vsh/module/vsh.self");
}
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 *.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.GracefulShutdown(false);
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::InstallFileInExData(const std::string& extension, const QString& path, const std::string& filename)
{
if (path.isEmpty() || filename.empty() || extension.empty())
{
return false;
}
// Copy file atomically with thread/process-safe error checking for file size
const std::string to_path = rpcs3::utils::get_hdd0_dir() + "/home/" + Emu.GetUsr() + "/exdata/" + filename.substr(0, filename.find_last_of('.'));
fs::pending_file to(to_path + "." + extension);
fs::file from(sstr(path));
if (!to.file || !from)
{
return false;
}
to.file.write(from.to_vector<u8>());
from.close();
if (to.file.size() < 0x10)
{
// Not a RAP file
return false;
}
#ifdef _WIN32
// In the case of an unexpected crash during the operation, the temporary file can be used as the deleted file
// See below
to.file.sync();
// In case we want to rename upper-case file to lower-case
// Windows will ignore such rename operation if the file exists
// So delete it
fs::remove_file(to_path + "." + fmt::to_upper(extension));
#endif
return to.commit();
}
bool main_window::InstallPackages(QStringList file_paths, bool from_boot)
{
if (file_paths.isEmpty())
{
ensure(!from_boot);
// 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 *.PKG *.rap *.RAP *.edat *.EDAT);;Package files (*.pkg *.PKG);;Rap files (*.rap *.RAP);;Edat files (*.edat *.EDAT);;All files (*.*)"));
if (paths.isEmpty())
{
return true;
}
file_paths.append(paths);
const QFileInfo file_info(file_paths[0]);
m_gui_settings->SetValue(gui::fd_install_pkg, file_info.path());
}
if (file_paths.count() == 1 && file_paths.front().endsWith(".pkg", Qt::CaseInsensitive))
{
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.is_valid)
{
QMessageBox::warning(this, tr("Invalid package!"), tr("The selected package is invalid!\n\nPath:\n%0").arg(file_path));
return false;
}
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("Changelog:\n%0", "Block for Changelog").arg(info.changelog);
}
const QString info_string = QStringLiteral("%0\n\n%1%2%3%4").arg(file_info.fileName()).arg(info.title).arg(info.local_cat).arg(info.title_id).arg(info.version);
QString message = tr("Do you want to install this package?\n\n%0").arg(info_string);
QMessageBox mb(QMessageBox::Icon::Question, tr("PKG Decrypter / Installer"), message, QMessageBox::Yes | QMessageBox::No, this);
mb.setDefaultButton(QMessageBox::No);
if (!info.changelog.isEmpty())
{
mb.setInformativeText(tr("To see the changelog, please click \"Show Details\"."));
mb.setDetailedText(tr("%0").arg(info.changelog));
// Smartass hack to make the unresizeable message box wide enough for the changelog
const int log_width = QLabel(info.changelog).sizeHint().width();
while (QLabel(message).sizeHint().width() < log_width)
{
message += " ";
}
mb.setText(message);
}
if (mb.exec() != QMessageBox::Yes)
{
gui_log.notice("PKG: Cancelled installation from drop.\n%s\n%s", info_string, info.changelog);
return true;
}
}
// Install rap files if available
int installed_rap_and_edat_count = 0;
const auto install_filetype = [&installed_rap_and_edat_count, &file_paths](const std::string extension)
{
const QString pattern = QString(".*\\.%1").arg(QString::fromStdString(extension));
for (const auto& file : file_paths.filter(QRegularExpression(pattern, QRegularExpression::PatternOption::CaseInsensitiveOption)))
{
const QFileInfo file_info(file);
const std::string filename = sstr(file_info.fileName());
if (InstallFileInExData(extension, file, filename))
{
gui_log.success("Successfully copied %s file: %s", extension, filename);
installed_rap_and_edat_count++;
}
else
{
gui_log.error("Could not copy %s file: %s", extension, filename);
}
}
};
if (!from_boot)
{
if (!m_gui_settings->GetBootConfirmation(this))
{
// Last chance to cancel the operation
return true;
}
if (!Emu.IsStopped())
{
Emu.GracefulShutdown(false);
}
install_filetype("rap");
install_filetype("edat");
}
if (installed_rap_and_edat_count > 0)
{
// Refresh game list since we probably unlocked some games now.
m_game_list_frame->Refresh(true);
}
// Find remaining package files
file_paths = file_paths.filter(QRegularExpression(".*\\.pkg", QRegularExpression::PatternOption::CaseInsensitiveOption));
if (file_paths.isEmpty())
{
return true;
}
if (from_boot)
{
return HandlePackageInstallation(file_paths, true);
}
// 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, false);
});
return true;
}
bool main_window::HandlePackageInstallation(QStringList file_paths, bool from_boot)
{
if (file_paths.empty())
{
return false;
}
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 true;
}
if (!from_boot)
{
if (!m_gui_settings->GetBootConfirmation(this))
{
return true;
}
Emu.GracefulShutdown(false);
}
std::vector<std::string> path_vec;
for (const compat::package_info& pkg : packages)
{
path_vec.push_back(pkg.path.toStdString());
}
gui_log.notice("About to install packages:\n%s", fmt::merge(path_vec, "\n"));
progress_dialog pdlg(tr("RPCS3 Package Installer"), tr("Installing package, please wait..."), tr("Cancel"), 0, 1000, false, this);
pdlg.setAutoClose(false);
pdlg.show();
package_error error = package_error::no_error;
auto get_app_info = [](compat::package_info& package)
{
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);
}
}
return app_info;
};
bool cancelled = false;
std::deque<package_reader> readers;
for (const compat::package_info& info : packages)
{
readers.emplace_back(sstr(info.path));
}
std::deque<std::string> bootable_paths;
// Run PKG unpacking asynchronously
named_thread worker("PKG Installer", [&readers, &error, &bootable_paths]
{
error = package_reader::extract_data(readers, bootable_paths);
return error == package_error::no_error;
});
pdlg.show();
// Wait for the completion
for (usz i = 0, set_text = umax; i < readers.size() && error == package_error::no_error;)
{
std::this_thread::sleep_for(5ms);
if (pdlg.wasCanceled())
{
cancelled = true;
for (package_reader& reader : readers)
{
reader.abort_extract();
}
break;
}
// Update progress window