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 */
|
} /* PHYSFS_getSearchPath */
|
||||||
|
|
||||||
|
|
||||||
int PHYSFS_setSaneConfig(const char *appName, const char *archiveExt,
|
int PHYSFS_setSaneConfig(const char *organization, const char *appName,
|
||||||
int includeCdRoms, int archivesFirst)
|
const char *archiveExt, int includeCdRoms,
|
||||||
|
int archivesFirst)
|
||||||
{
|
{
|
||||||
const char *basedir = PHYSFS_getBaseDir();
|
const char *basedir = PHYSFS_getBaseDir();
|
||||||
const char *userdir = PHYSFS_getUserDir();
|
const char *userdir = PHYSFS_getUserDir();
|
||||||
|
@ -644,10 +645,10 @@ int PHYSFS_setSaneConfig(const char *appName, const char *archiveExt,
|
||||||
char *str;
|
char *str;
|
||||||
|
|
||||||
/* set write dir... */
|
/* set write dir... */
|
||||||
str = malloc(strlen(userdir) + (strlen(appName) * 2) +
|
str = malloc(strlen(userdir) + (strlen(organization) * 2) +
|
||||||
(strlen(dirsep) * 2) + 2);
|
(strlen(appName) * 2) + (strlen(dirsep) * 3) + 2);
|
||||||
BAIL_IF_MACRO(str == NULL, ERR_OUT_OF_MEMORY, 0);
|
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))
|
if (!PHYSFS_setWriteDir(str))
|
||||||
{
|
{
|
||||||
|
@ -660,31 +661,12 @@ int PHYSFS_setSaneConfig(const char *appName, const char *archiveExt,
|
||||||
} /* if */
|
} /* if */
|
||||||
} /* 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... */
|
/* Put write dir related dirs on search path... */
|
||||||
PHYSFS_addToSearchPath(str, 1);
|
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);
|
free(str);
|
||||||
|
|
||||||
/* Put base path stuff on search path... */
|
/* Put base path on search path... */
|
||||||
PHYSFS_addToSearchPath(basedir, 1);
|
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... */
|
/* handle CD-ROMs... */
|
||||||
if (includeCdRoms)
|
if (includeCdRoms)
|
||||||
|
@ -692,16 +674,8 @@ int PHYSFS_setSaneConfig(const char *appName, const char *archiveExt,
|
||||||
char **cds = PHYSFS_getCdRomDirs();
|
char **cds = PHYSFS_getCdRomDirs();
|
||||||
char **i;
|
char **i;
|
||||||
for (i = cds; *i != NULL; i++)
|
for (i = cds; *i != NULL; i++)
|
||||||
{
|
|
||||||
PHYSFS_addToSearchPath(*i, 1);
|
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);
|
PHYSFS_freeList(cds);
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
|
|
12
physfs.h
12
physfs.h
|
@ -478,7 +478,7 @@ __EXPORT__ char **PHYSFS_getSearchPath(void);
|
||||||
* Helper function.
|
* Helper function.
|
||||||
*
|
*
|
||||||
* Set up sane, default paths. The write dir will be set to
|
* 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
|
* The above is sufficient to make sure your program's configuration directory
|
||||||
* is separated from other clutter, and platform-independent. The period
|
* 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 search path will be:
|
||||||
*
|
*
|
||||||
* - The Write Dir (created if it doesn't exist)
|
* - 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 (PHYSFS_getBaseDir())
|
||||||
* - The Base Dir/appName (if it exists)
|
|
||||||
* - All found CD-ROM dirs (optionally)
|
* - 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
|
* These directories are then searched for files ending with the extension
|
||||||
* (archiveExt), which, if they are valid and supported archives, will also
|
* (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 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.
|
* 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
|
* @param appName Program-specific name of your program, to separate it
|
||||||
* from other programs using PhysicsFS.
|
* 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.
|
* @param archivesFirst Non-zero to prepend the archives to the search path.
|
||||||
* Zero to append them. Ignored if !(archiveExt).
|
* Zero to append them. Ignored if !(archiveExt).
|
||||||
|
*
|
||||||
* @return nonzero on success, zero on error. Specifics of the error can be
|
* @return nonzero on success, zero on error. Specifics of the error can be
|
||||||
* gleaned from PHYSFS_getLastError().
|
* gleaned from PHYSFS_getLastError().
|
||||||
*/
|
*/
|
||||||
__EXPORT__ int PHYSFS_setSaneConfig(const char *appName,
|
__EXPORT__ int PHYSFS_setSaneConfig(const char *organization,
|
||||||
|
const char *appName,
|
||||||
const char *archiveExt,
|
const char *archiveExt,
|
||||||
int includeCdRoms,
|
int includeCdRoms,
|
||||||
int archivesFirst);
|
int archivesFirst);
|
||||||
|
|
|
@ -242,6 +242,7 @@ static int cmd_permitsyms(char *args)
|
||||||
|
|
||||||
static int cmd_setsaneconfig(char *args)
|
static int cmd_setsaneconfig(char *args)
|
||||||
{
|
{
|
||||||
|
char *org;
|
||||||
char *appName;
|
char *appName;
|
||||||
char *arcExt;
|
char *arcExt;
|
||||||
int inclCD;
|
int inclCD;
|
||||||
|
@ -249,18 +250,16 @@ static int cmd_setsaneconfig(char *args)
|
||||||
char *ptr = args;
|
char *ptr = args;
|
||||||
|
|
||||||
/* ugly. */
|
/* 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++; arcExt = ptr;
|
||||||
ptr = strchr(ptr, ' '); *ptr = '\0'; ptr++; inclCD = atoi(arcExt);
|
ptr = strchr(ptr, ' '); *ptr = '\0'; ptr++; inclCD = atoi(arcExt);
|
||||||
arcsFirst = atoi(ptr);
|
arcsFirst = atoi(ptr);
|
||||||
|
|
||||||
if (strcmp(appName, "!") == 0)
|
|
||||||
appName = NULL;
|
|
||||||
|
|
||||||
if (strcmp(arcExt, "!") == 0)
|
if (strcmp(arcExt, "!") == 0)
|
||||||
arcExt = NULL;
|
arcExt = NULL;
|
||||||
|
|
||||||
if (PHYSFS_setSaneConfig(appName, arcExt, inclCD, arcsFirst))
|
if (PHYSFS_setSaneConfig(org, appName, arcExt, inclCD, arcsFirst))
|
||||||
printf("Successful.\n");
|
printf("Successful.\n");
|
||||||
else
|
else
|
||||||
printf("Failure. reason: %s.\n", PHYSFS_getLastError());
|
printf("Failure. reason: %s.\n", PHYSFS_getLastError());
|
||||||
|
|
Loading…
Reference in New Issue