horrible way to check icon

This commit is contained in:
Nishi 2025-12-28 00:36:31 +09:00
commit 3865552dff
Signed by: nishi
GPG key ID: 27EF69B208EB9343
4 changed files with 93 additions and 0 deletions

View file

@ -1,4 +1,5 @@
include(MDEBase)
include(MDEPkgConfig)
mde_setup_library(MDECore ${CMAKE_INSTALL_LIBDIR})
if(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows")

75
core/icon.c Normal file
View file

@ -0,0 +1,75 @@
#include "config.h"
#include <MDE/Core/Icon.h>
#include <MDE/Core/String.h>
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;
}

16
include/MDE/Core/Icon.h Normal file
View file

@ -0,0 +1,16 @@
#ifndef __MDE_CORE_ICON_H__
#define __MDE_CORE_ICON_H__
#include <MDE/MachDep.h>
#ifdef __cplusplus
extern "C" {
#endif
char* MDEIconLookUp(const char* genre, const char* name, int size);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -10,6 +10,7 @@
#include <MDE/Core/AboutDialog.h>
#include <MDE/Core/Thread.h>
#include <MDE/Core/Mutex.h>
#include <MDE/Core/Icon.h>
#include <MDE/Audio/Audio.h>