mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-29 16:26:39 +01:00
--logo-source / --load-config: support path with env variables (Windows)
This commit is contained in:
@@ -82,6 +82,7 @@ typedef enum FFPathType
|
||||
#define FF_PATHTYPE_ANY (FF_PATHTYPE_FILE | FF_PATHTYPE_DIRECTORY)
|
||||
|
||||
bool ffPathExists(const char* path, FFPathType pathType);
|
||||
bool ffPathExpandEnv(const char* in, FFstrbuf* out);
|
||||
|
||||
FF_C_SCANF(2, 3)
|
||||
const char* ffGetTerminalResponse(const char* request, const char* format, ...);
|
||||
|
||||
@@ -107,6 +107,11 @@ bool ffPathExists(const char* path, FFPathType type)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ffPathExpandEnv(const char* in, FFstrbuf* out)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const char* ffGetTerminalResponse(const char* request, const char* format, ...)
|
||||
{
|
||||
struct termios oldTerm, newTerm;
|
||||
|
||||
@@ -98,6 +98,18 @@ bool ffPathExists(const char* path, FFPathType type)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ffPathExpandEnv(const char* in, FFstrbuf* out)
|
||||
{
|
||||
DWORD length = ExpandEnvironmentStringsA(in, NULL, 0);
|
||||
if (length <= 1) return false;
|
||||
|
||||
ffStrbufClear(out);
|
||||
ffStrbufEnsureFree(out, (uint32_t)length);
|
||||
ExpandEnvironmentStringsA(in, out->chars, length);
|
||||
out->length = (uint32_t)length - 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ffSuppressIO(bool suppress)
|
||||
{
|
||||
(void) suppress; //Not implemented.
|
||||
|
||||
+9
-2
@@ -693,9 +693,16 @@ static void optionParseConfigFile(FFdata* data, const char* key, const char* val
|
||||
if(isJsonConfig ? parseJsoncFile(value) : parseConfigFile(data, value))
|
||||
return;
|
||||
|
||||
//Try to load as a relative path
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY absolutePath = ffStrbufCreateA(128);
|
||||
if (ffPathExpandEnv(value, &absolutePath))
|
||||
{
|
||||
bool success = isJsonConfig ? parseJsoncFile(value) : parseConfigFile(data, absolutePath.chars);
|
||||
|
||||
if(success)
|
||||
return;
|
||||
}
|
||||
|
||||
//Try to load as a relative path
|
||||
|
||||
FF_LIST_FOR_EACH(FFstrbuf, path, instance.state.platform.dataDirs)
|
||||
{
|
||||
|
||||
@@ -332,6 +332,11 @@ static void updateLogoPath(void)
|
||||
return;
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY fullPath = ffStrbufCreate();
|
||||
if (ffPathExpandEnv(options->source.chars, &fullPath) && ffPathExists(fullPath.chars, FF_PATHTYPE_FILE))
|
||||
{
|
||||
ffStrbufSet(&options->source, &fullPath);
|
||||
return;
|
||||
}
|
||||
|
||||
FF_LIST_FOR_EACH(FFstrbuf, dataDir, instance.state.platform.dataDirs)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user