moved "scripts" folder to "config/autostart"

All cfg-files in config/autostart get executed during startup.

- more appropriate directory name and place
- files are now sorted alphabetically, as promised
- doubles are removed (resulting from identical file names in home and
  install tree) since they would only result in files run twice
- scripts with file names prefixed with "_veryfirst_", "_beforesaved_"
  or "_aftersaved_" will be run as very first config file, right before
  saved.cfg or right after saved.cfg
- all remaining files will be run right before autoexec.cfg
- the directory "config/autostart" will be created, if it doesn't already
  exist in the home tree
This commit is contained in:
ac-stef
2015-03-24 02:06:19 +01:00
parent 5bf27f802c
commit 982bc037a7
4 changed files with 40 additions and 11 deletions
+11
View File
@@ -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.
-1
View File
@@ -479,4 +479,3 @@ run dyngamma
run autosave
persistidents 1
execdir scripts
-10
View File
@@ -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!
+29
View File
@@ -910,6 +910,30 @@ const char *rndmapname()
else return "";
}
#define AUTOSTARTPATH "config" PATHDIVS "autostart" PATHDIVS
void autostartscripts(const char *prefix)
{
static vector<char *> *files = NULL;
if(!files)
{ // first run: fetch file names and sort them
files = new vector<char *>;
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)