diff --git a/config/autostart/0.cfg b/config/autostart/0.cfg new file mode 100644 index 00000000..a7abcca5 --- /dev/null +++ b/config/autostart/0.cfg @@ -0,0 +1,11 @@ +// This is an example file that will be automatically executed upon AC startup. +// All .cfg files placed in this config/autostart/ directory will be automatically +// executed when you start AC. + +// Files here are executed in alphabetical (or more precise, ASCII) order. +// File names prefixed with "_veryfirst_" will be run before all other scripts. +// Files with names prefixed with "_beforesaved_" or "_aftersaved_" will be +// executed right before or after the file saved.cfg. +// All remaining files will be run right before autoexec.cfg. + + diff --git a/config/scripts.cfg b/config/scripts.cfg index 9dee52c6..08e213e0 100644 --- a/config/scripts.cfg +++ b/config/scripts.cfg @@ -479,4 +479,3 @@ run dyngamma run autosave persistidents 1 -execdir scripts diff --git a/scripts/0.cfg b/scripts/0.cfg deleted file mode 100644 index 2f9057b0..00000000 --- a/scripts/0.cfg +++ /dev/null @@ -1,10 +0,0 @@ -// This is an example file that will be automatically executed upon AC startup. -// All .cfg files placed in this /scripts/ directory, will be automatically -// executed when you start AC. - -// Files here are executed in alphabetical order, the order of priority is: -// 0-9, a-z, A-Z, and symbols. Therefore this file, (0.cfg) - will likely ALWAYS -// be executed before any other .cfg files you put into this directory. Use it -// for scripts that MUST be executed before others - for example. - -// NOTE: The /config/autoexec.cfg can still be used to override anything! \ No newline at end of file diff --git a/source/src/main.cpp b/source/src/main.cpp index 1f5e3498..ac3cf10e 100644 --- a/source/src/main.cpp +++ b/source/src/main.cpp @@ -910,6 +910,30 @@ const char *rndmapname() else return ""; } +#define AUTOSTARTPATH "config" PATHDIVS "autostart" PATHDIVS + +void autostartscripts(const char *prefix) +{ + static vector *files = NULL; + if(!files) + { // first run: fetch file names and sort them + files = new vector; + listfiles(AUTOSTARTPATH, "cfg", *files); + files->sort(stringsort); + for(int i = files->length() - 1; i > 0; i--) + { + if(!strcmp((*files)[i], (*files)[i - 1])) delstring(files->remove(i)); // delete doubles + } + } + loopv(*files) + { + if(*prefix && strncmp((*files)[i], prefix, strlen(prefix))) continue; + defformatstring(p)(AUTOSTARTPATH "%s.cfg", (*files)[i]); + execfile(p); + delstring(files->remove(i--)); + } +} + void createconfigtemplates(const char *templatezip) // create customisable config files in homedir - only if missing { if(addzip(templatezip)) @@ -941,6 +965,7 @@ void createconfigtemplates(const char *templatezip) // create customisable conf } removezip(templatezip); } + findfile(AUTOSTARTPATH "dummy", "w"); // create empty autostart directory, if it doesn't exist yet } extern void connectserv(char *, int *, char *); @@ -1205,6 +1230,7 @@ int main(int argc, char **argv) initlog("console"); per_idents = false; + autostartscripts("_veryfirst_"); // Main font file, all other font files execute from here. if(!execfile("config/font.cfg")) fatal("cannot find default font definitions"); // Check these 2 standard fonts have been executed. @@ -1262,12 +1288,14 @@ int main(int argc, char **argv) delete f; } + autostartscripts("_beforesaved_"); initing = INIT_LOAD; if(!execfile("config/saved.cfg")) { exec("config/defaults.cfg"); firstrun = true; } + autostartscripts("_aftersaved_"); exechook(HOOK_SP_MP, "afterinit", ""); if(compatibilitymode) { @@ -1275,6 +1303,7 @@ int main(int argc, char **argv) exec("config/compatibility.cfg"); // exec after saved.cfg to get "compatibilitymode", but before user scripts.. per_idents = true; } + autostartscripts(""); // all remaining scripts execfile("config/autoexec.cfg"); execfile("config/auth.cfg"); execute("addallfavcatmenus"); // exec here, to add all categories (including those defined in autoexec.cfg)