files.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. Copyright (C) 2004 Michael Liebscher <johnnycanuck@users.sourceforge.net>
  3. Copyright (C) 1997-2001 Id Software, Inc.
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License
  6. as published by the Free Software Foundation; either version 2
  7. of the License, or (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. */
  16. /*
  17. * files.c: Interface to file i/o layer.
  18. *
  19. * Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
  20. *
  21. * Acknowledgement:
  22. * This code was derived from Quake II, and was originally
  23. * written by Id Software, Inc.
  24. *
  25. */
  26. /*
  27. Notes:
  28. This module accesses data through a hierarchal file system, but the
  29. contents of the file system can be transparently merged from several
  30. sources.
  31. The "base directory" is the path to the directory holding the
  32. executable and all game directories. The sys_* files pass this to
  33. host_init in quakeparms_t->basedir. This can be overridden with the
  34. "-basedir" command line parm to allow code debugging in a different
  35. directory. The base directory is only used during file system
  36. initialization.
  37. The "game directory" is the first tree on the search path and directory
  38. that all generated files (save games, screen shots, demos, config
  39. files) will be saved to. This can be overridden with the "-game"
  40. command line parameter. The game directory can never be changed while
  41. the application is executing. This is a precaution against having a
  42. malicious server instruct clients to write files over areas they
  43. shouldn't.
  44. */
  45. #include "../wolfiphone.h"
  46. PRIVATE char fs_gamedir[ MAX_OSPATH ];
  47. /*
  48. -----------------------------------------------------------------------------
  49. Function: FS_Gamedir -Get root directory.
  50. Parameters: Nothing.
  51. Returns: String with the name of the root directory.
  52. Notes:
  53. -----------------------------------------------------------------------------
  54. */
  55. PUBLIC char *FS_Gamedir( void )
  56. {
  57. return fs_gamedir;
  58. }
  59. /*
  60. -----------------------------------------------------------------------------
  61. Function: FS_ListFiles -List files.
  62. Parameters:
  63. Returns:
  64. Notes:
  65. -----------------------------------------------------------------------------
  66. */
  67. PRIVATE char **FS_ListFiles( char *findname, int *numfiles, unsigned musthave, unsigned canthave )
  68. {
  69. char *s;
  70. int nfiles = 0;
  71. char **list = 0;
  72. s = FS_FindFirst( findname, musthave, canthave );
  73. while ( s )
  74. {
  75. if ( s[strlen(s)-1] != '.' )
  76. nfiles++;
  77. s = FS_FindNext( musthave, canthave );
  78. }
  79. FS_FindClose ();
  80. if ( !nfiles )
  81. return NULL;
  82. nfiles++; // add space for a guard
  83. *numfiles = nfiles;
  84. list = MM_MALLOC( sizeof( char * ) * nfiles );
  85. if( list == NULL )
  86. {
  87. MM_OUTOFMEM( "list" );
  88. }
  89. memset( list, 0, sizeof( char * ) * nfiles );
  90. s = FS_FindFirst( findname, musthave, canthave );
  91. nfiles = 0;
  92. while( s )
  93. {
  94. if( s[ strlen( s ) - 1 ] != '.' )
  95. {
  96. list[ nfiles ] = strdup( s );
  97. (void)my_strlwr( list[ nfiles ] );
  98. nfiles++;
  99. }
  100. s = FS_FindNext( musthave, canthave );
  101. }
  102. FS_FindClose();
  103. return list;
  104. }
  105. /*
  106. -----------------------------------------------------------------------------
  107. Function: FS_InitFilesystem -Initialize file system.
  108. Parameters: Nothing.
  109. Returns: Nothing.
  110. Notes:
  111. -----------------------------------------------------------------------------
  112. */
  113. PUBLIC void FS_InitFilesystem( void )
  114. {
  115. char *p;
  116. p = getenv("CWD");
  117. sprintf( fs_gamedir, "%s/base", p );
  118. }