physfs.c
changeset 101 bd18e17ad6ad
parent 100 d2f04ab4b412
child 103 cb5f60383994
equal deleted inserted replaced
100:d2f04ab4b412 101:bd18e17ad6ad
   633 
   633 
   634     return(retval);
   634     return(retval);
   635 } /* PHYSFS_getSearchPath */
   635 } /* PHYSFS_getSearchPath */
   636 
   636 
   637 
   637 
   638 int PHYSFS_setSaneConfig(const char *appName, const char *archiveExt,
   638 int PHYSFS_setSaneConfig(const char *organization, const char *appName,
   639                                      int includeCdRoms, int archivesFirst)
   639                          const char *archiveExt, int includeCdRoms,
       
   640                          int archivesFirst)
   640 {
   641 {
   641     const char *basedir = PHYSFS_getBaseDir();
   642     const char *basedir = PHYSFS_getBaseDir();
   642     const char *userdir = PHYSFS_getUserDir();
   643     const char *userdir = PHYSFS_getUserDir();
   643     const char *dirsep = PHYSFS_getDirSeparator();
   644     const char *dirsep = PHYSFS_getDirSeparator();
   644     char *str;
   645     char *str;
   645 
   646 
   646         /* set write dir... */
   647         /* set write dir... */
   647     str = malloc(strlen(userdir) + (strlen(appName) * 2) +
   648     str = malloc(strlen(userdir) + (strlen(organization) * 2) +
   648                  (strlen(dirsep) * 2) + 2);
   649                  (strlen(appName) * 2) + (strlen(dirsep) * 3) + 2);
   649     BAIL_IF_MACRO(str == NULL, ERR_OUT_OF_MEMORY, 0);
   650     BAIL_IF_MACRO(str == NULL, ERR_OUT_OF_MEMORY, 0);
   650     sprintf(str, "%s.%s", userdir, appName);
   651     sprintf(str, "%s.%s%s%s", userdir, organization, dirsep, appName);
   651 
   652 
   652     if (!PHYSFS_setWriteDir(str))
   653     if (!PHYSFS_setWriteDir(str))
   653     {
   654     {
   654         if ( (!PHYSFS_setWriteDir(userdir)) ||
   655         if ( (!PHYSFS_setWriteDir(userdir)) ||
   655              (!PHYSFS_mkdir(str + strlen(userdir))) )
   656              (!PHYSFS_mkdir(str + strlen(userdir))) )
   658             free(str);
   659             free(str);
   659             BAIL_IF_MACRO(1, ERR_CANT_SET_WRITE_DIR, 0);
   660             BAIL_IF_MACRO(1, ERR_CANT_SET_WRITE_DIR, 0);
   660         } /* if */
   661         } /* if */
   661     } /* if */
   662     } /* if */
   662 
   663 
   663     if (!PHYSFS_setWriteDir(str))
       
   664     {
       
   665         PHYSFS_setWriteDir(NULL);
       
   666         free(str);
       
   667         BAIL_IF_MACRO(1, ERR_CANT_SET_WRITE_DIR, 0);
       
   668     } /* if */
       
   669 
       
   670         /* Put write dir related dirs on search path... */
   664         /* Put write dir related dirs on search path... */
   671     PHYSFS_addToSearchPath(str, 1);
   665     PHYSFS_addToSearchPath(str, 1);
   672     PHYSFS_mkdir(appName); /* don't care if this fails. */
       
   673     strcat(str, dirsep);
       
   674     strcat(str, appName);
       
   675     PHYSFS_addToSearchPath(str, 1);
       
   676     free(str);
   666     free(str);
   677 
   667 
   678         /* Put base path stuff on search path... */
   668         /* Put base path on search path... */
   679     PHYSFS_addToSearchPath(basedir, 1);
   669     PHYSFS_addToSearchPath(basedir, 1);
   680     str = malloc(strlen(basedir) + (strlen(appName) * 2) +
       
   681                  (strlen(dirsep) * 2) + 2);
       
   682     if (str != NULL)
       
   683     {
       
   684         sprintf(str, "%s.%s", basedir, appName);
       
   685         PHYSFS_addToSearchPath(str, 1);
       
   686         free(str);
       
   687     } /* if */
       
   688 
   670 
   689         /* handle CD-ROMs... */
   671         /* handle CD-ROMs... */
   690     if (includeCdRoms)
   672     if (includeCdRoms)
   691     {
   673     {
   692         char **cds = PHYSFS_getCdRomDirs();
   674         char **cds = PHYSFS_getCdRomDirs();
   693         char **i;
   675         char **i;
   694         for (i = cds; *i != NULL; i++)
   676         for (i = cds; *i != NULL; i++)
   695         {
       
   696             PHYSFS_addToSearchPath(*i, 1);
   677             PHYSFS_addToSearchPath(*i, 1);
   697             str = malloc(strlen(*i) + strlen(appName) + strlen(dirsep) + 1);
   678 
   698             if (str != NULL)
       
   699             {
       
   700                 sprintf(str, "%s%s%s", *i, dirsep, appName);
       
   701                 PHYSFS_addToSearchPath(str, 1);
       
   702                 free(str);
       
   703             } /* if */
       
   704         } /* for */
       
   705         PHYSFS_freeList(cds);
   679         PHYSFS_freeList(cds);
   706     } /* if */
   680     } /* if */
   707 
   681 
   708         /* Root out archives, and add them to search path... */
   682         /* Root out archives, and add them to search path... */
   709     if (archiveExt != NULL)
   683     if (archiveExt != NULL)