mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
better handling of cache directory
This commit is contained in:
@@ -252,7 +252,7 @@ static inline void getDE(FFWMDEResult* result, ProcData* procData)
|
||||
return;
|
||||
}
|
||||
|
||||
if(strcasecmp(result->sessionDesktop, "KDE") == 0)
|
||||
if(strcasecmp(result->sessionDesktop, "KDE") == 0 || strcasecmp(result->sessionDesktop, "plasma") == 0 || strcasecmp(result->sessionDesktop, "plasmashell") == 0)
|
||||
getKDE(result);
|
||||
else if(strcasecmp(result->sessionDesktop, "Gnome") == 0 || strcasecmp(result->sessionDesktop, "ubuntu:GNOME") == 0 || strcasecmp(result->sessionDesktop, "ubuntu") == 0)
|
||||
getGnome(result);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "fastfetch.h"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
static bool strbufEqualsAdapter(const void* first, const void* second)
|
||||
{
|
||||
@@ -64,6 +65,24 @@ static void initConfigDirs(FFstate* state)
|
||||
#undef FF_ENSURE_ONLY_ONCE_IN_LIST
|
||||
}
|
||||
|
||||
static void initCacheDir(FFstate* state)
|
||||
{
|
||||
ffStrbufInitA(&state->cacheDir, 64);
|
||||
|
||||
ffStrbufAppendS(&state->cacheDir, getenv("XDG_CACHE_HOME"));
|
||||
|
||||
if(state->cacheDir.length == 0)
|
||||
{
|
||||
ffStrbufAppendS(&state->cacheDir, state->passwd->pw_dir);
|
||||
ffStrbufAppendS(&state->cacheDir, "/.cache/");
|
||||
}
|
||||
|
||||
mkdir(state->cacheDir.chars, S_IRWXU | S_IXGRP | S_IRGRP | S_IXOTH | S_IROTH); //I hope everybody has a cache folder but whow knews
|
||||
|
||||
ffStrbufAppendS(&state->cacheDir, "fastfetch/");
|
||||
mkdir(state->cacheDir.chars, S_IRWXU | S_IRGRP | S_IROTH);
|
||||
}
|
||||
|
||||
static void initState(FFstate* state)
|
||||
{
|
||||
state->current_row = 0;
|
||||
@@ -72,6 +91,7 @@ static void initState(FFstate* state)
|
||||
sysinfo(&state->sysinfo);
|
||||
|
||||
initConfigDirs(state);
|
||||
initCacheDir(state);
|
||||
}
|
||||
|
||||
static void defaultConfig(FFconfig* config)
|
||||
|
||||
+1
-39
@@ -3,7 +3,6 @@
|
||||
#include <malloc.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#define FF_IO_CACHE_VALUE_EXTENSION "ffcv"
|
||||
@@ -83,46 +82,9 @@ void ffPrintFormatString(FFinstance* instance, const char* moduleName, uint8_t m
|
||||
ffStrbufDestroy(&buffer);
|
||||
}
|
||||
|
||||
static void appendCacheDir(FFinstance* instance, FFstrbuf* buffer)
|
||||
{
|
||||
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
static FFstrbuf cacheDir;
|
||||
static bool init = false;
|
||||
|
||||
pthread_mutex_lock(&mutex);
|
||||
|
||||
if(init)
|
||||
{
|
||||
pthread_mutex_unlock(&mutex);
|
||||
ffStrbufAppend(buffer, &cacheDir);
|
||||
return;
|
||||
}
|
||||
|
||||
ffStrbufInitA(&cacheDir, 64);
|
||||
ffStrbufAppendS(&cacheDir, getenv("XDG_CACHE_HOME"));
|
||||
|
||||
if(cacheDir.length == 0)
|
||||
{
|
||||
ffStrbufSetS(&cacheDir, instance->state.passwd->pw_dir);
|
||||
ffStrbufAppendS(&cacheDir, "/.cache/");
|
||||
}
|
||||
|
||||
mkdir(cacheDir.chars, S_IRWXU | S_IXGRP | S_IRGRP | S_IXOTH | S_IROTH); //I hope everybody has a cache folder but whow knews
|
||||
|
||||
ffStrbufAppendS(&cacheDir, "fastfetch/");
|
||||
mkdir(cacheDir.chars, S_IRWXU | S_IRGRP | S_IROTH);
|
||||
|
||||
init = true;
|
||||
|
||||
pthread_mutex_unlock(&mutex);
|
||||
|
||||
ffStrbufAppend(buffer, &cacheDir);
|
||||
}
|
||||
|
||||
void ffGetCacheFilePath(FFinstance* instance, const char* moduleName, const char* extension, FFstrbuf* buffer)
|
||||
{
|
||||
appendCacheDir(instance, buffer);
|
||||
ffStrbufAppend(buffer, &instance->state.cacheDir);
|
||||
ffStrbufAppendS(buffer, moduleName);
|
||||
|
||||
if(extension != NULL)
|
||||
|
||||
@@ -161,6 +161,7 @@ typedef struct FFstate
|
||||
struct sysinfo sysinfo;
|
||||
|
||||
FFlist configDirs;
|
||||
FFstrbuf cacheDir;
|
||||
} FFstate;
|
||||
|
||||
typedef struct FFinstance
|
||||
|
||||
Reference in New Issue
Block a user