summaryrefslogtreecommitdiff
path: root/src/citra_qt
diff options
context:
space:
mode:
Diffstat (limited to 'src/citra_qt')
-rw-r--r--src/citra_qt/game_list.cpp22
-rw-r--r--src/citra_qt/game_list_p.h53
-rw-r--r--src/citra_qt/main.cpp10
3 files changed, 24 insertions, 61 deletions
diff --git a/src/citra_qt/game_list.cpp b/src/citra_qt/game_list.cpp
index d4ac9c96e..570647539 100644
--- a/src/citra_qt/game_list.cpp
+++ b/src/citra_qt/game_list.cpp
@@ -132,30 +132,16 @@ void GameListWorker::AddFstEntriesToGameList(const std::string& dir_path, bool d
132 if (deep_scan && FileUtil::IsDirectory(physical_name)) { 132 if (deep_scan && FileUtil::IsDirectory(physical_name)) {
133 AddFstEntriesToGameList(physical_name, true); 133 AddFstEntriesToGameList(physical_name, true);
134 } else { 134 } else {
135 std::string filename_filename, filename_extension; 135 std::unique_ptr<Loader::AppLoader> loader = Loader::GetLoader(physical_name);
136 Common::SplitPath(physical_name, nullptr, &filename_filename, &filename_extension); 136 if (!loader)
137
138 Loader::FileType guessed_filetype = Loader::GuessFromExtension(filename_extension);
139 if (guessed_filetype == Loader::FileType::Unknown)
140 return true;
141 Loader::FileType filetype = Loader::IdentifyFile(physical_name);
142 if (filetype == Loader::FileType::Unknown) {
143 LOG_WARNING(Frontend, "File %s is of indeterminate type and is possibly corrupted.", physical_name.c_str());
144 return true; 137 return true;
145 }
146 if (guessed_filetype != filetype) {
147 LOG_WARNING(Frontend, "Filetype and extension of file %s do not match.", physical_name.c_str());
148 }
149 138
150 std::vector<u8> smdh; 139 std::vector<u8> smdh;
151 std::unique_ptr<Loader::AppLoader> loader = Loader::GetLoader(FileUtil::IOFile(physical_name, "rb"), filetype, filename_filename, physical_name); 140 loader->ReadIcon(smdh);
152
153 if (loader)
154 loader->ReadIcon(smdh);
155 141
156 emit EntryReady({ 142 emit EntryReady({
157 new GameListItemPath(QString::fromStdString(physical_name), smdh), 143 new GameListItemPath(QString::fromStdString(physical_name), smdh),
158 new GameListItem(QString::fromStdString(Loader::GetFileTypeString(filetype))), 144 new GameListItem(QString::fromStdString(Loader::GetFileTypeString(loader->GetFileType()))),
159 new GameListItemSize(FileUtil::GetSize(physical_name)), 145 new GameListItemSize(FileUtil::GetSize(physical_name)),
160 }); 146 });
161 } 147 }
diff --git a/src/citra_qt/game_list_p.h b/src/citra_qt/game_list_p.h
index 284f5da81..121f90b0c 100644
--- a/src/citra_qt/game_list_p.h
+++ b/src/citra_qt/game_list_p.h
@@ -15,52 +15,21 @@
15#include "common/string_util.h" 15#include "common/string_util.h"
16#include "common/color.h" 16#include "common/color.h"
17 17
18#include "core/loader/loader.h" 18#include "core/loader/smdh.h"
19 19
20#include "video_core/utils.h" 20#include "video_core/utils.h"
21 21
22/** 22/**
23 * Tests if data is a valid SMDH by its length and magic number.
24 * @param smdh_data data buffer to test
25 * @return bool test result
26 */
27static bool IsValidSMDH(const std::vector<u8>& smdh_data) {
28 if (smdh_data.size() < sizeof(Loader::SMDH))
29 return false;
30
31 u32 magic;
32 memcpy(&magic, smdh_data.data(), 4);
33
34 return Loader::MakeMagic('S', 'M', 'D', 'H') == magic;
35}
36
37/**
38 * Gets game icon from SMDH 23 * Gets game icon from SMDH
39 * @param sdmh SMDH data 24 * @param sdmh SMDH data
40 * @param large If true, returns large icon (48x48), otherwise returns small icon (24x24) 25 * @param large If true, returns large icon (48x48), otherwise returns small icon (24x24)
41 * @return QPixmap game icon 26 * @return QPixmap game icon
42 */ 27 */
43static QPixmap GetIconFromSMDH(const Loader::SMDH& smdh, bool large) { 28static QPixmap GetQPixmapFromSMDH(const Loader::SMDH& smdh, bool large) {
44 u32 size; 29 std::vector<u16> icon_data = smdh.GetIcon(large);
45 const u8* icon_data; 30 const uchar* data = reinterpret_cast<const uchar*>(icon_data.data());
46 31 int size = large ? 48 : 24;
47 if (large) { 32 QImage icon(data, size, size, QImage::Format::Format_RGB16);
48 size = 48;
49 icon_data = smdh.large_icon.data();
50 } else {
51 size = 24;
52 icon_data = smdh.small_icon.data();
53 }
54
55 QImage icon(size, size, QImage::Format::Format_RGB888);
56 for (u32 x = 0; x < size; ++x) {
57 for (u32 y = 0; y < size; ++y) {
58 u32 coarse_y = y & ~7;
59 auto v = Color::DecodeRGB565(
60 icon_data + VideoCore::GetMortonOffset(x, y, 2) + coarse_y * size * 2);
61 icon.setPixel(x, y, qRgb(v.r(), v.g(), v.b()));
62 }
63 }
64 return QPixmap::fromImage(icon); 33 return QPixmap::fromImage(icon);
65} 34}
66 35
@@ -82,8 +51,8 @@ static QPixmap GetDefaultIcon(bool large) {
82 * @param language title language 51 * @param language title language
83 * @return QString short title 52 * @return QString short title
84 */ 53 */
85static QString GetShortTitleFromSMDH(const Loader::SMDH& smdh, Loader::SMDH::TitleLanguage language) { 54static QString GetQStringShortTitleFromSMDH(const Loader::SMDH& smdh, Loader::SMDH::TitleLanguage language) {
86 return QString::fromUtf16(smdh.titles[static_cast<int>(language)].short_title.data()); 55 return QString::fromUtf16(smdh.GetShortTitle(language).data());
87} 56}
88 57
89class GameListItem : public QStandardItem { 58class GameListItem : public QStandardItem {
@@ -112,7 +81,7 @@ public:
112 { 81 {
113 setData(game_path, FullPathRole); 82 setData(game_path, FullPathRole);
114 83
115 if (!IsValidSMDH(smdh_data)) { 84 if (!Loader::IsValidSMDH(smdh_data)) {
116 // SMDH is not valid, set a default icon 85 // SMDH is not valid, set a default icon
117 setData(GetDefaultIcon(true), Qt::DecorationRole); 86 setData(GetDefaultIcon(true), Qt::DecorationRole);
118 return; 87 return;
@@ -122,10 +91,10 @@ public:
122 memcpy(&smdh, smdh_data.data(), sizeof(Loader::SMDH)); 91 memcpy(&smdh, smdh_data.data(), sizeof(Loader::SMDH));
123 92
124 // Get icon from SMDH 93 // Get icon from SMDH
125 setData(GetIconFromSMDH(smdh, true), Qt::DecorationRole); 94 setData(GetQPixmapFromSMDH(smdh, true), Qt::DecorationRole);
126 95
127 // Get title form SMDH 96 // Get title form SMDH
128 setData(GetShortTitleFromSMDH(smdh, Loader::SMDH::TitleLanguage::English), TitleRole); 97 setData(GetQStringShortTitleFromSMDH(smdh, Loader::SMDH::TitleLanguage::English), TitleRole);
129 } 98 }
130 99
131 QVariant data(int role) const override { 100 QVariant data(int role) const override {
diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp
index a85c94a4b..6239160bc 100644
--- a/src/citra_qt/main.cpp
+++ b/src/citra_qt/main.cpp
@@ -272,7 +272,15 @@ bool GMainWindow::InitializeSystem() {
272} 272}
273 273
274bool GMainWindow::LoadROM(const std::string& filename) { 274bool GMainWindow::LoadROM(const std::string& filename) {
275 Loader::ResultStatus result = Loader::LoadFile(filename); 275 std::unique_ptr<Loader::AppLoader> app_loader = Loader::GetLoader(filename);
276 if (!app_loader) {
277 LOG_CRITICAL(Frontend, "Failed to obtain loader for %s!", filename.c_str());
278 QMessageBox::critical(this, tr("Error while loading ROM!"),
279 tr("The ROM format is not supported."));
280 return false;
281 }
282
283 Loader::ResultStatus result = app_loader->Load();
276 if (Loader::ResultStatus::Success != result) { 284 if (Loader::ResultStatus::Success != result) {
277 LOG_CRITICAL(Frontend, "Failed to load ROM!"); 285 LOG_CRITICAL(Frontend, "Failed to load ROM!");
278 System::Shutdown(); 286 System::Shutdown();