diff --git a/sc2/ChangeLog b/sc2/ChangeLog index b906692b3..8e99db4af 100644 --- a/sc2/ChangeLog +++ b/sc2/ChangeLog @@ -1,4 +1,6 @@ Changes towards version 0.7: +- Allow addons to override any content by placing zips into their + 'shadow-content' dir - Alex - Content reorg: font chars now use hexadecimal numbering - Alex - Content reorg: some race comm and ships renamed, ship files renamed, many ani files renamed, new naming scheme for ani frames and voice - Alex diff --git a/sc2/src/options.c b/sc2/src/options.c index eb29f90f4..b6783c512 100644 --- a/sc2/src/options.c +++ b/sc2/src/options.c @@ -77,8 +77,8 @@ static uio_MountHandle *mountContentDir (uio_Repository *repository, static void mountAddonDir (uio_Repository *repository, uio_MountHandle *contentMountHandle, const char *addonDirName); -static void mountDirZips (uio_MountHandle *contentHandle, - uio_DirHandle *dirHandle, const char *mountPoint); +static void mountDirZips (uio_DirHandle *dirHandle, const char *mountPoint, + int relativeFlags, uio_MountHandle *relativeHandle); // Looks for a file 'file' in all 'numLocs' locations from 'locs'. @@ -344,7 +344,7 @@ mountContentDir (uio_Repository *repository, const char *contentPath) packagesDir = uio_openDir (repository, "/packages", 0); if (packagesDir != NULL) { - mountDirZips (contentMountHandle, packagesDir, "/"); + mountDirZips (packagesDir, "/", uio_MOUNT_BELOW, contentMountHandle); uio_closeDir (packagesDir); } @@ -390,7 +390,7 @@ mountAddonDir (uio_Repository *repository, uio_MountHandle *contentMountHandle, return; } - mountDirZips (mountHandle, addonsDir, "addons"); + mountDirZips (addonsDir, "addons", uio_MOUNT_BELOW, mountHandle); availableAddons = uio_getDirList (addonsDir, "", "", match_MATCH_PREFIX); if (availableAddons != NULL) @@ -423,7 +423,7 @@ mountAddonDir (uio_Repository *repository, uio_MountHandle *contentMountHandle, "not found; addon skipped.", addon); continue; } - mountDirZips (mountHandle, addonDir, mountname); + mountDirZips (addonDir, mountname, uio_MOUNT_BELOW, mountHandle); uio_closeDir (addonDir); } } @@ -439,7 +439,8 @@ mountAddonDir (uio_Repository *repository, uio_MountHandle *contentMountHandle, } static void -mountDirZips (uio_MountHandle *contentHandle, uio_DirHandle *dirHandle, const char *mountPoint) +mountDirZips (uio_DirHandle *dirHandle, const char *mountPoint, + int relativeFlags, uio_MountHandle *relativeHandle) { static uio_AutoMount *autoMount[] = { NULL }; uio_DirList *dirList; @@ -454,8 +455,8 @@ mountDirZips (uio_MountHandle *contentHandle, uio_DirHandle *dirHandle, const ch { if (uio_mountDir (repository, mountPoint, uio_FSTYPE_ZIP, dirHandle, dirList->names[i], "/", autoMount, - uio_MOUNT_BELOW | uio_MOUNT_RDONLY, - contentHandle) == NULL) + relativeFlags | uio_MOUNT_RDONLY, + relativeHandle) == NULL) { log_add (log_Warning, "Warning: Could not mount '%s': %s.", dirList->names[i], strerror (errno)); @@ -513,18 +514,55 @@ loadAddon (const char *addon) return FALSE; } - loadIndices (addonDir); + loadIndices (addonDir); uio_closeDir (addonDir); uio_closeDir (addonsDir); return TRUE; } +void +prepareShadowAddons (const char **addons) +{ + uio_DirHandle *addonsDir; + const char *shadowDirName = "shadow-content"; + + addonsDir = uio_openDirRelative (contentDir, "addons", 0); + // If anything fails here, it will fail again later, so + // we'll just keep quiet about it for now + if (addonsDir == NULL) + return; + + for (; *addons != NULL; addons++) + { + const char *addon = *addons; + uio_DirHandle *addonDir; + uio_DirHandle *shadowDir; + + addonDir = uio_openDirRelative (addonsDir, addon, 0); + if (addonDir == NULL) + continue; + + // Mount addon's "shadow-content" on top of "/" + shadowDir = uio_openDirRelative (addonDir, shadowDirName, 0); + if (shadowDir) + { + log_add (log_Debug, "Mounting shadow content of '%s' addon", addon); + mountDirZips (shadowDir, "/", uio_MOUNT_TOP, NULL); + uio_closeDir (shadowDir); + } + uio_closeDir (addonDir); + } + + uio_closeDir (addonsDir); +} + void prepareAddons (const char **addons) { for (; *addons != NULL; addons++) { + log_add (log_Info, "Loading addon '%s'", *addons); if (!loadAddon (*addons)) { break; diff --git a/sc2/src/options.h b/sc2/src/options.h index fe29d95c8..4c138f0f7 100644 --- a/sc2/src/options.h +++ b/sc2/src/options.h @@ -71,6 +71,7 @@ void prepareConfigDir (const char *configDirName); void prepareMeleeDir (void); void prepareSaveDir (void); void prepareAddons (const char **addons); +void prepareShadowAddons (const char **addons); BOOLEAN loadAddon (const char *addon); int loadIndices (uio_DirHandle *baseDir); diff --git a/sc2/src/starcon2.c b/sc2/src/starcon2.c index 3b64393d8..4943fa6d5 100644 --- a/sc2/src/starcon2.c +++ b/sc2/src/starcon2.c @@ -444,6 +444,7 @@ main (int argc, char *argv[]) prepareContentDir (options.contentDir, options.addonDir, argv[0]); prepareMeleeDir (); prepareSaveDir (); + prepareShadowAddons (options.addons); #if 0 initTempDir (); #endif