From f51f3a765cf916697a2d2a02a2261ed6f56ae98d Mon Sep 17 00:00:00 2001 From: theoddone33 Date: Tue, 28 May 2002 06:28:20 +0000 Subject: [PATCH] Filesystem mods, actually reads some data files now --- Makefile | 2 +- include/pstypes.h | 11 ++- src/cfile/cfile.cpp | 67 +++++++++++++-- src/cfile/cfilesystem.cpp | 152 ++++++++++++++++++++++++++++++++--- src/freespace2/freespace.cpp | 10 ++- src/parse/parselo.cpp | 7 ++ src/platform/unix.cpp | 1 + 7 files changed, 224 insertions(+), 26 deletions(-) diff --git a/Makefile b/Makefile index 807c04c..dedb45d 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ AR=ar CODE_BINARY=code.a FS_BINARY=freespace2 LDFLAGS=$(shell sdl-config --libs) -CFLAGS=-DFS2_DEMO -Wall -g -DPLAT_UNIX -O2 $(shell sdl-config --cflags) -Iinclude/ -fwritable-strings +CFLAGS=-Wall -g -DPLAT_UNIX -O2 $(shell sdl-config --cflags) -Iinclude/ -fwritable-strings %.o: %.cpp $(CC) -c -o $@ $< $(CFLAGS) diff --git a/include/pstypes.h b/include/pstypes.h index 5812689..4fd7e59 100644 --- a/include/pstypes.h +++ b/include/pstypes.h @@ -7,8 +7,11 @@ * Header file containg global typedefs, constants and macros * * $Log$ - * Revision 1.1 2002/05/03 03:28:12 root - * Initial revision + * Revision 1.2 2002/05/28 06:28:20 theoddone33 + * Filesystem mods, actually reads some data files now + * + * Revision 1.1.1.1 2002/05/03 03:28:12 root + * Initial import. * * * 34 6/16/00 3:16p Jefff @@ -169,11 +172,11 @@ // #define MULTIPLAYER_BETA_BUILD // enable for multiplayer beta build // #define E3_BUILD // enable for 3dfx E3 build // #define PRESS_TOUR_BUILD // enable for press tour build -// #define FS2_DEMO // enable demo build for FS2 +#define FS2_DEMO // enable demo build for FS2 // #define PD_BUILD // fred documentation/evaluation build // #define FRENCH_BUILD // build for French (obsolete) // #define GERMAN_BUILD // build for German (this is now used) -#define RELEASE_REAL // this means that it is an actual release candidate, not just an optimized/release build +//#define RELEASE_REAL // this means that it is an actual release candidate, not just an optimized/release build // uncomment this #define for DVD version (makes popups say DVD instead of CD 2 or whatever): JCF 5/10/2000 // #define DVD_MESSAGE_HACK diff --git a/src/cfile/cfile.cpp b/src/cfile/cfile.cpp index c919e02..e5ac6b4 100644 --- a/src/cfile/cfile.cpp +++ b/src/cfile/cfile.cpp @@ -7,8 +7,11 @@ * Utilities for operating on files * * $Log$ - * Revision 1.1 2002/05/03 03:28:08 root - * Initial revision + * Revision 1.2 2002/05/28 06:28:20 theoddone33 + * Filesystem mods, actually reads some data files now + * + * Revision 1.1.1.1 2002/05/03 03:28:08 root + * Initial import. * * * 20 9/08/99 10:01p Dave @@ -189,6 +192,41 @@ cf_pathtype Pathtypes[CF_MAX_PATH_TYPES] = { // Root must be index 1!! { CF_TYPE_ROOT, "", ".mve", CF_TYPE_ROOT }, { CF_TYPE_DATA, "Data", ".cfg .log .txt", CF_TYPE_ROOT }, +#ifdef PLAT_UNIX + { CF_TYPE_MAPS, "Data/Maps", ".pcx .ani .tga", CF_TYPE_DATA }, + { CF_TYPE_TEXT, "Data/Text", ".txt .net", CF_TYPE_DATA }, + { CF_TYPE_MISSIONS, "Data/Missions", ".fs2 .fc2 .ntl .ssv", CF_TYPE_DATA }, + { CF_TYPE_MODELS, "Data/Models", ".pof", CF_TYPE_DATA }, + { CF_TYPE_TABLES, "Data/Tables", ".tbl", CF_TYPE_DATA }, + { CF_TYPE_SOUNDS, "Data/Sounds", ".wav", CF_TYPE_DATA }, + { CF_TYPE_SOUNDS_8B22K, "Data/Sounds/8b22k", ".wav", CF_TYPE_SOUNDS }, + { CF_TYPE_SOUNDS_16B11K, "Data/Sounds/16b11k", ".wav", CF_TYPE_SOUNDS }, + { CF_TYPE_VOICE, "Data/Voice", "", CF_TYPE_DATA }, + { CF_TYPE_VOICE_BRIEFINGS, "Data/Voice/Briefing", ".wav", CF_TYPE_VOICE }, + { CF_TYPE_VOICE_CMD_BRIEF, "Data/Voice/Command_briefings",".wav", CF_TYPE_VOICE }, + { CF_TYPE_VOICE_DEBRIEFINGS, "Data/Voice/Debriefing", ".wav", CF_TYPE_VOICE }, + { CF_TYPE_VOICE_PERSONAS, "Data/Voice/Personas", ".wav", CF_TYPE_VOICE }, + { CF_TYPE_VOICE_SPECIAL, "Data/Voice/Special", ".wav", CF_TYPE_VOICE }, + { CF_TYPE_VOICE_TRAINING, "Data/Voice/Training", ".wav", CF_TYPE_VOICE }, + { CF_TYPE_MUSIC, "Data/Music", ".wav", CF_TYPE_VOICE }, + { CF_TYPE_MOVIES, "Data/Movies", ".mve .msb", CF_TYPE_DATA }, + { CF_TYPE_INTERFACE, "Data/Interface", ".pcx .ani .tga", CF_TYPE_DATA }, + { CF_TYPE_FONT, "Data/Fonts", ".vf", CF_TYPE_DATA }, + { CF_TYPE_EFFECTS, "Data/Effects", ".ani .pcx .neb .tga", CF_TYPE_DATA }, + { CF_TYPE_HUD, "Data/Hud", ".ani .pcx .tga", CF_TYPE_DATA }, + { CF_TYPE_PLAYER_MAIN, "Data/Players", "", CF_TYPE_DATA }, + { CF_TYPE_PLAYER_IMAGES_MAIN, "Data/Players/Images", ".pcx", CF_TYPE_PLAYER_MAIN }, + { CF_TYPE_CACHE, "Data/Cache", ".clr .tmp", CF_TYPE_DATA }, //clr=cached color + { CF_TYPE_PLAYERS, "Data/Players", ".hcf", CF_TYPE_DATA }, + { CF_TYPE_SINGLE_PLAYERS, "Data/Players/Single", ".plr .csg .css", CF_TYPE_PLAYERS }, + { CF_TYPE_MULTI_PLAYERS, "Data/Players/Multi", ".plr", CF_TYPE_DATA }, + { CF_TYPE_MULTI_CACHE, "Data/MultiData", ".pcx .fs2", CF_TYPE_DATA }, + { CF_TYPE_CONFIG, "Data/Config", ".cfg", CF_TYPE_DATA }, + { CF_TYPE_SQUAD_IMAGES_MAIN, "Data/Players/Squads", ".pcx", CF_TYPE_DATA }, + { CF_TYPE_DEMOS, "Data/Demos", ".fsd", CF_TYPE_DATA }, + { CF_TYPE_CBANIMS, "Data/CBAnims", ".ani", CF_TYPE_DATA }, + { CF_TYPE_INTEL_ANIMS, "Data/IntelAnims", ".ani", CF_TYPE_DATA }, +#else { CF_TYPE_MAPS, "Data\\Maps", ".pcx .ani .tga", CF_TYPE_DATA }, { CF_TYPE_TEXT, "Data\\Text", ".txt .net", CF_TYPE_DATA }, { CF_TYPE_MISSIONS, "Data\\Missions", ".fs2 .fc2 .ntl .ssv", CF_TYPE_DATA }, @@ -222,6 +260,7 @@ cf_pathtype Pathtypes[CF_MAX_PATH_TYPES] = { { CF_TYPE_DEMOS, "Data\\Demos", ".fsd", CF_TYPE_DATA }, { CF_TYPE_CBANIMS, "Data\\CBAnims", ".ani", CF_TYPE_DATA }, { CF_TYPE_INTEL_ANIMS, "Data\\IntelAnims", ".ani", CF_TYPE_DATA }, +#endif }; @@ -268,13 +307,21 @@ int cfile_in_root_dir(char *exe_path) strncpy(path_copy, exe_path, 2047); // count how many slashes there are in the path +#ifdef PLAT_UNIX + tok = strtok(path_copy, "/"); +#else tok = strtok(path_copy, "\\"); +#endif if(tok == NULL){ return 1; } do { token_count++; +#ifdef PLAT_UNIX + tok = strtok(NULL, "/"); +#else tok = strtok(NULL, "\\"); +#endif } while(tok != NULL); // root directory if we have <= 1 slash @@ -309,7 +356,7 @@ int cfile_init(char *exe_dir, char *cdrom_dir) // are we in a root directory? if(cfile_in_root_dir(buf)){ #ifdef PLAT_UNIX - fprintf (stderr, "ERROR: Freespace2/Fred2 cannot be run from a drive root directory!"); + fprintf (stderr, "ERROR: Freespace2/Fred2 cannot be run from a drive root directory!\n"); #else MessageBox((HWND)NULL, "Freespace2/Fred2 cannot be run from a drive root directory!", "Error", MB_OK); #endif @@ -317,7 +364,11 @@ int cfile_init(char *exe_dir, char *cdrom_dir) } while (i--) { +#ifdef PLAT_UNIX + if (buf[i] == '/'){ +#else if (buf[i] == '\\'){ +#endif break; } } @@ -406,6 +457,7 @@ int cfile_push_chdir(int type) cf_create_default_path_string( dir, type, NULL ); _strlwr(dir); +#ifndef PLAT_UNIX Drive = strchr(dir, ':'); if (Drive) { @@ -414,7 +466,9 @@ int cfile_push_chdir(int type) Path = Drive+1; - } else { + } else +#endif + { Path = dir; } @@ -443,6 +497,7 @@ int cfile_chdir(char *dir) _getcwd(OriginalDirectory, 127); _strlwr(dir); +#ifndef PLAT_UNIX Drive = strchr(dir, ':'); if (Drive) { if (!cfile_chdrive( *(Drive - 1) - 'a' + 1, 1)) @@ -450,7 +505,9 @@ int cfile_chdir(char *dir) Path = Drive+1; - } else { + } else +#endif + { Path = dir; } diff --git a/src/cfile/cfilesystem.cpp b/src/cfile/cfilesystem.cpp index e3cef49..7851cf3 100644 --- a/src/cfile/cfilesystem.cpp +++ b/src/cfile/cfilesystem.cpp @@ -11,8 +11,11 @@ * all those locations, inherently enforcing precedence orders. * * $Log$ - * Revision 1.1 2002/05/03 03:28:08 root - * Initial revision + * Revision 1.2 2002/05/28 06:28:20 theoddone33 + * Filesystem mods, actually reads some data files now + * + * Revision 1.1.1.1 2002/05/03 03:28:08 root + * Initial import. * * * 6 9/08/99 10:01p Dave @@ -82,6 +85,10 @@ #include #include #include /* needed for memory mapping of file functions */ +#else +#include +#include +#include #endif #include "pstypes.h" @@ -212,6 +219,26 @@ int cf_get_packfile_count(cf_root *root) // count up how many packfiles we're gonna have packfile_count = 0; for (i=CF_TYPE_ROOT; ipath ); + + if(strlen(Pathtypes[i].path)){ + strcat( filespec, Pathtypes[i].path ); + strcat( filespec, "/" ); + } + + DIR *dirp; + struct dirent *dir; + + dirp = opendir (filespec); + if ( dirp ) { + while ((dir = readdir (dirp)) != NULL) + { + if (!fnmatch ("*.vp", dir->d_name, 0)) + packfile_count++; + } + } +#else strcpy( filespec, root->path ); if(strlen(Pathtypes[i].path)){ @@ -221,9 +248,6 @@ int cf_get_packfile_count(cf_root *root) strcat( filespec, "*.vp" ); -#ifdef PLAT_UNIX - STUB_FUNCTION; -#else int find_handle; _finddata_t find; @@ -285,17 +309,52 @@ void cf_build_pack_list( cf_root *root ) // now just setup all the root info root_index = 0; for (i=CF_TYPE_ROOT; ipath ); if(strlen(Pathtypes[i].path)){ strcat( filespec, Pathtypes[i].path ); - strcat( filespec, "\\" ); + strcat( filespec, "/" ); } - strcat( filespec, "*.vp" ); + fprintf (stderr, "DDOI: searching |%s|\n", filespec); -#ifdef PLAT_UNIX - STUB_FUNCTION; + DIR *dirp; + struct dirent *dir; + + dirp = opendir (filespec); + if ( dirp ) { + while ((dir = readdir (dirp)) != NULL) + { + if (!fnmatch ("*.vp", dir->d_name, 0)) + { + Assert(root_index < temp_root_count); + + // get a temp pointer + rptr_sort = &temp_roots_sort[root_index++]; + + // fill in all the proper info + strcpy(rptr_sort->path, root->path); + + if(strlen(Pathtypes[i].path)){ + strcat(rptr_sort->path, Pathtypes[i].path ); + strcat(rptr_sort->path, "/"); + } + + strcat(rptr_sort->path, dir->d_name ); + rptr_sort->roottype = CF_ROOTTYPE_PACK; + rptr_sort->cf_type = i; + } + } + } #else + strcpy( filespec, root->path ); + + if(strlen(Pathtypes[i].path)){ + strcat( filespec, Pathtypes[i].path ); + strcat( filespec, "\\" ); + } + strcat( filespec, "*.vp" ); int find_handle; _finddata_t find; @@ -370,8 +429,13 @@ void cf_build_root_list(char *cdrom_dir) } // do we already have a slash? as in the case of a root directory install +#ifdef PLAT_UNIX + if(strlen(root->path) && (root->path[strlen(root->path)-1] != '/')){ + strcat(root->path, "/"); // put trailing backslash on for easier path construction +#else if(strlen(root->path) && (root->path[strlen(root->path)-1] != '\\')){ strcat(root->path, "\\"); // put trailing backslash on for easier path construction +#endif } root->roottype = CF_ROOTTYPE_PATH; @@ -423,6 +487,49 @@ void cf_search_root_path(int root_index) for (i=CF_TYPE_ROOT; ipath ); + + if(strlen(Pathtypes[i].path)){ + strcat( search_path, Pathtypes[i].path ); + strcat( search_path, "/" ); + } + + fprintf (stderr, "DDOI: we're searching |%s|\n", search_path); + + dirp = opendir (search_path); + if ( dirp ) { + while ((dir = readdir (dirp)) != NULL) + { + if (!fnmatch ("*.*", dir->d_name, 0)) + { + char *ext = strchr( dir->d_name, '.' ); + if ( ext ) { + if ( is_ext_in_list( Pathtypes[i].extensions, ext ) ) { + // Found a file!!!! + cf_file *file = cf_create_file(); + + strcpy( file->name_ext, dir->d_name ); + file->root_index = root_index; + file->pathtype_index = i; +#if 0 + file->write_time = find.time_write; + file->size = find.size; +#else + STUB_FUNCTION; +#endif + file->pack_offset = 0; // Mark as a non-packed file + + //mprintf(( "Found file '%s'\n", file->name_ext )); + } + } + } + } + } +#else strcpy( search_path, root->path ); if(strlen(Pathtypes[i].path)){ @@ -432,9 +539,6 @@ void cf_search_root_path(int root_index) strcat( search_path, "*.*" ); -#ifdef STUB_FUNCTION - STUB_FUNCTION; -#else int find_handle; _finddata_t find; @@ -526,13 +630,21 @@ void cf_search_root_pack(int root_index) if ( !stricmp( find.filename, ".." )) { int l = strlen(search_path); char *p = &search_path[l-1]; +#ifdef PLAT_UNIX + while( (p > search_path) && (*p != '/') ) { +#else while( (p > search_path) && (*p != '\\') ) { +#endif p--; } *p = 0; } else { if ( strlen(search_path) ) { +#ifdef PLAT_UNIX + strcat( search_path, "/" ); +#else strcat( search_path, "\\" ); +#endif } strcat( search_path, find.filename ); } @@ -743,7 +855,11 @@ int cf_find_file_location( char *filespec, int pathtype, char *pack_filename, in strcpy( pack_filename, r->path ); if ( f->pack_offset < 1 ) { strcat( pack_filename, Pathtypes[f->pathtype_index].path ); +#ifdef PLAT_UNIX + strcat( pack_filename, "/" ); +#else strcat( pack_filename, "\\" ); +#endif strcat( pack_filename, f->name_ext ); } } @@ -765,7 +881,11 @@ int cf_find_file_location( char *filespec, int pathtype, char *pack_filename, in if(strlen(Pathtypes[f->pathtype_index].path)){ strcat( pack_filename, Pathtypes[f->pathtype_index].path ); +#ifdef PLAT_UNIX + strcat( pack_filename, "/" ); +#else strcat( pack_filename, "\\" ); +#endif } strcat( pack_filename, f->name_ext ); @@ -1092,7 +1212,11 @@ int cf_get_file_list_preallocated( int max, char arr[][MAX_FILENAME_LEN], char * // Output: path - Fully qualified pathname. void cf_create_default_path_string( char *path, int pathtype, char *filename, bool localize ) { +#ifdef PLAT_UNIX + if ( filename && strpbrk(filename,"/") ) { +#else if ( filename && strpbrk(filename,"/\\:") ) { +#endif // Already has full path strcpy( path, filename ); @@ -1111,7 +1235,11 @@ void cf_create_default_path_string( char *path, int pathtype, char *filename, bo // Don't add slash for root directory if (Pathtypes[pathtype].path[0] != '\0') { +#ifdef PLAT_UNIX + strcat(path, "/"); +#else strcat(path, "\\"); +#endif } // add filename diff --git a/src/freespace2/freespace.cpp b/src/freespace2/freespace.cpp index 2809a57..80262bb 100644 --- a/src/freespace2/freespace.cpp +++ b/src/freespace2/freespace.cpp @@ -7,6 +7,9 @@ * Freespace main body * * $Log$ + * Revision 1.6 2002/05/28 06:28:20 theoddone33 + * Filesystem mods, actually reads some data files now + * * Revision 1.5 2002/05/28 04:07:28 theoddone33 * New graphics stubbing arrangement * @@ -2040,12 +2043,11 @@ void game_init() char whee[1024]; #ifndef PLAT_UNIX GetCurrentDirectory(1024, whee); + strcat(whee, "\\"); #else - strcpy(whee, "."); - strcpy(whee,".\\."); - STUB_FUNCTION; + getcwd (whee, 1024); + strcat(whee, "/"); #endif - strcat(whee, "\\"); strcat(whee, EXE_FNAME); //Initialize the libraries diff --git a/src/parse/parselo.cpp b/src/parse/parselo.cpp index d12792d..faab2c9 100644 --- a/src/parse/parselo.cpp +++ b/src/parse/parselo.cpp @@ -7,6 +7,9 @@ * low level parse routines common to all types of parsers * * $Log$ + * Revision 1.3 2002/05/28 06:28:20 theoddone33 + * Filesystem mods, actually reads some data files now + * * Revision 1.2 2002/05/07 03:16:48 theoddone33 * The Great Newline Fix * @@ -1125,6 +1128,10 @@ void read_file_text(char *filename, int mode) mf = cfopen(filename, "rb", CFILE_NORMAL, mode); if (mf == NULL) { nprintf(("Error", "Wokka! Error opening mission.txt!\n")); +#ifdef PLAT_UNIX + nprintf (("DDOI", "Which is really %s!\n",filename)); + exit (1); +#endif longjmp(parse_abort, 5); } diff --git a/src/platform/unix.cpp b/src/platform/unix.cpp index 005aba8..80f5593 100644 --- a/src/platform/unix.cpp +++ b/src/platform/unix.cpp @@ -101,6 +101,7 @@ void outwnd_printf(char* id, char* format, ...) vsprintf (tmp, format, args); va_end(args); fprintf (stderr, "%s: %s", id, tmp); + if (!strcmp ("Error", id)) exit (1); } void outwnd_printf2(char* format, ...) -- 2.39.2