From 37ace657990e4c58b63cf55b9eca9a947b42da8f Mon Sep 17 00:00:00 2001 From: meep-eep Date: Sun, 31 Aug 2003 22:44:03 +0000 Subject: [PATCH] added '--addon ' git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@1165 8092fc87-c524-0410-9efc-e669fe64eaf9 --- sc2/ChangeLog | 1 + sc2/src/options.c | 87 +++++++++++++++++++++++++++++++++++----------- sc2/src/options.h | 2 +- sc2/src/starcon2.c | 71 ++++++++++++++++++++++++++----------- 4 files changed, 119 insertions(+), 42 deletions(-) diff --git a/sc2/ChangeLog b/sc2/ChangeLog index 9be2fc66d..c619c182a 100644 --- a/sc2/ChangeLog +++ b/sc2/ChangeLog @@ -1,4 +1,5 @@ Changes towards version 0.3: +- added '--addon ' - SvdB - keys.cfg from incompatible control scheme version is now renamed automatically to keys.old -Mika - Added warranty message in the console on startup, SvdB diff --git a/sc2/src/options.c b/sc2/src/options.c index b42f8b290..158a66a87 100644 --- a/sc2/src/options.c +++ b/sc2/src/options.c @@ -50,10 +50,12 @@ extern uio_DirHandle *rootDir; static void mountContentDir (uio_Repository *repository, - const char *contentPath); + const char *contentPath, const char **addons); +static void mountDirZips (uio_MountHandle *contentHandle, + uio_DirHandle *dirHandle); void -prepareContentDir (char *contentDirName) +prepareContentDir (char *contentDirName, const char **addons) { const char *testfile = "version"; char cwd[PATH_MAX]; @@ -72,7 +74,7 @@ prepareContentDir (char *contentDirName) "directory.\n"); exit (EXIT_FAILURE); } - mountContentDir (repository, cwd); + mountContentDir (repository, cwd, addons); } void @@ -161,9 +163,10 @@ prepareMeleeDir (void) { } static void -mountContentDir (uio_Repository *repository, const char *contentPath) { +mountContentDir (uio_Repository *repository, const char *contentPath, + const char **addons) { uio_MountHandle *contentHandle; - uio_DirHandle *packagesDir; + uio_DirHandle *packagesDir, *addonsDir, *addonDir; static uio_AutoMount *autoMount[] = { NULL }; contentHandle = uio_mountDir (repository, "/", @@ -185,29 +188,73 @@ mountContentDir (uio_Repository *repository, const char *contentPath) { packagesDir = uio_openDir (repository, "/packages", 0); if (packagesDir == NULL) { // No packages dir means no packages to load. + if (addons[0] != NULL) { + // addons were specified, but there's no /packages dir, + // let alone a /packages/addons dir. + fprintf (stderr, "Warning: There's no 'packages/addons' " + "directory in the 'content' directory;\n\t'--addon' " + "options are ignored.\n"); + } return; } - { - uio_DirList *dirList; + mountDirZips (contentHandle, packagesDir); - dirList = uio_getDirList(packagesDir, "", ".zip", match_MATCH_SUFFIX); - if (dirList != NULL) { - int i; + // NB: note the difference between addonsDir and addonDir. + // the former is the dir 'packages/addons', the latter a directory + // in that dir. + addonsDir = uio_openDirRelative (packagesDir, "addons", 0); + if (addonsDir == NULL) { + // No addon dir found. + fprintf (stderr, "Warning: There's no 'packages/addons' " + "directory in the 'content' directory;\n\t'--addon' " + "options are ignored.\n"); + uio_closeDir (packagesDir); + return; + } - for (i = 0; i < dirList->numNames; i++) { - if (uio_mountDir (repository, "/", uio_FSTYPE_ZIP, - packagesDir, dirList->names[i], "/", autoMount, - uio_MOUNT_BELOW | uio_MOUNT_RDONLY, - contentHandle) == NULL) { - fprintf(stderr, "Warning: Could not mount '%s': %s.\n", - dirList->names[i], strerror(errno)); - } + uio_closeDir (packagesDir); + + for (; *addons != NULL; addons++) + { + addonDir = uio_openDirRelative (addonsDir, *addons, 0); + if (addonDir == NULL) { + fprintf (stderr, "Warning: directory 'packages/addons/%s' " + "not found; addon skipped.\n", *addons); + continue; + } + + mountDirZips (contentHandle, addonDir); + + uio_closeDir (addonDir); + } + + uio_closeDir (addonsDir); +} + +static void +mountDirZips (uio_MountHandle *contentHandle, uio_DirHandle *dirHandle) +{ + static uio_AutoMount *autoMount[] = { NULL }; + uio_DirList *dirList; + + dirList = uio_getDirList (dirHandle, "", ".zip", match_MATCH_SUFFIX); + if (dirList != NULL) { + int i; + + for (i = 0; i < dirList->numNames; i++) { + if (uio_mountDir (repository, "/", uio_FSTYPE_ZIP, + dirHandle, dirList->names[i], "/", autoMount, + uio_MOUNT_BELOW | uio_MOUNT_RDONLY, + contentHandle) == NULL) { + fprintf (stderr, "Warning: Could not mount '%s': %s.\n", + dirList->names[i], strerror (errno)); } } - uio_freeDirList (dirList); } - uio_closeDir(packagesDir); + uio_freeDirList (dirList); } + + diff --git a/sc2/src/options.h b/sc2/src/options.h index e7bd3ec06..f49184fea 100644 --- a/sc2/src/options.h +++ b/sc2/src/options.h @@ -44,7 +44,7 @@ extern uio_DirHandle *configDir; extern uio_DirHandle *saveDir; extern uio_DirHandle *meleeDir; -void prepareContentDir (char *contentDirName); +void prepareContentDir (char *contentDirName, const char **addons); void prepareConfigDir(void); void prepareMeleeDir(void); void prepareSaveDir(void); diff --git a/sc2/src/starcon2.c b/sc2/src/starcon2.c index 210b80844..6d32d89b0 100644 --- a/sc2/src/starcon2.c +++ b/sc2/src/starcon2.c @@ -75,6 +75,8 @@ main (int argc, char *argv[]) char contentdir[1000]; float gamma = 1.0; int gammaset = 0; + const char **addons; + int numAddons; enum { @@ -83,7 +85,8 @@ main (int argc, char *argv[]) FONT_OPT, SCROLL_OPT, SOUND_OPT, - STEREOSFX_OPT + STEREOSFX_OPT, + ADDON_OPT }; int option_index = 0, c; @@ -113,6 +116,7 @@ main (int argc, char *argv[]) {"scroll", 1, NULL, SCROLL_OPT}, {"sound", 1, NULL, SOUND_OPT}, {"stereosfx", 0, NULL, STEREOSFX_OPT}, + {"addon", 1, NULL, ADDON_OPT}, {0, 0, 0, 0} }; @@ -130,6 +134,17 @@ main (int argc, char *argv[]) strcpy (contentdir, "content"); #endif + /* InitThreadSystem should come before anything else. + * The memory system uses semaphores. + * Everything else uses the memory system. + */ + InitThreadSystem (); + mem_init (); + + addons = HMalloc(1 * sizeof (const char *)); + addons[0] = NULL; + numAddons = 0; + while ((c = getopt_long(argc, argv, "r:d:foc:b:spn:?hM:S:T:m:q:ug:", long_options, &option_index)) != -1) { switch (c) { @@ -269,48 +284,62 @@ main (int argc, char *argv[]) case STEREOSFX_OPT: optStereoSFX = TRUE; break; + case ADDON_OPT: + numAddons++; + addons = HRealloc(addons, + (numAddons + 1) * sizeof (const char *)); + addons[numAddons - 1] = optarg; + addons[numAddons] = NULL; + break; default: printf ("\nOption %s not found!\n", long_options[option_index].name); case '?': case 'h': - printf("\nOptions:\n"); - printf(" -r, --res=WIDTHxHEIGHT (default 640x480, bigger works only with --opengl)\n"); + printf("Options:\n"); + printf(" -r, --res=WIDTHxHEIGHT (default 640x480, bigger " + "works only with --opengl)\n"); printf(" -d, --bpp=BITSPERPIXEL (default 16)\n"); printf(" -f, --fullscreen (default off)\n"); printf(" -o, --opengl (default off)\n"); - printf(" -c, --scale=MODE (bilinear, biadapt or biadv, default is none)\n"); - printf(" -b, --meleescale=MODE (nearest or trilinear, default is trilinear)\n"); + printf(" -c, --scale=MODE (bilinear, biadapt or biadv, " + "default is none)\n"); + printf(" -b, --meleescale=MODE (nearest or trilinear, " + "default is trilinear)\n"); printf(" -s, --scanlines (default off)\n"); printf(" -p, --fps (default off)\n"); - printf(" -g, --gamma=CORRECTIONVALUE (default 1.0, which causes no change)\n"); + printf(" -g, --gamma=CORRECTIONVALUE (default 1.0, which " + "causes no change)\n"); printf(" -n, --contentdir=CONTENTDIR\n"); printf(" -M, --musicvol=VOLUME (0-100, default 100)\n"); printf(" -S, --sfxvol=VOLUME (0-100, default 100)\n"); printf(" -T, --speechvol=VOLUME (0-100, default 100)\n"); - printf(" -q, --audioquality=QUALITY (high, medium or low, default medium)\n"); + printf(" -q, --audioquality=QUALITY (high, medium or low, " + "default medium)\n"); printf(" -u, --nosubtitles\n"); - printf(" --sound=DRIVER (openal, mixsdl, none; default mixsdl)\n"); - printf(" --stereosfx (enables positional sound effects, currently only for openal)\n"); - printf("The following options can take either '3do' or 'pc' as an option:\n"); + printf(" --addon (using a specific addon; " + "may be specified multiple times)\n"); + printf(" --sound=DRIVER (openal, mixsdl, none; default " + "mixsdl)\n"); + printf(" --stereosfx (enables positional sound effects, " + "currently only for openal)\n"); + printf("The following options can take either '3do' or 'pc' " + "as an option:\n"); printf(" -m, --music : Music version (default 3do)\n"); - printf(" --cscan : coarse-scan display, pc=text, 3do=hieroglyphs (default 3do)\n"); - printf(" --menu : menu type, pc=text, 3do=graphical (default 3do)\n"); + printf(" --cscan : coarse-scan display, pc=text, " + "3do=hieroglyphs (default 3do)\n"); + printf(" --menu : menu type, pc=text, 3do=graphical " + "(default 3do)\n"); printf(" --font : font types and colors (default pc)\n"); - printf(" --scroll : ff/frev during comm. pc=per-page, 3do=smooth (default pc)\n"); + printf(" --scroll : ff/frev during comm. pc=per-page, " + "3do=smooth (default pc)\n"); return 0; break; } } - /* InitThreadSystem should come before anything else. - * The memory system uses semaphores. - * Everything else uses the memory system. - */ - InitThreadSystem (); - mem_init (); - initIO(); - prepareContentDir (contentdir); + prepareContentDir (contentdir, addons); + HFree (addons); prepareConfigDir (); prepareMeleeDir (); prepareSaveDir ();