Skip to content

Commit c64cbf5

Browse files
committed
fastfetch: load config from fastfetch binary path
Fix #1649
1 parent d11235b commit c64cbf5

File tree

3 files changed

+30
-18
lines changed

3 files changed

+30
-18
lines changed

src/fastfetch.c

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -472,31 +472,27 @@ static void optionParseConfigFile(FFdata* data, const char* key, const char* val
472472

473473
if (parseJsoncFile(value)) return;
474474

475-
//Try to load as a relative path
476-
477475
FF_STRBUF_AUTO_DESTROY absolutePath = ffStrbufCreateA(128);
478-
FF_LIST_FOR_EACH(FFstrbuf, path, instance.state.platform.dataDirs)
476+
477+
//Try to load as a relative path with the directory of fastfetch binary
478+
if (instance.state.platform.exePath.length)
479479
{
480-
//We need to copy it, because if a config file loads a config file, the value of path must be unchanged
481-
ffStrbufSet(&absolutePath, path);
482-
ffStrbufAppendS(&absolutePath, "fastfetch/presets/");
480+
ffStrbufSet(&absolutePath, &instance.state.platform.exePath);
481+
ffStrbufSubstrBeforeLastC(&absolutePath, '/');
482+
ffStrbufAppendS(&absolutePath, "/");
483483
ffStrbufAppendS(&absolutePath, value);
484484

485-
bool success = parseJsoncFile(absolutePath.chars);
486-
if (!success)
487-
{
488-
ffStrbufAppendS(&absolutePath, ".jsonc");
489-
success = parseJsoncFile(absolutePath.chars);
490-
}
491-
492-
if (success) return;
485+
if (parseJsoncFile(absolutePath.chars)) return;
486+
ffStrbufClear(&absolutePath);
493487
}
494488

489+
//Try to load as a relative path
490+
491+
FF_LIST_FOR_EACH(FFstrbuf, path, instance.state.platform.dataDirs)
495492
{
496-
//Try exe path
497-
ffStrbufSet(&absolutePath, &instance.state.platform.exePath);
498-
ffStrbufSubstrBeforeLastC(&absolutePath, '/');
499-
ffStrbufAppendS(&absolutePath, "/presets/");
493+
//We need to copy it, because if a config file loads a config file, the value of path must be unchanged
494+
ffStrbufSet(&absolutePath, path);
495+
ffStrbufAppendS(&absolutePath, "fastfetch/presets/");
500496
ffStrbufAppendS(&absolutePath, value);
501497

502498
bool success = parseJsoncFile(absolutePath.chars);

src/util/platform/FFPlatform_unix.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,14 @@ static void getDataDirs(FFPlatform* platform)
172172
#endif
173173
ffPlatformPathAddAbsolute(&platform->dataDirs, FASTFETCH_TARGET_DIR_USR "/local/share/");
174174
ffPlatformPathAddAbsolute(&platform->dataDirs, FASTFETCH_TARGET_DIR_USR "/share/");
175+
176+
if (platform->exePath.length > 0)
177+
{
178+
// Add ${currentExePath}
179+
FF_STRBUF_AUTO_DESTROY path = ffStrbufCreateCopy(&platform->exePath);
180+
ffStrbufSubstrBeforeLastC(&path, '/');
181+
ffPlatformPathAddAbsolute(&platform->dataDirs, path.chars);
182+
}
175183
}
176184

177185
static void getUserName(FFPlatform* platform, const struct passwd* pwd)

src/util/platform/FFPlatform_windows.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,14 @@ static void getDataDirs(FFPlatform* platform)
129129
platformPathAddKnownFolder(&platform->dataDirs, &FOLDERID_RoamingAppData);
130130
platformPathAddKnownFolder(&platform->dataDirs, &FOLDERID_LocalAppData);
131131
ffPlatformPathAddHome(&platform->dataDirs, platform, "");
132+
133+
if (platform->exePath.length > 0)
134+
{
135+
// Add ${currentExePath}
136+
FF_STRBUF_AUTO_DESTROY path = ffStrbufCreateCopy(&platform->exePath);
137+
ffStrbufSubstrBeforeLastC(&path, '/');
138+
ffPlatformPathAddAbsolute(&platform->dataDirs, path.chars);
139+
}
132140
}
133141

134142
static void getUserName(FFPlatform* platform)

0 commit comments

Comments
 (0)