mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-08-23 05:00:55 +01:00
[MIRROR] Adds configuration consistency tests (#3036)
* Adds configuration consistency tests (#56562) Co-authored-by: Mothblocks <35135081+Jared-Fogle@ users.noreply.github.com> * Adds configuration consistency tests Co-authored-by: Jordan Brown <Cyberboss@users.noreply.github.com> Co-authored-by: Mothblocks <35135081+Jared-Fogle@ users.noreply.github.com>
This commit is contained in:
co-authored by
Mothblocks
Jordan Brown
parent
174a415226
commit
51bb9fb188
@@ -43,11 +43,11 @@
|
||||
CRASH("/datum/controller/configuration/Load() called more than once!")
|
||||
InitEntries()
|
||||
LoadModes()
|
||||
if(fexists("[directory]/config.txt") && LoadEntries("config.txt") <= 1)
|
||||
if(fexists("[directory]/[DEFAULT_CONFIGURATION_FILE]") && LoadEntries(DEFAULT_CONFIGURATION_FILE) <= 1)
|
||||
var/list/legacy_configs = list("game_options.txt", "dbconfig.txt", "comms.txt")
|
||||
for(var/I in legacy_configs)
|
||||
if(fexists("[directory]/[I]"))
|
||||
log_config("No $include directives found in config.txt! Loading legacy [legacy_configs.Join("/")] files...")
|
||||
log_config("No [CONFIGURATION_INCLUDE_TOKEN] directives found in [DEFAULT_CONFIGURATION_FILE]! Loading legacy [legacy_configs.Join("/")] files...")
|
||||
for(var/J in legacy_configs)
|
||||
LoadEntries(J)
|
||||
break
|
||||
@@ -101,27 +101,36 @@
|
||||
entries -= CE.name
|
||||
entries_by_type -= CE.type
|
||||
|
||||
/datum/controller/configuration/proc/LoadEntries(filename, list/stack = list())
|
||||
/****
|
||||
* Breaks up a file into an associated list of lowercase entries and their values. The null entry represents a nested list of entries that are commented out
|
||||
* filename - The filename in directory to load
|
||||
*/
|
||||
/datum/controller/configuration/proc/ParseConfigFile(filename)
|
||||
if(IsAdminAdvancedProcCall())
|
||||
return
|
||||
|
||||
var/filename_to_test = world.system_type == MS_WINDOWS ? lowertext(filename) : filename
|
||||
if(filename_to_test in stack)
|
||||
log_config("Warning: Config recursion detected ([english_list(stack)]), breaking!")
|
||||
return
|
||||
stack = stack + filename_to_test
|
||||
if(world.system_type == MS_WINDOWS)
|
||||
filename = lowertext(filename)
|
||||
|
||||
log_config("Loading config file [filename]...")
|
||||
var/list/lines = world.file2list("[directory]/[filename]")
|
||||
var/list/_entries = entries
|
||||
var/list/results = list()
|
||||
for(var/L in lines)
|
||||
L = trim(L)
|
||||
if(!L)
|
||||
continue
|
||||
|
||||
var/firstchar = L[1]
|
||||
var/disabled = FALSE
|
||||
if(firstchar == "#")
|
||||
continue
|
||||
if(length(L) > 1 && L[2] == "#")
|
||||
// comment
|
||||
continue
|
||||
|
||||
// disabled entry
|
||||
disabled = TRUE
|
||||
L = trim(copytext(L, 2, length(L) + 1))
|
||||
firstchar = L[1]
|
||||
|
||||
var/lockthis = firstchar == "@"
|
||||
if(lockthis)
|
||||
@@ -140,7 +149,31 @@
|
||||
if(!entry)
|
||||
continue
|
||||
|
||||
if(entry == "$include")
|
||||
if(disabled)
|
||||
LAZYADD(results[null], entry)
|
||||
else if(entry == CONFIGURATION_INCLUDE_TOKEN)
|
||||
LAZYADD(results[entry], value)
|
||||
else
|
||||
results[entry] = value
|
||||
|
||||
return results
|
||||
|
||||
/datum/controller/configuration/proc/LoadEntries(filename, list/stack = list())
|
||||
if(IsAdminAdvancedProcCall())
|
||||
return
|
||||
|
||||
var/filename_to_test = world.system_type == MS_WINDOWS ? lowertext(filename) : filename
|
||||
if(filename_to_test in stack)
|
||||
log_config("Warning: Config recursion detected ([english_list(stack)]), breaking!")
|
||||
return
|
||||
stack += filename_to_test
|
||||
|
||||
var/list/parsed_entries = ParseConfigFile(filename_to_test)
|
||||
// Don't care about disabled entries here
|
||||
parsed_entries -= null
|
||||
for(var/entry in parsed_entries)
|
||||
var/value = parsed_entries[entry]
|
||||
if(entry == CONFIGURATION_INCLUDE_TOKEN)
|
||||
if(!value)
|
||||
log_config("Warning: Invalid $include directive: [value]")
|
||||
else
|
||||
@@ -148,7 +181,12 @@
|
||||
++.
|
||||
continue
|
||||
|
||||
var/datum/config_entry/E = _entries[entry]
|
||||
var/firstchar = entry[1]
|
||||
var/lockthis = firstchar == "@"
|
||||
if(lockthis)
|
||||
entry = copytext(entry, length(firstchar) + 1)
|
||||
|
||||
var/datum/config_entry/E = entries[entry]
|
||||
if(!E)
|
||||
log_config("Unknown setting in configuration: '[entry]'")
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user