Changed PHYSFS_setSaneConfig()'s behaviour. API BREAKAGE.
This commit is contained in:
parent
c3a00ee94b
commit
1e6f2bc0d9
42
physfs.c
42
physfs.c
|
@ -635,8 +635,9 @@ 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();
|
||||
|
@ -644,10 +645,10 @@ int PHYSFS_setSaneConfig(const char *appName, const char *archiveExt,
|
|||
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 @@ 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)
|
||||
|
@ -692,16 +674,8 @@ int PHYSFS_setSaneConfig(const char *appName, const char *archiveExt,
|
|||
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 */
|
||||
|
||||
|
|
12
physfs.h
12
physfs.h
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -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);
|
||||
|
|
|
@ -242,6 +242,7 @@ static int cmd_permitsyms(char *args)
|
|||
|
||||
static int cmd_setsaneconfig(char *args)
|
||||
{
|
||||
char *org;
|
||||
char *appName;
|
||||
char *arcExt;
|
||||
int inclCD;
|
||||
|
@ -249,18 +250,16 @@ static int cmd_setsaneconfig(char *args)
|
|||
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());
|
||||
|
|
Loading…
Reference in New Issue