Changed PHYSFS_setSaneConfig()'s behaviour. API BREAKAGE.
--- a/physfs.c Fri Sep 14 22:59:53 2001 +0000
+++ b/physfs.c Wed Sep 26 01:44:41 2001 +0000
@@ -635,8 +635,9 @@
} /* PHYSFS_getSearchPath */
-int PHYSFS_setSaneConfig(const char *appName, const char *archiveExt,
- int includeCdRoms, int archivesFirst)
+int PHYSFS_setSaneConfig(const char *organization, const char *appName,
+ const char *archiveExt, int includeCdRoms,
+ int archivesFirst)
{
const char *basedir = PHYSFS_getBaseDir();
const char *userdir = PHYSFS_getUserDir();
@@ -644,10 +645,10 @@
char *str;
/* set write dir... */
- str = malloc(strlen(userdir) + (strlen(appName) * 2) +
- (strlen(dirsep) * 2) + 2);
+ str = malloc(strlen(userdir) + (strlen(organization) * 2) +
+ (strlen(appName) * 2) + (strlen(dirsep) * 3) + 2);
BAIL_IF_MACRO(str == NULL, ERR_OUT_OF_MEMORY, 0);
- sprintf(str, "%s.%s", userdir, appName);
+ sprintf(str, "%s.%s%s%s", userdir, organization, dirsep, appName);
if (!PHYSFS_setWriteDir(str))
{
@@ -660,31 +661,12 @@
} /* if */
} /* if */
- if (!PHYSFS_setWriteDir(str))
- {
- PHYSFS_setWriteDir(NULL);
- free(str);
- BAIL_IF_MACRO(1, ERR_CANT_SET_WRITE_DIR, 0);
- } /* if */
-
/* Put write dir related dirs on search path... */
PHYSFS_addToSearchPath(str, 1);
- PHYSFS_mkdir(appName); /* don't care if this fails. */
- strcat(str, dirsep);
- strcat(str, appName);
- PHYSFS_addToSearchPath(str, 1);
free(str);
- /* Put base path stuff on search path... */
+ /* Put base path on search path... */
PHYSFS_addToSearchPath(basedir, 1);
- str = malloc(strlen(basedir) + (strlen(appName) * 2) +
- (strlen(dirsep) * 2) + 2);
- if (str != NULL)
- {
- sprintf(str, "%s.%s", basedir, appName);
- PHYSFS_addToSearchPath(str, 1);
- free(str);
- } /* if */
/* handle CD-ROMs... */
if (includeCdRoms)
@@ -692,16 +674,8 @@
char **cds = PHYSFS_getCdRomDirs();
char **i;
for (i = cds; *i != NULL; i++)
- {
PHYSFS_addToSearchPath(*i, 1);
- str = malloc(strlen(*i) + strlen(appName) + strlen(dirsep) + 1);
- if (str != NULL)
- {
- sprintf(str, "%s%s%s", *i, dirsep, appName);
- PHYSFS_addToSearchPath(str, 1);
- free(str);
- } /* if */
- } /* for */
+
PHYSFS_freeList(cds);
} /* if */
--- a/physfs.h Fri Sep 14 22:59:53 2001 +0000
+++ b/physfs.h Wed Sep 26 01:44:41 2001 +0000
@@ -478,7 +478,7 @@
* Helper function.
*
* Set up sane, default paths. The write dir will be set to
- * "userdir/.appName", which is created if it doesn't exist.
+ * "userdir/.organization/appName", which is created if it doesn't exist.
*
* The above is sufficient to make sure your program's configuration directory
* is separated from other clutter, and platform-independent. The period
@@ -487,11 +487,8 @@
* The search path will be:
*
* - The Write Dir (created if it doesn't exist)
- * - The Write Dir/appName (created if it doesn't exist)
* - The Base Dir (PHYSFS_getBaseDir())
- * - The Base Dir/appName (if it exists)
* - All found CD-ROM dirs (optionally)
- * - All found CD-ROM dirs/appName (optionally, and if they exist)
*
* These directories are then searched for files ending with the extension
* (archiveExt), which, if they are valid and supported archives, will also
@@ -503,6 +500,9 @@
* All of this can be accomplished from the application, but this just does it
* all for you. Feel free to add more to the search path manually, too.
*
+ * @param organization Name of your company/group/etc to be used as a
+ * dirname, so keep it small, and no-frills.
+ *
* @param appName Program-specific name of your program, to separate it
* from other programs using PhysicsFS.
*
@@ -524,10 +524,12 @@
*
* @param archivesFirst Non-zero to prepend the archives to the search path.
* Zero to append them. Ignored if !(archiveExt).
+ *
* @return nonzero on success, zero on error. Specifics of the error can be
* gleaned from PHYSFS_getLastError().
*/
-__EXPORT__ int PHYSFS_setSaneConfig(const char *appName,
+__EXPORT__ int PHYSFS_setSaneConfig(const char *organization,
+ const char *appName,
const char *archiveExt,
int includeCdRoms,
int archivesFirst);
--- a/test/test_physfs.c Fri Sep 14 22:59:53 2001 +0000
+++ b/test/test_physfs.c Wed Sep 26 01:44:41 2001 +0000
@@ -242,6 +242,7 @@
static int cmd_setsaneconfig(char *args)
{
+ char *org;
char *appName;
char *arcExt;
int inclCD;
@@ -249,18 +250,16 @@
char *ptr = args;
/* ugly. */
- appName = ptr;
+ org = ptr;
+ ptr = strchr(ptr, ' '); *ptr = '\0'; ptr++; appName = ptr;
ptr = strchr(ptr, ' '); *ptr = '\0'; ptr++; arcExt = ptr;
ptr = strchr(ptr, ' '); *ptr = '\0'; ptr++; inclCD = atoi(arcExt);
arcsFirst = atoi(ptr);
- if (strcmp(appName, "!") == 0)
- appName = NULL;
-
if (strcmp(arcExt, "!") == 0)
arcExt = NULL;
- if (PHYSFS_setSaneConfig(appName, arcExt, inclCD, arcsFirst))
+ if (PHYSFS_setSaneConfig(org, appName, arcExt, inclCD, arcsFirst))
printf("Successful.\n");
else
printf("Failure. reason: %s.\n", PHYSFS_getLastError());