forked from id-Software/Wolf3D-iOS
/
files.c
187 lines (138 loc) · 4.66 KB
/
files.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*
Copyright (C) 2004 Michael Liebscher <johnnycanuck@users.sourceforge.net>
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* files.c: Interface to file i/o layer.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
*
* Acknowledgement:
* This code was derived from Quake II, and was originally
* written by Id Software, Inc.
*
*/
/*
Notes:
This module accesses data through a hierarchal file system, but the
contents of the file system can be transparently merged from several
sources.
The "base directory" is the path to the directory holding the
executable and all game directories. The sys_* files pass this to
host_init in quakeparms_t->basedir. This can be overridden with the
"-basedir" command line parm to allow code debugging in a different
directory. The base directory is only used during file system
initialization.
The "game directory" is the first tree on the search path and directory
that all generated files (save games, screen shots, demos, config
files) will be saved to. This can be overridden with the "-game"
command line parameter. The game directory can never be changed while
the application is executing. This is a precaution against having a
malicious server instruct clients to write files over areas they
shouldn't.
*/
#include "../wolfiphone.h"
PRIVATE char fs_gamedir[ MAX_OSPATH ];
//PRIVATE char fs_soddir[ MAX_OSPATH ]; //gsh
/*
-----------------------------------------------------------------------------
Function: FS_Gamedir -Get root directory.
Parameters: Nothing.
Returns: String with the name of the root directory.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC char *FS_Gamedir( void )
{
/*
//gsh... this is a trick to load in where the iphoneDocDirectory is
if (currentMap.episode >= 6)
{
// sprintf( fs_soddir, "%s/SODbase", iphoneDocDirectory ); //if you're downloading the SOD data
sprintf( fs_soddir, "%s/", iphoneDocDirectory ); //if you're only downloading the spear maps
return fs_soddir;
}*/
return fs_gamedir;
}
/*
//gsh this is so that we can force a non-SOD folder
//it's only getting used in the FSOpenFile() of fileio.c
PUBLIC char *FS_ForceGamedir( void )
{
return fs_gamedir;
}*/
/*
-----------------------------------------------------------------------------
Function: FS_ListFiles -List files.
Parameters:
Returns:
Notes:
-----------------------------------------------------------------------------
*/
PRIVATE char **FS_ListFiles( char *findname, int *numfiles, unsigned musthave, unsigned canthave )
{
char *s;
int nfiles = 0;
char **list = 0;
s = FS_FindFirst( findname, musthave, canthave );
while ( s )
{
if ( s[strlen(s)-1] != '.' )
nfiles++;
s = FS_FindNext( musthave, canthave );
}
FS_FindClose ();
if ( !nfiles )
return NULL;
nfiles++; // add space for a guard
*numfiles = nfiles;
list = MM_MALLOC( sizeof( char * ) * nfiles );
if( list == NULL )
{
MM_OUTOFMEM( "list" );
}
memset( list, 0, sizeof( char * ) * nfiles );
s = FS_FindFirst( findname, musthave, canthave );
nfiles = 0;
while( s )
{
if( s[ strlen( s ) - 1 ] != '.' )
{
list[ nfiles ] = strdup( s );
(void)my_strlwr( list[ nfiles ] );
nfiles++;
}
s = FS_FindNext( musthave, canthave );
}
FS_FindClose();
return list;
}
/*
-----------------------------------------------------------------------------
Function: FS_InitFilesystem -Initialize file system.
Parameters: Nothing.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void FS_InitFilesystem( void )
{
#define BASE_DIRECTORY "/base"
int length = SysIPhoneGetPathToMainBundleLength();
// Make sure the path will fit.
int fullPathLength = length + strlen( BASE_DIRECTORY ) + 1;
assert( fullPathLength < MAX_OSPATH );
SysIPhoneGetPathToMainBundle( fs_gamedir, length + 1 );
strcpy( fs_gamedir + length, BASE_DIRECTORY );
}