2 * $Logfile: /Freespace2/code/CFile/CfileSystem.cpp $
7 * Functions to keep track of and find files that can exist
8 * on the harddrive, cd-rom, or in a pack file on either of those.
9 * This keeps a list of all the files in packfiles or on CD-rom
10 * and when you need a file you call one function which then searches
11 * all those locations, inherently enforcing precedence orders.
14 * Revision 1.1 2002/05/03 03:28:08 root
18 * 6 9/08/99 10:01p Dave
19 * Make sure game won't run in a drive's root directory. Make sure
20 * standalone routes suqad war messages properly to the host.
22 * 5 9/03/99 1:31a Dave
23 * CD checking by act. Added support to play 2 cutscenes in a row
24 * seamlessly. Fixed super low level cfile bug related to files in the
25 * root directory of a CD. Added cheat code to set campaign mission # in
28 * 4 2/22/99 10:31p Andsager
29 * Get rid of unneeded includes.
31 * 3 10/13/98 9:19a Andsager
32 * Add localization support to cfile. Optional parameter with cfopen that
33 * looks for localized files.
35 * 2 10/07/98 10:52a Dave
38 * 1 10/07/98 10:48a Dave
40 * 14 8/31/98 2:06p Dave
41 * Make cfile sort the ordering or vp files. Added support/checks for
42 * recognizing "mission disk" players.
44 * 13 6/23/98 4:18p Hoffoss
45 * Fixed some bugs with AC release build.
47 * 12 5/20/98 10:46p John
48 * Added code that doesn't include duplicate filenames in any file list
51 * 11 5/14/98 2:14p Lawrance2
52 * Use filespec filtering for packfiles
54 * 10 5/03/98 11:53a John
55 * Fixed filename case mangling.
57 * 9 5/02/98 11:06p Allender
58 * correctly deal with pack pathnames
60 * 8 5/01/98 11:41a Allender
61 * Fixed bug with mission saving in Fred.
63 * 7 5/01/98 10:21a John
64 * Added code to find all pack files in all trees. Added code to create
65 * any directories that we write to.
67 * 6 4/30/98 10:21p John
68 * Added code to cleanup cfilesystem
70 * 5 4/30/98 10:18p John
71 * added source safe header
84 #include <winbase.h> /* needed for memory mapping of file functions */
92 #include "cfilesystem.h"
96 #define CF_ROOTTYPE_PATH 0
97 #define CF_ROOTTYPE_PACK 1
100 // specifying hard drive tree
101 // searching for pack files on hard drive // Found by searching all known paths
102 // specifying cd-rom tree
103 // searching for pack files on CD-rom tree
104 typedef struct cf_root {
105 char path[CF_MAX_PATHNAME_LENGTH]; // Contains something like c:\projects\freespace or c:\projects\freespace\freespace.vp
106 int roottype; // CF_ROOTTYPE_PATH = Path, CF_ROOTTYPE_PACK =Pack file
109 // convenient type for sorting (see cf_build_pack_list())
110 typedef struct cf_root_sort {
111 char path[CF_MAX_PATHNAME_LENGTH];
116 #define CF_NUM_ROOTS_PER_BLOCK 32
117 #define CF_MAX_ROOT_BLOCKS 256 // Can store 32*256 = 8192 Roots
118 #define CF_MAX_ROOTS (CF_NUM_ROOTS_PER_BLOCK * CF_MAX_ROOT_BLOCKS)
120 typedef struct cf_root_block {
121 cf_root roots[CF_NUM_ROOTS_PER_BLOCK];
124 static int Num_roots = 0;
125 static cf_root_block *Root_blocks[CF_MAX_ROOT_BLOCKS];
128 // Created by searching all roots in order. This means Files is then sorted by precedence.
129 typedef struct cf_file {
130 char name_ext[CF_MAX_FILENAME_LENGTH]; // Filename and extension
131 int root_index; // Where in Roots this is located
132 int pathtype_index; // Where in Paths this is located
133 time_t write_time; // When it was last written
134 int size; // How big it is in bytes
135 int pack_offset; // For pack files, where it is at. 0 if not in a pack file. This can be used to tell if in a pack file.
138 #define CF_NUM_FILES_PER_BLOCK 256
139 #define CF_MAX_FILE_BLOCKS 128 // Can store 256*128 = 32768 files
141 typedef struct cf_file_block {
142 cf_file files[CF_NUM_FILES_PER_BLOCK];
145 static int Num_files = 0;
146 static cf_file_block *File_blocks[CF_MAX_FILE_BLOCKS];
149 // Return a pointer to to file 'index'.
150 cf_file *cf_get_file(int index)
152 int block = index / CF_NUM_FILES_PER_BLOCK;
153 int offset = index % CF_NUM_FILES_PER_BLOCK;
155 return &File_blocks[block]->files[offset];
158 // Create a new file and return a pointer to it.
159 cf_file *cf_create_file()
161 int block = Num_files / CF_NUM_FILES_PER_BLOCK;
162 int offset = Num_files % CF_NUM_FILES_PER_BLOCK;
164 if ( File_blocks[block] == NULL ) {
165 File_blocks[block] = (cf_file_block *)malloc( sizeof(cf_file_block) );
166 Assert( File_blocks[block] != NULL);
171 return &File_blocks[block]->files[offset];
174 extern int cfile_inited;
176 // Create a new root and return a pointer to it. The structure is assumed unitialized.
177 cf_root *cf_get_root(int n)
179 int block = n / CF_NUM_ROOTS_PER_BLOCK;
180 int offset = n % CF_NUM_ROOTS_PER_BLOCK;
185 return &Root_blocks[block]->roots[offset];
189 // Create a new root and return a pointer to it. The structure is assumed unitialized.
190 cf_root *cf_create_root()
192 int block = Num_roots / CF_NUM_ROOTS_PER_BLOCK;
193 int offset = Num_roots % CF_NUM_ROOTS_PER_BLOCK;
195 if ( Root_blocks[block] == NULL ) {
196 Root_blocks[block] = (cf_root_block *)malloc( sizeof(cf_root_block) );
197 Assert(Root_blocks[block] != NULL);
202 return &Root_blocks[block]->roots[offset];
205 // return the # of packfiles which exist
206 int cf_get_packfile_count(cf_root *root)
208 char filespec[MAX_PATH_LEN];
212 // count up how many packfiles we're gonna have
214 for (i=CF_TYPE_ROOT; i<CF_MAX_PATH_TYPES; i++ ) {
215 strcpy( filespec, root->path );
217 if(strlen(Pathtypes[i].path)){
218 strcat( filespec, Pathtypes[i].path );
219 strcat( filespec, "\\" );
222 strcat( filespec, "*.vp" );
230 find_handle = _findfirst( filespec, &find );
232 if (find_handle != -1) {
234 if (!(find.attrib & _A_SUBDIR)) {
238 } while (!_findnext(find_handle, &find));
240 _findclose( find_handle );
245 return packfile_count;
248 // packfile sort function
249 int cf_packfile_sort_func(const void *elem1, const void *elem2)
251 cf_root_sort *r1, *r2;
252 r1 = (cf_root_sort*)elem1;
253 r2 = (cf_root_sort*)elem2;
255 // if the 2 directory types are the same, do a string compare
256 if(r1->cf_type == r2->cf_type){
257 return stricmp(r1->path, r2->path);
260 // otherwise return them in order of CF_TYPE_* precedence
261 return (r1->cf_type < r2->cf_type) ? -1 : 1;
264 // Go through a root and look for pack files
265 void cf_build_pack_list( cf_root *root )
267 char filespec[MAX_PATH_LEN];
269 cf_root_sort *temp_roots_sort, *rptr_sort;
270 int temp_root_count, root_index;
272 // determine how many packfiles there are
273 temp_root_count = cf_get_packfile_count(root);
274 if(temp_root_count <= 0){
278 // allocate a temporary array of temporary roots so we can easily sort them
279 temp_roots_sort = (cf_root_sort*)malloc(sizeof(cf_root_sort) * temp_root_count);
280 if(temp_roots_sort == NULL){
285 // now just setup all the root info
287 for (i=CF_TYPE_ROOT; i<CF_MAX_PATH_TYPES; i++ ) {
288 strcpy( filespec, root->path );
290 if(strlen(Pathtypes[i].path)){
291 strcat( filespec, Pathtypes[i].path );
292 strcat( filespec, "\\" );
294 strcat( filespec, "*.vp" );
302 find_handle = _findfirst( filespec, &find );
304 if (find_handle != -1) {
307 if (!(find.attrib & _A_SUBDIR)) {
308 Assert(root_index < temp_root_count);
310 // get a temp pointer
311 rptr_sort = &temp_roots_sort[root_index++];
313 // fill in all the proper info
314 strcpy(rptr_sort->path, root->path);
316 if(strlen(Pathtypes[i].path)){
317 strcat(rptr_sort->path, Pathtypes[i].path );
318 strcat(rptr_sort->path, "\\");
321 strcat(rptr_sort->path, find.name );
322 rptr_sort->roottype = CF_ROOTTYPE_PACK;
323 rptr_sort->cf_type = i;
326 } while (!_findnext(find_handle, &find));
328 _findclose( find_handle );
333 // these should always be the same
334 Assert(root_index == temp_root_count);
337 qsort(temp_roots_sort, temp_root_count, sizeof(cf_root_sort), cf_packfile_sort_func);
339 // now insert them all into the real root list properly
341 for(i=0; i<temp_root_count; i++){
342 new_root = cf_create_root();
343 strcpy( new_root->path, root->path );
345 // mwa -- 4/2/98 put in the next 2 lines because the path name needs to be there
346 // to find the files.
347 strcpy(new_root->path, temp_roots_sort[i].path);
348 new_root->roottype = CF_ROOTTYPE_PACK;
351 // free up the temp list
352 free(temp_roots_sort);
356 void cf_build_root_list(char *cdrom_dir)
362 //======================================================
363 // First, check the current directory.
364 // strcpy( root->path, "d:\\projects\\freespace\\" );
366 root = cf_create_root();
368 if ( !_getcwd(root->path, CF_MAX_PATHNAME_LENGTH ) ) {
369 Error(LOCATION, "Can't get current working directory -- %d", errno );
372 // do we already have a slash? as in the case of a root directory install
373 if(strlen(root->path) && (root->path[strlen(root->path)-1] != '\\')){
374 strcat(root->path, "\\"); // put trailing backslash on for easier path construction
376 root->roottype = CF_ROOTTYPE_PATH;
378 //======================================================
379 // Next, check any VP files under the current directory.
380 cf_build_pack_list(root);
383 //======================================================
384 // Check the real CD if one...
385 if ( cdrom_dir && strlen(cdrom_dir) ) {
386 root = cf_create_root();
387 strcpy( root->path, cdrom_dir );
388 root->roottype = CF_ROOTTYPE_PATH;
390 //======================================================
391 // Next, check any VP files in the CD-ROM directory.
392 cf_build_pack_list(root);
398 // Given a lower case list of file extensions
399 // separated by spaces, return zero if ext is
401 int is_ext_in_list( char *ext_list, char *ext )
405 strncpy( tmp_ext, ext, 127 );
407 if ( strstr(ext_list, tmp_ext )) {
414 void cf_search_root_path(int root_index)
418 cf_root *root = cf_get_root(root_index);
420 mprintf(( "Searching root '%s'\n", root->path ));
422 char search_path[CF_MAX_PATHNAME_LENGTH];
424 for (i=CF_TYPE_ROOT; i<CF_MAX_PATH_TYPES; i++ ) {
426 strcpy( search_path, root->path );
428 if(strlen(Pathtypes[i].path)){
429 strcat( search_path, Pathtypes[i].path );
430 strcat( search_path, "\\" );
433 strcat( search_path, "*.*" );
441 find_handle = _findfirst( search_path, &find );
443 if (find_handle != -1) {
445 if (!(find.attrib & _A_SUBDIR)) {
447 char *ext = strchr( find.name, '.' );
449 if ( is_ext_in_list( Pathtypes[i].extensions, ext ) ) {
451 cf_file *file = cf_create_file();
453 strcpy( file->name_ext, find.name );
454 file->root_index = root_index;
455 file->pathtype_index = i;
456 file->write_time = find.time_write;
457 file->size = find.size;
458 file->pack_offset = 0; // Mark as a non-packed file
460 //mprintf(( "Found file '%s'\n", file->name_ext ));
467 } while (!_findnext(find_handle, &find));
469 _findclose( find_handle );
477 typedef struct VP_FILE_HEADER {
484 typedef struct VP_FILE {
491 void cf_search_root_pack(int root_index)
495 cf_root *root = cf_get_root(root_index);
497 //mprintf(( "Searching root pack '%s'\n", root->path ));
501 FILE *fp = fopen( root->path, "rb" );
502 // Read the file header
507 VP_FILE_HEADER VP_header;
509 Assert( sizeof(VP_header) == 16 );
510 fread(&VP_header, 1, sizeof(VP_header), fp);
513 fseek(fp, VP_header.index_offset, SEEK_SET);
515 char search_path[CF_MAX_PATHNAME_LENGTH];
517 strcpy( search_path, "" );
519 // Go through all the files
520 for (i=0; i<VP_header.num_files; i++ ) {
523 fread( &find, sizeof(VP_FILE), 1, fp );
525 if ( find.size == 0 ) {
526 if ( !stricmp( find.filename, ".." )) {
527 int l = strlen(search_path);
528 char *p = &search_path[l-1];
529 while( (p > search_path) && (*p != '\\') ) {
534 if ( strlen(search_path) ) {
535 strcat( search_path, "\\" );
537 strcat( search_path, find.filename );
540 //mprintf(( "Current dir = '%s'\n", search_path ));
544 for (j=CF_TYPE_ROOT; j<CF_MAX_PATH_TYPES; j++ ) {
546 if ( !stricmp( search_path, Pathtypes[j].path )) {
548 char *ext = strchr( find.filename, '.' );
550 if ( is_ext_in_list( Pathtypes[j].extensions, ext ) ) {
552 cf_file *file = cf_create_file();
554 strcpy( file->name_ext, find.filename );
555 file->root_index = root_index;
556 file->pathtype_index = j;
557 file->write_time = find.write_time;
558 file->size = find.size;
559 file->pack_offset = find.offset; // Mark as a non-packed file
561 //mprintf(( "Found pack file '%s'\n", file->name_ext ));
575 void cf_build_file_list()
581 // For each root, find all files...
582 for (i=1; i<Num_roots; i++ ) {
583 cf_root *root = cf_get_root(i);
584 if ( root->roottype == CF_ROOTTYPE_PATH ) {
585 cf_search_root_path(i);
586 } else if ( root->roottype == CF_ROOTTYPE_PACK ) {
587 cf_search_root_pack(i);
594 void cf_build_secondary_filelist(char *cdrom_dir)
602 // Init the path types
603 for (i=0; i<CF_MAX_PATH_TYPES; i++ ) {
604 Assert( Pathtypes[i].index == i );
605 if ( Pathtypes[i].extensions ) {
606 strlwr(Pathtypes[i].extensions);
610 // Init the root blocks
611 for (i=0; i<CF_MAX_ROOT_BLOCKS; i++ ) {
612 Root_blocks[i] = NULL;
615 // Init the file blocks
616 for (i=0; i<CF_MAX_FILE_BLOCKS; i++ ) {
617 File_blocks[i] = NULL;
620 mprintf(( "Building file index...\n" ));
622 // build the list of searchable roots
623 cf_build_root_list(cdrom_dir);
625 // build the list of files themselves
626 cf_build_file_list();
628 mprintf(( "Found %d roots and %d files.\n", Num_roots, Num_files ));
631 void cf_free_secondary_filelist()
635 // Free the root blocks
636 for (i=0; i<CF_MAX_ROOT_BLOCKS; i++ ) {
637 if ( Root_blocks[i] ) {
638 free( Root_blocks[i] );
639 Root_blocks[i] = NULL;
644 // Init the file blocks
645 for (i=0; i<CF_MAX_FILE_BLOCKS; i++ ) {
646 if ( File_blocks[i] ) {
647 free( File_blocks[i] );
648 File_blocks[i] = NULL;
654 // Searches for a file. Follows all rules and precedence and searches
655 // CD's and pack files.
656 // Input: filespace - Filename & extension
657 // pathtype - See CF_TYPE_ defines in CFILE.H
658 // Output: pack_filename - Absolute path and filename of this file. Could be a packfile or the actual file.
660 // offset - Offset into pack file. 0 if not a packfile.
661 // Returns: If not found returns 0.
662 int cf_find_file_location( char *filespec, int pathtype, char *pack_filename, int *size, int *offset, bool localize )
666 Assert(filespec && strlen(filespec));
668 // see if we have something other than just a filename
669 // our current rules say that any file that specifies a direct
670 // path will try to be opened on that path. If that open
671 // fails, then we will open the file based on the extension
674 // NOTE: full path should also include localization, if so desired
675 if ( strpbrk(filespec,"/\\:") ) { // do we have a full path already?
676 FILE *fp = fopen(filespec, "rb" );
678 if ( size ) *size = filelength(fileno(fp));
679 if ( offset ) *offset = 0;
680 if ( pack_filename ) {
681 strcpy( pack_filename, filespec );
687 return 0; // If they give a full path, fail if not found.
690 // Search the hard drive for files first.
691 int num_search_dirs = 0;
692 int search_order[CF_MAX_PATH_TYPES];
694 if ( CF_TYPE_SPECIFIED(pathtype) ) {
695 search_order[num_search_dirs++] = pathtype;
698 for (i=CF_TYPE_ROOT; i<CF_MAX_PATH_TYPES; i++) {
699 if ( i != pathtype ) {
700 search_order[num_search_dirs++] = i;
704 for (i=0; i<num_search_dirs; i++ ) {
705 char longname[MAX_PATH_LEN];
707 cf_create_default_path_string( longname, search_order[i], filespec, localize );
709 FILE *fp = fopen(longname, "rb" );
711 if ( size ) *size = filelength(fileno(fp));
712 if ( offset ) *offset = 0;
713 if ( pack_filename ) {
714 strcpy( pack_filename, longname );
721 // Search the pak files and CD-ROM.
723 for (i=0; i<Num_files; i++ ) {
724 cf_file * f = cf_get_file(i);
726 // only search paths we're supposed to...
727 if ( (pathtype != CF_TYPE_ANY) && (pathtype != f->pathtype_index) ) {
732 // create localized filespec
733 char temp[MAX_PATH_LEN];
734 strcpy(temp, filespec);
735 lcl_add_dir_to_path_with_filename(filespec);
737 if ( !stricmp(filespec, f->name_ext) ) {
738 if ( size ) *size = f->size;
739 if ( offset ) *offset = f->pack_offset;
740 if ( pack_filename ) {
741 cf_root * r = cf_get_root(f->root_index);
743 strcpy( pack_filename, r->path );
744 if ( f->pack_offset < 1 ) {
745 strcat( pack_filename, Pathtypes[f->pathtype_index].path );
746 strcat( pack_filename, "\\" );
747 strcat( pack_filename, f->name_ext );
752 // restore original filespec
753 strcpy(filespec, temp);
756 // file either not localized or localized version not found
757 if ( !stricmp(filespec, f->name_ext) ) {
758 if ( size ) *size = f->size;
759 if ( offset ) *offset = f->pack_offset;
760 if ( pack_filename ) {
761 cf_root * r = cf_get_root(f->root_index);
763 strcpy( pack_filename, r->path );
764 if ( f->pack_offset < 1 ) {
766 if(strlen(Pathtypes[f->pathtype_index].path)){
767 strcat( pack_filename, Pathtypes[f->pathtype_index].path );
768 strcat( pack_filename, "\\" );
771 strcat( pack_filename, f->name_ext );
782 // Returns true if filename matches filespec, else zero if not
783 int cf_matches_spec(char *filespec, char *filename)
785 char *src_ext, *dst_ext;
787 src_ext = strchr(filespec, '.');
793 dst_ext = strchr(filename, '.');
797 return !stricmp(dst_ext, src_ext);
800 int (*Get_file_list_filter)(char *filename) = NULL;
801 int Skip_packfile_search = 0;
803 int cf_file_already_in_list( int num_files, char **list, char *filename )
807 char name_no_extension[MAX_PATH_LEN];
809 strcpy(name_no_extension, filename );
810 char *p = strchr( name_no_extension, '.' );
813 for (i=0; i<num_files; i++ ) {
814 if ( !stricmp(list[i], name_no_extension ) ) {
823 // An alternative cf_get_file_list(), dynamic list version.
824 // This one has a 'type', which is a CF_TYPE_* value. Because this specifies the directory
825 // location, 'filter' only needs to be the filter itself, with no path information.
826 // See above descriptions of cf_get_file_list() for more information about how it all works.
827 int cf_get_file_list( int max, char **list, int pathtype, char *filter, int sort, file_list_info *info )
830 int i, l, find_handle, num_files = 0, own_flag = 0;
836 Get_file_list_filter = NULL;
842 if (!info && (sort == CF_SORT_TIME)) {
843 info = (file_list_info *) malloc(sizeof(file_list_info) * max);
847 char filespec[MAX_PATH_LEN];
849 cf_create_default_path_string( filespec, pathtype, filter );
854 find_handle = _findfirst( filespec, &find );
855 if (find_handle != -1) {
857 if (num_files >= max)
860 if (!(find.attrib & _A_SUBDIR)) {
861 if ( !Get_file_list_filter || (*Get_file_list_filter)(find.name) ) {
862 ptr = strrchr(find.name, '.');
866 l = strlen(find.name);
868 list[num_files] = (char *)malloc(l + 1);
869 strncpy(list[num_files], find.name, l);
870 list[num_files][l] = 0;
872 info[num_files].write_time = find.time_write;
878 } while (!_findnext(find_handle, &find));
880 _findclose( find_handle );
885 // Search all the packfiles and CD.
886 if ( !Skip_packfile_search ) {
887 for (i=0; i<Num_files; i++ ) {
888 cf_file * f = cf_get_file(i);
890 // only search paths we're supposed to...
891 if ( (pathtype != CF_TYPE_ANY) && (pathtype != f->pathtype_index) ) {
895 if (num_files >= max)
898 if ( !cf_matches_spec( filter,f->name_ext)) {
902 if ( cf_file_already_in_list(num_files,list,f->name_ext)) {
906 if ( !Get_file_list_filter || (*Get_file_list_filter)(f->name_ext) ) {
908 //mprintf(( "Found '%s' in root %d path %d\n", f->name_ext, f->root_index, f->pathtype_index ));
910 ptr = strrchr(f->name_ext, '.');
912 l = ptr - f->name_ext;
914 l = strlen(f->name_ext);
916 list[num_files] = (char *)malloc(l + 1);
917 strncpy(list[num_files], f->name_ext, l);
918 list[num_files][l] = 0;
921 info[num_files].write_time = f->write_time;
931 if (sort != CF_SORT_NONE) {
932 cf_sort_filenames( num_files, list, sort, info );
939 Get_file_list_filter = NULL;
943 int cf_file_already_in_list_preallocated( int num_files, char arr[][MAX_FILENAME_LEN], char *filename )
947 char name_no_extension[MAX_PATH_LEN];
949 strcpy(name_no_extension, filename );
950 char *p = strchr( name_no_extension, '.' );
953 for (i=0; i<num_files; i++ ) {
954 if ( !stricmp(arr[i], name_no_extension ) ) {
963 // An alternative cf_get_file_list(), fixed array version.
964 // This one has a 'type', which is a CF_TYPE_* value. Because this specifies the directory
965 // location, 'filter' only needs to be the filter itself, with no path information.
966 // See above descriptions of cf_get_file_list() for more information about how it all works.
967 int cf_get_file_list_preallocated( int max, char arr[][MAX_FILENAME_LEN], char **list, int pathtype, char *filter, int sort, file_list_info *info )
969 int i, num_files = 0, own_flag = 0;
972 Get_file_list_filter = NULL;
977 for (i=0; i<max; i++) {
981 sort = CF_SORT_NONE; // sorting of array directly not supported. Sorting done on list only
984 if (!info && (sort == CF_SORT_TIME)) {
985 info = (file_list_info *) malloc(sizeof(file_list_info) * max);
989 char filespec[MAX_PATH_LEN];
991 cf_create_default_path_string( filespec, pathtype, filter );
993 // Search the default directories
1000 find_handle = _findfirst( filespec, &find );
1001 if (find_handle != -1) {
1003 if (num_files >= max)
1006 if (!(find.attrib & _A_SUBDIR)) {
1008 if ( !Get_file_list_filter || (*Get_file_list_filter)(find.name) ) {
1010 strncpy(arr[num_files], find.name, MAX_FILENAME_LEN - 1 );
1011 char *ptr = strrchr(arr[num_files], '.');
1017 info[num_files].write_time = find.time_write;
1024 } while (!_findnext(find_handle, &find));
1026 _findclose( find_handle );
1031 // Search all the packfiles and CD.
1032 if ( !Skip_packfile_search ) {
1033 for (i=0; i<Num_files; i++ ) {
1034 cf_file * f = cf_get_file(i);
1036 // only search paths we're supposed to...
1037 if ( (pathtype != CF_TYPE_ANY) && (pathtype != f->pathtype_index) ) {
1041 if (num_files >= max)
1044 if ( !cf_matches_spec( filter,f->name_ext)) {
1048 if ( cf_file_already_in_list_preallocated( num_files, arr, f->name_ext )) {
1052 if ( !Get_file_list_filter || (*Get_file_list_filter)(f->name_ext) ) {
1054 //mprintf(( "Found '%s' in root %d path %d\n", f->name_ext, f->root_index, f->pathtype_index ));
1056 strncpy(arr[num_files], f->name_ext, MAX_FILENAME_LEN - 1 );
1057 char *ptr = strrchr(arr[num_files], '.');
1063 info[num_files].write_time = f->write_time;
1072 if (sort != CF_SORT_NONE) {
1074 cf_sort_filenames( num_files, list, sort, info );
1081 Get_file_list_filter = NULL;
1085 // Returns the default storage path for files given a
1086 // particular pathtype. In other words, the path to
1087 // the unpacked, non-cd'd, stored on hard drive path.
1088 // If filename isn't null it will also tack the filename
1089 // on the end, creating a completely valid filename.
1090 // Input: pathtype - CF_TYPE_??
1091 // filename - optional, if set, tacks the filename onto end of path.
1092 // Output: path - Fully qualified pathname.
1093 void cf_create_default_path_string( char *path, int pathtype, char *filename, bool localize )
1095 if ( filename && strpbrk(filename,"/\\:") ) {
1096 // Already has full path
1097 strcpy( path, filename );
1100 cf_root *root = cf_get_root(0);
1103 strcpy(path, filename);
1107 Assert(CF_TYPE_SPECIFIED(pathtype));
1109 strcpy(path, root->path);
1110 strcat(path, Pathtypes[pathtype].path);
1112 // Don't add slash for root directory
1113 if (Pathtypes[pathtype].path[0] != '\0') {
1119 strcat(path, filename);
1121 // localize filename
1123 // create copy of path
1124 char temp_path[MAX_PATH_LEN];
1125 strcpy(temp_path, path);
1127 // localize the path
1128 lcl_add_dir_to_path_with_filename(path);
1130 // verify localized path
1131 FILE *fp = fopen(path, "rb");
1135 strcpy(path, temp_path);