Skip to content

Commit 290e721

Browse files
committed
--logo-source / --load-config: support path with env variables (Windows)
1 parent a34980e commit 290e721

File tree

5 files changed

+32
-2
lines changed

5 files changed

+32
-2
lines changed

src/common/io/io.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ typedef enum FFPathType
8282
#define FF_PATHTYPE_ANY (FF_PATHTYPE_FILE | FF_PATHTYPE_DIRECTORY)
8383

8484
bool ffPathExists(const char* path, FFPathType pathType);
85+
bool ffPathExpandEnv(const char* in, FFstrbuf* out);
8586

8687
FF_C_SCANF(2, 3)
8788
const char* ffGetTerminalResponse(const char* request, const char* format, ...);

src/common/io/io_unix.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ bool ffPathExists(const char* path, FFPathType type)
107107
return false;
108108
}
109109

110+
bool ffPathExpandEnv(const char* in, FFstrbuf* out)
111+
{
112+
return false;
113+
}
114+
110115
const char* ffGetTerminalResponse(const char* request, const char* format, ...)
111116
{
112117
struct termios oldTerm, newTerm;

src/common/io/io_windows.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,18 @@ bool ffPathExists(const char* path, FFPathType type)
9898
return false;
9999
}
100100

101+
bool ffPathExpandEnv(const char* in, FFstrbuf* out)
102+
{
103+
DWORD length = ExpandEnvironmentStringsA(in, NULL, 0);
104+
if (length <= 1) return false;
105+
106+
ffStrbufClear(out);
107+
ffStrbufEnsureFree(out, (uint32_t)length);
108+
ExpandEnvironmentStringsA(in, out->chars, length);
109+
out->length = (uint32_t)length - 1;
110+
return true;
111+
}
112+
101113
bool ffSuppressIO(bool suppress)
102114
{
103115
(void) suppress; //Not implemented.

src/fastfetch.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -693,9 +693,16 @@ static void optionParseConfigFile(FFdata* data, const char* key, const char* val
693693
if(isJsonConfig ? parseJsoncFile(value) : parseConfigFile(data, value))
694694
return;
695695

696-
//Try to load as a relative path
697-
698696
FF_STRBUF_AUTO_DESTROY absolutePath = ffStrbufCreateA(128);
697+
if (ffPathExpandEnv(value, &absolutePath))
698+
{
699+
bool success = isJsonConfig ? parseJsoncFile(value) : parseConfigFile(data, absolutePath.chars);
700+
701+
if(success)
702+
return;
703+
}
704+
705+
//Try to load as a relative path
699706

700707
FF_LIST_FOR_EACH(FFstrbuf, path, instance.state.platform.dataDirs)
701708
{

src/logo/logo.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,11 @@ static void updateLogoPath(void)
332332
return;
333333

334334
FF_STRBUF_AUTO_DESTROY fullPath = ffStrbufCreate();
335+
if (ffPathExpandEnv(options->source.chars, &fullPath) && ffPathExists(fullPath.chars, FF_PATHTYPE_FILE))
336+
{
337+
ffStrbufSet(&options->source, &fullPath);
338+
return;
339+
}
335340

336341
FF_LIST_FOR_EACH(FFstrbuf, dataDir, instance.state.platform.dataDirs)
337342
{

0 commit comments

Comments
 (0)