Removed PHYSFS_Archiver's isArchive() method.
authorRyan C. Gordon <icculus@icculus.org>
Tue, 24 Aug 2010 10:05:58 -0400
changeset 1113 2136d64bd1ad
parent 1112 12e187aa051c
child 1114 db75213cb4b5
Removed PHYSFS_Archiver's isArchive() method. It was redundant with openArchive().
src/archiver_dir.c
src/archiver_grp.c
src/archiver_hog.c
src/archiver_iso9660.c
src/archiver_lzma.c
src/archiver_mvl.c
src/archiver_qpak.c
src/archiver_wad.c
src/archiver_zip.c
src/physfs.c
src/physfs_internal.h
--- a/src/archiver_dir.c	Tue Aug 24 10:03:25 2010 -0400
+++ b/src/archiver_dir.c	Tue Aug 24 10:05:58 2010 -0400
@@ -63,13 +63,6 @@
 } /* DIR_fileClose */
 
 
-static int DIR_isArchive(const char *filename, int forWriting)
-{
-    /* directories ARE archives in this driver... */
-    return __PHYSFS_platformIsDirectory(filename);
-} /* DIR_isArchive */
-
-
 static void *DIR_openArchive(const char *name, int forWriting)
 {
     const char *dirsep = PHYSFS_getDirSeparator();
@@ -77,9 +70,7 @@
     size_t namelen = strlen(name);
     size_t seplen = strlen(dirsep);
 
-    /* !!! FIXME: when is this not called right before openArchive? */
-    BAIL_IF_MACRO(!DIR_isArchive(name, forWriting),
-                    ERR_UNSUPPORTED_ARCHIVE, 0);
+    BAIL_IF_MACRO(!__PHYSFS_platformIsDirectory(name), ERR_NOT_AN_ARCHIVE, NULL);
 
     retval = allocator.Malloc(namelen + seplen + 1);
     BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
@@ -246,7 +237,6 @@
 const PHYSFS_Archiver __PHYSFS_Archiver_DIR =
 {
     &__PHYSFS_ArchiveInfo_DIR,
-    DIR_isArchive,          /* isArchive() method      */
     DIR_openArchive,        /* openArchive() method    */
     DIR_enumerateFiles,     /* enumerateFiles() method */
     DIR_exists,             /* exists() method         */
--- a/src/archiver_grp.c	Tue Aug 24 10:03:25 2010 -0400
+++ b/src/archiver_grp.c	Tue Aug 24 10:05:58 2010 -0400
@@ -179,19 +179,6 @@
 } /* grp_open */
 
 
-static int GRP_isArchive(const char *filename, int forWriting)
-{
-    void *fh;
-    PHYSFS_uint32 fileCount;
-    int retval = grp_open(filename, forWriting, &fh, &fileCount);
-
-    if (fh != NULL)
-        __PHYSFS_platformClose(fh);
-
-    return retval;
-} /* GRP_isArchive */
-
-
 static int grp_entry_cmp(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
 {
     if (one != two)
@@ -451,7 +438,6 @@
 const PHYSFS_Archiver __PHYSFS_Archiver_GRP =
 {
     &__PHYSFS_ArchiveInfo_GRP,
-    GRP_isArchive,          /* isArchive() method      */
     GRP_openArchive,        /* openArchive() method    */
     GRP_enumerateFiles,     /* enumerateFiles() method */
     GRP_exists,             /* exists() method         */
--- a/src/archiver_hog.c	Tue Aug 24 10:03:25 2010 -0400
+++ b/src/archiver_hog.c	Tue Aug 24 10:05:58 2010 -0400
@@ -216,19 +216,6 @@
 } /* hog_open */
 
 
-static int HOG_isArchive(const char *filename, int forWriting)
-{
-    void *fh;
-    PHYSFS_uint32 fileCount;
-    int retval = hog_open(filename, forWriting, &fh, &fileCount);
-
-    if (fh != NULL)
-        __PHYSFS_platformClose(fh);
-
-    return retval;
-} /* HOG_isArchive */
-
-
 static int hog_entry_cmp(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
 {
     if (one != two)
@@ -304,7 +291,7 @@
     PHYSFS_sint64 modtime = __PHYSFS_platformGetLastModTime(name);
     HOGinfo *info = (HOGinfo *) allocator.Malloc(sizeof (HOGinfo));
 
-    BAIL_IF_MACRO(info == NULL, ERR_OUT_OF_MEMORY, 0);
+    BAIL_IF_MACRO(info == NULL, ERR_OUT_OF_MEMORY, NULL);
     memset(info, '\0', sizeof (HOGinfo));
     info->filename = (char *) allocator.Malloc(strlen(name) + 1);
     GOTO_IF_MACRO(!info->filename, ERR_OUT_OF_MEMORY, HOG_openArchive_failed);
@@ -486,7 +473,6 @@
 const PHYSFS_Archiver __PHYSFS_Archiver_HOG =
 {
     &__PHYSFS_ArchiveInfo_HOG,
-    HOG_isArchive,          /* isArchive() method      */
     HOG_openArchive,        /* openArchive() method    */
     HOG_enumerateFiles,     /* enumerateFiles() method */
     HOG_exists,             /* exists() method         */
--- a/src/archiver_iso9660.c	Tue Aug 24 10:03:25 2010 -0400
+++ b/src/archiver_iso9660.c	Tue Aug 24 10:05:58 2010 -0400
@@ -483,13 +483,12 @@
  * Archive management functions
  ******************************************************************************/
 
-static int ISO9660_isArchive(const char *filename, int forWriting)
+/* !!! FIXME: don't open/close file here, merge with openArchive(). */
+static int isIso(const char *filename)
 {
     char magicnumber[6] = {0,0,0,0,0,0};
     void *in;
 
-    BAIL_IF_MACRO(forWriting, ERR_ARC_IS_READ_ONLY, 0);
-
     in = __PHYSFS_platformOpenRead(filename);
     BAIL_IF_MACRO(in == NULL, NULL, 0);
 
@@ -510,7 +509,7 @@
     __PHYSFS_platformClose(in);
 
     return (strcmp(magicnumber, "CD001") == 0);
-} /* ISO9660_isArchive */
+} /* isIso */
 
 
 static void *ISO9660_openArchive(const char *filename, int forWriting)
@@ -518,7 +517,9 @@
     ISO9660Handle *handle;
     int founddescriptor = 0;
     int foundjoliet = 0;
-    BAIL_IF_MACRO(forWriting, ERR_ARC_IS_READ_ONLY, NULL);
+
+    BAIL_IF_MACRO(forWriting, ERR_ARC_IS_READ_ONLY, 0);
+    BAIL_IF_MACRO(!isIso(filename), ERR_UNSUPPORTED_ARCHIVE, NULL);
 
     handle = allocator.Malloc(sizeof(ISO9660Handle));
     GOTO_IF_MACRO(!handle, ERR_OUT_OF_MEMORY, errorcleanup);
@@ -985,7 +986,6 @@
 const PHYSFS_Archiver __PHYSFS_Archiver_ISO9660 =
 {
     &__PHYSFS_ArchiveInfo_ISO9660,
-    ISO9660_isArchive,          /* isArchive() method      */
     ISO9660_openArchive,        /* openArchive() method    */
     ISO9660_enumerateFiles,     /* enumerateFiles() method */
     ISO9660_exists,             /* exists() method         */
--- a/src/archiver_lzma.c	Tue Aug 24 10:03:25 2010 -0400
+++ b/src/archiver_lzma.c	Tue Aug 24 10:05:58 2010 -0400
@@ -430,13 +430,12 @@
 } /* LZMA_fileClose */
 
 
-static int LZMA_isArchive(const char *filename, int forWriting)
+/* !!! FIXME: don't open/close file here, merge with openArchive(). */
+static int isLzma(const char *filename)
 {
     PHYSFS_uint8 sig[k7zSignatureSize];
     void *in;
 
-    BAIL_IF_MACRO(forWriting, ERR_ARC_IS_READ_ONLY, 0);
-
     in = __PHYSFS_platformOpenRead(filename);
     BAIL_IF_MACRO(in == NULL, NULL, 0);
 
@@ -451,7 +450,7 @@
 
     /* Test whether sig is the 7z signature */
     return TestSignatureCandidate(sig);
-} /* LZMA_isArchive */
+} /* isLzma */
 
 
 static void *LZMA_openArchive(const char *name, int forWriting)
@@ -460,7 +459,7 @@
     LZMAarchive *archive = NULL;
 
     BAIL_IF_MACRO(forWriting, ERR_ARC_IS_READ_ONLY, NULL);
-    BAIL_IF_MACRO(!LZMA_isArchive(name,forWriting), ERR_UNSUPPORTED_ARCHIVE, 0);
+    BAIL_IF_MACRO(!isLzma(name), ERR_UNSUPPORTED_ARCHIVE, NULL);
 
     archive = (LZMAarchive *) allocator.Malloc(sizeof (LZMAarchive));
     BAIL_IF_MACRO(archive == NULL, ERR_OUT_OF_MEMORY, NULL);
@@ -721,7 +720,6 @@
 const PHYSFS_Archiver __PHYSFS_Archiver_LZMA =
 {
     &__PHYSFS_ArchiveInfo_LZMA,
-    LZMA_isArchive,          /* isArchive() method      */
     LZMA_openArchive,        /* openArchive() method    */
     LZMA_enumerateFiles,     /* enumerateFiles() method */
     LZMA_exists,             /* exists() method         */
--- a/src/archiver_mvl.c	Tue Aug 24 10:03:25 2010 -0400
+++ b/src/archiver_mvl.c	Tue Aug 24 10:05:58 2010 -0400
@@ -176,19 +176,6 @@
 } /* mvl_open */
 
 
-static int MVL_isArchive(const char *filename, int forWriting)
-{
-    void *fh;
-    PHYSFS_uint32 fileCount;
-    int retval = mvl_open(filename, forWriting, &fh, &fileCount);
-
-    if (fh != NULL)
-        __PHYSFS_platformClose(fh);
-
-    return retval;
-} /* MVL_isArchive */
-
-
 static int mvl_entry_cmp(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
 {
     if (one != two)
@@ -446,7 +433,6 @@
 const PHYSFS_Archiver __PHYSFS_Archiver_MVL =
 {
     &__PHYSFS_ArchiveInfo_MVL,
-    MVL_isArchive,          /* isArchive() method      */
     MVL_openArchive,        /* openArchive() method    */
     MVL_enumerateFiles,     /* enumerateFiles() method */
     MVL_exists,             /* exists() method         */
--- a/src/archiver_qpak.c	Tue Aug 24 10:03:25 2010 -0400
+++ b/src/archiver_qpak.c	Tue Aug 24 10:05:58 2010 -0400
@@ -204,19 +204,6 @@
 } /* qpak_open */
 
 
-static int QPAK_isArchive(const char *filename, int forWriting)
-{
-    void *fh;
-    PHYSFS_uint32 fileCount;
-    int retval = qpak_open(filename, forWriting, &fh, &fileCount);
-
-    if (fh != NULL)
-        __PHYSFS_platformClose(fh);
-
-    return retval;
-} /* QPAK_isArchive */
-
-
 static int qpak_entry_cmp(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
 {
     if (one != two)
@@ -607,7 +594,6 @@
 const PHYSFS_Archiver __PHYSFS_Archiver_QPAK =
 {
     &__PHYSFS_ArchiveInfo_QPAK,
-    QPAK_isArchive,          /* isArchive() method      */
     QPAK_openArchive,        /* openArchive() method    */
     QPAK_enumerateFiles,     /* enumerateFiles() method */
     QPAK_exists,             /* exists() method         */
--- a/src/archiver_wad.c	Tue Aug 24 10:03:25 2010 -0400
+++ b/src/archiver_wad.c	Tue Aug 24 10:05:58 2010 -0400
@@ -203,19 +203,6 @@
 } /* wad_open */
 
 
-static int WAD_isArchive(const char *filename, int forWriting)
-{
-    void *fh;
-    PHYSFS_uint32 fileCount,offset;
-    int retval = wad_open(filename, forWriting, &fh, &fileCount,&offset);
-
-    if (fh != NULL)
-        __PHYSFS_platformClose(fh);
-
-    return retval;
-} /* WAD_isArchive */
-
-
 static int wad_entry_cmp(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
 {
     if (one != two)
@@ -505,7 +492,6 @@
 const PHYSFS_Archiver __PHYSFS_Archiver_WAD =
 {
     &__PHYSFS_ArchiveInfo_WAD,
-    WAD_isArchive,          /* isArchive() method      */
     WAD_openArchive,        /* openArchive() method    */
     WAD_enumerateFiles,     /* enumerateFiles() method */
     WAD_exists,             /* exists() method         */
--- a/src/archiver_zip.c	Tue Aug 24 10:03:25 2010 -0400
+++ b/src/archiver_zip.c	Tue Aug 24 10:05:58 2010 -0400
@@ -450,7 +450,8 @@
 } /* zip_find_end_of_central_dir */
 
 
-static int ZIP_isArchive(const char *filename, int forWriting)
+/* !!! FIXME: don't open/close file here, merge with openArchive(). */
+static int isZip(const char *filename)
 {
     PHYSFS_uint32 sig;
     int retval = 0;
@@ -479,7 +480,7 @@
 
     __PHYSFS_platformClose(in);
     return retval;
-} /* ZIP_isArchive */
+} /* isZip */
 
 
 static void zip_free_entries(ZIPentry *entries, PHYSFS_uint32 max)
@@ -1084,6 +1085,7 @@
     PHYSFS_uint32 cent_dir_ofs;
 
     BAIL_IF_MACRO(forWriting, ERR_ARC_IS_READ_ONLY, NULL);
+    BAIL_IF_MACRO(!isZip(name), NULL, NULL);
 
     if ((in = __PHYSFS_platformOpenRead(name)) == NULL)
         goto zip_openarchive_failed;
@@ -1432,7 +1434,6 @@
 const PHYSFS_Archiver __PHYSFS_Archiver_ZIP =
 {
     &__PHYSFS_ArchiveInfo_ZIP,
-    ZIP_isArchive,          /* isArchive() method      */
     ZIP_openArchive,        /* openArchive() method    */
     ZIP_enumerateFiles,     /* enumerateFiles() method */
     ZIP_exists,             /* exists() method         */
--- a/src/physfs.c	Tue Aug 24 10:03:25 2010 -0400
+++ b/src/physfs.c	Tue Aug 24 10:05:58 2010 -0400
@@ -103,7 +103,6 @@
 
 static const PHYSFS_Archiver *archivers[] =
 {
-    &__PHYSFS_Archiver_DIR,
 #if (defined PHYSFS_SUPPORTS_ZIP)
     &__PHYSFS_Archiver_ZIP,
 #endif
@@ -401,22 +400,19 @@
                              const char *d, int forWriting)
 {
     DirHandle *retval = NULL;
-    if (funcs->isArchive(d, forWriting))
+    void *opaque = funcs->openArchive(d, forWriting);
+    if (opaque != NULL)
     {
-        void *opaque = funcs->openArchive(d, forWriting);
-        if (opaque != NULL)
+        retval = (DirHandle *) allocator.Malloc(sizeof (DirHandle));
+        if (retval == NULL)
+            funcs->dirClose(opaque);
+        else
         {
-            retval = (DirHandle *) allocator.Malloc(sizeof (DirHandle));
-            if (retval == NULL)
-                funcs->dirClose(opaque);
-            else
-            {
-                memset(retval, '\0', sizeof (DirHandle));
-                retval->mountPoint = NULL;
-                retval->funcs = funcs;
-                retval->opaque = opaque;
-            } /* else */
-        } /* if */
+            memset(retval, '\0', sizeof (DirHandle));
+            retval->mountPoint = NULL;
+            retval->funcs = funcs;
+            retval->opaque = opaque;
+        } /* else */
     } /* if */
 
     return retval;
@@ -431,6 +427,11 @@
 
     BAIL_IF_MACRO(!__PHYSFS_platformExists(d), ERR_NO_SUCH_FILE, NULL);
 
+    /* DIR gets first shot (unlike the rest, it doesn't deal with files). */
+    retval = tryOpenDir(&__PHYSFS_Archiver_DIR, d, forWriting);
+    if (retval != NULL)
+        return retval;
+
     ext = find_filename_extension(d);
     if (ext != NULL)
     {
--- a/src/physfs_internal.h	Tue Aug 24 10:03:25 2010 -0400
+++ b/src/physfs_internal.h	Tue Aug 24 10:05:58 2010 -0400
@@ -740,16 +740,6 @@
      *  continue to call other methods based on that.
      */
 
-
-        /*
-         * Returns non-zero if (filename) is a valid archive that this
-         *  driver can handle. This filename is in platform-dependent
-         *  notation. forWriting is non-zero if this is to be used for
-         *  the write directory, and zero if this is to be used for an
-         *  element of the search path.
-         */
-    int (*isArchive)(const char *filename, int forWriting);
-
         /*
          * Open a dirhandle for dir/archive (name).
          *  This filename is in platform-dependent notation.