FS2_Open
Open source remastering of the Freespace 2 engine
cfilesystem.cpp File Reference
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <sstream>
#include <algorithm>
#include "cfile/cfile.h"
#include "cfile/cfilesystem.h"
#include "cmdline/cmdline.h"
#include "globalincs/pstypes.h"
#include "localization/localize.h"

Go to the source code of this file.

Classes

struct  cf_root
 
struct  cf_root_sort
 
struct  cf_root_block
 
struct  cf_file
 
struct  cf_file_block
 
struct  VP_FILE_HEADER
 
struct  VP_FILE
 

Macros

#define CF_ROOTTYPE_PATH   0
 
#define CF_ROOTTYPE_PACK   1
 
#define CF_NUM_ROOTS_PER_BLOCK   32
 
#define CF_MAX_ROOT_BLOCKS   256
 
#define CF_MAX_ROOTS   (CF_NUM_ROOTS_PER_BLOCK * CF_MAX_ROOT_BLOCKS)
 
#define CF_NUM_FILES_PER_BLOCK   512
 
#define CF_MAX_FILE_BLOCKS   128
 

Typedefs

typedef struct cf_root cf_root
 
typedef struct cf_root_sort cf_root_sort
 
typedef struct cf_root_block cf_root_block
 
typedef struct cf_file cf_file
 
typedef struct cf_file_block cf_file_block
 
typedef struct VP_FILE_HEADER VP_FILE_HEADER
 
typedef struct VP_FILE VP_FILE
 

Functions

cf_filecf_get_file (int index)
 
cf_filecf_create_file ()
 
cf_rootcf_get_root (int n)
 
cf_rootcf_create_root ()
 
int cf_get_packfile_count (cf_root *root)
 
bool cf_packfile_sort_func (const cf_root_sort &r1, const cf_root_sort &r2)
 
void cf_build_pack_list (cf_root *root)
 
void cf_build_root_list (const char *cdrom_dir)
 
int is_ext_in_list (const char *ext_list, const char *ext)
 
void cf_search_root_path (int root_index)
 
void cf_search_root_pack (int root_index)
 
void cf_build_file_list ()
 
void cf_build_secondary_filelist (const char *cdrom_dir)
 
void cf_free_secondary_filelist ()
 
int cf_find_file_location (const char *filespec, int pathtype, int max_out, char *pack_filename, int *size, int *offset, bool localize)
 
char * stristr (char *str, const char *substr)
 
int cf_find_file_location_ext (const char *filename, const int ext_num, const char **ext_list, int pathtype, int max_out, char *pack_filename, int *size, int *offset, bool localize)
 
int cf_matches_spec (const char *filespec, const char *filename)
 
int cf_get_file_list (SCP_vector< SCP_string > &list, int pathtype, const char *filter, int sort, SCP_vector< file_list_info > *info)
 
int cf_file_already_in_list (int num_files, char **list, const char *filename)
 
int cf_get_file_list (int max, char **list, int pathtype, const char *filter, int sort, file_list_info *info)
 
int cf_file_already_in_list_preallocated (int num_files, char arr[][MAX_FILENAME_LEN], const char *filename)
 
int cf_get_file_list_preallocated (int max, char arr[][MAX_FILENAME_LEN], char **list, int pathtype, const char *filter, int sort, file_list_info *info)
 
int cf_create_default_path_string (char *path, uint path_max, int pathtype, const char *filename, bool localize)
 
int cf_create_default_path_string (SCP_string &path, int pathtype, const char *filename, bool localize)
 
void cfile_spew_pack_file_crcs ()
 

Variables

char * Pilot_file_path = NULL
 
int cfile_inited
 
int(* Get_file_list_filter )(const char *filename) = NULL
 
const char * Get_file_list_child = NULL
 
int Skip_packfile_search = 0
 

Macro Definition Documentation

#define CF_MAX_FILE_BLOCKS   128

Definition at line 89 of file cfilesystem.cpp.

#define CF_MAX_ROOT_BLOCKS   256

Definition at line 66 of file cfilesystem.cpp.

#define CF_MAX_ROOTS   (CF_NUM_ROOTS_PER_BLOCK * CF_MAX_ROOT_BLOCKS)

Definition at line 67 of file cfilesystem.cpp.

#define CF_NUM_FILES_PER_BLOCK   512

Definition at line 88 of file cfilesystem.cpp.

#define CF_NUM_ROOTS_PER_BLOCK   32

Definition at line 65 of file cfilesystem.cpp.

#define CF_ROOTTYPE_PACK   1

Definition at line 43 of file cfilesystem.cpp.

#define CF_ROOTTYPE_PATH   0

Definition at line 42 of file cfilesystem.cpp.

Typedef Documentation

typedef struct cf_file cf_file
typedef struct cf_file_block cf_file_block
typedef struct cf_root cf_root
typedef struct cf_root_block cf_root_block
typedef struct cf_root_sort cf_root_sort
typedef struct VP_FILE VP_FILE

Function Documentation

void cf_build_file_list ( )

Definition at line 753 of file cfilesystem.cpp.

void cf_build_pack_list ( cf_root root)

Definition at line 234 of file cfilesystem.cpp.

void cf_build_root_list ( const char *  cdrom_dir)

