Skip to content

Commit

Permalink
Changed PHYSFS_setSaneConfig()'s behaviour. API BREAKAGE.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Sep 26, 2001
1 parent c3a00ee commit 1e6f2bc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 44 deletions.
42 changes: 8 additions & 34 deletions physfs.c
Expand Up @@ -635,19 +635,20 @@ char **PHYSFS_getSearchPath(void)
} /* 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();
const char *dirsep = PHYSFS_getDirSeparator();
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))
{
Expand All @@ -660,48 +661,21 @@ int PHYSFS_setSaneConfig(const char *appName, const char *archiveExt,
} /* 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)
{
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 */

Expand Down
12 changes: 7 additions & 5 deletions physfs.h
Expand Up @@ -478,7 +478,7 @@ __EXPORT__ char **PHYSFS_getSearchPath(void);
* 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
Expand All @@ -487,11 +487,8 @@ __EXPORT__ char **PHYSFS_getSearchPath(void);
* 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
Expand All @@ -503,6 +500,9 @@ __EXPORT__ char **PHYSFS_getSearchPath(void);
* 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.
*
Expand All @@ -524,10 +524,12 @@ __EXPORT__ char **PHYSFS_getSearchPath(void);
*
* @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);
Expand Down
9 changes: 4 additions & 5 deletions test/test_physfs.c
Expand Up @@ -242,25 +242,24 @@ static int cmd_permitsyms(char *args)

static int cmd_setsaneconfig(char *args)
{
char *org;
char *appName;
char *arcExt;
int inclCD;
int arcsFirst;
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());
Expand Down

0 comments on commit 1e6f2bc

Please sign in to comment.