Fastfetch: change the order of loading config files

This commit is contained in:
李通洲
2023-11-14 09:58:42 +08:00
parent ee7d3d471e
commit fceb19affe
3 changed files with 12 additions and 12 deletions
+2
View File
@@ -3,6 +3,8 @@
Changes:
* The deprecated flag `--gen-config conf` is removed
* Flag `--gen-config` now does the same thing as `--migrate-config`, which can be used as config migration and default config file generation. Flag `--migrate-config` is removed
* Fastfetch now searchs for config files in the order of `fastfetch --list-config-paths`, and won't load other config if one is found.
* Flag `--load-user-config` now works in command line flags, but not in config file.
# 2.2.3
+1
View File
@@ -20,6 +20,7 @@ Config options:
-c, --config <file>: Load a config file or preset (+)
--gen-config <?file>: Generate a config file (or print the file if <file> is `-`), with options specified in the command line (if any)
--gen-config-force <?file>: Generate a config file. Overwrite the existing one
--load-user-config <?bool>: Set if user config should be loaded. Default is true if env-var `NO_CONFIG` is not set
General options:
--thread <?bool>: Use separate threads to send HTTP requests
+9 -12
View File
@@ -160,6 +160,7 @@ static void listConfigPaths(void)
FF_LIST_FOR_EACH(FFstrbuf, folder, instance.state.platform.configDirs)
{
bool exists = false;
uint32_t length = folder->length + sizeof("fastfetch");
ffStrbufAppendS(folder, "fastfetch/config.jsonc");
exists = ffPathExists(folder->chars, FF_PATHTYPE_FILE);
if (!exists)
@@ -168,6 +169,7 @@ static void listConfigPaths(void)
ffStrbufAppendS(folder, "conf");
exists = ffPathExists(folder->chars, FF_PATHTYPE_FILE);
}
ffStrbufSubstrBefore(folder, length);
printf("%s%s\n", folder->chars, exists ? " (*)" : "");
}
}
@@ -218,7 +220,7 @@ static bool parseJsoncFile(const char* path)
static bool parseConfigFile(FFdata* data, const char* path)
{
FILE* file = fopen(path, "r");
FF_AUTO_CLOSE_FILE FILE* file = fopen(path, "r");
if(file == NULL)
return false;
@@ -311,7 +313,6 @@ static bool parseConfigFile(FFdata* data, const char* path)
if(line != NULL)
free(line);
fclose(file);
return true;
}
@@ -572,9 +573,8 @@ static void parseConfigFiles(FFdata* data)
{
if (__builtin_expect(instance.state.genConfigPath.length == 0, true))
{
for (uint32_t i = instance.state.platform.configDirs.length; i > 0; --i)
FF_LIST_FOR_EACH(FFstrbuf, dir, instance.state.platform.configDirs)
{
FFstrbuf* dir = ffListGet(&instance.state.platform.configDirs, i - 1);
uint32_t dirLength = dir->length;
ffStrbufAppendS(dir, "fastfetch/config.jsonc");
@@ -583,17 +583,14 @@ static void parseConfigFiles(FFdata* data)
if (success) return;
}
}
for (uint32_t i = instance.state.platform.configDirs.length; i > 0; --i)
FF_LIST_FOR_EACH(FFstrbuf, dir, instance.state.platform.configDirs)
{
if (!data->loadUserConfig)
return;
FFstrbuf* dir = ffListGet(&instance.state.platform.configDirs, i - 1);
uint32_t dirLength = dir->length;
ffStrbufAppendS(dir, "fastfetch/config.conf");
parseConfigFile(data, dir->chars);
bool success = parseConfigFile(data, dir->chars);
ffStrbufSubstrBefore(dir, dirLength);
if (success) return;
}
}
@@ -710,11 +707,11 @@ int main(int argc, char** argv)
FFdata data = {
.structure = ffStrbufCreate(),
.customValues = ffListCreate(sizeof(FFCustomValue)),
.loadUserConfig = true,
.loadUserConfig = !getenv("NO_CONFIG"),
};
parseArguments(&data, argc, argv, parseCommand);
if(!getenv("NO_CONFIG") && data.loadUserConfig)
if(data.loadUserConfig)
parseConfigFiles(&data);
parseArguments(&data, argc, argv, (void*) parseOption);