Definition at line 364 of file cfilesystem.cpp.

void cf_build_secondary_filelist ( const char *  cdrom_dir)

Definition at line 772 of file cfilesystem.cpp.

int cf_create_default_path_string ( char *  path,
uint  path_max,
int  pathtype,
const char *  filename,
bool  localize 
)

Definition at line 2004 of file cfilesystem.cpp.

int cf_create_default_path_string ( SCP_string path,
int  pathtype,
const char *  filename,
bool  localize 
)

Definition at line 2076 of file cfilesystem.cpp.

cf_file* cf_create_file ( )

Definition at line 109 of file cfilesystem.cpp.

cf_root* cf_create_root ( )

Definition at line 142 of file cfilesystem.cpp.

int cf_file_already_in_list ( int  num_files,
char **  list,
const char *  filename 
)

Definition at line 1594 of file cfilesystem.cpp.

int cf_file_already_in_list_preallocated ( int  num_files,
char  arr[][MAX_FILENAME_LEN],
const char *  filename 
)

Definition at line 1793 of file cfilesystem.cpp.

int cf_find_file_location ( const char *  filespec,
int  pathtype,
int  max_out,
char *  pack_filename,
int size,
int offset,
bool  localize 
)

Searches for a file.

Note
Follows all rules and precedence and searches CD's and pack files.
Parameters
filespecFilename & extension
pathtypeSee CF_TYPE_ defines in CFILE.H
max_outMaximum string length that should be stuffed into pack_filename
pack_filenameOUTPUT: Absolute path and filename of this file. Could be a packfile or the actual file.
sizeOUTPUT: File size
offsetOUTPUT: Offset into pack file. 0 if not a packfile.
localizeUndertake localization
Returns
If not found returns 0.

Definition at line 839 of file cfilesystem.cpp.

int cf_find_file_location_ext ( const char *  filename,
const int  ext_num,
const char **  ext_list,
int  pathtype,
int  max_out,
char *  pack_filename,
int size,
int offset,
bool  localize 
)

Searches for a file.

Note
Follows all rules and precedence and searches CD's and pack files. Searches all locations in order for first filename using filter list.
This function is exponentially slow, so don't use it unless truely needed
Parameters
filenameFilename & extension
ext_numNumber of extensions to look for
ext_listExtension filter list
pathtypeSee CF_TYPE_ defines in CFILE.H
max_outMaximum string length that should be stuffed into pack_filename
pack_filenameOUTPUT: Absolute path and filename of this file. Could be a packfile or the actual file.
sizeOUTPUT: File size
offsetOUTPUT: Offset into pack file. 0 if not a packfile.
localizeUndertake localization
Returns
If not found returns -1, else returns offset into ext_list.

Definition at line 1050 of file cfilesystem.cpp.

void cf_free_secondary_filelist ( )

Definition at line 801 of file cfilesystem.cpp.

cf_file* cf_get_file ( int  index)

Definition at line 100 of file cfilesystem.cpp.

int cf_get_file_list ( SCP_vector< SCP_string > &  list,
int  pathtype,
const char *  filter,
int  sort,
SCP_vector< file_list_info > *  info 
)

Definition at line 1417 of file cfilesystem.cpp.

int cf_get_file_list ( int  max,
char **  list,
int  pathtype,
const char *  filter,
int  sort,
file_list_info info 
)

Definition at line 1618 of file cfilesystem.cpp.

int cf_get_file_list_preallocated ( int  max,
char  arr[][MAX_FILENAME_LEN],
char **  list,
int  pathtype,
const char *  filter,
int  sort,
file_list_info info 
)

Definition at line 1817 of file cfilesystem.cpp.

int cf_get_packfile_count ( cf_root root)

Definition at line 158 of file cfilesystem.cpp.

cf_root* cf_get_root ( int  n)

Definition at line 129 of file cfilesystem.cpp.

int cf_matches_spec ( const char *  filespec,
const char *  filename 
)

Definition at line 1324 of file cfilesystem.cpp.

bool cf_packfile_sort_func ( const cf_root_sort r1,
const cf_root_sort r2 
)

Definition at line 222 of file cfilesystem.cpp.

void cf_search_root_pack ( int  root_index)

Definition at line 645 of file cfilesystem.cpp.

void cf_search_root_path ( int  root_index)

Definition at line 514 of file cfilesystem.cpp.

void cfile_spew_pack_file_crcs ( )

Definition at line 2128 of file cfilesystem.cpp.

int is_ext_in_list ( const char *  ext_list,
const char *  ext 
)

Definition at line 501 of file cfilesystem.cpp.

char* stristr ( char *  str,
const char *  substr 
)

Definition at line 3729 of file parselo.cpp.

Variable Documentation

int cfile_inited

Definition at line 94 of file cfile.cpp.

const char* Get_file_list_child = NULL

Definition at line 1361 of file cfilesystem.cpp.

int(* Get_file_list_filter) (const char *filename) = NULL

Definition at line 1360 of file cfilesystem.cpp.

char* Pilot_file_path = NULL

Definition at line 46 of file cfilesystem.cpp.

int Skip_packfile_search = 0

Definition at line 1362 of file cfilesystem.cpp.