mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
Logo: adds automatic cleanup of temporary media cover files
This commit is contained in:
@@ -241,6 +241,7 @@ static inline bool ffSearchUserConfigFile(const FFlist* configDirs, const char*
|
||||
}
|
||||
|
||||
FFNativeFD ffGetNullFD(void);
|
||||
bool ffRemoveFile(const char* fileName);
|
||||
|
||||
#ifdef _WIN32
|
||||
// Only O_RDONLY is supported
|
||||
|
||||
@@ -372,3 +372,8 @@ FFNativeFD ffGetNullFD(void)
|
||||
hNullFile = open("/dev/null", O_WRONLY | O_CLOEXEC);
|
||||
return hNullFile;
|
||||
}
|
||||
|
||||
bool ffRemoveFile(const char* fileName)
|
||||
{
|
||||
return unlink(fileName) == 0;
|
||||
}
|
||||
|
||||
@@ -371,3 +371,8 @@ FFNativeFD ffGetNullFD(void)
|
||||
});
|
||||
return hNullFile;
|
||||
}
|
||||
|
||||
bool ffRemoveFile(const char* fileName)
|
||||
{
|
||||
return DeleteFileA(fileName) != FALSE;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ const FFMediaResult* ffDetectMedia(bool saveCover)
|
||||
ffStrbufInit(&result.url);
|
||||
ffStrbufInit(&result.status);
|
||||
ffStrbufInit(&result.cover);
|
||||
result.removeCoverAfterUse = false;
|
||||
ffDetectMediaImpl(&result, saveCover);
|
||||
|
||||
if(result.song.length == 0 && result.error.length == 0)
|
||||
|
||||
@@ -14,6 +14,7 @@ typedef struct FFMediaResult
|
||||
FFstrbuf url;
|
||||
FFstrbuf status;
|
||||
FFstrbuf cover;
|
||||
bool removeCoverAfterUse;
|
||||
} FFMediaResult;
|
||||
|
||||
const FFMediaResult* ffDetectMedia(bool saveCover);
|
||||
|
||||
@@ -44,7 +44,7 @@ static const char* getMediaByMediaRemote(FFMediaResult* result, bool saveCover)
|
||||
FF_CFTYPE_AUTO_RELEASE CFStringRef ext = UTTypeCopyPreferredTagWithClass(uti, kUTTagClassFilenameExtension);
|
||||
#pragma clang diagnostic pop
|
||||
NSString *tmpDir = NSTemporaryDirectory();
|
||||
NSString *uuid = [[NSUUID UUID] UUIDString];
|
||||
NSString *uuid = NSUUID.UUID.UUIDString;
|
||||
NSString *path = [tmpDir stringByAppendingPathComponent:[NSString stringWithFormat:@"ff_%@.%@", uuid, ext ? (__bridge NSString *) ext : @"img"]];
|
||||
if ([artworkData writeToFile:path atomically:NO])
|
||||
ffStrbufSetS(&result->cover, path.UTF8String);
|
||||
@@ -160,5 +160,7 @@ void ffDetectMediaImpl(FFMediaResult* media, bool saveCover)
|
||||
if (ffStrbufStartsWithIgnCaseS(&media->player, "com."))
|
||||
ffStrbufSubstrAfter(&media->player, strlen("com.") - 1);
|
||||
ffStrbufReplaceAllC(&media->player, '.', ' ');
|
||||
if (media->cover.length > 0)
|
||||
media->removeCoverAfterUse = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,8 @@ static const char* getMedia(FFMediaResult* media, bool saveCover)
|
||||
ffStrbufSetWS(&media->album, result.album);
|
||||
ffStrbufSetWS(&media->cover, result.cover);
|
||||
ffStrbufSetStatic(&media->status, result.status);
|
||||
if (media->cover.length > 0)
|
||||
media->removeCoverAfterUse = true;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "util/stringUtils.h"
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
typedef enum __attribute__((__packed__)) FFLogoSize
|
||||
@@ -474,6 +475,16 @@ static bool logoPrintData(bool doColorReplacement, FFstrbuf* source)
|
||||
return true;
|
||||
}
|
||||
|
||||
static void removeMediaCoverFile(void)
|
||||
{
|
||||
const FFMediaResult* media = ffDetectMedia(true);
|
||||
if (media->cover.length > 0)
|
||||
{
|
||||
ffRemoveFile(media->cover.chars);
|
||||
ffStrbufDestroy((FFstrbuf*) &media->cover);
|
||||
}
|
||||
}
|
||||
|
||||
static bool updateLogoPath(void)
|
||||
{
|
||||
FFOptionsLogo* options = &instance.config.logo;
|
||||
@@ -490,6 +501,7 @@ static bool updateLogoPath(void)
|
||||
if (media->cover.length == 0)
|
||||
return false;
|
||||
ffStrbufSet(&options->source, &media->cover);
|
||||
if (media->removeCoverAfterUse) atexit(removeMediaCoverFile);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user