mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-30 00:37:23 +01:00
Detect data dirs at runtime
* Respecting the current platform * Using them where appropiate
This commit is contained in:
@@ -10,6 +10,7 @@ Features:
|
||||
* Look for config files in `$APPDATA` ([RoamingAppData](https://superuser.com/questions/21458/why-are-there-directories-called-local-locallow-and-roaming-under-users-user#answer-21462)) (Windows)
|
||||
* Look for config files in `~/Library/Preferences` (macOS)
|
||||
* Add `--list-config-paths` option which list search paths of config files
|
||||
* Add `--list-data-paths` option which list search paths for presets and logos
|
||||
|
||||
Logos:
|
||||
* Raspbian (@IamNoRobot, #373)
|
||||
|
||||
+127
-106
@@ -18,140 +18,160 @@
|
||||
#include <signal.h>
|
||||
#endif
|
||||
|
||||
static void initConfigDirs(FFstate* state)
|
||||
#define FF_ENSURE_ONLY_ONCE_IN_LIST(list, element) \
|
||||
if(ffListFirstIndexComp(list, element, (bool(*)(const void*, const void*))ffStrbufEqual) < list->length - 1) \
|
||||
{ \
|
||||
ffStrbufDestroy(ffListGet(list, list->length - 1)); \
|
||||
--list->length; \
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
void pathsAddKnownFolder(FFlist* dirs, REFKNOWNFOLDERID folderId)
|
||||
{
|
||||
ffListInit(&state->configDirs, sizeof(FFstrbuf));
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
PWSTR pPath;
|
||||
if(SUCCEEDED(SHGetKnownFolderPath(folderId, 0, NULL, &pPath)))
|
||||
{
|
||||
PWSTR pPath;
|
||||
if(SUCCEEDED(SHGetKnownFolderPath(&FOLDERID_RoamingAppData, 0, NULL, &pPath)))
|
||||
{
|
||||
FFstrbuf* buffer = (FFstrbuf*) ffListAdd(&state->configDirs);
|
||||
ffStrbufInit(buffer);
|
||||
ffStrbufSetWS(buffer, pPath);
|
||||
ffStrbufReplaceAllC(buffer, '\\', '/');
|
||||
ffStrbufEnsureEndsWithC(buffer, '/');
|
||||
}
|
||||
CoTaskMemFree(pPath);
|
||||
}
|
||||
|
||||
#elif defined(__APPLE__)
|
||||
|
||||
{
|
||||
FFstrbuf* buffer = (FFstrbuf*) ffListAdd(&state->configDirs);
|
||||
ffStrbufInitS(buffer, state->passwd->pw_dir);
|
||||
ffStrbufAppendS(buffer, "/Library/Preferences/");
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
const char* xdgConfigHome = getenv("XDG_CONFIG_HOME");
|
||||
if(ffStrSet(xdgConfigHome))
|
||||
{
|
||||
FFstrbuf* buffer = (FFstrbuf*) ffListAdd(&state->configDirs);
|
||||
ffStrbufInitA(buffer, 64);
|
||||
ffStrbufAppendS(buffer, xdgConfigHome);
|
||||
FFstrbuf* buffer = (FFstrbuf*) ffListAdd(dirs);
|
||||
ffStrbufInit(buffer);
|
||||
ffStrbufSetWS(buffer, pPath);
|
||||
ffStrbufReplaceAllC(buffer, '\\', '/');
|
||||
ffStrbufEnsureEndsWithC(buffer, '/');
|
||||
FF_ENSURE_ONLY_ONCE_IN_LIST(dirs, buffer);
|
||||
}
|
||||
CoTaskMemFree(pPath);
|
||||
}
|
||||
|
||||
#endif
|
||||
void pathsAddEnvSuffix(FFlist* dirs, const char* env, const char* suffix)
|
||||
{
|
||||
const char* value = getenv(env);
|
||||
if(!ffStrSet(value))
|
||||
return;
|
||||
|
||||
#define FF_ENSURE_ONLY_ONCE_IN_LIST(element) \
|
||||
if(ffListFirstIndexComp(&state->configDirs, element, (bool(*)(const void*, const void*))ffStrbufEqual) < state->configDirs.length - 1) \
|
||||
{ \
|
||||
ffStrbufDestroy(ffListGet(&state->configDirs, state->configDirs.length - 1)); \
|
||||
--state->configDirs.length; \
|
||||
}
|
||||
FFstrbuf* buffer = ffListAdd(dirs);
|
||||
ffStrbufInitA(buffer, 64);
|
||||
ffStrbufAppendS(buffer, value);
|
||||
ffStrbufReplaceAllC(buffer, '\\', '/');
|
||||
ffStrbufEnsureEndsWithC(buffer, '/');
|
||||
ffStrbufAppendS(buffer, suffix);
|
||||
ffStrbufEnsureEndsWithC(buffer, '/');
|
||||
FF_ENSURE_ONLY_ONCE_IN_LIST(dirs, buffer);
|
||||
}
|
||||
#endif
|
||||
|
||||
FFstrbuf* userConfigHome = ffListAdd(&state->configDirs);
|
||||
ffStrbufInitA(userConfigHome, 64);
|
||||
ffStrbufAppendS(userConfigHome, state->passwd->pw_dir);
|
||||
ffStrbufAppendS(userConfigHome, "/.config/");
|
||||
FF_ENSURE_ONLY_ONCE_IN_LIST(userConfigHome)
|
||||
void pathsAddHome(FFlist* dirs, FFstate* state, const char* suffix)
|
||||
{
|
||||
FFstrbuf* buffer = (FFstrbuf*) ffListAdd(dirs);
|
||||
ffStrbufInitA(buffer, 64);
|
||||
ffStrbufAppendS(buffer, state->passwd->pw_dir);
|
||||
ffStrbufAppendS(buffer, suffix);
|
||||
ffStrbufEnsureEndsWithC(buffer, '/');
|
||||
FF_ENSURE_ONLY_ONCE_IN_LIST(dirs, buffer);
|
||||
}
|
||||
|
||||
FFstrbuf* userHome = ffListAdd(&state->configDirs);
|
||||
ffStrbufInitA(userHome, 64);
|
||||
ffStrbufAppendS(userHome, state->passwd->pw_dir);
|
||||
ffStrbufEnsureEndsWithC(userHome, '/');
|
||||
FF_ENSURE_ONLY_ONCE_IN_LIST(userHome)
|
||||
void pathsAddAbsolute(FFlist* dirs, const char* path)
|
||||
{
|
||||
FFstrbuf* buffer = (FFstrbuf*) ffListAdd(dirs);
|
||||
ffStrbufInitA(buffer, 64);
|
||||
ffStrbufAppendS(buffer, path);
|
||||
ffStrbufEnsureEndsWithC(buffer, '/');
|
||||
FF_ENSURE_ONLY_ONCE_IN_LIST(dirs, buffer);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
if(getenv("MSYSTEM") && getenv("HOME"))
|
||||
{
|
||||
// We are in MSYS2 / Git Bash
|
||||
|
||||
FFstrbuf* msysConfigHome = ffListAdd(&state->configDirs);
|
||||
ffStrbufInitA(msysConfigHome, 64);
|
||||
ffStrbufAppendS(msysConfigHome, getenv("HOME"));
|
||||
ffStrbufReplaceAllC(msysConfigHome, '\\', '/');
|
||||
ffStrbufEnsureEndsWithC(msysConfigHome, '/');
|
||||
ffStrbufAppendS(msysConfigHome, ".config/");
|
||||
FF_ENSURE_ONLY_ONCE_IN_LIST(msysConfigHome)
|
||||
|
||||
FFstrbuf* msysHome = ffListAdd(&state->configDirs);
|
||||
ffStrbufInitA(msysHome, 64);
|
||||
ffStrbufAppendS(msysHome, getenv("HOME"));
|
||||
ffStrbufReplaceAllC(msysHome, '\\', '/');
|
||||
ffStrbufEnsureEndsWithC(msysHome, '/');
|
||||
FF_ENSURE_ONLY_ONCE_IN_LIST(msysHome)
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if !defined(_WIN32) && !defined(__APPLE__)
|
||||
|
||||
FFstrbuf xdgConfigDirs;
|
||||
ffStrbufInitA(&xdgConfigDirs, 64);
|
||||
ffStrbufAppendS(&xdgConfigDirs, getenv("XDG_CONFIG_DIRS"));
|
||||
void pathsAddEnv(FFlist* dirs, const char* env)
|
||||
{
|
||||
FFstrbuf value;
|
||||
ffStrbufInitA(&value, 64);
|
||||
ffStrbufAppendS(&value, getenv(env));
|
||||
|
||||
uint32_t startIndex = 0;
|
||||
while (startIndex < xdgConfigDirs.length)
|
||||
while (startIndex < value.length)
|
||||
{
|
||||
uint32_t colonIndex = ffStrbufNextIndexC(&xdgConfigDirs, startIndex, ':');
|
||||
xdgConfigDirs.chars[colonIndex] = '\0';
|
||||
uint32_t colonIndex = ffStrbufNextIndexC(&value, startIndex, ':');
|
||||
value.chars[colonIndex] = '\0';
|
||||
|
||||
if(!ffStrSet(xdgConfigDirs.chars + startIndex))
|
||||
if(!ffStrSet(value.chars + startIndex))
|
||||
{
|
||||
startIndex = colonIndex + 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
FFstrbuf* buffer = (FFstrbuf*) ffListAdd(&state->configDirs);
|
||||
ffStrbufInitA(buffer, 64);
|
||||
ffStrbufAppendS(buffer, xdgConfigDirs.chars + startIndex);
|
||||
ffStrbufEnsureEndsWithC(buffer, '/');
|
||||
FF_ENSURE_ONLY_ONCE_IN_LIST(buffer);
|
||||
pathsAddAbsolute(dirs, value.chars + startIndex);
|
||||
|
||||
startIndex = colonIndex + 1;
|
||||
}
|
||||
ffStrbufDestroy(&xdgConfigDirs);
|
||||
|
||||
FFstrbuf* systemConfigHome = ffListAdd(&state->configDirs);
|
||||
ffStrbufInitA(systemConfigHome, 64);
|
||||
ffStrbufAppendS(systemConfigHome, FASTFETCH_TARGET_DIR_ETC"/xdg/");
|
||||
FF_ENSURE_ONLY_ONCE_IN_LIST(systemConfigHome)
|
||||
ffStrbufDestroy(&value);
|
||||
}
|
||||
|
||||
static void initConfigDirs(FFstate* state)
|
||||
{
|
||||
ffListInit(&state->configDirs, sizeof(FFstrbuf));
|
||||
|
||||
#ifdef _WIN32
|
||||
pathsAddKnownFolder(&state->configDirs, &FOLDERID_RoamingAppData);
|
||||
pathsAddKnownFolder(&state->configDirs, &FOLDERID_LocalAppData);
|
||||
#elif defined(__APPLE__)
|
||||
pathsAddHome(&state->configDirs, state, "/Library/Preferences/");
|
||||
#else
|
||||
pathsAddEnv(&state->configDirs, "XDG_CONFIG_HOME");
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
FFstrbuf* systemConfig = ffListAdd(&state->configDirs);
|
||||
ffStrbufInitA(systemConfig, 64);
|
||||
ffStrbufAppendS(systemConfig, FASTFETCH_TARGET_DIR_ETC"/");
|
||||
FF_ENSURE_ONLY_ONCE_IN_LIST(systemConfig)
|
||||
|
||||
FFstrbuf* systemConfigInstall = ffListAdd(&state->configDirs);
|
||||
ffStrbufInitA(systemConfigInstall, 64);
|
||||
ffStrbufAppendS(systemConfigInstall, FASTFETCH_TARGET_DIR_INSTALL_SYSCONF"/");
|
||||
FF_ENSURE_ONLY_ONCE_IN_LIST(systemConfigInstall)
|
||||
|
||||
pathsAddHome(&state->configDirs, state, "/.config/");
|
||||
pathsAddHome(&state->configDirs, state, "");
|
||||
|
||||
#ifdef _WIN32
|
||||
if(getenv("MSYSTEM") && getenv("HOME"))
|
||||
{
|
||||
// We are in MSYS2 / Git Bash
|
||||
pathsAddEnvSuffix(&state->configDirs, "HOME", ".config/");
|
||||
pathsAddEnvSuffix(&state->configDirs, "HOME", "");
|
||||
}
|
||||
#endif
|
||||
|
||||
#undef FF_ENSURE_ONLY_ONCE_IN_LIST
|
||||
#if !defined(_WIN32) && !defined(__APPLE__)
|
||||
pathsAddEnv(&state->configDirs, "XDG_CONFIG_DIRS");
|
||||
pathsAddAbsolute(&state->configDirs, FASTFETCH_TARGET_DIR_ETC"/xdg/");
|
||||
#endif
|
||||
|
||||
#if !defined(_WIN32)
|
||||
pathsAddAbsolute(&state->configDirs, FASTFETCH_TARGET_DIR_ETC"/");
|
||||
pathsAddAbsolute(&state->configDirs, FASTFETCH_TARGET_DIR_INSTALL_SYSCONF"/");
|
||||
#endif
|
||||
}
|
||||
|
||||
static void initDataDirs(FFstate* state)
|
||||
{
|
||||
ffListInit(&state->dataDirs, sizeof(FFstrbuf));
|
||||
|
||||
#ifdef _WIN32
|
||||
pathsAddKnownFolder(&state->dataDirs, &FOLDERID_RoamingAppData);
|
||||
pathsAddKnownFolder(&state->dataDirs, &FOLDERID_LocalAppData);
|
||||
#elif defined(__APPLE__)
|
||||
pathsAddHome(&state->dataDirs, state, "/Library/Application Support/");
|
||||
#else
|
||||
pathsAddEnv(&state->dataDirs, "XDG_DATA_HOME");
|
||||
#endif
|
||||
|
||||
pathsAddHome(&state->dataDirs, state, "/.local/share/");
|
||||
pathsAddHome(&state->dataDirs, state, "");
|
||||
|
||||
#ifdef _WIN32
|
||||
if(getenv("MSYSTEM") && getenv("HOME"))
|
||||
{
|
||||
// We are in MSYS2 / Git Bash
|
||||
pathsAddEnvSuffix(&state->dataDirs, "HOME", ".local/share/");
|
||||
pathsAddEnvSuffix(&state->dataDirs, "HOME", "");
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(_WIN32) && !defined(__APPLE__)
|
||||
pathsAddEnv(&state->dataDirs, "XDG_DATA_DIRS");
|
||||
#endif
|
||||
|
||||
#if !defined(_WIN32)
|
||||
pathsAddAbsolute(&state->dataDirs, FASTFETCH_TARGET_DIR_USR"/local/share/");
|
||||
pathsAddAbsolute(&state->dataDirs, FASTFETCH_TARGET_DIR_USR"/share/");
|
||||
#endif
|
||||
}
|
||||
|
||||
static void initState(FFstate* state)
|
||||
@@ -172,6 +192,7 @@ static void initState(FFstate* state)
|
||||
uname(&state->utsname);
|
||||
|
||||
initConfigDirs(state);
|
||||
initDataDirs(state);
|
||||
}
|
||||
|
||||
static void initModuleArg(FFModuleArgs* args)
|
||||
|
||||
+4
-19
@@ -144,11 +144,6 @@ done:
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ffParsePropFile(const char* filename, const char* start, FFstrbuf* buffer)
|
||||
{
|
||||
return ffParsePropFileValues(filename, 1, (FFpropquery[]){{start, buffer}});
|
||||
}
|
||||
|
||||
bool ffParsePropFileHomeValues(const FFinstance* instance, const char* relativeFile, uint32_t numQueries, FFpropquery* queries)
|
||||
{
|
||||
FFstrbuf absolutePath;
|
||||
@@ -164,22 +159,17 @@ bool ffParsePropFileHomeValues(const FFinstance* instance, const char* relativeF
|
||||
return result;
|
||||
}
|
||||
|
||||
bool ffParsePropFileHome(const FFinstance* instance, const char* relativeFile, const char* start, FFstrbuf* buffer)
|
||||
{
|
||||
return ffParsePropFileHomeValues(instance, relativeFile, 1, (FFpropquery[]){{start, buffer}});
|
||||
}
|
||||
|
||||
bool ffParsePropFileConfigValues(const FFinstance* instance, const char* relativeFile, uint32_t numQueries, FFpropquery* queries)
|
||||
bool ffParsePropFileListValues(const FFlist* list, const char* relativeFile, uint32_t numQueries, FFpropquery* queries)
|
||||
{
|
||||
bool foundAFile = false;
|
||||
|
||||
FFstrbuf baseDir;
|
||||
ffStrbufInitA(&baseDir, 64);
|
||||
|
||||
for(uint32_t i = 0; i < instance->state.configDirs.length; i++)
|
||||
for(uint32_t i = 0; i < list->length; i++)
|
||||
{
|
||||
//We need to copy the config dir each time, because it used by multiple threads, so we can't directly write to it.
|
||||
ffStrbufSet(&baseDir, ffListGet(&instance->state.configDirs, i));
|
||||
//We need to copy the dir each time, because it used by multiple threads, so we can't directly write to it.
|
||||
ffStrbufSet(&baseDir, ffListGet(list, i));
|
||||
ffStrbufAppendS(&baseDir, relativeFile);
|
||||
|
||||
if(ffParsePropFileValues(baseDir.chars, numQueries, queries))
|
||||
@@ -203,8 +193,3 @@ bool ffParsePropFileConfigValues(const FFinstance* instance, const char* relativ
|
||||
|
||||
return foundAFile;
|
||||
}
|
||||
|
||||
bool ffParsePropFileConfig(const FFinstance* instance, const char* relativeFile, const char* start, FFstrbuf* buffer)
|
||||
{
|
||||
return ffParsePropFileConfigValues(instance, relativeFile, 1, (FFpropquery[]){{start, buffer}});
|
||||
}
|
||||
|
||||
+36
-4
@@ -14,10 +14,42 @@ typedef struct FFpropquery
|
||||
bool ffParsePropLine(const char* line, const char* start, FFstrbuf* buffer);
|
||||
bool ffParsePropLines(const char* lines, const char* start, FFstrbuf* buffer);
|
||||
bool ffParsePropFileValues(const char* filename, uint32_t numQueries, FFpropquery* queries);
|
||||
bool ffParsePropFile(const char* filename, const char* start, FFstrbuf* buffer);
|
||||
bool ffParsePropFileHomeValues(const FFinstance* instance, const char* relativeFile, uint32_t numQueries, FFpropquery* queries);
|
||||
bool ffParsePropFileHome(const FFinstance* instance, const char* relativeFile, const char* start, FFstrbuf* buffer);
|
||||
bool ffParsePropFileConfigValues(const FFinstance* instance, const char* relativeFile, uint32_t numQueries, FFpropquery* queries);
|
||||
bool ffParsePropFileConfig(const FFinstance* instance, const char* relativeFile, const char* start, FFstrbuf* buffer);
|
||||
bool ffParsePropFileListValues(const FFlist* list, const char* relativeFile, uint32_t numQueries, FFpropquery* queries);
|
||||
|
||||
static inline bool ffParsePropFile(const char* filename, const char* start, FFstrbuf* buffer)
|
||||
{
|
||||
return ffParsePropFileValues(filename, 1, (FFpropquery[]){{start, buffer}});
|
||||
}
|
||||
|
||||
static inline bool ffParsePropFileHome(const FFinstance* instance, const char* relativeFile, const char* start, FFstrbuf* buffer)
|
||||
{
|
||||
return ffParsePropFileHomeValues(instance, relativeFile, 1, (FFpropquery[]){{start, buffer}});
|
||||
}
|
||||
|
||||
static inline bool ffParsePropFileList(const FFlist* list, const char* relativeFile, const char* start, FFstrbuf* buffer)
|
||||
{
|
||||
return ffParsePropFileListValues(list, relativeFile, 1, (FFpropquery[]){{start, buffer}});
|
||||
}
|
||||
|
||||
static inline bool ffParsePropFileConfigValues(const FFinstance* instance, const char* relativeFile, uint32_t numQueries, FFpropquery* queries)
|
||||
{
|
||||
return ffParsePropFileListValues(&instance->state.configDirs, relativeFile, numQueries, queries);
|
||||
}
|
||||
|
||||
static inline bool ffParsePropFileConfig(const FFinstance* instance, const char* relativeFile, const char* start, FFstrbuf* buffer)
|
||||
{
|
||||
return ffParsePropFileConfigValues(instance, relativeFile, 1, (FFpropquery[]){{start, buffer}});
|
||||
}
|
||||
|
||||
static inline bool ffParsePropFileDataValues(const FFinstance* instance, const char* relativeFile, uint32_t numQueries, FFpropquery* queries)
|
||||
{
|
||||
return ffParsePropFileListValues(&instance->state.dataDirs, relativeFile, numQueries, queries);
|
||||
}
|
||||
|
||||
static inline bool ffParsePropFileData(const FFinstance* instance, const char* relativeFile, const char* start, FFstrbuf* buffer)
|
||||
{
|
||||
return ffParsePropFileDataValues(instance, relativeFile, 1, (FFpropquery[]){{start, buffer}});
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -5,6 +5,7 @@ Informative options:
|
||||
-h,--help <command>: Show help for a specific command
|
||||
-v,--version: Show the version of fastfetch
|
||||
--list-config-paths: List search paths of config files
|
||||
--list-data-paths: List search paths of presets and logos
|
||||
--list-logos: List available logos
|
||||
--list-modules: List available modules
|
||||
--list-presets: List presets fastfetch knows about; they can be loaded with --load-config (+)
|
||||
|
||||
@@ -73,7 +73,7 @@ static bool detectCursorFromXDG(const FFinstance* instance, bool user, FFCursorR
|
||||
if(user)
|
||||
ffParsePropFileHome(instance, ".icons/default/index.theme", "Inherits =", &result->theme);
|
||||
else
|
||||
ffParsePropFile(FASTFETCH_TARGET_DIR_USR"/share/icons/default/index.theme", "Inherits =", &result->theme);
|
||||
ffParsePropFileData(instance, "icons/default/index.theme", "Inherits =", &result->theme);
|
||||
|
||||
return result->theme.length > 0;
|
||||
}
|
||||
|
||||
@@ -116,38 +116,34 @@ static void applyBetterWM(FFDisplayServerResult* result, const char* processName
|
||||
ffStrbufAppend(&result->wmPrettyName, &result->wmProcessName);
|
||||
}
|
||||
|
||||
static void getKDE(FFDisplayServerResult* result)
|
||||
static void getKDE(const FFinstance* instance, FFDisplayServerResult* result)
|
||||
{
|
||||
ffStrbufSetS(&result->deProcessName, "plasmashell");
|
||||
ffStrbufSetS(&result->dePrettyName, "KDE Plasma");
|
||||
|
||||
ffParsePropFile(FASTFETCH_TARGET_DIR_USR"/share/xsessions/plasma.desktop", "X-KDE-PluginInfo-Version =", &result->deVersion);
|
||||
ffParsePropFileData(instance, "xsessions/plasma.desktop", "X-KDE-PluginInfo-Version =", &result->deVersion);
|
||||
if(result->deVersion.length == 0)
|
||||
ffParsePropFile(FASTFETCH_TARGET_DIR_USR"/share/xsessions/plasma5.desktop", "X-KDE-PluginInfo-Version =", &result->deVersion);
|
||||
ffParsePropFileData(instance, "xsessions/plasma5.desktop", "X-KDE-PluginInfo-Version =", &result->deVersion);
|
||||
if(result->deVersion.length == 0)
|
||||
ffParsePropFile(FASTFETCH_TARGET_DIR_USR"/share/wayland-sessions/plasmawayland.desktop", "X-KDE-PluginInfo-Version =", &result->deVersion);
|
||||
ffParsePropFileData(instance, "wayland-sessions/plasmawayland.desktop", "X-KDE-PluginInfo-Version =", &result->deVersion);
|
||||
if(result->deVersion.length == 0)
|
||||
ffParsePropFile(FASTFETCH_TARGET_DIR_USR"/share/wayland-sessions/plasmawayland5.desktop", "X-KDE-PluginInfo-Version =", &result->deVersion);
|
||||
if(result->deVersion.length == 0)
|
||||
ffParsePropFile(FASTFETCH_TARGET_DIR_USR"/local/share/xsessions/plasma.desktop", "X-KDE-PluginInfo-Version =", &result->deVersion);
|
||||
if(result->deVersion.length == 0)
|
||||
ffParsePropFile(FASTFETCH_TARGET_DIR_USR"/local/share/wayland-sessions/plasmawayland.desktop", "X-KDE-PluginInfo-Version =", &result->deVersion);
|
||||
ffParsePropFileData(instance, "wayland-sessions/plasmawayland5.desktop", "X-KDE-PluginInfo-Version =", &result->deVersion);
|
||||
|
||||
applyBetterWM(result, getenv("KDEWM"));
|
||||
}
|
||||
|
||||
static void getGnome(FFDisplayServerResult* result)
|
||||
static void getGnome(const FFinstance* instance, FFDisplayServerResult* result)
|
||||
{
|
||||
ffStrbufSetS(&result->deProcessName, "gnome-shell");
|
||||
ffStrbufSetS(&result->dePrettyName, "GNOME");
|
||||
ffParsePropFile(FASTFETCH_TARGET_DIR_USR"/share/gnome-shell/org.gnome.Extensions", "version :", &result->deVersion);
|
||||
ffParsePropFileData(instance, "gnome-shell/org.gnome.Extensions", "version :", &result->deVersion);
|
||||
}
|
||||
|
||||
static void getCinnamon(FFDisplayServerResult* result)
|
||||
static void getCinnamon(const FFinstance* instance, FFDisplayServerResult* result)
|
||||
{
|
||||
ffStrbufSetS(&result->deProcessName, "cinnamon");
|
||||
ffStrbufSetS(&result->dePrettyName, "Cinnamon");
|
||||
ffParsePropFile(FASTFETCH_TARGET_DIR_USR"/share/applications/cinnamon.desktop", "X-GNOME-Bugzilla-Version =", &result->deVersion);
|
||||
ffParsePropFileData(instance, "applications/cinnamon.desktop", "X-GNOME-Bugzilla-Version =", &result->deVersion);
|
||||
}
|
||||
|
||||
static void getMate(const FFinstance* instance, FFDisplayServerResult* result)
|
||||
@@ -164,7 +160,7 @@ static void getMate(const FFinstance* instance, FFDisplayServerResult* result)
|
||||
FFstrbuf micro;
|
||||
ffStrbufInit(µ);
|
||||
|
||||
ffParsePropFileValues(FASTFETCH_TARGET_DIR_USR"/share/mate-about/mate-version.xml", 3, (FFpropquery[]) {
|
||||
ffParsePropFileDataValues(instance, "mate-about/mate-version.xml", 3, (FFpropquery[]) {
|
||||
{"<platform>", &major},
|
||||
{"<minor>", &minor},
|
||||
{"<micro>", µ}
|
||||
@@ -193,7 +189,7 @@ static void getXFCE4(const FFinstance* instance, FFDisplayServerResult* result)
|
||||
{
|
||||
ffStrbufSetS(&result->deProcessName, "xfce4-session");
|
||||
ffStrbufSetS(&result->dePrettyName, "Xfce4");
|
||||
ffParsePropFile(FASTFETCH_TARGET_DIR_USR"/share/gtk-doc/html/libxfce4ui/index.html", "<div><p class=\"releaseinfo\">Version", &result->deVersion);
|
||||
ffParsePropFileData(instance, "gtk-doc/html/libxfce4ui/index.html", "<div><p class=\"releaseinfo\">Version", &result->deVersion);
|
||||
|
||||
if(result->deVersion.length == 0 && instance->config.allowSlowOperations)
|
||||
{
|
||||
@@ -214,12 +210,12 @@ static void getLXQt(const FFinstance* instance, FFDisplayServerResult* result)
|
||||
{
|
||||
ffStrbufSetS(&result->deProcessName, "lxqt-session");
|
||||
ffStrbufSetS(&result->dePrettyName, "LXQt");
|
||||
ffParsePropFile(FASTFETCH_TARGET_DIR_USR"/lib/pkgconfig/lxqt.pc", "Version:", &result->deVersion);
|
||||
ffParsePropFileData(instance, "gconfig/lxqt.pc", "Version:", &result->deVersion);
|
||||
|
||||
if(result->deVersion.length == 0)
|
||||
ffParsePropFile(FASTFETCH_TARGET_DIR_USR"/share/cmake/lxqt/lxqt-config.cmake", "set ( LXQT_VERSION", &result->deVersion);
|
||||
ffParsePropFileData(instance, "cmake/lxqt/lxqt-config.cmake", "set ( LXQT_VERSION", &result->deVersion);
|
||||
if(result->deVersion.length == 0)
|
||||
ffParsePropFile(FASTFETCH_TARGET_DIR_USR"/share/cmake/lxqt/lxqt-config-version.cmake", "set ( PACKAGE_VERSION", &result->deVersion);
|
||||
ffParsePropFileData(instance, "cmake/lxqt/lxqt-config-version.cmake", "set ( PACKAGE_VERSION", &result->deVersion);
|
||||
|
||||
if(result->deVersion.length == 0 && instance->config.allowSlowOperations)
|
||||
{
|
||||
@@ -253,19 +249,19 @@ static void applyPrettyNameIfDE(const FFinstance* instance, FFDisplayServerResul
|
||||
strcasecmp(name, "plasma") == 0 ||
|
||||
strcasecmp(name, "plasmashell") == 0 ||
|
||||
strcasecmp(name, "plasmawayland") == 0
|
||||
) getKDE(result);
|
||||
) getKDE(instance, result);
|
||||
|
||||
else if(
|
||||
strcasecmp(name, "Gnome") == 0 ||
|
||||
strcasecmp(name, "ubuntu:GNOME") == 0 ||
|
||||
strcasecmp(name, "ubuntu") == 0 ||
|
||||
strcasecmp(name, "gnome-shell") == 0
|
||||
) getGnome(result);
|
||||
) getGnome(instance, result);
|
||||
|
||||
else if(
|
||||
strcasecmp(name, "X-Cinnamon") == 0 ||
|
||||
strcasecmp(name, "Cinnamon") == 0
|
||||
) getCinnamon(result);
|
||||
) getCinnamon(instance, result);
|
||||
|
||||
else if(
|
||||
strcasecmp(name, "XFCE") == 0 ||
|
||||
|
||||
@@ -58,7 +58,7 @@ static void pciDetectVendorName(FFGPUResult* gpu, PCIData* pci, struct pci_dev*
|
||||
ffStrbufSetS(&gpu->vendor, FF_GPU_VENDOR_NAME_NVIDIA);
|
||||
}
|
||||
|
||||
static void drmDetectDeviceName(FFGPUResult* gpu, PCIData* pci, struct pci_dev* device)
|
||||
static void drmDetectDeviceName(const FFinstance* instance, FFGPUResult* gpu, PCIData* pci, struct pci_dev* device)
|
||||
{
|
||||
u8 revId;
|
||||
bool revIdSet = false;;
|
||||
@@ -82,7 +82,7 @@ static void drmDetectDeviceName(FFGPUResult* gpu, PCIData* pci, struct pci_dev*
|
||||
ffStrbufInit(&query);
|
||||
ffStrbufAppendF(&query, "%X, %X,", device->device_id, revId);
|
||||
|
||||
ffParsePropFile(FASTFETCH_TARGET_DIR_USR"/share/libdrm/amdgpu.ids", query.chars, &gpu->name);
|
||||
ffParsePropFileData(instance, "libdrm/amdgpu.ids", query.chars, &gpu->name);
|
||||
|
||||
ffStrbufDestroy(&query);
|
||||
|
||||
@@ -94,11 +94,11 @@ static void drmDetectDeviceName(FFGPUResult* gpu, PCIData* pci, struct pci_dev*
|
||||
ffStrbufRemoveStringsA(&gpu->name, sizeof(removeStrings) / sizeof(removeStrings[0]), removeStrings);
|
||||
}
|
||||
|
||||
static void pciDetectDeviceName(FFGPUResult* gpu, PCIData* pci, struct pci_dev* device)
|
||||
static void pciDetectDeviceName(const FFinstance* instance, FFGPUResult* gpu, PCIData* pci, struct pci_dev* device)
|
||||
{
|
||||
if(ffStrbufCompS(&gpu->vendor, FF_GPU_VENDOR_NAME_AMD) == 0)
|
||||
{
|
||||
drmDetectDeviceName(gpu, pci, device);
|
||||
drmDetectDeviceName(instance, gpu, pci, device);
|
||||
if(gpu->name.length > 0)
|
||||
return;
|
||||
}
|
||||
@@ -188,7 +188,7 @@ static void pciHandleDevice(const FFinstance* instance, FFlist* results, PCIData
|
||||
pciDetectVendorName(gpu, pci, device);
|
||||
|
||||
ffStrbufInit(&gpu->name);
|
||||
pciDetectDeviceName(gpu, pci, device);
|
||||
pciDetectDeviceName(instance, gpu, pci, device);
|
||||
|
||||
ffStrbufInit(&gpu->driver);
|
||||
pciDetectDriverName(gpu, pci, device);
|
||||
|
||||
@@ -88,15 +88,15 @@ static void detectKonsole(const FFinstance* instance, FFTerminalFontResult* term
|
||||
}
|
||||
|
||||
FFstrbuf profilePath;
|
||||
ffStrbufInitA(&profilePath, 64);
|
||||
ffStrbufAppendS(&profilePath, ".local/share/konsole/");
|
||||
ffStrbufInitA(&profilePath, 32);
|
||||
ffStrbufAppendS(&profilePath, "konsole/");
|
||||
ffStrbufAppend(&profilePath, &profile);
|
||||
|
||||
ffStrbufDestroy(&profile);
|
||||
|
||||
FFstrbuf fontName;
|
||||
ffStrbufInit(&fontName);
|
||||
ffParsePropFileHome(instance, profilePath.chars, "Font =", &fontName);
|
||||
ffParsePropFileData(instance, profilePath.chars, "Font =", &fontName);
|
||||
|
||||
if(fontName.length == 0)
|
||||
ffStrbufAppendF(&terminalFont->error, "Couldn't find \"Font=%%[^\\n]\" in \"%s\"", profilePath.chars);
|
||||
|
||||
+28
-31
@@ -526,17 +526,11 @@ static inline void listAvailablePresetsFromFolder(FFstrbuf* folder, uint8_t inde
|
||||
|
||||
static inline void listAvailablePresets(FFinstance* instance)
|
||||
{
|
||||
FFstrbuf folder;
|
||||
ffStrbufInitA(&folder, 64);
|
||||
|
||||
ffStrbufSetS(&folder, instance->state.passwd->pw_dir);
|
||||
ffStrbufAppendS(&folder, "/.local/share/fastfetch/presets/");
|
||||
listAvailablePresetsFromFolder(&folder, 0, NULL);
|
||||
|
||||
ffStrbufSetS(&folder, FASTFETCH_TARGET_DIR_USR"/share/fastfetch/presets/");
|
||||
listAvailablePresetsFromFolder(&folder, 0, NULL);
|
||||
|
||||
ffStrbufDestroy(&folder);
|
||||
FF_LIST_FOR_EACH(FFstrbuf, path, instance->state.dataDirs)
|
||||
{
|
||||
ffStrbufAppendS(path, "fastfetch/presets/");
|
||||
listAvailablePresetsFromFolder(path, 0, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static void listConfigPaths(FFinstance* instance)
|
||||
@@ -548,6 +542,15 @@ static void listConfigPaths(FFinstance* instance)
|
||||
}
|
||||
}
|
||||
|
||||
static void listDataPaths(FFinstance* instance)
|
||||
{
|
||||
FF_LIST_FOR_EACH(FFstrbuf, folder, instance->state.dataDirs)
|
||||
{
|
||||
ffStrbufAppendS(folder, "fastfetch/");
|
||||
puts(folder->chars);
|
||||
}
|
||||
}
|
||||
|
||||
static void parseOption(FFinstance* instance, FFdata* data, const char* key, const char* value);
|
||||
|
||||
static bool parseConfigFile(FFinstance* instance, FFdata* data, const char* path)
|
||||
@@ -645,37 +648,26 @@ static void optionParseConfigFile(FFinstance* instance, FFdata* data, const char
|
||||
if(parseConfigFile(instance, data, value))
|
||||
return;
|
||||
|
||||
//Try to load as an user preset
|
||||
//Try to load as a relative path
|
||||
|
||||
FFstrbuf filename;
|
||||
ffStrbufInitA(&filename, 64);
|
||||
|
||||
ffStrbufAppendS(&filename, instance->state.passwd->pw_dir);
|
||||
ffStrbufAppendS(&filename, "/.local/share/fastfetch/presets/");
|
||||
ffStrbufAppendS(&filename, value);
|
||||
|
||||
if(parseConfigFile(instance, data, filename.chars))
|
||||
FF_LIST_FOR_EACH(FFstrbuf, path, instance->state.dataDirs)
|
||||
{
|
||||
ffStrbufDestroy(&filename);
|
||||
return;
|
||||
}
|
||||
uint32_t pathLength = path->length;
|
||||
|
||||
ffStrbufAppendS(path, "fastfetch/presets/");
|
||||
ffStrbufAppendS(path, value);
|
||||
|
||||
//Try to load as a system preset
|
||||
bool success = parseConfigFile(instance, data, path->chars);
|
||||
|
||||
ffStrbufSetS(&filename, FASTFETCH_TARGET_DIR_USR"/share/fastfetch/presets/");
|
||||
ffStrbufAppendS(&filename, value);
|
||||
ffStrbufSubstrBefore(path, pathLength);
|
||||
|
||||
if(parseConfigFile(instance, data, filename.chars))
|
||||
{
|
||||
ffStrbufDestroy(&filename);
|
||||
return;
|
||||
if(success)
|
||||
return;
|
||||
}
|
||||
|
||||
//File not found
|
||||
|
||||
fprintf(stderr, "Error: couldn't find config: %s\n", value);
|
||||
ffStrbufDestroy(&filename);
|
||||
exit(414);
|
||||
}
|
||||
|
||||
@@ -917,6 +909,11 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
|
||||
listConfigPaths(instance);
|
||||
exit(0);
|
||||
}
|
||||
else if(strcasecmp(subkey, "-data-paths") == 0)
|
||||
{
|
||||
listDataPaths(instance);
|
||||
exit(0);
|
||||
}
|
||||
else if(strcasecmp(subkey, "-features") == 0)
|
||||
{
|
||||
ffListFeatures();
|
||||
|
||||
+2
-1
@@ -211,7 +211,8 @@ typedef struct FFstate
|
||||
struct passwd* passwd;
|
||||
struct utsname utsname;
|
||||
|
||||
FFlist configDirs;
|
||||
FFlist configDirs; // List of FFstrbuf, trailing slash included
|
||||
FFlist dataDirs; // List of FFstrbuf, trailing slash included
|
||||
} FFstate;
|
||||
|
||||
typedef struct FFinstance
|
||||
|
||||
Reference in New Issue
Block a user