Added PHYSFS_unmount(), deprecated addToSearchPath and removeFromSearchPath.

This commit is contained in:
Ryan C. Gordon 2010-08-22 03:43:22 -04:00
parent c306d73fdc
commit c1969d0595
4 changed files with 63 additions and 19 deletions

View File

@ -88,6 +88,7 @@
%rename(stat) PHYSFS_stat; %rename(stat) PHYSFS_stat;
%rename(readBytes) PHYSFS_readBytes; %rename(readBytes) PHYSFS_readBytes;
%rename(writeBytes) PHYSFS_writeBytes; %rename(writeBytes) PHYSFS_writeBytes;
%rename(unmount) PHYSFS_unmount;
#endif #endif
%include "../src/physfs.h" %include "../src/physfs.h"

View File

@ -1003,6 +1003,12 @@ int PHYSFS_addToSearchPath(const char *newDir, int appendToPath)
int PHYSFS_removeFromSearchPath(const char *oldDir) int PHYSFS_removeFromSearchPath(const char *oldDir)
{
return PHYSFS_unmount(oldDir);
} /* PHYSFS_removeFromSearchPath */
int PHYSFS_unmount(const char *oldDir)
{ {
DirHandle *i; DirHandle *i;
DirHandle *prev = NULL; DirHandle *prev = NULL;
@ -1030,7 +1036,7 @@ int PHYSFS_removeFromSearchPath(const char *oldDir)
} /* for */ } /* for */
BAIL_MACRO_MUTEX(ERR_NOT_IN_SEARCH_PATH, stateLock, 0); BAIL_MACRO_MUTEX(ERR_NOT_IN_SEARCH_PATH, stateLock, 0);
} /* PHYSFS_removeFromSearchPath */ } /* PHYSFS_unmount */
char **PHYSFS_getSearchPath(void) char **PHYSFS_getSearchPath(void)
@ -1081,7 +1087,7 @@ static void setSaneCfgAddPath(const char *i, const size_t l, const char *dirsep,
if (str != NULL) if (str != NULL)
{ {
sprintf(str, "%s%s%s", d, dirsep, i); sprintf(str, "%s%s%s", d, dirsep, i);
PHYSFS_addToSearchPath(str, archivesFirst == 0); PHYSFS_mount(str, NULL, archivesFirst == 0);
__PHYSFS_smallFree(str); __PHYSFS_smallFree(str);
} /* if */ } /* if */
} /* setSaneCfgAddPath */ } /* setSaneCfgAddPath */
@ -1133,11 +1139,11 @@ int PHYSFS_setSaneConfig(const char *organization, const char *appName,
} /* if */ } /* if */
/* Put write dir first in search path... */ /* Put write dir first in search path... */
PHYSFS_addToSearchPath(str, 0); PHYSFS_mount(str, NULL, 0);
__PHYSFS_smallFree(str); __PHYSFS_smallFree(str);
/* Put base path on search path... */ /* Put base path on search path... */
PHYSFS_addToSearchPath(basedir, 1); PHYSFS_mount(basedir, NULL, 1);
/* handle CD-ROMs... */ /* handle CD-ROMs... */
if (includeCdRoms) if (includeCdRoms)
@ -1145,7 +1151,7 @@ int PHYSFS_setSaneConfig(const char *organization, const char *appName,
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_mount(*i, NULL, 1);
PHYSFS_freeList(cds); PHYSFS_freeList(cds);
} /* if */ } /* if */

View File

