Qt: fix appicon for ISO

This commit is contained in:
Megamouse
2026-01-10 07:40:35 +01:00
parent 6bd4f52173
commit 98e64d7821
2 changed files with 49 additions and 21 deletions
+35 -10
View File
@@ -393,11 +393,29 @@ namespace gui
std::string icon_path = fs::get_config_dir() + "/Icons/game_icons/" + title_id + "/ICON0.PNG"; std::string icon_path = fs::get_config_dir() + "/Icons/game_icons/" + title_id + "/ICON0.PNG";
bool found_file = fs::is_file(icon_path); bool found_file = fs::is_file(icon_path);
std::unique_ptr<QPixmap> pixmap;
if (!found_file) if (!found_file)
{ {
// Get Icon for the gs_frame from path. this handles presumably all possible use cases // Get Icon for the gs_frame from path. this handles presumably all possible use cases
std::vector<std::string> path_list;
const bool is_archive = is_file_iso(path);
if (is_archive)
{
icon_path = "PS3_GAME/ICON0.PNG";
QPixmap px;
if (load_iso_icon(px, icon_path, path))
{
found_file = true;
pixmap = std::make_unique<QPixmap>(std::move(px));
}
}
else
{
const QString qpath = QString::fromStdString(path); const QString qpath = QString::fromStdString(path);
const std::string path_list[] = { path, qpath.section("/", 0, -2, QString::SectionIncludeTrailingSep).toStdString(), path_list = { path, qpath.section("/", 0, -2, QString::SectionIncludeTrailingSep).toStdString(),
qpath.section("/", 0, -3, QString::SectionIncludeTrailingSep).toStdString() }; qpath.section("/", 0, -3, QString::SectionIncludeTrailingSep).toStdString() };
for (const std::string& pth : path_list) for (const std::string& pth : path_list)
@@ -417,11 +435,12 @@ namespace gui
} }
} }
} }
}
if (found_file) if (found_file)
{ {
// load the image from path. It will most likely be a rectangle // load the image from path. It will most likely be a rectangle
const QImage source = QImage(QString::fromStdString(icon_path)); const QImage source = pixmap ? pixmap->toImage() : QImage(QString::fromStdString(icon_path));
const int edge_max = std::max(source.width(), source.height()); const int edge_max = 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?) // create a new transparent image with square size and same format as source (maybe handle other formats than RGB32 as well?)
@@ -683,15 +702,9 @@ namespace gui
return QString("%1 days ago %2").arg(current_date - exctrated_date).arg(date.toString(fmt_relative)); return QString("%1 days ago %2").arg(current_date - exctrated_date).arg(date.toString(fmt_relative));
} }
bool load_icon(QPixmap& icon, const std::string& icon_path, const std::string& archive_path) bool load_iso_icon(QPixmap& icon, const std::string& icon_path, const std::string& archive_path)
{ {
if (icon_path.empty()) return false; if (icon_path.empty() || archive_path.empty()) return false;
if (archive_path.empty())
{
return icon.load(QString::fromStdString(icon_path));
}
if (!is_file_iso(archive_path)) return false; if (!is_file_iso(archive_path)) return false;
iso_archive archive(archive_path); iso_archive archive(archive_path);
@@ -707,6 +720,18 @@ namespace gui
return icon.loadFromData(data); return icon.loadFromData(data);
} }
bool load_icon(QPixmap& icon, const std::string& icon_path, const std::string& archive_path)
{
if (icon_path.empty()) return false;
if (archive_path.empty())
{
return icon.load(QString::fromStdString(icon_path));
}
return load_iso_icon(icon, icon_path, archive_path);
}
QString format_timestamp(s64 time, const QString& fmt) QString format_timestamp(s64 time, const QString& fmt)
{ {
return format_datetime(datetime(time), fmt); return format_datetime(datetime(time), fmt);
+3
View File
@@ -179,6 +179,9 @@ namespace gui
} }
// Loads an icon from an (ISO) archive file. // Loads an icon from an (ISO) archive file.
bool load_iso_icon(QPixmap& icon, const std::string& icon_path, const std::string& archive_path);
// Loads an icon (optionally from an (ISO) archive file).
bool load_icon(QPixmap& icon, const std::string& icon_path, const std::string& archive_path); bool load_icon(QPixmap& icon, const std::string& icon_path, const std::string& archive_path);
template <typename T> template <typename T>