Read Linux steam icons

This commit is contained in:
Guillaume Meunier
2025-08-09 15:02:28 +02:00
parent d5ef8c1a85
commit 45d5d6dd7a
5 changed files with 72 additions and 5 deletions
+1
View File
@@ -185,6 +185,7 @@ endif()
if (WIVRN_BUILD_DASHBOARD OR WIVRN_BUILD_SERVER) if (WIVRN_BUILD_DASHBOARD OR WIVRN_BUILD_SERVER)
pkg_check_modules(librsvg-2.0 REQUIRED IMPORTED_TARGET librsvg-2.0) pkg_check_modules(librsvg-2.0 REQUIRED IMPORTED_TARGET librsvg-2.0)
find_package(LibArchive)
find_package(PNG) find_package(PNG)
endif() endif()
+1 -1
View File
@@ -50,7 +50,7 @@ if (WIVRN_BUILD_DASHBOARD OR WIVRN_BUILD_SERVER)
utils/ini.cpp utils/ini.cpp
application.cpp application.cpp
) )
target_link_libraries(wivrn-common-server PRIVATE nlohmann_json::nlohmann_json PNG::PNG PkgConfig::librsvg-2.0 PUBLIC wivrn-common-base) target_link_libraries(wivrn-common-server PRIVATE nlohmann_json::nlohmann_json PNG::PNG PkgConfig::librsvg-2.0 LibArchive::LibArchive PUBLIC wivrn-common-base)
if (WIVRN_BUILD_TEST) if (WIVRN_BUILD_TEST)
add_executable(list-apps add_executable(list-apps
+3 -3
View File
@@ -84,7 +84,7 @@ steam_app_info read_steam_app_info(const std::filesystem::path & root)
return {}; return {};
} }
std::filesystem::path find_steam_icon(const std::filesystem::path & root, int app_id, const steam_app_info & info) std::optional<std::filesystem::path> find_steam_icon(const std::filesystem::path & root, int app_id, const steam_app_info & info)
{ {
const auto & app_info = info.get(app_id); const auto & app_info = info.get(app_id);
@@ -102,7 +102,7 @@ std::filesystem::path find_steam_icon(const std::filesystem::path & root, int ap
try try
{ {
std::string icon{std::get<std::string_view>(app_info.at("common.LinuxClientIcon"))}; std::string icon{std::get<std::string_view>(app_info.at("common.linuxclienticon"))};
auto icon_path = root / "steam/games" / (icon + ".zip"); auto icon_path = root / "steam/games" / (icon + ".zip");
@@ -113,7 +113,7 @@ std::filesystem::path find_steam_icon(const std::filesystem::path & root, int ap
{ {
} }
return {}; return std::nullopt;
} }
void read_steam_vr_apps(std::unordered_map<std::string, application> & res) void read_steam_vr_apps(std::unordered_map<std::string, application> & res)
+64 -1
View File
@@ -18,6 +18,8 @@
#include "load_icon.h" #include "load_icon.h"
#include <archive.h>
#include <archive_entry.h>
#include <cairo.h> #include <cairo.h>
#include <fstream> #include <fstream>
#include <librsvg/rsvg.h> #include <librsvg/rsvg.h>
@@ -537,6 +539,67 @@ std::vector<std::byte> load_ico(const std::filesystem::path & filename, int size
throw std::runtime_error{"Wrong magic number in " + filename.native()}; throw std::runtime_error{"Wrong magic number in " + filename.native()};
} }
std::vector<std::byte> load_zip(const std::filesystem::path & filename, int size)
{
std::unique_ptr<archive, decltype(&archive_read_free)> zip{archive_read_new(), &archive_read_free};
archive_read_support_filter_all(zip.get());
archive_read_support_format_all(zip.get());
if (auto rc = archive_read_open_filename(zip.get(), filename.c_str(), 1'000'000); rc != ARCHIVE_OK)
throw std::runtime_error{"Cannot open " + filename.native() + ": " + archive_error_string(zip.get())};
archive_entry * entry;
int width = 0;
int height = 0;
std::vector<std::byte> png;
while (archive_read_next_header(zip.get(), &entry) == ARCHIVE_OK)
{
printf("%s\n", archive_entry_pathname(entry));
std::vector<std::byte> buffer;
buffer.resize(archive_entry_size(entry));
if (auto status = archive_read_data(zip.get(), buffer.data(), buffer.size()); status < 0)
continue;
// Try reading the PNG
std::vector<uint8_t> pixels;
png_image png_ref{
.version = PNG_IMAGE_VERSION,
.format = PNG_FORMAT_BGRA,
};
if (not png_image_begin_read_from_memory(&png_ref, buffer.data(), buffer.size()))
{
png_image_free(&png_ref);
continue;
}
// Keep the largest icon only
if (png_ref.width * png_ref.height < width * height)
continue;
pixels.resize(PNG_IMAGE_SIZE(png_ref));
if (!png_image_finish_read(&png_ref, nullptr, pixels.data(), 0, nullptr))
{
png_image_free(&png_ref);
continue;
}
// PNG read successfully: keep it until we find a better one
width = png_ref.width;
height = png_ref.height;
png = std::move(buffer);
png_image_free(&png_ref);
}
return png;
}
std::unordered_map<std::filesystem::path, std::vector<std::byte>> icon_cache; std::unordered_map<std::filesystem::path, std::vector<std::byte>> icon_cache;
} // namespace } // namespace
@@ -561,7 +624,7 @@ const std::vector<std::byte> & wivrn::load_icon(const std::filesystem::path & fi
else if (filename.extension() == ".zip") else if (filename.extension() == ".zip")
{ {
// Steam icon (Linux) // Steam icon (Linux)
// TODO icon = load_zip(filename, size);
} }
else else
{ {
+3
View File
@@ -18,6 +18,7 @@
#include "steam_app_info.h" #include "steam_app_info.h"
#include <bit> #include <bit>
#include <cctype>
#include <cstring> #include <cstring>
#include <fstream> #include <fstream>
#include <span> #include <span>
@@ -89,6 +90,8 @@ void read_vdf(wivrn::steam_app_info::info & info, const std::string & prefix, st
while (type != 8) while (type != 8)
{ {
std::string name{string_table.at(read<uint32_t>(bindata))}; std::string name{string_table.at(read<uint32_t>(bindata))};
for (char & c: name)
c = std::tolower(c);
// https://github.com/ValveResourceFormat/ValveKeyValue/blob/master/ValveKeyValue/ValveKeyValue/KeyValues1/KV1BinaryNodeType.cs // https://github.com/ValveResourceFormat/ValveKeyValue/blob/master/ValveKeyValue/ValveKeyValue/KeyValues1/KV1BinaryNodeType.cs
switch (type) switch (type)