--logo-source / --load-config: support path with env variables (Windows)

This commit is contained in:
李通洲
2023-08-13 10:18:16 +08:00
parent a34980e339
commit 290e721ee1
5 changed files with 32 additions and 2 deletions
+1
View File
@@ -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, ...);
+5
View File
@@ -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;
+12
View File
@@ -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
View File
@@ -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)
{
+5
View File
@@ -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)
{