Media (Windows): detect with external DLL

For backup only
This commit is contained in:
李通洲
2024-06-11 14:44:47 +08:00
parent 9104db0d21
commit ff3ddc774e
4 changed files with 80 additions and 15 deletions
+4
View File
@@ -20,6 +20,10 @@ const FFMediaResult* ffDetectMedia(void)
if(result.song.length == 0 && result.error.length == 0)
ffStrbufAppendS(&result.error, "No media found");
ffStrbufTrimRightSpace(&result.song);
ffStrbufTrimRightSpace(&result.artist);
ffStrbufTrimRightSpace(&result.album);
ffStrbufTrimRightSpace(&result.player);
}
return &result;
+52
View File
@@ -0,0 +1,52 @@
#include "fastfetch.h"
#include "common/library.h"
#include "util/windows/unicode.h"
#include "media.h"
#define FF_MEDIA_WIN_RESULT_BUFLEN 256
typedef struct FFMediaWinResult
{
wchar_t playerId[FF_MEDIA_WIN_RESULT_BUFLEN];
wchar_t song[FF_MEDIA_WIN_RESULT_BUFLEN];
wchar_t artist[FF_MEDIA_WIN_RESULT_BUFLEN];
wchar_t album[FF_MEDIA_WIN_RESULT_BUFLEN];
char status[FF_MEDIA_WIN_RESULT_BUFLEN];
char error[FF_MEDIA_WIN_RESULT_BUFLEN];
} FFMediaWinResult;
bool ffMediaWinDetectMedia(FFMediaWinResult* result);
static const char* getMedia(FFMediaResult* media)
{
FF_LIBRARY_LOAD(libffdll, NULL, "dlopen fastfetch-dll" FF_LIBRARY_EXTENSION " failed", "fastfetch-dll" FF_LIBRARY_EXTENSION, 0)
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libffdll, ffMediaWinDetectMedia)
libffdll = NULL; // Don't close libffdll or it may crash
FFMediaWinResult result = {};
if (!ffffMediaWinDetectMedia(&result))
{
ffStrbufAppendS(&media->error, result.error);
ffStrbufAppendS(&media->error, " (DLL error)");
return NULL;
}
ffStrbufSetWS(&media->playerId, result.playerId);
ffStrbufSet(&media->player, &media->playerId);
if (ffStrbufEndsWithIgnCaseS(&media->player, ".exe"))
ffStrbufSubstrBefore(&media->player, media->player.length - 4);
else
ffStrbufSubstrAfterFirstC(&media->player, '!'); // UWP ID
ffStrbufSetWS(&media->song, result.song);
ffStrbufSetWS(&media->artist, result.artist);
ffStrbufSetWS(&media->album, result.album);
ffStrbufSetS(&media->status, result.status);
return NULL;
}
void ffDetectMediaImpl(FFMediaResult* media)
{
const char* error = getMedia(media);
ffStrbufAppendS(&media->error, error);
}