From 3865552dff11ca09e47e13e4183edd51c2c59767 Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Sun, 28 Dec 2025 00:36:31 +0900 Subject: [PATCH] horrible way to check icon --- core/CMakeLists.txt | 1 + core/icon.c | 75 ++++++++++++++++++++++++++++++++++++++++ include/MDE/Core/Icon.h | 16 +++++++++ include/MDE/Foundation.h | 1 + 4 files changed, 93 insertions(+) create mode 100644 core/icon.c create mode 100644 include/MDE/Core/Icon.h diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index acc5e39..329858c 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -1,4 +1,5 @@ include(MDEBase) +include(MDEPkgConfig) mde_setup_library(MDECore ${CMAKE_INSTALL_LIBDIR}) if(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows") diff --git a/core/icon.c b/core/icon.c new file mode 100644 index 0000000..08942fb --- /dev/null +++ b/core/icon.c @@ -0,0 +1,75 @@ +#include "config.h" + +#include +#include + +static char* try_file(const char* path, const char* genre, const char* name, int size) { + char sz[512]; + char* s; + char* s2; + char* s3; + char* s4; + char* s5; + char* s6; + char* t; + FILE* f; + + sprintf(sz, "%dx%d", size, size); + + s = MDEStringConcatenate(path, "/"); + s2 = MDEStringConcatenate(s, sz); + s3 = MDEStringConcatenate(s2, "/"); + s4 = MDEStringConcatenate(s3, genre); + s5 = MDEStringConcatenate(s4, "/"); + s6 = MDEStringConcatenate(s5, name); + t = MDEStringConcatenate(s6, ".png"); + + free(s6); + free(s5); + free(s4); + free(s3); + free(s2); + free(s); + + if((f = fopen(t, "rb")) == NULL) { + free(t); + return NULL; + } + fclose(f); + + return t; +} + +char* MDEIconLookUp(const char* genre, const char* name, int size) { + char* s; + const char* g = genre; + int i = 0; + const char* genres[] = { + "actions", + "apps", + "categories", + "devices", + "emblems", + "emotes", + "mimetypes", + "places", + "status", + NULL}; + + do { + if(genre == NULL) g = genres[i]; + if(g == NULL) break; + if((s = try_file(DATAROOTDIR "/icons/mde", g, name, size)) != NULL) return s; + if((s = try_file(DATAROOTDIR "/icons/hicolor", g, name, size)) != NULL) return s; +#ifdef __NetBSD__ + if((s = try_file("/usr/pkg/share/icons/hicolor", g, name, size)) != NULL) return s; +#endif + if((s = try_file("/usr/share/icons/hicolor", g, name, size)) != NULL) return s; + + i++; + + if(genre != NULL) break; + } while(1); + + return NULL; +} diff --git a/include/MDE/Core/Icon.h b/include/MDE/Core/Icon.h new file mode 100644 index 0000000..45d645a --- /dev/null +++ b/include/MDE/Core/Icon.h @@ -0,0 +1,16 @@ +#ifndef __MDE_CORE_ICON_H__ +#define __MDE_CORE_ICON_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +char* MDEIconLookUp(const char* genre, const char* name, int size); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/MDE/Foundation.h b/include/MDE/Foundation.h index f380fb3..8052034 100644 --- a/include/MDE/Foundation.h +++ b/include/MDE/Foundation.h @@ -10,6 +10,7 @@ #include #include #include +#include #include