@@ -42,22 +42,22 @@ Anachronox Data Packages
4242=============================================================================
4343*/
4444
45- static constexpr unsigned int ADAT_MAGIC = GENERATE_MAGICID( ' A' , ' D' , ' A' , ' T' );
45+ static constexpr unsigned int ADAT_MAGIC = GENERATE_MAGICID( ' A' , ' D' , ' A' , ' T' );
4646static constexpr unsigned int ADAT_VERSION = 9 ;
4747
4848struct Package
4949{
5050 struct Index
5151 {
52- char name[ 128 ]; /* the name of the file, excludes 'model/' etc. */
52+ char name[ 128 ]; /* the name of the file, excludes 'model/' etc. */
5353 uint32_t offset; /* offset into the dat that the file resides */
5454 uint32_t length; /* decompressed length of the file */
5555 uint32_t compressedLength; /* length of the file in the dat */
5656 uint32_t u0;
5757 };
5858
59- std::string mappedDir; /* e.g., 'models' */
60- std::string path;
59+ std::string mappedDir; /* e.g., 'models' */
60+ std::string path;
6161 std::vector< Index > indices; /* index data */
6262
6363 /* *
@@ -106,9 +106,9 @@ struct Package
106106 file.read ( ( char * ) src.data (), fileIndex->compressedLength );
107107
108108 // decompress it
109- auto dst = ( uint8_t * ) Z_Malloc ( fileIndex->length );
109+ auto dst = ( uint8_t * ) Z_Malloc ( fileIndex->length );
110110 size_t dstLength = fileIndex->length ;
111- bool status = FS_DecompressFile ( src.data (), fileIndex->compressedLength , dst, &dstLength, fileIndex->length );
111+ bool status = FS_DecompressFile ( src.data (), fileIndex->compressedLength , dst, &dstLength, fileIndex->length );
112112
113113 file.close ();
114114
@@ -160,6 +160,13 @@ void FS_CanonicalisePath( char *path )
160160 }
161161}
162162
163+ std::string chr::io::SanitizePath ( std::string path )
164+ {
165+ path.erase ( std::remove ( path.begin (), path.end (), ' \" ' ), path.end () );
166+ std::ranges::replace ( path, ' \\ ' , ' /' );
167+ return path;
168+ }
169+
163170/* *
164171 * Decompress the given file and carry out validation.
165172 */
@@ -250,17 +257,17 @@ static bool FS_MountPackage( FILE *filePtr, const char *identity, Package *out )
250257// in memory
251258//
252259
253- static char fs_gamedir[ MAX_OSPATH ];
260+ static char fs_gamedir[ MAX_OSPATH ];
254261static cvar_t *fs_basedir;
255262static cvar_t *fs_cddir;
256263
257264cvar_t *fs_gamedirvar;
258265
259266struct searchpath_t
260267{
261- char filename[ MAX_OSPATH ]{ ' \0 ' };
268+ char filename[ MAX_OSPATH ]{ ' \0 ' };
262269 std::map< std::string, Package > packDirectories;
263- struct searchpath_t *next{ nullptr };
270+ struct searchpath_t *next{ nullptr };
264271};
265272
266273static searchpath_t *fs_searchpaths;
@@ -283,9 +290,7 @@ The "game directory" is the first tree on the search path and directory that all
283290 */
284291long FS_GetLocalFileLength ( const char *path )
285292{
286- struct stat buf
287- {
288- };
293+ struct stat buf{};
289294 if ( stat ( path, &buf ) != 0 )
290295 return -1 ;
291296
@@ -306,9 +311,9 @@ bool FS_CreatePath( char *path )
306311 {
307312 if ( *ofs == ' /' )
308313 {// create the directory
309- *ofs = 0 ;
314+ *ofs = 0 ;
310315 status = Sys_Mkdir ( path );
311- *ofs = ' /' ;
316+ *ofs = ' /' ;
312317 if ( status != 0 )
313318 break ;
314319 }
@@ -413,16 +418,16 @@ void CDAudio_Stop();
413418#define MAX_READ 0x10000 // read in blocks of 64k
414419void FS_Read ( void *buffer, int len, FILE *f )
415420{
416- int block, remaining;
417- int read;
421+ int block, remaining;
422+ int read;
418423 byte *buf;
419- int tries;
424+ int tries;
420425
421426 buf = ( byte * ) buffer;
422427
423428 // read in chunks for progress bar
424429 remaining = len;
425- tries = 0 ;
430+ tries = 0 ;
426431 while ( remaining )
427432 {
428433 block = remaining;
@@ -468,7 +473,7 @@ int FS_LoadFile( const char *path, void **buffer )
468473
469474 // look for it in the filesystem or pack files
470475 uint32_t length;
471- void *buf = FS_FOpenFile ( upath, &length );
476+ void *buf = FS_FOpenFile ( upath, &length );
472477 if ( buf == nullptr )
473478 {
474479 if ( buffer != nullptr )
@@ -511,7 +516,7 @@ static void FS_AddGameDirectory( const char *dir )
511516 //
512517 auto search = new searchpath_t ;
513518 strcpy ( search->filename , dir );
514- search->next = fs_searchpaths;
519+ search->next = fs_searchpaths;
515520 fs_searchpaths = search;
516521
517522 /* now go ahead and mount all the default packages under that dir */
@@ -579,7 +584,7 @@ FS_ExecAutoexec
579584void FS_ExecAutoexec ()
580585{
581586 char *dir;
582- char name[ MAX_QPATH ];
587+ char name[ MAX_QPATH ];
583588
584589 dir = Cvar_VariableString ( " gamedir" );
585590 if ( *dir )
@@ -646,9 +651,9 @@ void FS_SetGamedir( const char *dir )
646651*/
647652char **FS_ListFiles ( char *findname, int *numfiles, unsigned musthave, unsigned canthave )
648653{
649- char *s;
650- int nfiles = 0 ;
651- char **list = nullptr ;
654+ char *s;
655+ int nfiles = 0 ;
656+ char **list = nullptr ;
652657
653658 s = Sys_FindFirst ( findname, musthave, canthave );
654659 while ( s )
@@ -668,7 +673,7 @@ char **FS_ListFiles( char *findname, int *numfiles, unsigned musthave, unsigned
668673 list = ( char ** ) malloc ( sizeof ( char * ) * nfiles );
669674 memset ( list, 0 , sizeof ( char * ) * nfiles );
670675
671- s = Sys_FindFirst ( findname, musthave, canthave );
676+ s = Sys_FindFirst ( findname, musthave, canthave );
672677 nfiles = 0 ;
673678 while ( s )
674679 {
@@ -690,11 +695,11 @@ char **FS_ListFiles( char *findname, int *numfiles, unsigned musthave, unsigned
690695*/
691696void FS_Dir_f ()
692697{
693- char *path = nullptr ;
694- char findname[ 1024 ];
695- char wildcard[ 1024 ] = " *.*" ;
698+ char *path = nullptr ;
699+ char findname[ 1024 ];
700+ char wildcard[ 1024 ] = " *.*" ;
696701 char **dirnames;
697- int ndirs;
702+ int ndirs;
698703
699704 if ( Cmd_Argc () != 1 )
700705 strcpy ( wildcard, Cmd_Argv ( 1 ) );
@@ -826,7 +831,7 @@ static void ExtractCommand()
826831 for ( const auto &j : i.second .indices )
827832 {
828833 unsigned int fileSize;
829- void *p = i.second .LoadFile ( j.name , &fileSize );
834+ void *p = i.second .LoadFile ( j.name , &fileSize );
830835 if ( p == nullptr )
831836 {
832837 Com_Printf ( " Failed to load %s\n " , j.name );
0 commit comments