Configuration files - loading and unloading
Posted: Sun Jan 10, 2010 7:12 pm
According to what I've read in the UnloadConfigFile() description, when I open a file, it's reference becomes available globally (if a script has access to the reference, it may get data from the config file).
Based on that. I've made a set of wrapper functions to handle config file openning and realoding.
Basically, GetConfigFileRef is going to get a config file ref for the file passed as argument and store it in a global prop. It'll also return that reference.
ForceConfigFileReload is going to unload that config file and make an error to be placed at the global prop so that GetConfigFileRef gets a new reference next time it's called.
I did this to avoid unnecessary reloading of config files. This seems too good. But... Are there problems? I mean, is there anything that could go wrong by doing this?
Another question. What happens if I call ReadConfigFile() more than once for the same file?
Based on that. I've made a set of wrapper functions to handle config file openning and realoding.
Code: Select all
use uo;
use cfgfile;
function GetConfigFileRef(cf_prop, file_string)
var r := GetGlobalProperty(cf_prop);
if(r == error)
r:= ReadConfigFile(file_string);
SetGlobalProperty(cf_prop, r);
endif
return r;
endfunction
function ForceConfigFileReload(cf_prop, file_string)
UnloadConfigFile(file_string);
SetGlobalProperty(cf_prop, error);
endfunctionForceConfigFileReload is going to unload that config file and make an error to be placed at the global prop so that GetConfigFileRef gets a new reference next time it's called.
I did this to avoid unnecessary reloading of config files. This seems too good. But... Are there problems? I mean, is there anything that could go wrong by doing this?
Another question. What happens if I call ReadConfigFile() more than once for the same file?