physfs.c
changeset 398 aa1e763b09ae
parent 393 468f75bf4d7d
child 427 c38ace41039f
equal deleted inserted replaced
397:12ff23d3d716 398:aa1e763b09ae
   207         ver->patch = PHYSFS_VER_PATCH;
   207         ver->patch = PHYSFS_VER_PATCH;
   208     } /* if */
   208     } /* if */
   209 } /* PHYSFS_getLinkedVersion */
   209 } /* PHYSFS_getLinkedVersion */
   210 
   210 
   211 
   211 
       
   212 static const char *find_filename_extension(const char *fname)
       
   213 {
       
   214     const char *retval = strchr(fname, '.');
       
   215     const char *p = retval;
       
   216 
       
   217     while (p != NULL)
       
   218     {
       
   219         p = strchr(p + 1, '.');
       
   220         if (p != NULL)
       
   221             retval = p;
       
   222     } /* while */
       
   223 
       
   224     if (retval != NULL)
       
   225         retval++;  /* skip '.' */
       
   226 
       
   227     return(retval);
       
   228 } /* find_filename_extension */
       
   229 
       
   230 
   212 static DirHandle *openDirectory(const char *d, int forWriting)
   231 static DirHandle *openDirectory(const char *d, int forWriting)
   213 {
   232 {
   214     const DirFunctions **i;
   233     const DirFunctions **i;
       
   234     const char *ext;
   215 
   235 
   216     BAIL_IF_MACRO(!__PHYSFS_platformExists(d), ERR_NO_SUCH_FILE, NULL);
   236     BAIL_IF_MACRO(!__PHYSFS_platformExists(d), ERR_NO_SUCH_FILE, NULL);
   217 
   237 
   218     for (i = dirFunctions; *i != NULL; i++)
   238     ext = find_filename_extension(d);
   219     {
   239     if (ext != NULL)
   220         if ((*i)->isArchive(d, forWriting))
   240     {
   221             return( (*i)->openArchive(d, forWriting) );
   241         /* Look for archivers with matching file extensions first... */
   222     } /* for */
   242         for (i = dirFunctions; *i != NULL; i++)
       
   243         {
       
   244             if (__PHYSFS_platformStricmp(ext, (*i)->info->extension) == 0)
       
   245             {
       
   246                 if ((*i)->isArchive(d, forWriting))
       
   247                     return( (*i)->openArchive(d, forWriting) );
       
   248             } /* if */
       
   249         } /* for */
       
   250 
       
   251         /* failing an exact file extension match, try all the others... */
       
   252         for (i = dirFunctions; *i != NULL; i++)
       
   253         {
       
   254             if (__PHYSFS_platformStricmp(ext, (*i)->info->extension) != 0)
       
   255             {
       
   256                 if ((*i)->isArchive(d, forWriting))
       
   257                     return( (*i)->openArchive(d, forWriting) );
       
   258             } /* if */
       
   259         } /* for */
       
   260     } /* if */
       
   261 
       
   262     else  /* no extension? Try them all. */
       
   263     {
       
   264         for (i = dirFunctions; *i != NULL; i++)
       
   265         {
       
   266             if ((*i)->isArchive(d, forWriting))
       
   267                 return( (*i)->openArchive(d, forWriting) );
       
   268         } /* for */
       
   269     } /* else */
   223 
   270 
   224     __PHYSFS_setError(ERR_UNSUPPORTED_ARCHIVE);
   271     __PHYSFS_setError(ERR_UNSUPPORTED_ARCHIVE);
   225     return(NULL);
   272     return(NULL);
   226 } /* openDirectory */
   273 } /* openDirectory */
   227 
   274