@ -800,8 +800,14 @@ PHYSFS_DECL int PHYSFS_setWriteDir(const char *newDir);
* \fn int PHYSFS_addToSearchPath(const char *newDir, int appendToPath) * \fn int PHYSFS_addToSearchPath(const char *newDir, int appendToPath)
* \brief Add an archive or directory to the search path. * \brief Add an archive or directory to the search path.
* *
* This is a legacy call in PhysicsFS 2.0, equivalent to: * \deprecated As of PhysicsFS 2.0, use PHYSFS_mount() instead. This
* function just wraps it anyhow.
*
* This function is equivalent to:
*
* \code
* PHYSFS_mount(newDir, NULL, appendToPath); * PHYSFS_mount(newDir, NULL, appendToPath);
* \endcode
* *
* You must use this and not PHYSFS_mount if binary compatibility with * You must use this and not PHYSFS_mount if binary compatibility with
* PhysicsFS 1.0 is important (which it may not be for many people). * PhysicsFS 1.0 is important (which it may not be for many people).
@ -810,27 +816,35 @@ PHYSFS_DECL int PHYSFS_setWriteDir(const char *newDir);
* \sa PHYSFS_removeFromSearchPath * \sa PHYSFS_removeFromSearchPath
* \sa PHYSFS_getSearchPath * \sa PHYSFS_getSearchPath
*/ */
PHYSFS_DECL int PHYSFS_addToSearchPath(const char *newDir, int appendToPath); PHYSFS_DECL int PHYSFS_addToSearchPath(const char *newDir, int appendToPath)
PHYSFS_DEPRECATED;
/** /**
* \fn int PHYSFS_removeFromSearchPath(const char *oldDir) * \fn int PHYSFS_removeFromSearchPath(const char *oldDir)
* \brief Remove a directory or archive from the search path. * \brief Remove a directory or archive from the search path.
* *
* This must be a (case-sensitive) match to a dir or archive already in the * \deprecated As of PhysicsFS 2.1, use PHYSFS_unmount() instead. This
* search path, specified in platform-dependent notation. * function just wraps it anyhow. There's no functional difference
* except the vocabulary changed from "adding to the search path"
* to "mounting" when that functionality was extended, and thus
* the preferred way to accomplish this function's work is now
* called "unmounting."
* *
* This call will fail (and fail to remove from the path) if the element still * This function is equivalent to:
* has files open in it.
* *
* \param oldDir dir/archive to remove. * \code
* \return nonzero on success, zero on failure. * PHYSFS_unmount(oldDir);
* Specifics of the error can be gleaned from PHYSFS_getLastError(). * \endcode
*
* You must use this and not PHYSFS_unmount if binary compatibility with
* PhysicsFS 1.0 is important (which it may not be for many people).
* *
* \sa PHYSFS_addToSearchPath * \sa PHYSFS_addToSearchPath
* \sa PHYSFS_getSearchPath * \sa PHYSFS_getSearchPath
* \sa PHYSFS_unmount
*/ */
PHYSFS_DECL int PHYSFS_removeFromSearchPath(const char *oldDir); PHYSFS_DECL int PHYSFS_removeFromSearchPath(const char *oldDir)
PHYSFS_DEPRECATED;
/** /**
@ -2475,6 +2489,28 @@ PHYSFS_DECL void PHYSFS_utf8FromLatin1(const char *src, char *dst,
/* Everything above this line is part of the PhysicsFS 2.0 API. */ /* Everything above this line is part of the PhysicsFS 2.0 API. */
/**
* \fn int PHYSFS_unmount(const char *oldDir)
* \brief Remove a directory or archive from the search path.
*
* This is functionally equivalent to PHYSFS_removeFromSearchPath(), but that
* function is deprecated to keep the vocabulary paired with PHYSFS_mount().
*
* This must be a (case-sensitive) match to a dir or archive already in the
* search path, specified in platform-dependent notation.
*
* This call will fail (and fail to remove from the path) if the element still
* has files open in it.
*
* \param oldDir dir/archive to remove.
* \return nonzero on success, zero on failure.
* Specifics of the error can be gleaned from PHYSFS_getLastError().
*
* \sa PHYSFS_getSearchPath
* \sa PHYSFS_mount
*/
PHYSFS_DECL int PHYSFS_unmount(const char *oldDir);
/** /**
* \fn const PHYSFS_Allocator *PHYSFS_getAllocator(void) * \fn const PHYSFS_Allocator *PHYSFS_getAllocator(void)
* \brief Discover the current allocator. * \brief Discover the current allocator.

View File

@ -119,7 +119,7 @@ static int cmd_addarchive(char *args)
/*printf("[%s], [%d]\n", args, appending);*/ /*printf("[%s], [%d]\n", args, appending);*/
if (PHYSFS_addToSearchPath(args, appending)) if (PHYSFS_mount(args, NULL, appending))
printf("Successful.\n"); printf("Successful.\n");
else else
printf("Failure. reason: %s.\n", PHYSFS_getLastError()); printf("Failure. reason: %s.\n", PHYSFS_getLastError());
@ -189,7 +189,7 @@ static int cmd_removearchive(char *args)
args[strlen(args) - 1] = '\0'; args[strlen(args) - 1] = '\0';
} /* if */ } /* if */
if (PHYSFS_removeFromSearchPath(args)) if (PHYSFS_unmount(args))
printf("Successful.\n"); printf("Successful.\n");
else else
printf("Failure. reason: %s.\n", PHYSFS_getLastError()); printf("Failure. reason: %s.\n", PHYSFS_getLastError());
@ -1024,6 +1024,7 @@ static const command_info commands[] =
{ "addarchive", cmd_addarchive, 2, "<archiveLocation> <append>" }, { "addarchive", cmd_addarchive, 2, "<archiveLocation> <append>" },
{ "mount", cmd_mount, 3, "<archiveLocation> <mntpoint> <append>" }, { "mount", cmd_mount, 3, "<archiveLocation> <mntpoint> <append>" },
{ "removearchive", cmd_removearchive, 1, "<archiveLocation>" }, { "removearchive", cmd_removearchive, 1, "<archiveLocation>" },
{ "unmount", cmd_removearchive, 1, "<archiveLocation>" },
{ "enumerate", cmd_enumerate, 1, "<dirToEnumerate>" }, { "enumerate", cmd_enumerate, 1, "<dirToEnumerate>" },
{ "ls", cmd_enumerate, 1, "<dirToEnumerate>" }, { "ls", cmd_enumerate, 1, "<dirToEnumerate>" },
{ "getlasterror", cmd_getlasterror, 0, NULL }, { "getlasterror", cmd_getlasterror, 0, NULL },