fastfetch: load config from fastfetch binary path

Fix #1649
This commit is contained in:
Carter Li authored and 李通洲 committed 2025-03-31 10:48:09 +08:00
1 parent d11235bbe2
commit c64cbf57d8
3 files changed
+30 -18

No files matched your search

+14 -18
View File
@@ -472,9 +472,22 @@ static void optionParseConfigFile(FFdata* data, const char* key, const char* val
if (parseJsoncFile(value)) return;
FF_STRBUF_AUTO_DESTROY absolutePath = ffStrbufCreateA(128);
//Try to load as a relative path with the directory of fastfetch binary
if (instance.state.platform.exePath.length)
{
ffStrbufSet(&absolutePath, &instance.state.platform.exePath);
ffStrbufSubstrBeforeLastC(&absolutePath, '/');
ffStrbufAppendS(&absolutePath, "/");
ffStrbufAppendS(&absolutePath, value);
if (parseJsoncFile(absolutePath.chars)) return;
ffStrbufClear(&absolutePath);
}
//Try to load as a relative path
FF_STRBUF_AUTO_DESTROY absolutePath = ffStrbufCreateA(128);
FF_LIST_FOR_EACH(FFstrbuf, path, instance.state.platform.dataDirs)
{
//We need to copy it, because if a config file loads a config file, the value of path must be unchanged
@@ -492,23 +505,6 @@ static void optionParseConfigFile(FFdata* data, const char* key, const char* val
if (success) return;
}
{
//Try exe path
ffStrbufSet(&absolutePath, &instance.state.platform.exePath);
ffStrbufSubstrBeforeLastC(&absolutePath, '/');
ffStrbufAppendS(&absolutePath, "/presets/");
ffStrbufAppendS(&absolutePath, value);
bool success = parseJsoncFile(absolutePath.chars);
if (!success)
{
ffStrbufAppendS(&absolutePath, ".jsonc");
success = parseJsoncFile(absolutePath.chars);
}
if (success) return;
}
//File not found
fprintf(stderr, "Error: couldn't find config: %s\n", value);
+8
View File
@@ -172,6 +172,14 @@ static void getDataDirs(FFPlatform* platform)
#endif
ffPlatformPathAddAbsolute(&platform->dataDirs, FASTFETCH_TARGET_DIR_USR "/local/share/");
ffPlatformPathAddAbsolute(&platform->dataDirs, FASTFETCH_TARGET_DIR_USR "/share/");
if (platform->exePath.length > 0)
{
// Add ${currentExePath}
FF_STRBUF_AUTO_DESTROY path = ffStrbufCreateCopy(&platform->exePath);
ffStrbufSubstrBeforeLastC(&path, '/');
ffPlatformPathAddAbsolute(&platform->dataDirs, path.chars);
}
}
static void getUserName(FFPlatform* platform, const struct passwd* pwd)
+8
View File
@@ -129,6 +129,14 @@ static void getDataDirs(FFPlatform* platform)
platformPathAddKnownFolder(&platform->dataDirs, &FOLDERID_RoamingAppData);
platformPathAddKnownFolder(&platform->dataDirs, &FOLDERID_LocalAppData);
ffPlatformPathAddHome(&platform->dataDirs, platform, "");
if (platform->exePath.length > 0)
{
// Add ${currentExePath}
FF_STRBUF_AUTO_DESTROY path = ffStrbufCreateCopy(&platform->exePath);
ffStrbufSubstrBeforeLastC(&path, '/');
ffPlatformPathAddAbsolute(&platform->dataDirs, path.chars);
}
}
static void getUserName(FFPlatform* platform)