forked from RPCS3/rpcs3
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_window.cpp
1930 lines (1631 loc) · 56.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 <QApplication>
#include <QMenuBar>
#include <QMessageBox>
#include <QFileDialog>
#include <QVBoxLayout>
#include <QDockWidget>
#include <QDesktopWidget>
#include <QMimeData>
#ifdef WITH_DISCORD_RPC
#include "_discord_utils.h"
#endif
#include "qt_utils.h"
#include "vfs_dialog.h"
#include "save_manager_dialog.h"
#include "trophy_manager_dialog.h"
#include "user_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 "auto_pause_settings_dialog.h"
#include "cg_disasm_window.h"
#include "memory_string_searcher.h"
#include "memory_viewer_panel.h"
#include "rsx_debugger.h"
#include "main_window.h"
#include "emu_settings.h"
#include "about_dialog.h"
#include "pad_settings_dialog.h"
#include "progress_dialog.h"
#include <thread>
#include "stdafx.h"
#include "Emu/System.h"
#include "Emu/Memory/vm.h"
#include "Crypto/unpkg.h"
#include "Crypto/unself.h"
#include "Loader/PUP.h"
#include "Loader/TAR.h"
#include "Loader/PSF.h"
#include "Utilities/Thread.h"
#include "Utilities/StrUtil.h"
#include "rpcs3_version.h"
#include "Utilities/sysinfo.h"
#include "ui_main_window.h"
inline std::string sstr(const QString& _in) { return _in.toStdString(); }
main_window::main_window(std::shared_ptr<gui_settings> guiSettings, std::shared_ptr<emu_settings> emuSettings, QWidget *parent)
: QMainWindow(parent), guiSettings(guiSettings), emuSettings(emuSettings), m_sys_menu_opened(false), ui(new Ui::main_window)
{
}
main_window::~main_window()
{
delete ui;
#ifdef WITH_DISCORD_RPC
discord::shutdown();
#endif
}
/* An init method is used so that RPCS3App can create the necessary connects before calling init (specifically the stylesheet connect).
* Simplifies logic a bit.
*/
void main_window::Init()
{
Q_INIT_RESOURCE(resources);
ui->setupUi(this);
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::version.to_string()));
Q_EMIT RequestGlobalStylesheetChange(guiSettings->GetCurrentStylesheetPath());
ConfigureGuiFromSettings(true);
#ifdef BRANCH
if ("RPCS3/rpcs3/master"s != STRINGIZE(BRANCH) && ""s != STRINGIZE(BRANCH))
#else
if (false)
#endif
{
LOG_WARNING(GENERAL, "Experimental Build Warning! Build origin: " STRINGIZE(BRANCH));
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(STRINGIZE(BRANCH))));
msg.layout()->setSizeConstraint(QLayout::SetFixedSize);
if (msg.exec() == QMessageBox::No)
{
std::exit(EXIT_SUCCESS);
}
}
show(); // needs to be done before creating the thumbnail toolbar
// enable play options if a recent game exists
const bool enable_play_last = !m_recentGameActs.isEmpty();
if (enable_play_last)
{
ui->sysPauseAct->setEnabled(true);
ui->sysPauseAct->setText(tr("&Start last played game\tCtrl+E"));
ui->sysPauseAct->setIcon(m_icon_play);
ui->toolbar_start->setToolTip(tr("Start last played game"));
ui->toolbar_start->setEnabled(true);
}
// 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(enable_play_last ? tr("Start last played game") : tr("Start emulation"));
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, [=]() { Emu.Stop(); });
connect(m_thumb_restart, &QWinThumbnailToolButton::clicked, [=]() { 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_gameListFrame->FixNarrowColumns();
}
// returns appIcon
QIcon main_window::GetAppIcon()
{
return m_appIcon;
}
// loads the appIcon from path and embeds it centered into an empty square icon
void main_window::SetAppIconFromPath(const std::string& path)
{
// get Icon for the gs_frame from path. this handles presumably all possible use cases
QString qpath = qstr(path);
std::string path_list[] = { path, sstr(qpath.section("/", 0, -2)), sstr(qpath.section("/", 0, -3)) };
for (std::string pth : path_list)
{
if (!fs::is_dir(pth)) continue;
const std::string sfo_dir = Emu.GetSfoDirFromGamePath(pth, Emu.GetUsr());
const std::string ico = sfo_dir + "/ICON0.PNG";
if (fs::is_file(ico))
{
// load the image from path. It will most likely be a rectangle
QImage source = QImage(qstr(ico));
int edgeMax = std::max(source.width(), source.height());
// create a new transparent image with square size and same format as source (maybe handle other formats than RGB32 as well?)
QImage::Format format = source.format() == QImage::Format_RGB32 ? QImage::Format_ARGB32 : source.format();
QImage dest = QImage(edgeMax, edgeMax, format);
dest.fill(QColor("transparent"));
// get the location to draw the source image centered within the dest image.
QPoint destPos = source.width() > source.height() ? QPoint(0, (source.width() - source.height()) / 2) : QPoint((source.height() - source.width()) / 2, 0);
// Paint the source into/over the dest
QPainter painter(&dest);
painter.drawImage(destPos, source);
painter.end();
// set Icon
m_appIcon = QIcon(QPixmap::fromImage(dest));
return;
}
}
// if nothing was found reset the icon to default
m_appIcon = QApplication::windowIcon();
}
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;
guiSettings->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_gameListFrame->ResizeIcons(index);
}
void main_window::OnPlayOrPause()
{
if (Emu.IsReady())
{
Emu.Run();
}
else if (Emu.IsPaused())
{
Emu.Resume();
}
else if (Emu.IsRunning())
{
Emu.Pause();
}
else if (!Emu.GetBoot().empty())
{
Emu.Load();
}
else if (Emu.IsStopped() && !m_recentGameActs.isEmpty())
{
BootRecentAction(m_recentGameActs.first());
}
}
void main_window::Boot(const std::string& path, bool direct, bool add_only, bool force_global_config)
{
if (!Emu.IsStopped())
{
int result;
guiSettings->ShowConfirmationBox(tr("Close Running Game?"),
tr("Booting another game will close the current game.\nDo you really want to boot another game?\n\nAny unsaved progress will be lost!\n"),
gui::ib_confirm_boot, &result, this);
if (result != QMessageBox::Yes)
{
return;
}
}
SetAppIconFromPath(path);
Emu.SetForceBoot(true);
Emu.Stop();
if (Emu.BootGame(path, direct, add_only, force_global_config))
{
LOG_SUCCESS(LOADER, "Boot successful.");
const std::string serial = Emu.GetTitleID().empty() ? "" : "[" + Emu.GetTitleID() + "] ";
AddRecentAction(gui::Recent_Game(qstr(Emu.GetBoot()), qstr(serial + Emu.GetTitle())));
}
else
{
LOG_ERROR(GENERAL, "Boot failed: %s", path);
}
m_gameListFrame->Refresh(true);
}
void main_window::BootElf()
{
bool stopped = false;
if (Emu.IsRunning())
{
Emu.Pause();
stopped = true;
}
QString path_last_ELF = guiSettings->GetValue(gui::fd_boot_elf).toString();
QString filePath = 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 (filePath == NULL)
{
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
guiSettings->SetValue(gui::fd_boot_elf, filePath);
const std::string path = sstr(QFileInfo(filePath).canonicalFilePath());
LOG_NOTICE(LOADER, "Booting from BootElf...");
Boot(path, true);
}
void main_window::BootGame()
{
bool stopped = false;
if (Emu.IsRunning())
{
Emu.Pause();
stopped = true;
}
QString path_last_Game = guiSettings->GetValue(gui::fd_boot_game).toString();
QString dirPath = QFileDialog::getExistingDirectory(this, tr("Select Game Folder"), path_last_Game, QFileDialog::ShowDirsOnly);
if (dirPath == NULL)
{
if (stopped) Emu.Resume();
return;
}
guiSettings->SetValue(gui::fd_boot_game, QFileInfo(dirPath).path());
const std::string path = sstr(dirPath);
LOG_NOTICE(LOADER, "Booting from BootGame...");
Boot(path);
}
void main_window::BootRsxCapture(std::string path)
{
if (path.empty())
{
bool is_stopped = false;
if (Emu.IsRunning())
{
Emu.Pause();
is_stopped = true;
}
QString filePath = QFileDialog::getOpenFileName(this, tr("Select RSX Capture"), qstr(fs::get_config_dir() + "captures/"), tr("RRC files (*.rrc);;All files (*.*)"));
if (filePath.isEmpty())
{
if (is_stopped)
{
Emu.Resume();
}
return;
}
path = sstr(filePath);
}
Emu.SetForceBoot(true);
Emu.Stop();
if (!Emu.BootRsxCapture(path))
{
LOG_ERROR(GENERAL, "Capture Boot Failed. path: %s", path);
}
else
{
LOG_SUCCESS(LOADER, "Capture Boot Success. path: %s", path);
}
}
void main_window::InstallPkg(const QString& dropPath, bool is_bulk)
{
QString filePath = dropPath;
if (m_install_bulk == QMessageBox::NoToAll)
{
LOG_NOTICE(LOADER, "PKG: Skipped installation from drop. File: %s", sstr(filePath));
return;
}
else if (m_install_bulk == QMessageBox::YesToAll)
{
LOG_NOTICE(LOADER, "PKG: Continuing bulk installation from drop. File: %s", sstr(filePath));
}
else if (filePath.isEmpty())
{
QString path_last_PKG = guiSettings->GetValue(gui::fd_install_pkg).toString();
filePath = QFileDialog::getOpenFileName(this, tr("Select PKG To Install"), path_last_PKG, tr("PKG files (*.pkg);;All files (*.*)"));
}
else if (is_bulk)
{
QMessageBox::StandardButton ret = QMessageBox::question(this, tr("PKG Decrypter / Installer"), tr("Install package: %1?").arg(filePath),
QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::NoToAll | QMessageBox::No, QMessageBox::No);
if (ret == QMessageBox::No)
{
LOG_NOTICE(LOADER, "PKG: Cancelled installation from drop. File: %s", sstr(filePath));
return;
}
else if (ret == QMessageBox::NoToAll)
{
LOG_NOTICE(LOADER, "PKG: Cancelled bulk installation from drop. File: %s", sstr(filePath));
m_install_bulk = ret;
return;
}
else if (ret == QMessageBox::YesToAll)
{
LOG_NOTICE(LOADER, "PKG: Accepted bulk installation from drop. File: %s", sstr(filePath));
m_install_bulk = ret;
}
}
else
{
if (QMessageBox::question(this, tr("PKG Decrypter / Installer"), tr("Install package: %1?").arg(filePath),
QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::Yes)
{
LOG_NOTICE(LOADER, "PKG: Cancelled installation from drop. File: %s", sstr(filePath));
return;
}
}
if (filePath.isEmpty())
{
return;
}
Emu.SetForceBoot(true);
Emu.Stop();
guiSettings->SetValue(gui::fd_install_pkg, QFileInfo(filePath).path());
const std::string fileName = sstr(QFileInfo(filePath).fileName());
const std::string path = sstr(filePath);
progress_dialog pdlg(tr("Installing package ... please wait ..."), tr("Cancel"), 0, 1000, this);
pdlg.setWindowTitle(tr("RPCS3 Package Installer"));
pdlg.setWindowModality(Qt::WindowModal);
pdlg.setFixedWidth(QLabel("This is the very length of the progressdialog due to hidpi reasons.").sizeHint().width());
pdlg.show();
// Synchronization variable
atomic_t<double> progress(0.);
// Run PKG unpacking asynchronously
named_thread worker("PKG Installer", [&]
{
return pkg_install(path, progress);
});
{
// Wait for the completion
while (std::this_thread::sleep_for(5ms), worker != thread_state::finished)
{
if (pdlg.wasCanceled())
{
progress -= 1.;
break;
}
// Update progress window
double pval = progress;
pval < 0 ? pval += 1. : pval;
pdlg.SetValue(static_cast<int>(pval * pdlg.maximum()));
QCoreApplication::processEvents();
}
if (worker())
{
pdlg.SetValue(pdlg.maximum());
std::this_thread::sleep_for(100ms);
}
}
if (worker())
{
m_gameListFrame->Refresh(true);
LOG_SUCCESS(GENERAL, "Successfully installed %s.", fileName);
guiSettings->ShowInfoBox(tr("Success!"), tr("Successfully installed software from package!"), gui::ib_pkg_success, this);
}
}
void main_window::InstallPup(const QString& dropPath)
{
QString filePath = dropPath;
if (filePath.isEmpty())
{
QString path_last_PUP = guiSettings->GetValue(gui::fd_install_pup).toString();
filePath = QFileDialog::getOpenFileName(this, tr("Select PS3UPDAT.PUP To Install"), path_last_PUP, tr("PS3 update file (PS3UPDAT.PUP)"));
}
else
{
if (QMessageBox::question(this, tr("RPCS3 Firmware Installer"), tr("Install firmware: %1?").arg(filePath),
QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::Yes)
{
LOG_NOTICE(LOADER, "Firmware: Cancelled installation from drop. File: %s", sstr(filePath));
return;
}
}
if (filePath == NULL)
{
return;
}
Emu.SetForceBoot(true);
Emu.Stop();
guiSettings->SetValue(gui::fd_install_pup, QFileInfo(filePath).path());
const std::string path = sstr(filePath);
fs::file pup_f(path);
if (!pup_f)
{
LOG_ERROR(GENERAL, "Error opening PUP file %s", path);
QMessageBox::critical(this, tr("Failure!"), tr("The selected firmware file couldn't be opened."));
return;
}
pup_object pup(pup_f);
if (!pup)
{
LOG_ERROR(GENERAL, "Error while installing firmware: PUP file is invalid.");
QMessageBox::critical(this, tr("Failure!"), tr("Error while installing firmware: PUP file is invalid."));
return;
}
fs::file update_files_f = pup.get_file(0x300);
tar_object update_files(update_files_f);
auto updatefilenames = update_files.get_filenames();
updatefilenames.erase(std::remove_if(
updatefilenames.begin(), updatefilenames.end(), [](std::string s) { return s.find("dev_flash_") == std::string::npos; }),
updatefilenames.end());
std::string version_string = pup.get_file(0x100).to_string();
size_t version_pos = version_string.find('\n');
if (version_pos != std::string::npos)
{
version_string.erase(version_pos);
}
const std::string cur_version = "4.84";
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;
}
progress_dialog pdlg(tr("Installing firmware version %1\nPlease wait...").arg(qstr(version_string)), tr("Cancel"), 0, static_cast<int>(updatefilenames.size()), this);
pdlg.setWindowTitle(tr("RPCS3 Firmware Installer"));
pdlg.setWindowModality(Qt::WindowModal);
pdlg.setFixedWidth(QLabel("This is the very length of the progressdialog due to hidpi reasons.").sizeHint().width());
pdlg.show();
// Synchronization variable
atomic_t<int> progress(0);
{
// Run asynchronously
named_thread worker("Firmware Installer", [&]
{
for (const auto& updatefilename : updatefilenames)
{
if (progress == -1) break;
fs::file updatefile = update_files.get_file(updatefilename);
SCEDecrypter self_dec(updatefile);
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)
{
LOG_ERROR(GENERAL, "Error while installing firmware: PUP contents are invalid.");
QMessageBox::critical(this, tr("Failure!"), tr("Error while installing firmware: PUP contents are invalid."));
progress = -1;
}
tar_object dev_flash_tar(dev_flash_tar_f[2]);
if (!dev_flash_tar.extract(g_cfg.vfs.get_dev_flash(), "dev_flash/"))
{
LOG_ERROR(GENERAL, "Error while installing firmware: TAR contents are invalid.");
QMessageBox::critical(this, tr("Failure!"), tr("Error while installing firmware: TAR contents are invalid."));
progress = -1;
}
if (progress >= 0)
progress += 1;
}
});
// Wait for the completion
while (std::this_thread::sleep_for(5ms), std::abs(progress) < pdlg.maximum())
{
if (pdlg.wasCanceled())
{
progress = -1;
break;
}
// Update progress window
pdlg.SetValue(static_cast<int>(progress));
QCoreApplication::processEvents();
}
update_files_f.close();
pup_f.close();
if (progress > 0)
{
pdlg.SetValue(pdlg.maximum());
std::this_thread::sleep_for(100ms);
}
}
if (progress > 0)
{
LOG_SUCCESS(GENERAL, "Successfully installed PS3 firmware version %s.", version_string);
guiSettings->ShowInfoBox(tr("Success!"), tr("Successfully installed PS3 firmware and LLE Modules!"), gui::ib_pup_success, this);
Emu.SetForceBoot(true);
Emu.BootGame(g_cfg.vfs.get_dev_flash() + "sys/external/", true);
}
}
// This is ugly, but PS3 headers shall not be included there.
extern void sysutil_send_system_cmd(u64 status, u64 param);
void main_window::DecryptSPRXLibraries()
{
QString path_last_SPRX = guiSettings->GetValue(gui::fd_decrypt_sprx).toString();
QStringList modules = QFileDialog::getOpenFileNames(this, tr("Select SPRX files"), path_last_SPRX, tr("SPRX files (*.sprx)"));
if (modules.isEmpty())
{
return;
}
Emu.SetForceBoot(true);
Emu.Stop();
guiSettings->SetValue(gui::fd_decrypt_sprx, QFileInfo(modules.first()).path());
LOG_NOTICE(GENERAL, "Decrypting SPRX libraries...");
for (const QString& module : modules)
{
std::string prx_path = sstr(module);
const std::string& prx_dir = fs::get_parent_dir(prx_path);
fs::file elf_file(prx_path);
if (elf_file && elf_file.size() >= 4 && elf_file.read<u32>() == "SCE\0"_u32)
{
const std::size_t prx_ext_pos = prx_path.find_last_of('.');
const std::string& prx_name = prx_path.substr(prx_dir.size());
elf_file = decrypt_self(std::move(elf_file));
prx_path.erase(prx_path.size() - 4, 1); // change *.sprx to *.prx
if (elf_file)
{
if (fs::file new_file{ prx_path, fs::rewrite })
{
new_file.write(elf_file.to_string());
LOG_SUCCESS(GENERAL, "Decrypted %s", prx_dir + prx_name);
}
else
{
LOG_ERROR(GENERAL, "Failed to create %s", prx_path);
}
}
else
{
LOG_ERROR(GENERAL, "Failed to decrypt %s", prx_dir + prx_name);
}
}
}
LOG_NOTICE(GENERAL, "Finished decrypting all SPRX libraries.");
}
/** Needed so that when a backup occurs of window state in guisettings, the state is current.
* Also, so that on close, the window state is preserved.
*/
void main_window::SaveWindowState()
{
// Save gui settings
guiSettings->SetValue(gui::mw_geometry, saveGeometry());
guiSettings->SetValue(gui::mw_windowState, saveState());
guiSettings->SetValue(gui::mw_mwState, m_mw->saveState());
// Save column settings
m_gameListFrame->SaveSettings();
// Save splitter state
m_debuggerFrame->SaveSettings();
}
void main_window::RepaintThumbnailIcons()
{
QColor newColor = gui::utils::get_label_color("thumbnail_icon_color");
auto icon = [&newColor](const QString& path)
{
return gui::utils::get_colorized_icon(QPixmap::fromImage(gui::utils::get_opaque_image_area(path)), Qt::black, newColor);
};
#ifdef _WIN32
if (!m_thumb_bar) return;
m_icon_thumb_play = icon(":/Icons/play.png");
m_icon_thumb_pause = icon(":/Icons/pause.png");
m_icon_thumb_stop = icon(":/Icons/stop.png");
m_icon_thumb_restart = icon(":/Icons/restart.png");
m_thumb_playPause->setIcon(Emu.IsRunning() ? m_icon_thumb_pause : m_icon_thumb_play);
m_thumb_stop->setIcon(m_icon_thumb_stop);
m_thumb_restart->setIcon(m_icon_thumb_restart);
#endif
}
void main_window::RepaintToolBarIcons()
{
QColor newColor = gui::utils::get_label_color("toolbar_icon_color");
auto icon = [&newColor](const QString& path)
{
return gui::utils::get_colorized_icon(QIcon(path), Qt::black, newColor);
};
m_icon_play = icon(":/Icons/play.png");
m_icon_pause = icon(":/Icons/pause.png");
m_icon_stop = icon(":/Icons/stop.png");
m_icon_restart = icon(":/Icons/restart.png");
m_icon_fullscreen_on = icon(":/Icons/fullscreen.png");
m_icon_fullscreen_off = icon(":/Icons/exit_fullscreen.png");
ui->toolbar_config ->setIcon(icon(":/Icons/configure.png"));
ui->toolbar_controls->setIcon(icon(":/Icons/controllers.png"));
ui->toolbar_open ->setIcon(icon(":/Icons/open.png"));
ui->toolbar_grid ->setIcon(icon(":/Icons/grid.png"));
ui->toolbar_list ->setIcon(icon(":/Icons/list.png"));
ui->toolbar_refresh ->setIcon(icon(":/Icons/refresh.png"));
ui->toolbar_stop ->setIcon(icon(":/Icons/stop.png"));
if (Emu.IsRunning())
{
ui->toolbar_start->setIcon(m_icon_pause);
}
else if (Emu.IsStopped() && !Emu.GetBoot().empty())
{
ui->toolbar_start->setIcon(m_icon_restart);
}
else
{
ui->toolbar_start->setIcon(m_icon_play);
}
if (isFullScreen())
{
ui->toolbar_fullscreen->setIcon(m_icon_fullscreen_off);
}
else
{
ui->toolbar_fullscreen->setIcon(m_icon_fullscreen_on);
}
ui->sizeSlider->setStyleSheet(ui->sizeSlider->styleSheet().append("QSlider::handle:horizontal{ background: rgba(%1, %2, %3, %4); }")
.arg(newColor.red()).arg(newColor.green()).arg(newColor.blue()).arg(newColor.alpha()));
// resize toolbar elements
// for highdpi resize toolbar icons and height dynamically
// choose factors to mimic Gui-Design in main_window.ui
// TODO: delete this in case Qt::AA_EnableHighDpiScaling is enabled in main.cpp
#ifdef _WIN32
const int toolIconHeight = menuBar()->sizeHint().height() * 1.5;
ui->toolBar->setIconSize(QSize(toolIconHeight, toolIconHeight));
#endif
const int toolBarHeight = ui->toolBar->sizeHint().height();
for (const auto& act : ui->toolBar->actions())
{
if (act->isSeparator())
{
continue;
}
ui->toolBar->widgetForAction(act)->setMinimumWidth(toolBarHeight);
}
ui->sizeSliderContainer->setFixedWidth(toolBarHeight * 4);
ui->mw_searchbar->setFixedWidth(toolBarHeight * 5);
}
void main_window::OnEmuRun()
{
m_debuggerFrame->EnableButtons(true);
#ifdef _WIN32
m_thumb_playPause->setToolTip(tr("Pause emulation"));
m_thumb_playPause->setIcon(m_icon_thumb_pause);
#endif
ui->sysPauseAct->setText(tr("&Pause\tCtrl+P"));
ui->sysPauseAct->setIcon(m_icon_pause);
ui->toolbar_start->setIcon(m_icon_pause);
ui->toolbar_start->setText(tr("Pause"));
ui->toolbar_start->setToolTip(tr("Pause emulation"));
EnableMenus(true);
#ifdef WITH_DISCORD_RPC
// Discord Rich Presence Integration
if (guiSettings->GetValue(gui::m_richPresence).toBool())
{
discord::update_presence(Emu.GetTitleID(), Emu.GetTitle());
}
#endif
}
void main_window::OnEmuResume()
{
#ifdef _WIN32
m_thumb_playPause->setToolTip(tr("Pause emulation"));
m_thumb_playPause->setIcon(m_icon_thumb_pause);
#endif
ui->sysPauseAct->setText(tr("&Pause\tCtrl+P"));
ui->sysPauseAct->setIcon(m_icon_pause);
ui->toolbar_start->setIcon(m_icon_pause);
ui->toolbar_start->setText(tr("Pause"));
ui->toolbar_start->setToolTip(tr("Pause emulation"));
}
void main_window::OnEmuPause()
{
#ifdef _WIN32
m_thumb_playPause->setToolTip(tr("Resume emulation"));
m_thumb_playPause->setIcon(m_icon_thumb_play);
#endif
ui->sysPauseAct->setText(tr("&Resume\tCtrl+E"));
ui->sysPauseAct->setIcon(m_icon_play);
ui->toolbar_start->setIcon(m_icon_play);
ui->toolbar_start->setText(tr("Play"));
ui->toolbar_start->setToolTip(tr("Resume emulation"));
}
void main_window::OnEmuStop()
{
m_debuggerFrame->EnableButtons(false);
m_debuggerFrame->ClearBreakpoints();
ui->sysPauseAct->setText(Emu.IsReady() ? tr("&Start\tCtrl+E") : tr("&Resume\tCtrl+E"));
ui->sysPauseAct->setIcon(m_icon_play);
#ifdef _WIN32
m_thumb_playPause->setToolTip(Emu.IsReady() ? tr("Start emulation") : tr("Resume emulation"));
m_thumb_playPause->setIcon(m_icon_thumb_play);
#endif
EnableMenus(false);
if (!Emu.GetBoot().empty())
{
ui->toolbar_start->setEnabled(true);
ui->toolbar_start->setIcon(m_icon_restart);
ui->toolbar_start->setText(tr("Restart"));
ui->toolbar_start->setToolTip(tr("Restart emulation"));
ui->sysRebootAct->setEnabled(true);
#ifdef _WIN32
m_thumb_restart->setEnabled(true);
#endif
}
else
{
ui->toolbar_start->setIcon(m_icon_play);
ui->toolbar_start->setText(tr("Play"));
ui->toolbar_start->setToolTip(Emu.IsReady() ? tr("Start emulation") : tr("Resume emulation"));
}
ui->actionManage_Users->setEnabled(true);
#ifdef WITH_DISCORD_RPC
// Discord Rich Presence Integration
if (guiSettings->GetValue(gui::m_richPresence).toBool())
{
discord::update_presence(sstr(guiSettings->GetValue(gui::m_discordState).toString()));
}
#endif
}
void main_window::OnEmuReady()
{
m_debuggerFrame->EnableButtons(true);
#ifdef _WIN32
m_thumb_playPause->setToolTip(Emu.IsReady() ? tr("Start emulation") : tr("Resume emulation"));
m_thumb_playPause->setIcon(m_icon_thumb_play);
#endif
ui->sysPauseAct->setText(Emu.IsReady() ? tr("&Start\tCtrl+E") : tr("&Resume\tCtrl+E"));
ui->sysPauseAct->setIcon(m_icon_play);
ui->toolbar_start->setIcon(m_icon_play);
ui->toolbar_start->setText(tr("Play"));
ui->toolbar_start->setToolTip(Emu.IsReady() ? tr("Start emulation") : tr("Resume emulation"));
EnableMenus(true);
ui->actionManage_Users->setEnabled(false);
}
void main_window::EnableMenus(bool enabled)
{
// Thumbnail Buttons
#ifdef _WIN32
m_thumb_playPause->setEnabled(enabled);
m_thumb_stop->setEnabled(enabled);
m_thumb_restart->setEnabled(enabled);
#endif
// Toolbar
ui->toolbar_start->setEnabled(enabled);
ui->toolbar_stop->setEnabled(enabled);
// Emulation
ui->sysPauseAct->setEnabled(enabled);
ui->sysStopAct->setEnabled(enabled);
ui->sysRebootAct->setEnabled(enabled);
// PS3 Commands
ui->sysSendOpenMenuAct->setEnabled(enabled);
ui->sysSendExitAct->setEnabled(enabled);
// Tools
ui->toolskernel_explorerAct->setEnabled(enabled);
ui->toolsmemory_viewerAct->setEnabled(enabled);
ui->toolsRsxDebuggerAct->setEnabled(enabled);
ui->toolsStringSearchAct->setEnabled(enabled);
}
void main_window::BootRecentAction(const QAction* act)
{
if (Emu.IsRunning())
{
return;
}
const QString pth = act->data().toString();
const std::string path = sstr(pth);
QString nam;
bool containsPath = false;
int idx = -1;
for (int i = 0; i < m_rg_entries.count(); i++)
{
if (m_rg_entries.at(i).first == pth)
{
idx = i;
containsPath = true;
nam = m_rg_entries.at(idx).second;
}
}
// path is invalid: remove action from list return
if ((containsPath && nam.isEmpty()) || (!QFileInfo(pth).isDir() && !QFileInfo(pth).isFile()))
{
if (containsPath)
{
// clear menu of actions
for (auto act : m_recentGameActs)
{
ui->bootRecentMenu->removeAction(act);
}