| 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 |
#include "q_shared.h" |
| 33 |
#include "qcommon.h" |
| 34 |
#include "unzip.h" |
| 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 |
#ifndef STANDALONE |
| 178 |
#define DEMO_PAK0_CHECKSUM 2985612116u |
| 179 |
static const unsigned int pak_checksums[] = { |
| 180 |
1566731103u, |
| 181 |
298122907u, |
| 182 |
412165236u, |
| 183 |
2991495316u, |
| 184 |
1197932710u, |
| 185 |
4087071573u, |
| 186 |
3709064859u, |
| 187 |
908855077u, |
| 188 |
977125798u |
| 189 |
}; |
| 190 |
|
| 191 |
static const unsigned int missionpak_checksums[] = |
| 192 |
{ |
| 193 |
2430342401u, |
| 194 |
511014160u, |
| 195 |
2662638993u, |
| 196 |
1438664554u |
| 197 |
}; |
| 198 |
#endif |
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
#define MAX_ZPATH 256 |
| 209 |
#define MAX_SEARCH_PATHS 4096 |
| 210 |
#define MAX_FILEHASH_SIZE 1024 |
| 211 |
|
| 212 |
typedef struct fileInPack_s { |
| 213 |
char *name; |
| 214 |
unsigned long pos; |
| 215 |
unsigned long len; |
| 216 |
struct fileInPack_s* next; |
| 217 |
} fileInPack_t; |
| 218 |
|
| 219 |
typedef struct { |
| 220 |
char pakPathname[MAX_OSPATH]; |
| 221 |
char pakFilename[MAX_OSPATH]; |
| 222 |
char pakBasename[MAX_OSPATH]; |
| 223 |
char pakGamename[MAX_OSPATH]; |
| 224 |
unzFile handle; |
| 225 |
unsigned int checksum; |
| 226 |
int pure_checksum; |
| 227 |
int numfiles; |
| 228 |
int referenced; |
| 229 |
int hashSize; |
| 230 |
fileInPack_t* *hashTable; |
| 231 |
fileInPack_t* buildBuffer; |
| 232 |
} pack_t; |
| 233 |
|
| 234 |
typedef struct { |
| 235 |
char path[MAX_OSPATH]; |
| 236 |
char fullpath[MAX_OSPATH]; |
| 237 |
char gamedir[MAX_OSPATH]; |
| 238 |
} directory_t; |
| 239 |
|
| 240 |
typedef struct searchpath_s { |
| 241 |
struct searchpath_s *next; |
| 242 |
|
| 243 |
pack_t *pack; |
| 244 |
directory_t *dir; |
| 245 |
} searchpath_t; |
| 246 |
|
| 247 |
static char fs_gamedir[MAX_OSPATH]; |
| 248 |
static cvar_t *fs_debug; |
| 249 |
static cvar_t *fs_homeconfigpath; |
| 250 |
static cvar_t *fs_homedatapath; |
| 251 |
static cvar_t *fs_homestatepath; |
| 252 |
|
| 253 |
static cvar_t *fs_apppath; |
| 254 |
static cvar_t *fs_steampath; |
| 255 |
static cvar_t *fs_gogpath; |
| 256 |
static cvar_t *fs_microsoftstorepath; |
| 257 |
|
| 258 |
static cvar_t *fs_basepath; |
| 259 |
static cvar_t *fs_basegame; |
| 260 |
static cvar_t *fs_gamedirvar; |
| 261 |
static searchpath_t *fs_searchpaths; |
| 262 |
static int fs_readCount; |
| 263 |
static int fs_loadCount; |
| 264 |
static int fs_loadStack; |
| 265 |
static int fs_packFiles = 0; |
| 266 |
|
| 267 |
static cvar_t *fs_pathVars[16]; |
| 268 |
|
| 269 |
static int fs_checksumFeed; |
| 270 |
|
| 271 |
typedef union qfile_gus { |
| 272 |
FILE* o; |
| 273 |
unzFile z; |
| 274 |
} qfile_gut; |
| 275 |
|
| 276 |
typedef struct qfile_us { |
| 277 |
qfile_gut file; |
| 278 |
qboolean unique; |
| 279 |
} qfile_ut; |
| 280 |
|
| 281 |
typedef struct { |
| 282 |
qfile_ut handleFiles; |
| 283 |
qboolean handleSync; |
| 284 |
int fileSize; |
| 285 |
int zipFilePos; |
| 286 |
int zipFileLen; |
| 287 |
qboolean zipFile; |
| 288 |
char name[MAX_ZPATH]; |
| 289 |
} fileHandleData_t; |
| 290 |
|
| 291 |
static fileHandleData_t fsh[MAX_FILE_HANDLES]; |
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
static qboolean fs_reordered; |
| 296 |
|
| 297 |
|
| 298 |
static int fs_numServerPaks = 0; |
| 299 |
static unsigned int fs_serverPaks[MAX_SEARCH_PATHS]; |
| 300 |
static char *fs_serverPakNames[MAX_SEARCH_PATHS]; |
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
static int fs_numServerReferencedPaks; |
| 305 |
static unsigned int fs_serverReferencedPaks[MAX_SEARCH_PATHS]; |
| 306 |
static char *fs_serverReferencedPakNames[MAX_SEARCH_PATHS]; |
| 307 |
|
| 308 |
|
| 309 |
char lastValidBase[MAX_OSPATH]; |
| 310 |
char lastValidComBaseGame[MAX_OSPATH]; |
| 311 |
char lastValidFsBaseGame[MAX_OSPATH]; |
| 312 |
char lastValidGame[MAX_OSPATH]; |
| 313 |
|
| 314 |
#ifdef FS_MISSING |
| 315 |
FILE* missingFiles = NULL; |
| 316 |
#endif |
| 317 |
|
| 318 |
|
| 319 |
#if __STDC_VERSION__ < 199901L |
| 320 |
# if __GNUC__ >= 2 || _MSC_VER >= 1300 |
| 321 |
# define __func__ __FUNCTION__ |
| 322 |
# else |
| 323 |
# define __func__ "(unknown)" |
| 324 |
# endif |
| 325 |
#endif |
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
qboolean FS_Initialized( void ) { |
| 334 |
return (fs_searchpaths != NULL); |
| 335 |
} |
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
qboolean FS_PakIsPure( pack_t *pack ) { |
| 343 |
int i; |
| 344 |
|
| 345 |
if ( fs_numServerPaks ) { |
| 346 |
for ( i = 0 ; i < fs_numServerPaks ; i++ ) { |
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
if ( pack->checksum == fs_serverPaks[i] ) { |
| 351 |
return qtrue; |
| 352 |
} |
| 353 |
} |
| 354 |
return qfalse; |
| 355 |
} |
| 356 |
return qtrue; |
| 357 |
} |
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
int FS_LoadStack( void ) |
| 367 |
{ |
| 368 |
return fs_loadStack; |
| 369 |
} |
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
static long FS_HashFileName( const char *fname, int hashSize ) { |
| 377 |
int i; |
| 378 |
long hash; |
| 379 |
char letter; |
| 380 |
|
| 381 |
hash = 0; |
| 382 |
i = 0; |
| 383 |
while (fname[i] != '\0') { |
| 384 |
letter = tolower(fname[i]); |
| 385 |
if (letter =='.') break; |
| 386 |
if (letter =='\\') letter = '/'; |
| 387 |
if (letter == PATH_SEP) letter = '/'; |
| 388 |
hash+=(long)(letter)*(i+119); |
| 389 |
i++; |
| 390 |
} |
| 391 |
hash = (hash ^ (hash >> 10) ^ (hash >> 20)); |
| 392 |
hash &= (hashSize-1); |
| 393 |
return hash; |
| 394 |
} |
| 395 |
|
| 396 |
static fileHandle_t FS_HandleForFile(void) { |
| 397 |
int i; |
| 398 |
|
| 399 |
for ( i = 1 ; i < MAX_FILE_HANDLES ; i++ ) { |
| 400 |
if ( fsh[i].handleFiles.file.o == NULL ) { |
| 401 |
return i; |
| 402 |
} |
| 403 |
} |
| 404 |
Com_Error( ERR_DROP, "FS_HandleForFile: none free" ); |
| 405 |
return 0; |
| 406 |
} |
| 407 |
|
| 408 |
static FILE *FS_FileForHandle( fileHandle_t f ) { |
| 409 |
if ( f < 1 || f >= MAX_FILE_HANDLES ) { |
| 410 |
Com_Error( ERR_DROP, "FS_FileForHandle: out of range" ); |
| 411 |
} |
| 412 |
if (fsh[f].zipFile == qtrue) { |
| 413 |
Com_Error( ERR_DROP, "FS_FileForHandle: can't get FILE on zip file" ); |
| 414 |
} |
| 415 |
if ( ! fsh[f].handleFiles.file.o ) { |
| 416 |
Com_Error( ERR_DROP, "FS_FileForHandle: NULL" ); |
| 417 |
} |
| 418 |
|
| 419 |
return fsh[f].handleFiles.file.o; |
| 420 |
} |
| 421 |
|
| 422 |
void FS_ForceFlush( fileHandle_t f ) { |
| 423 |
FILE *file; |
| 424 |
|
| 425 |
file = FS_FileForHandle(f); |
| 426 |
setvbuf( file, NULL, _IONBF, 0 ); |
| 427 |
} |
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
long FS_fplength(FILE *h) |
| 436 |
{ |
| 437 |
long pos; |
| 438 |
long end; |
| 439 |
|
| 440 |
pos = ftell(h); |
| 441 |
fseek(h, 0, SEEK_END); |
| 442 |
end = ftell(h); |
| 443 |
fseek(h, pos, SEEK_SET); |
| 444 |
|
| 445 |
return end; |
| 446 |
} |
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
long FS_filelength(fileHandle_t f) |
| 458 |
{ |
| 459 |
FILE *h; |
| 460 |
|
| 461 |
h = FS_FileForHandle(f); |
| 462 |
|
| 463 |
if(h == NULL) |
| 464 |
return -1; |
| 465 |
else |
| 466 |
return FS_fplength(h); |
| 467 |
} |
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
static void FS_ReplaceSeparators( char *path ) { |
| 477 |
char *s; |
| 478 |
qboolean lastCharWasSep = qfalse; |
| 479 |
|
| 480 |
for ( s = path ; *s ; s++ ) { |
| 481 |
if ( *s == '/' || *s == '\\' ) { |
| 482 |
if ( !lastCharWasSep ) { |
| 483 |
*s = PATH_SEP; |
| 484 |
lastCharWasSep = qtrue; |
| 485 |
} else { |
| 486 |
memmove (s, s + 1, strlen (s)); |
| 487 |
} |
| 488 |
} else { |
| 489 |
lastCharWasSep = qfalse; |
| 490 |
} |
| 491 |
} |
| 492 |
} |
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
char *FS_BuildOSPath( const char *base, const char *game, const char *qpath ) { |
| 502 |
char temp[MAX_OSPATH]; |
| 503 |
static char ospath[2][MAX_OSPATH]; |
| 504 |
static int toggle; |
| 505 |
|
| 506 |
toggle ^= 1; |
| 507 |
|
| 508 |
if( !game || !game[0] ) { |
| 509 |
game = fs_gamedir; |
| 510 |
} |
| 511 |
|
| 512 |
Com_sprintf( temp, sizeof(temp), "/%s/%s", game, qpath ); |
| 513 |
FS_ReplaceSeparators( temp ); |
| 514 |
Com_sprintf( ospath[toggle], sizeof( ospath[0] ), "%s%s", base, temp ); |
| 515 |
|
| 516 |
return ospath[toggle]; |
| 517 |
} |
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
char *FS_BaseDir_BuildOSPath( const char *base, const char *qpath ) { |
| 527 |
char *ospath = FS_BuildOSPath(base, qpath, ""); |
| 528 |
ospath[strlen(ospath) - 1] = '\0'; |
| 529 |
|
| 530 |
return ospath; |
| 531 |
} |
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
qboolean FS_CreatePath (const char *OSPath) { |
| 542 |
char *ofs; |
| 543 |
char path[MAX_OSPATH]; |
| 544 |
|
| 545 |
if (!OSPath || !*OSPath) { |
| 546 |
return qfalse; |
| 547 |
} |
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
if ( strstr( OSPath, ".." ) || strstr( OSPath, "::" ) ) { |
| 552 |
Com_Printf( "WARNING: refusing to create relative path \"%s\"\n", OSPath ); |
| 553 |
return qtrue; |
| 554 |
} |
| 555 |
|
| 556 |
Q_strncpyz( path, OSPath, sizeof( path ) ); |
| 557 |
FS_ReplaceSeparators( path ); |
| 558 |
|
| 559 |
|
| 560 |
ofs = strchr( path, PATH_SEP ); |
| 561 |
if ( ofs != NULL ) { |
| 562 |
ofs++; |
| 563 |
} |
| 564 |
|
| 565 |
for (; ofs != NULL && *ofs ; ofs++) { |
| 566 |
if (*ofs == PATH_SEP) { |
| 567 |
|
| 568 |
*ofs = 0; |
| 569 |
if (!Sys_Mkdir (path)) { |
| 570 |
Com_Error( ERR_FATAL, "FS_CreatePath: failed to create path \"%s\"", |
| 571 |
path ); |
| 572 |
} |
| 573 |
*ofs = PATH_SEP; |
| 574 |
} |
| 575 |
} |
| 576 |
|
| 577 |
return qfalse; |
| 578 |
} |
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
static void FS_CheckFilenameIsMutable( const char *filename, |
| 588 |
const char *function ) |
| 589 |
{ |
| 590 |
|
| 591 |
if( Sys_DllExtension( filename ) |
| 592 |
|| COM_CompareExtension( filename, ".qvm" ) |
| 593 |
|| COM_CompareExtension( filename, ".pk3" ) ) |
| 594 |
{ |
| 595 |
Com_Error( ERR_FATAL, "%s: Not allowed to manipulate '%s' due " |
| 596 |
"to %s extension", function, filename, COM_GetExtension( filename ) ); |
| 597 |
} |
| 598 |
} |
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
void FS_Remove( const char *osPath ) { |
| 607 |
FS_CheckFilenameIsMutable( osPath, __func__ ); |
| 608 |
|
| 609 |
remove( osPath ); |
| 610 |
} |
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
void FS_Remove_HomeData( const char *homePath ) { |
| 619 |
FS_CheckFilenameIsMutable( homePath, __func__ ); |
| 620 |
|
| 621 |
remove( FS_BuildOSPath( fs_homedatapath->string, |
| 622 |
fs_gamedir, homePath ) ); |
| 623 |
} |
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
qboolean FS_FileInPathExists(const char *testpath) |
| 633 |
{ |
| 634 |
FILE *filep; |
| 635 |
|
| 636 |
filep = Sys_FOpen(testpath, "rb"); |
| 637 |
|
| 638 |
if(filep) |
| 639 |
{ |
| 640 |
fclose(filep); |
| 641 |
return qtrue; |
| 642 |
} |
| 643 |
|
| 644 |
return qfalse; |
| 645 |
} |
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
qboolean FS_FileExists_HomeData(const char *file) |
| 658 |
{ |
| 659 |
return FS_FileInPathExists(FS_BuildOSPath(fs_homedatapath->string, fs_gamedir, file)); |
| 660 |
} |
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
static qboolean FS_BaseDir_FileExists_HomeData( const char *file ) |
| 670 |
{ |
| 671 |
return FS_FileInPathExists(FS_BaseDir_BuildOSPath(fs_homedatapath->string, file)); |
| 672 |
} |
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
static fileHandle_t FS_OSPath_FOpenFileWrite( const char *ospath, const char *filename ) { |
| 681 |
fileHandle_t f; |
| 682 |
|
| 683 |
if ( !fs_searchpaths ) { |
| 684 |
Com_Error( ERR_FATAL, "Filesystem call made without initialization" ); |
| 685 |
} |
| 686 |
|
| 687 |
f = FS_HandleForFile(); |
| 688 |
fsh[f].zipFile = qfalse; |
| 689 |
|
| 690 |
if ( fs_debug->integer ) { |
| 691 |
Com_Printf( "FS_OSPath_FOpenFileWrite: %s\n", ospath ); |
| 692 |
} |
| 693 |
|
| 694 |
FS_CheckFilenameIsMutable( ospath, __func__ ); |
| 695 |
|
| 696 |
if( FS_CreatePath( ospath ) ) { |
| 697 |
return 0; |
| 698 |
} |
| 699 |
|
| 700 |
fsh[f].handleFiles.file.o = Sys_FOpen( ospath, "wb" ); |
| 701 |
|
| 702 |
Q_strncpyz( fsh[f].name, filename, sizeof( fsh[f].name ) ); |
| 703 |
|
| 704 |
fsh[f].handleSync = qfalse; |
| 705 |
if (!fsh[f].handleFiles.file.o) { |
| 706 |
f = 0; |
| 707 |
} |
| 708 |
return f; |
| 709 |
} |
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
fileHandle_t FS_BaseDir_FOpenFileWrite_HomeConfig( const char *filename ) { |
| 717 |
return FS_OSPath_FOpenFileWrite( |
| 718 |
FS_BaseDir_BuildOSPath(fs_homeconfigpath->string, filename), filename); |
| 719 |
} |
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
fileHandle_t FS_BaseDir_FOpenFileWrite_HomeData( const char *filename ) { |
| 727 |
return FS_OSPath_FOpenFileWrite( |
| 728 |
FS_BaseDir_BuildOSPath(fs_homedatapath->string, filename), filename); |
| 729 |
} |
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
fileHandle_t FS_BaseDir_FOpenFileWrite_HomeState( const char *filename ) { |
| 737 |
return FS_OSPath_FOpenFileWrite( |
| 738 |
FS_BaseDir_BuildOSPath(fs_homestatepath->string, filename), filename); |
| 739 |
} |
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
long FS_BaseDir_FOpenFileRead(const char *filename, fileHandle_t *fp) |
| 750 |
{ |
| 751 |
char *ospath; |
| 752 |
fileHandle_t f = 0; |
| 753 |
|
| 754 |
if ( !fs_searchpaths ) { |
| 755 |
Com_Error( ERR_FATAL, "Filesystem call made without initialization" ); |
| 756 |
} |
| 757 |
|
| 758 |
f = FS_HandleForFile(); |
| 759 |
fsh[f].zipFile = qfalse; |
| 760 |
|
| 761 |
Q_strncpyz( fsh[f].name, filename, sizeof( fsh[f].name ) ); |
| 762 |
|
| 763 |
|
| 764 |
S_ClearSoundBuffer(); |
| 765 |
|
| 766 |
for(int i = 0; i < ARRAY_LEN( fs_pathVars ) && !fsh[f].handleFiles.file.o; i++) { |
| 767 |
const cvar_t *pathVar = fs_pathVars[i]; |
| 768 |
|
| 769 |
if (!pathVar || !pathVar->string[0]) { |
| 770 |
continue; |
| 771 |
} |
| 772 |
|
| 773 |
ospath = FS_BaseDir_BuildOSPath( pathVar->string, filename ); |
| 774 |
|
| 775 |
if ( fs_debug->integer ) |
| 776 |
{ |
| 777 |
Com_Printf( "FS_BaseDir_FOpenFileRead (%s): %s\n", pathVar->name, ospath ); |
| 778 |
} |
| 779 |
|
| 780 |
fsh[f].handleFiles.file.o = Sys_FOpen( ospath, "rb" ); |
| 781 |
fsh[f].handleSync = qfalse; |
| 782 |
} |
| 783 |
|
| 784 |
if (!fsh[f].handleFiles.file.o) |
| 785 |
{ |
| 786 |
f = 0; |
| 787 |
} |
| 788 |
|
| 789 |
*fp = f; |
| 790 |
if (f) { |
| 791 |
return FS_filelength(f); |
| 792 |
} |
| 793 |
|
| 794 |
return -1; |
| 795 |
} |
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
void FS_BaseDir_Rename_HomeData( const char *from, const char *to, qboolean safe ) { |
| 805 |
char *from_ospath, *to_ospath; |
| 806 |
|
| 807 |
if ( !fs_searchpaths ) { |
| 808 |
Com_Error( ERR_FATAL, "Filesystem call made without initialization" ); |
| 809 |
} |
| 810 |
|
| 811 |
|
| 812 |
S_ClearSoundBuffer(); |
| 813 |
|
| 814 |
from_ospath = FS_BaseDir_BuildOSPath( fs_homedatapath->string, from ); |
| 815 |
to_ospath = FS_BaseDir_BuildOSPath( fs_homedatapath->string, to ); |
| 816 |
|
| 817 |
if ( fs_debug->integer ) { |
| 818 |
Com_Printf( "FS_BaseDir_Rename_HomeData: %s --> %s\n", from_ospath, to_ospath ); |
| 819 |
} |
| 820 |
|
| 821 |
if ( safe ) { |
| 822 |
FS_CheckFilenameIsMutable( to_ospath, __func__ ); |
| 823 |
} |
| 824 |
|
| 825 |
rename(from_ospath, to_ospath); |
| 826 |
} |
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
void FS_FCloseFile( fileHandle_t f ) { |
| 839 |
if ( !fs_searchpaths ) { |
| 840 |
Com_Error( ERR_FATAL, "Filesystem call made without initialization" ); |
| 841 |
} |
| 842 |
|
| 843 |
if (fsh[f].zipFile == qtrue) { |
| 844 |
unzCloseCurrentFile( fsh[f].handleFiles.file.z ); |
| 845 |
if ( fsh[f].handleFiles.unique ) { |
| 846 |
unzClose( fsh[f].handleFiles.file.z ); |
| 847 |
} |
| 848 |
Com_Memset( &fsh[f], 0, sizeof( fsh[f] ) ); |
| 849 |
return; |
| 850 |
} |
| 851 |
|
| 852 |
|
| 853 |
if (fsh[f].handleFiles.file.o) { |
| 854 |
fclose (fsh[f].handleFiles.file.o); |
| 855 |
} |
| 856 |
Com_Memset( &fsh[f], 0, sizeof( fsh[f] ) ); |
| 857 |
} |
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
fileHandle_t FS_FOpenFileWrite_HomeConfig( const char *filename ) { |
| 865 |
return FS_OSPath_FOpenFileWrite( |
| 866 |
FS_BuildOSPath(fs_homeconfigpath->string, fs_gamedir, filename), filename); |
| 867 |
} |
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
fileHandle_t FS_FOpenFileWrite_HomeData( const char *filename ) { |
| 875 |
return FS_OSPath_FOpenFileWrite( |
| 876 |
FS_BuildOSPath(fs_homedatapath->string, fs_gamedir, filename), filename); |
| 877 |
} |
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
fileHandle_t FS_FOpenFileWrite_HomeState( const char *filename ) { |
| 885 |
return FS_OSPath_FOpenFileWrite( |
| 886 |
FS_BuildOSPath(fs_homestatepath->string, fs_gamedir, filename), filename); |
| 887 |
} |
| 888 |
|
| 889 |
|
| 890 |
|
| 891 |
|
| 892 |
|
| 893 |
|
| 894 |
|
| 895 |
fileHandle_t FS_FOpenFileAppend_HomeData( const char *filename ) { |
| 896 |
char *ospath; |
| 897 |
fileHandle_t f; |
| 898 |
|
| 899 |
if ( !fs_searchpaths ) { |
| 900 |
Com_Error( ERR_FATAL, "Filesystem call made without initialization" ); |
| 901 |
} |
| 902 |
|
| 903 |
f = FS_HandleForFile(); |
| 904 |
fsh[f].zipFile = qfalse; |
| 905 |
|
| 906 |
Q_strncpyz( fsh[f].name, filename, sizeof( fsh[f].name ) ); |
| 907 |
|
| 908 |
|
| 909 |
S_ClearSoundBuffer(); |
| 910 |
|
| 911 |
ospath = FS_BuildOSPath( fs_homedatapath->string, fs_gamedir, filename ); |
| 912 |
|
| 913 |
if ( fs_debug->integer ) { |
| 914 |
Com_Printf( "FS_FOpenFileAppend_HomeData: %s\n", ospath ); |
| 915 |
} |
| 916 |
|
| 917 |
FS_CheckFilenameIsMutable( ospath, __func__ ); |
| 918 |
|
| 919 |
if( FS_CreatePath( ospath ) ) { |
| 920 |
return 0; |
| 921 |
} |
| 922 |
|
| 923 |
fsh[f].handleFiles.file.o = Sys_FOpen( ospath, "ab" ); |
| 924 |
fsh[f].handleSync = qfalse; |
| 925 |
if (!fsh[f].handleFiles.file.o) { |
| 926 |
f = 0; |
| 927 |
} |
| 928 |
return f; |
| 929 |
} |
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
fileHandle_t FS_FCreateOpenPipeFile( const char *filename ) { |
| 938 |
char *ospath; |
| 939 |
FILE *fifo; |
| 940 |
fileHandle_t f; |
| 941 |
|
| 942 |
if ( !fs_searchpaths ) { |
| 943 |
Com_Error( ERR_FATAL, "Filesystem call made without initialization" ); |
| 944 |
} |
| 945 |
|
| 946 |
f = FS_HandleForFile(); |
| 947 |
fsh[f].zipFile = qfalse; |
| 948 |
|
| 949 |
Q_strncpyz( fsh[f].name, filename, sizeof( fsh[f].name ) ); |
| 950 |
|
| 951 |
|
| 952 |
S_ClearSoundBuffer(); |
| 953 |
|
| 954 |
ospath = FS_BuildOSPath( fs_homedatapath->string, fs_gamedir, filename ); |
| 955 |
|
| 956 |
if ( fs_debug->integer ) { |
| 957 |
Com_Printf( "FS_FCreateOpenPipeFile: %s\n", ospath ); |
| 958 |
} |
| 959 |
|
| 960 |
FS_CheckFilenameIsMutable( ospath, __func__ ); |
| 961 |
|
| 962 |
fifo = Sys_Mkfifo( ospath ); |
| 963 |
if( fifo ) { |
| 964 |
fsh[f].handleFiles.file.o = fifo; |
| 965 |
fsh[f].handleSync = qfalse; |
| 966 |
} |
| 967 |
else |
| 968 |
{ |
| 969 |
Com_Printf( S_COLOR_YELLOW "WARNING: Could not create new com_pipefile at %s. " |
| 970 |
"com_pipefile will not be used.\n", ospath ); |
| 971 |
f = 0; |
| 972 |
} |
| 973 |
|
| 974 |
return f; |
| 975 |
} |
| 976 |
|
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
|
| 984 |
qboolean FS_FilenameCompare( const char *s1, const char *s2 ) { |
| 985 |
int c1, c2; |
| 986 |
|
| 987 |
do { |
| 988 |
c1 = *s1++; |
| 989 |
c2 = *s2++; |
| 990 |
|
| 991 |
if (c1 >= 'a' && c1 <= 'z') { |
| 992 |
c1 -= ('a' - 'A'); |
| 993 |
} |
| 994 |
if (c2 >= 'a' && c2 <= 'z') { |
| 995 |
c2 -= ('a' - 'A'); |
| 996 |
} |
| 997 |
|
| 998 |
if ( c1 == '\\' || c1 == ':' ) { |
| 999 |
c1 = '/'; |
| 1000 |
} |
| 1001 |
if ( c2 == '\\' || c2 == ':' ) { |
| 1002 |
c2 = '/'; |
| 1003 |
} |
| 1004 |
|
| 1005 |
if (c1 != c2) { |
| 1006 |
return qtrue; |
| 1007 |
} |
| 1008 |
} while (c1); |
| 1009 |
|
| 1010 |
return qfalse; |
| 1011 |
} |
| 1012 |
|
| 1013 |
|
| 1014 |
|
| 1015 |
|
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
qboolean FS_IsExt(const char *filename, const char *ext, int namelen) |
| 1022 |
{ |
| 1023 |
int extlen; |
| 1024 |
|
| 1025 |
extlen = strlen(ext); |
| 1026 |
|
| 1027 |
if(extlen > namelen) |
| 1028 |
return qfalse; |
| 1029 |
|
| 1030 |
filename += namelen - extlen; |
| 1031 |
|
| 1032 |
return !Q_stricmp(filename, ext); |
| 1033 |
} |
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
|
| 1039 |
|
| 1040 |
|
| 1041 |
|
| 1042 |
|
| 1043 |
qboolean FS_IsDemoExt(const char *filename, int namelen) |
| 1044 |
{ |
| 1045 |
char *ext_test; |
| 1046 |
int index, protocol; |
| 1047 |
|
| 1048 |
ext_test = strrchr(filename, '.'); |
| 1049 |
if(ext_test && !Q_stricmpn(ext_test + 1, DEMOEXT, ARRAY_LEN(DEMOEXT) - 1)) |
| 1050 |
{ |
| 1051 |
protocol = atoi(ext_test + ARRAY_LEN(DEMOEXT)); |
| 1052 |
|
| 1053 |
if(protocol == com_protocol->integer) |
| 1054 |
return qtrue; |
| 1055 |
|
| 1056 |
#ifdef LEGACY_PROTOCOL |
| 1057 |
if(protocol == com_legacyprotocol->integer) |
| 1058 |
return qtrue; |
| 1059 |
#endif |
| 1060 |
|
| 1061 |
for(index = 0; demo_protocols[index]; index++) |
| 1062 |
{ |
| 1063 |
if(demo_protocols[index] == protocol) |
| 1064 |
return qtrue; |
| 1065 |
} |
| 1066 |
} |
| 1067 |
|
| 1068 |
return qfalse; |
| 1069 |
} |
| 1070 |
|
| 1071 |
|
| 1072 |
|
| 1073 |
|
| 1074 |
|
| 1075 |
|
| 1076 |
|
| 1077 |
|
| 1078 |
|
| 1079 |
extern qboolean com_fullyInitialized; |
| 1080 |
|
| 1081 |
long FS_FOpenFileReadDir(const char *filename, searchpath_t *search, fileHandle_t *file, qboolean uniqueFILE, qboolean unpure) |
| 1082 |
{ |
| 1083 |
long hash; |
| 1084 |
pack_t *pak; |
| 1085 |
fileInPack_t *pakFile; |
| 1086 |
directory_t *dir; |
| 1087 |
char *netpath; |
| 1088 |
FILE *filep; |
| 1089 |
int len; |
| 1090 |
|
| 1091 |
if(filename == NULL) |
| 1092 |
Com_Error(ERR_FATAL, "FS_FOpenFileRead: NULL 'filename' parameter passed"); |
| 1093 |
|
| 1094 |
|
| 1095 |
if(filename[0] == '/' || filename[0] == '\\') |
| 1096 |
filename++; |
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
|
| 1101 |
if(strstr(filename, ".." ) || strstr(filename, "::")) |
| 1102 |
{ |
| 1103 |
if(file == NULL) |
| 1104 |
return qfalse; |
| 1105 |
|
| 1106 |
*file = 0; |
| 1107 |
return -1; |
| 1108 |
} |
| 1109 |
|
| 1110 |
|
| 1111 |
|
| 1112 |
if(com_fullyInitialized && strstr(filename, "q3key")) |
| 1113 |
{ |
| 1114 |
if(file == NULL) |
| 1115 |
return qfalse; |
| 1116 |
|
| 1117 |
*file = 0; |
| 1118 |
return -1; |
| 1119 |
} |
| 1120 |
|
| 1121 |
if(file == NULL) |
| 1122 |
{ |
| 1123 |
|
| 1124 |
|
| 1125 |
|
| 1126 |
if(search->pack) |
| 1127 |
{ |
| 1128 |
hash = FS_HashFileName(filename, search->pack->hashSize); |
| 1129 |
|
| 1130 |
if(search->pack->hashTable[hash]) |
| 1131 |
{ |
| 1132 |
|
| 1133 |
pak = search->pack; |
| 1134 |
pakFile = pak->hashTable[hash]; |
| 1135 |
|
| 1136 |
do |
| 1137 |
{ |
| 1138 |
|
| 1139 |
if(!FS_FilenameCompare(pakFile->name, filename)) |
| 1140 |
{ |
| 1141 |
|
| 1142 |
if(pakFile->len) |
| 1143 |
return pakFile->len; |
| 1144 |
else |
| 1145 |
{ |
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
return 1; |
| 1150 |
} |
| 1151 |
} |
| 1152 |
|
| 1153 |
pakFile = pakFile->next; |
| 1154 |
} while(pakFile != NULL); |
| 1155 |
} |
| 1156 |
} |
| 1157 |
else if(search->dir) |
| 1158 |
{ |
| 1159 |
dir = search->dir; |
| 1160 |
|
| 1161 |
netpath = FS_BuildOSPath(dir->path, dir->gamedir, filename); |
| 1162 |
filep = Sys_FOpen(netpath, "rb"); |
| 1163 |
|
| 1164 |
if(filep) |
| 1165 |
{ |
| 1166 |
len = FS_fplength(filep); |
| 1167 |
fclose(filep); |
| 1168 |
|
| 1169 |
if(len) |
| 1170 |
return len; |
| 1171 |
else |
| 1172 |
return 1; |
| 1173 |
} |
| 1174 |
} |
| 1175 |
|
| 1176 |
return 0; |
| 1177 |
} |
| 1178 |
|
| 1179 |
*file = FS_HandleForFile(); |
| 1180 |
fsh[*file].handleFiles.unique = uniqueFILE; |
| 1181 |
|
| 1182 |
|
| 1183 |
if(search->pack) |
| 1184 |
{ |
| 1185 |
hash = FS_HashFileName(filename, search->pack->hashSize); |
| 1186 |
|
| 1187 |
if(search->pack->hashTable[hash]) |
| 1188 |
{ |
| 1189 |
|
| 1190 |
if(!unpure && !FS_PakIsPure(search->pack)) |
| 1191 |
{ |
| 1192 |
*file = 0; |
| 1193 |
return -1; |
| 1194 |
} |
| 1195 |
|
| 1196 |
|
| 1197 |
pak = search->pack; |
| 1198 |
pakFile = pak->hashTable[hash]; |
| 1199 |
|
| 1200 |
do |
| 1201 |
{ |
| 1202 |
|
| 1203 |
if(!FS_FilenameCompare(pakFile->name, filename)) |
| 1204 |
{ |
| 1205 |
|
| 1206 |
|
| 1207 |
|
| 1208 |
|
| 1209 |
|
| 1210 |
|
| 1211 |
len = strlen(filename); |
| 1212 |
|
| 1213 |
if (!(pak->referenced & FS_GENERAL_REF)) |
| 1214 |
{ |
| 1215 |
if(!FS_IsExt(filename, ".shader", len) && |
| 1216 |
!FS_IsExt(filename, ".txt", len) && |
| 1217 |
!FS_IsExt(filename, ".cfg", len) && |
| 1218 |
!FS_IsExt(filename, ".config", len) && |
| 1219 |
!FS_IsExt(filename, ".bot", len) && |
| 1220 |
!FS_IsExt(filename, ".arena", len) && |
| 1221 |
!FS_IsExt(filename, ".menu", len) && |
| 1222 |
Q_stricmp(filename, "vm/qagame.qvm") != 0 && |
| 1223 |
!strstr(filename, "levelshots")) |
| 1224 |
{ |
| 1225 |
pak->referenced |= FS_GENERAL_REF; |
| 1226 |
} |
| 1227 |
} |
| 1228 |
|
| 1229 |
if(strstr(filename, "cgame.qvm")) |
| 1230 |
pak->referenced |= FS_CGAME_REF; |
| 1231 |
if(strstr(filename, "ui.qvm")) |
| 1232 |
pak->referenced |= FS_UI_REF; |
| 1233 |
|
| 1234 |
if(uniqueFILE) |
| 1235 |
{ |
| 1236 |
|
| 1237 |
fsh[*file].handleFiles.file.z = unzOpen(pak->pakFilename); |
| 1238 |
|
| 1239 |
if(fsh[*file].handleFiles.file.z == NULL) |
| 1240 |
Com_Error(ERR_FATAL, "Couldn't open %s", pak->pakFilename); |
| 1241 |
} |
| 1242 |
else |
| 1243 |
fsh[*file].handleFiles.file.z = pak->handle; |
| 1244 |
|
| 1245 |
Q_strncpyz(fsh[*file].name, filename, sizeof(fsh[*file].name)); |
| 1246 |
fsh[*file].zipFile = qtrue; |
| 1247 |
|
| 1248 |
|
| 1249 |
unzSetOffset(fsh[*file].handleFiles.file.z, pakFile->pos); |
| 1250 |
|
| 1251 |
|
| 1252 |
unzOpenCurrentFile(fsh[*file].handleFiles.file.z); |
| 1253 |
fsh[*file].zipFilePos = pakFile->pos; |
| 1254 |
fsh[*file].zipFileLen = pakFile->len; |
| 1255 |
|
| 1256 |
if(fs_debug->integer) |
| 1257 |
{ |
| 1258 |
Com_Printf("FS_FOpenFileRead: %s (found in '%s')\n", |
| 1259 |
filename, pak->pakFilename); |
| 1260 |
} |
| 1261 |
|
| 1262 |
return pakFile->len; |
| 1263 |
} |
| 1264 |
|
| 1265 |
pakFile = pakFile->next; |
| 1266 |
} while(pakFile != NULL); |
| 1267 |
} |
| 1268 |
} |
| 1269 |
else if(search->dir) |
| 1270 |
{ |
| 1271 |
|
| 1272 |
|
| 1273 |
|
| 1274 |
|
| 1275 |
len = strlen(filename); |
| 1276 |
|
| 1277 |
|
| 1278 |
|
| 1279 |
|
| 1280 |
|
| 1281 |
if(!unpure && fs_numServerPaks) |
| 1282 |
{ |
| 1283 |
if(!FS_IsExt(filename, ".cfg", len) && |
| 1284 |
!FS_IsExt(filename, ".menu", len) && |
| 1285 |
!FS_IsExt(filename, ".game", len) && |
| 1286 |
!FS_IsExt(filename, ".dat", len) && |
| 1287 |
!FS_IsDemoExt(filename, len)) |
| 1288 |
{ |
| 1289 |
*file = 0; |
| 1290 |
return -1; |
| 1291 |
} |
| 1292 |
} |
| 1293 |
|
| 1294 |
dir = search->dir; |
| 1295 |
|
| 1296 |
netpath = FS_BuildOSPath(dir->path, dir->gamedir, filename); |
| 1297 |
filep = Sys_FOpen(netpath, "rb"); |
| 1298 |
|
| 1299 |
if (filep == NULL) |
| 1300 |
{ |
| 1301 |
*file = 0; |
| 1302 |
return -1; |
| 1303 |
} |
| 1304 |
|
| 1305 |
Q_strncpyz(fsh[*file].name, filename, sizeof(fsh[*file].name)); |
| 1306 |
fsh[*file].zipFile = qfalse; |
| 1307 |
|
| 1308 |
if(fs_debug->integer) |
| 1309 |
{ |
| 1310 |
Com_Printf("FS_FOpenFileRead: %s (found in '%s%c%s')\n", filename, |
| 1311 |
dir->path, PATH_SEP, dir->gamedir); |
| 1312 |
} |
| 1313 |
|
| 1314 |
fsh[*file].handleFiles.file.o = filep; |
| 1315 |
return FS_fplength(filep); |
| 1316 |
} |
| 1317 |
|
| 1318 |
*file = 0; |
| 1319 |
return -1; |
| 1320 |
} |
| 1321 |
|
| 1322 |
|
| 1323 |
|
| 1324 |
|
| 1325 |
|
| 1326 |
|
| 1327 |
|
| 1328 |
|
| 1329 |
|
| 1330 |
|
| 1331 |
|
| 1332 |
long FS_FOpenFileRead(const char *filename, fileHandle_t *file, qboolean uniqueFILE) |
| 1333 |
{ |
| 1334 |
searchpath_t *search; |
| 1335 |
long len; |
| 1336 |
qboolean isLocalConfig; |
| 1337 |
|
| 1338 |
if(!fs_searchpaths) |
| 1339 |
Com_Error(ERR_FATAL, "Filesystem call made without initialization"); |
| 1340 |
|
| 1341 |
isLocalConfig = !strcmp(filename, "autoexec.cfg") || !strcmp(filename, Q3CONFIG_CFG); |
| 1342 |
for(search = fs_searchpaths; search; search = search->next) |
| 1343 |
{ |
| 1344 |
|
| 1345 |
if (isLocalConfig && search->pack) |
| 1346 |
continue; |
| 1347 |
|
| 1348 |
len = FS_FOpenFileReadDir(filename, search, file, uniqueFILE, qfalse); |
| 1349 |
|
| 1350 |
if(file == NULL) |
| 1351 |
{ |
| 1352 |
if(len > 0) |
| 1353 |
return len; |
| 1354 |
} |
| 1355 |
else |
| 1356 |
{ |
| 1357 |
if(len >= 0 && *file) |
| 1358 |
return len; |
| 1359 |
} |
| 1360 |
|
| 1361 |
} |
| 1362 |
|
| 1363 |
#ifdef FS_MISSING |
| 1364 |
if(missingFiles) |
| 1365 |
fprintf(missingFiles, "%s\n", filename); |
| 1366 |
#endif |
| 1367 |
|
| 1368 |
if(file) |
| 1369 |
{ |
| 1370 |
*file = 0; |
| 1371 |
return -1; |
| 1372 |
} |
| 1373 |
else |
| 1374 |
{ |
| 1375 |
|
| 1376 |
|
| 1377 |
return 0; |
| 1378 |
} |
| 1379 |
} |
| 1380 |
|
| 1381 |
|
| 1382 |
|
| 1383 |
|
| 1384 |
|
| 1385 |
|
| 1386 |
|
| 1387 |
|
| 1388 |
|
| 1389 |
|
| 1390 |
|
| 1391 |
|
| 1392 |
|
| 1393 |
|
| 1394 |
|
| 1395 |
|
| 1396 |
|
| 1397 |
|
| •1398 |
int FS_FindVM(void **startSearch, char *found, int foundlen, const char *name, int enableDll, int forceDll) |
| 1399 |
{ |
| 1400 |
searchpath_t *search, *lastSearch; |
| 1401 |
directory_t *dir; |
| 1402 |
pack_t *pack; |
| 1403 |
char qvmName[MAX_OSPATH]; |
| 1404 |
char *netpath; |
| 1405 |
|
| 1406 |
if(!fs_searchpaths) |
| 1407 |
Com_Error(ERR_FATAL, "Filesystem call made without initialization"); |
| 1408 |
|
| 1409 |
Com_sprintf(qvmName, sizeof(qvmName), "vm/%s.qvm", name); |
| 1410 |
|
| 1411 |
lastSearch = *startSearch; |
| 1412 |
if(*startSearch == NULL) |
| 1413 |
search = fs_searchpaths; |
| 1414 |
else |
| 1415 |
search = lastSearch->next; |
| 1416 |
|
| 1417 |
while(search) |
| 1418 |
{ |
| •1419 |
if(search->dir && (forceDll || !fs_numServerPaks)) |
| 1420 |
{ |
| 1421 |
dir = search->dir; |
| 1422 |
|
| 1423 |
if(enableDll) |
| 1424 |
{ |
| 1425 |
|
| 1426 |
|
| 1427 |
|
| 1428 |
const char *dllNameFormats[] = |
| 1429 |
{ |
| 1430 |
"%s" DLL_EXT, |
| 1431 |
"%s" ARCH_STRING DLL_EXT |
| 1432 |
}; |
| 1433 |
|
| 1434 |
for(int i = 0; i < ARRAY_LEN(dllNameFormats); i++) |
| 1435 |
{ |
| 1436 |
char dllName[MAX_OSPATH]; |
| 1437 |
Com_sprintf(dllName, sizeof(dllName), dllNameFormats[i], name); |
| 1438 |
netpath = FS_BuildOSPath(dir->path, dir->gamedir, dllName); |
| 1439 |
|
| 1440 |
if(FS_FileInPathExists(netpath)) |
| 1441 |
{ |
| 1442 |
Q_strncpyz(found, netpath, foundlen); |
| 1443 |
*startSearch = search; |
| 1444 |
|
| 1445 |
return VMI_NATIVE; |
| 1446 |
} |
| 1447 |
} |
| 1448 |
} |
| 1449 |
|
| 1450 |
if(FS_FOpenFileReadDir(qvmName, search, NULL, qfalse, qfalse) > 0) |
| 1451 |
{ |
| 1452 |
*startSearch = search; |
| 1453 |
return VMI_COMPILED; |
| 1454 |
} |
| 1455 |
} |
| •1456 |
else if(search->pack && !forceDll) |
| 1457 |
{ |
| 1458 |
pack = search->pack; |
| 1459 |
|
| 1460 |
if(lastSearch && lastSearch->pack) |
| 1461 |
{ |
| 1462 |
|
| 1463 |
|
| 1464 |
|
| 1465 |
if(!FS_FilenameCompare(lastSearch->pack->pakPathname, pack->pakPathname)) |
| 1466 |
{ |
| 1467 |
search = search->next; |
| 1468 |
continue; |
| 1469 |
} |
| 1470 |
} |
| 1471 |
|
| 1472 |
if(FS_FOpenFileReadDir(qvmName, search, NULL, qfalse, qfalse) > 0) |
| 1473 |
{ |
| 1474 |
*startSearch = search; |
| 1475 |
|
| 1476 |
return VMI_COMPILED; |
| 1477 |
} |
| 1478 |
} |
| 1479 |
|
| 1480 |
search = search->next; |
| 1481 |
} |
| 1482 |
|
| 1483 |
return -1; |
| 1484 |
} |
| 1485 |
|
| 1486 |
|
| 1487 |
|
| 1488 |
|
| 1489 |
|
| 1490 |
|
| 1491 |
|
| 1492 |
|
| 1493 |
int FS_Read( void *buffer, int len, fileHandle_t f ) { |
| 1494 |
int block, remaining; |
| 1495 |
int read; |
| 1496 |
byte *buf; |
| 1497 |
int tries; |
| 1498 |
|
| 1499 |
if ( !fs_searchpaths ) { |
| 1500 |
Com_Error( ERR_FATAL, "Filesystem call made without initialization" ); |
| 1501 |
} |
| 1502 |
|
| 1503 |
if ( !f ) { |
| 1504 |
return 0; |
| 1505 |
} |
| 1506 |
|
| 1507 |
buf = (byte *)buffer; |
| 1508 |
fs_readCount += len; |
| 1509 |
|
| 1510 |
if (fsh[f].zipFile == qfalse) { |
| 1511 |
remaining = len; |
| 1512 |
tries = 0; |
| 1513 |
while (remaining) { |
| 1514 |
block = remaining; |
| 1515 |
read = fread (buf, 1, block, fsh[f].handleFiles.file.o); |
| 1516 |
if (read == 0) { |
| 1517 |
|
| 1518 |
|
| 1519 |
if (!tries) { |
| 1520 |
tries = 1; |
| 1521 |
} else { |
| 1522 |
return len-remaining; |
| 1523 |
} |
| 1524 |
} |
| 1525 |
|
| 1526 |
if (read == -1) { |
| 1527 |
Com_Error (ERR_FATAL, "FS_Read: -1 bytes read"); |
| 1528 |
} |
| 1529 |
|
| 1530 |
remaining -= read; |
| 1531 |
buf += read; |
| 1532 |
} |
| 1533 |
return len; |
| 1534 |
} else { |
| 1535 |
return unzReadCurrentFile(fsh[f].handleFiles.file.z, buffer, len); |
| 1536 |
} |
| 1537 |
} |
| 1538 |
|
| 1539 |
|
| 1540 |
|
| 1541 |
|
| 1542 |
|
| 1543 |
|
| 1544 |
|
| 1545 |
|
| 1546 |
int FS_Write( const void *buffer, int len, fileHandle_t h ) { |
| 1547 |
int block, remaining; |
| 1548 |
int written; |
| 1549 |
byte *buf; |
| 1550 |
int tries; |
| 1551 |
FILE *f; |
| 1552 |
|
| 1553 |
if ( !fs_searchpaths ) { |
| 1554 |
Com_Error( ERR_FATAL, "Filesystem call made without initialization" ); |
| 1555 |
} |
| 1556 |
|
| 1557 |
if ( !h ) { |
| 1558 |
return 0; |
| 1559 |
} |
| 1560 |
|
| 1561 |
f = FS_FileForHandle(h); |
| 1562 |
buf = (byte *)buffer; |
| 1563 |
|
| 1564 |
remaining = len; |
| 1565 |
tries = 0; |
| 1566 |
while (remaining) { |
| 1567 |
block = remaining; |
| 1568 |
written = fwrite (buf, 1, block, f); |
| 1569 |
if (written == 0) { |
| 1570 |
if (!tries) { |
| 1571 |
tries = 1; |
| 1572 |
} else { |
| 1573 |
Com_Printf( "FS_Write: 0 bytes written\n" ); |
| 1574 |
return 0; |
| 1575 |
} |
| 1576 |
} |
| 1577 |
|
| 1578 |
if (written == -1) { |
| 1579 |
Com_Printf( "FS_Write: -1 bytes written\n" ); |
| 1580 |
return 0; |
| 1581 |
} |
| 1582 |
|
| 1583 |
remaining -= written; |
| 1584 |
buf += written; |
| 1585 |
} |
| 1586 |
if ( fsh[h].handleSync ) { |
| 1587 |
fflush( f ); |
| 1588 |
} |
| 1589 |
return len; |
| 1590 |
} |
| 1591 |
|
| 1592 |
void QDECL FS_Printf( fileHandle_t h, const char *fmt, ... ) { |
| 1593 |
va_list argptr; |
| 1594 |
char msg[MAXPRINTMSG]; |
| 1595 |
|
| 1596 |
va_start (argptr,fmt); |
| 1597 |
Q_vsnprintf (msg, sizeof(msg), fmt, argptr); |
| 1598 |
va_end (argptr); |
| 1599 |
|
| 1600 |
FS_Write(msg, strlen(msg), h); |
| 1601 |
} |
| 1602 |
|
| 1603 |
#define PK3_SEEK_BUFFER_SIZE 65536 |
| 1604 |
|
| 1605 |
|
| 1606 |
|
| 1607 |
|
| 1608 |
|
| 1609 |
|
| 1610 |
|
| 1611 |
int FS_Seek( fileHandle_t f, long offset, int origin ) { |
| 1612 |
if ( !fs_searchpaths ) { |
| 1613 |
Com_Error( ERR_FATAL, "Filesystem call made without initialization" ); |
| 1614 |
return -1; |
| 1615 |
} |
| 1616 |
|
| 1617 |
if (fsh[f].zipFile == qtrue) { |
| 1618 |
|
| 1619 |
|
| 1620 |
byte buffer[PK3_SEEK_BUFFER_SIZE]; |
| 1621 |
int remainder; |
| 1622 |
int currentPosition = FS_FTell( f ); |
| 1623 |
|
| 1624 |
|
| 1625 |
if ( offset < 0 ) { |
| 1626 |
switch( origin ) { |
| 1627 |
case FS_SEEK_END: |
| 1628 |
remainder = fsh[f].zipFileLen + offset; |
| 1629 |
break; |
| 1630 |
|
| 1631 |
case FS_SEEK_CUR: |
| 1632 |
remainder = currentPosition + offset; |
| 1633 |
break; |
| 1634 |
|
| 1635 |
case FS_SEEK_SET: |
| 1636 |
default: |
| 1637 |
remainder = 0; |
| 1638 |
break; |
| 1639 |
} |
| 1640 |
|
| 1641 |
if ( remainder < 0 ) { |
| 1642 |
remainder = 0; |
| 1643 |
} |
| 1644 |
|
| 1645 |
origin = FS_SEEK_SET; |
| 1646 |
} else { |
| 1647 |
if ( origin == FS_SEEK_END ) { |
| 1648 |
remainder = fsh[f].zipFileLen - currentPosition + offset; |
| 1649 |
} else { |
| 1650 |
remainder = offset; |
| 1651 |
} |
| 1652 |
} |
| 1653 |
|
| 1654 |
switch( origin ) { |
| 1655 |
case FS_SEEK_SET: |
| 1656 |
if ( remainder == currentPosition ) { |
| 1657 |
return offset; |
| 1658 |
} |
| 1659 |
unzSetOffset(fsh[f].handleFiles.file.z, fsh[f].zipFilePos); |
| 1660 |
unzOpenCurrentFile(fsh[f].handleFiles.file.z); |
| 1661 |
|
| 1662 |
|
| 1663 |
case FS_SEEK_END: |
| 1664 |
case FS_SEEK_CUR: |
| 1665 |
while( remainder > PK3_SEEK_BUFFER_SIZE ) { |
| 1666 |
FS_Read( buffer, PK3_SEEK_BUFFER_SIZE, f ); |
| 1667 |
remainder -= PK3_SEEK_BUFFER_SIZE; |
| 1668 |
} |
| 1669 |
FS_Read( buffer, remainder, f ); |
| 1670 |
return offset; |
| 1671 |
|
| 1672 |
default: |
| 1673 |
Com_Error( ERR_FATAL, "Bad origin in FS_Seek" ); |
| 1674 |
return -1; |
| 1675 |
} |
| 1676 |
} else { |
| 1677 |
FILE *file; |
| 1678 |
file = FS_FileForHandle(f); |
| 1679 |
int _origin = SEEK_SET; |
| 1680 |
switch( origin ) { |
| 1681 |
case FS_SEEK_CUR: |
| 1682 |
_origin = SEEK_CUR; |
| 1683 |
break; |
| 1684 |
case FS_SEEK_END: |
| 1685 |
_origin = SEEK_END; |
| 1686 |
break; |
| 1687 |
case FS_SEEK_SET: |
| 1688 |
_origin = SEEK_SET; |
| 1689 |
break; |
| 1690 |
default: |
| 1691 |
Com_Error( ERR_FATAL, "Bad origin in FS_Seek" ); |
| 1692 |
break; |
| 1693 |
} |
| 1694 |
|
| 1695 |
return fseek( file, offset, _origin ); |
| 1696 |
} |
| 1697 |
} |
| 1698 |
|
| 1699 |
|
| 1700 |
|
| 1701 |
|
| 1702 |
|
| 1703 |
|
| 1704 |
|
| 1705 |
|
| 1706 |
|
| 1707 |
|
| 1708 |
int FS_FileIsInPAK(const char *filename, int *pChecksum ) { |
| 1709 |
searchpath_t *search; |
| 1710 |
pack_t *pak; |
| 1711 |
fileInPack_t *pakFile; |
| 1712 |
long hash = 0; |
| 1713 |
|
| 1714 |
if ( !fs_searchpaths ) { |
| 1715 |
Com_Error( ERR_FATAL, "Filesystem call made without initialization" ); |
| 1716 |
} |
| 1717 |
|
| 1718 |
if ( !filename ) { |
| 1719 |
Com_Error( ERR_FATAL, "FS_FOpenFileRead: NULL 'filename' parameter passed" ); |
| 1720 |
} |
| 1721 |
|
| 1722 |
|
| 1723 |
if ( filename[0] == '/' || filename[0] == '\\' ) { |
| 1724 |
filename++; |
| 1725 |
} |
| 1726 |
|
| 1727 |
|
| 1728 |
|
| 1729 |
|
| 1730 |
if ( strstr( filename, ".." ) || strstr( filename, "::" ) ) { |
| 1731 |
return -1; |
| 1732 |
} |
| 1733 |
|
| 1734 |
|
| 1735 |
|
| 1736 |
|
| 1737 |
|
| 1738 |
for ( search = fs_searchpaths ; search ; search = search->next ) { |
| 1739 |
|
| 1740 |
if (search->pack) { |
| 1741 |
hash = FS_HashFileName(filename, search->pack->hashSize); |
| 1742 |
} |
| 1743 |
|
| 1744 |
if ( search->pack && search->pack->hashTable[hash] ) { |
| 1745 |
|
| 1746 |
if ( !FS_PakIsPure(search->pack) ) { |
| 1747 |
continue; |
| 1748 |
} |
| 1749 |
|
| 1750 |
|
| 1751 |
pak = search->pack; |
| 1752 |
pakFile = pak->hashTable[hash]; |
| 1753 |
do { |
| 1754 |
|
| 1755 |
if ( !FS_FilenameCompare( pakFile->name, filename ) ) { |
| 1756 |
if (pChecksum) { |
| 1757 |
*pChecksum = pak->pure_checksum; |
| 1758 |
} |
| 1759 |
return 1; |
| 1760 |
} |
| 1761 |
pakFile = pakFile->next; |
| 1762 |
} while(pakFile != NULL); |
| 1763 |
} |
| 1764 |
} |
| 1765 |
return -1; |
| 1766 |
} |
| 1767 |
|
| 1768 |
|
| 1769 |
|
| 1770 |
|
| 1771 |
|
| 1772 |
|
| 1773 |
|
| 1774 |
|
| 1775 |
|
| 1776 |
|
| 1777 |
long FS_ReadFileDir(const char *qpath, void *searchPath, qboolean unpure, void **buffer) |
| 1778 |
{ |
| 1779 |
fileHandle_t h; |
| 1780 |
searchpath_t *search; |
| 1781 |
byte* buf; |
| 1782 |
qboolean isConfig; |
| 1783 |
long len; |
| 1784 |
|
| 1785 |
if ( !fs_searchpaths ) { |
| 1786 |
Com_Error( ERR_FATAL, "Filesystem call made without initialization" ); |
| 1787 |
} |
| 1788 |
|
| 1789 |
if ( !qpath || !qpath[0] ) { |
| 1790 |
Com_Error( ERR_FATAL, "FS_ReadFile with empty name" ); |
| 1791 |
} |
| 1792 |
|
| 1793 |
buf = NULL; |
| 1794 |
|
| 1795 |
|
| 1796 |
|
| 1797 |
if ( strstr( qpath, ".cfg" ) ) { |
| 1798 |
isConfig = qtrue; |
| 1799 |
if ( com_journal && com_journal->integer == 2 ) { |
| 1800 |
int r; |
| 1801 |
|
| 1802 |
Com_DPrintf( "Loading %s from journal file.\n", qpath ); |
| 1803 |
r = FS_Read( &len, sizeof( len ), com_journalDataFile ); |
| 1804 |
if ( r != sizeof( len ) ) { |
| 1805 |
if (buffer != NULL) *buffer = NULL; |
| 1806 |
return -1; |
| 1807 |
} |
| 1808 |
|
| 1809 |
if (!len) { |
| 1810 |
if (buffer == NULL) { |
| 1811 |
return 1; |
| 1812 |
} |
| 1813 |
*buffer = NULL; |
| 1814 |
return -1; |
| 1815 |
} |
| 1816 |
if (buffer == NULL) { |
| 1817 |
return len; |
| 1818 |
} |
| 1819 |
|
| 1820 |
buf = Hunk_AllocateTempMemory(len+1); |
| 1821 |
*buffer = buf; |
| 1822 |
|
| 1823 |
r = FS_Read( buf, len, com_journalDataFile ); |
| 1824 |
if ( r != len ) { |
| 1825 |
Com_Error( ERR_FATAL, "Read from journalDataFile failed" ); |
| 1826 |
} |
| 1827 |
|
| 1828 |
fs_loadCount++; |
| 1829 |
fs_loadStack++; |
| 1830 |
|
| 1831 |
|
| 1832 |
buf[len] = 0; |
| 1833 |
|
| 1834 |
return len; |
| 1835 |
} |
| 1836 |
} else { |
| 1837 |
isConfig = qfalse; |
| 1838 |
} |
| 1839 |
|
| 1840 |
search = searchPath; |
| 1841 |
|
| 1842 |
if(search == NULL) |
| 1843 |
{ |
| 1844 |
|
| 1845 |
len = FS_FOpenFileRead(qpath, &h, qfalse); |
| 1846 |
} |
| 1847 |
else |
| 1848 |
{ |
| 1849 |
|
| 1850 |
len = FS_FOpenFileReadDir(qpath, search, &h, qfalse, unpure); |
| 1851 |
} |
| 1852 |
|
| 1853 |
if ( h == 0 ) { |
| 1854 |
if ( buffer ) { |
| 1855 |
*buffer = NULL; |
| 1856 |
} |
| 1857 |
|
| 1858 |
if ( isConfig && com_journal && com_journal->integer == 1 ) { |
| 1859 |
Com_DPrintf( "Writing zero for %s to journal file.\n", qpath ); |
| 1860 |
len = 0; |
| 1861 |
FS_Write( &len, sizeof( len ), com_journalDataFile ); |
| 1862 |
FS_Flush( com_journalDataFile ); |
| 1863 |
} |
| 1864 |
return -1; |
| 1865 |
} |
| 1866 |
|
| 1867 |
if ( !buffer ) { |
| 1868 |
if ( isConfig && com_journal && com_journal->integer == 1 ) { |
| 1869 |
Com_DPrintf( "Writing len for %s to journal file.\n", qpath ); |
| 1870 |
FS_Write( &len, sizeof( len ), com_journalDataFile ); |
| 1871 |
FS_Flush( com_journalDataFile ); |
| 1872 |
} |
| 1873 |
FS_FCloseFile( h); |
| 1874 |
return len; |
| 1875 |
} |
| 1876 |
|
| 1877 |
fs_loadCount++; |
| 1878 |
fs_loadStack++; |
| 1879 |
|
| 1880 |
buf = Hunk_AllocateTempMemory(len+1); |
| 1881 |
*buffer = buf; |
| 1882 |
|
| 1883 |
FS_Read (buf, len, h); |
| 1884 |
|
| 1885 |
|
| 1886 |
buf[len] = 0; |
| 1887 |
FS_FCloseFile( h ); |
| 1888 |
|
| 1889 |
|
| 1890 |
if ( isConfig && com_journal && com_journal->integer == 1 ) { |
| 1891 |
Com_DPrintf( "Writing %s to journal file.\n", qpath ); |
| 1892 |
FS_Write( &len, sizeof( len ), com_journalDataFile ); |
| 1893 |
FS_Write( buf, len, com_journalDataFile ); |
| 1894 |
FS_Flush( com_journalDataFile ); |
| 1895 |
} |
| 1896 |
return len; |
| 1897 |
} |
| 1898 |
|
| 1899 |
|
| 1900 |
|
| 1901 |
|
| 1902 |
|
| 1903 |
|
| 1904 |
|
| 1905 |
|
| 1906 |
|
| 1907 |
long FS_ReadFile(const char *qpath, void **buffer) |
| 1908 |
{ |
| 1909 |
return FS_ReadFileDir(qpath, NULL, qfalse, buffer); |
| 1910 |
} |
| 1911 |
|
| 1912 |
|
| 1913 |
|
| 1914 |
|
| 1915 |
|
| 1916 |
|
| 1917 |
void FS_FreeFile( void *buffer ) { |
| 1918 |
if ( !fs_searchpaths ) { |
| 1919 |
Com_Error( ERR_FATAL, "Filesystem call made without initialization" ); |
| 1920 |
} |
| 1921 |
if ( !buffer ) { |
| 1922 |
Com_Error( ERR_FATAL, "FS_FreeFile( NULL )" ); |
| 1923 |
} |
| 1924 |
fs_loadStack--; |
| 1925 |
|
| 1926 |
Hunk_FreeTempMemory( buffer ); |
| 1927 |
|
| 1928 |
|
| 1929 |
if ( fs_loadStack == 0 ) { |
| 1930 |
Hunk_ClearTempMemory(); |
| 1931 |
} |
| 1932 |
} |
| 1933 |
|
| 1934 |
|
| 1935 |
|
| 1936 |
|
| 1937 |
|
| 1938 |
|
| 1939 |
|
| 1940 |
|
| 1941 |
void FS_WriteFile( const char *qpath, const void *buffer, int size ) { |
| 1942 |
fileHandle_t f; |
| 1943 |
|
| 1944 |
if ( !fs_searchpaths ) { |
| 1945 |
Com_Error( ERR_FATAL, "Filesystem call made without initialization" ); |
| 1946 |
} |
| 1947 |
|
| 1948 |
if ( !qpath || !buffer ) { |
| 1949 |
Com_Error( ERR_FATAL, "FS_WriteFile: NULL parameter" ); |
| 1950 |
} |
| 1951 |
|
| 1952 |
f = FS_FOpenFileWrite_HomeData( qpath ); |
| 1953 |
if ( !f ) { |
| 1954 |
Com_Printf( "Failed to open %s\n", qpath ); |
| 1955 |
return; |
| 1956 |
} |
| 1957 |
|
| 1958 |
FS_Write( buffer, size, f ); |
| 1959 |
|
| 1960 |
FS_FCloseFile( f ); |
| 1961 |
} |
| 1962 |
|
| 1963 |
|
| 1964 |
|
| 1965 |
|
| 1966 |
|
| 1967 |
|
| 1968 |
|
| 1969 |
|
| 1970 |
|
| 1971 |
|
| 1972 |
|
| 1973 |
|
| 1974 |
|
| 1975 |
|
| 1976 |
|
| 1977 |
|
| 1978 |
|
| 1979 |
|
| 1980 |
|
| 1981 |
static pack_t *FS_LoadZipFile(const char *zipfile, const char *basename) |
| 1982 |
{ |
| 1983 |
fileInPack_t *buildBuffer; |
| 1984 |
pack_t *pack; |
| 1985 |
unzFile uf; |
| 1986 |
int err; |
| 1987 |
unz_global_info gi; |
| 1988 |
char filename_inzip[MAX_ZPATH]; |
| 1989 |
unz_file_info file_info; |
| 1990 |
int i, len; |
| 1991 |
long hash; |
| 1992 |
int fs_numHeaderLongs; |
| 1993 |
int *fs_headerLongs; |
| 1994 |
char *namePtr; |
| 1995 |
|
| 1996 |
fs_numHeaderLongs = 0; |
| 1997 |
|
| 1998 |
uf = unzOpen(zipfile); |
| 1999 |
err = unzGetGlobalInfo (uf,&gi); |
| 2000 |
|
| 2001 |
if (err != UNZ_OK) |
| 2002 |
return NULL; |
| 2003 |
|
| 2004 |
len = 0; |
| 2005 |
unzGoToFirstFile(uf); |
| 2006 |
for (i = 0; i < gi.number_entry; i++) |
| 2007 |
{ |
| 2008 |
err = unzGetCurrentFileInfo(uf, &file_info, filename_inzip, sizeof(filename_inzip), NULL, 0, NULL, 0); |
| 2009 |
if (err != UNZ_OK) { |
| 2010 |
break; |
| 2011 |
} |
| 2012 |
len += strlen(filename_inzip) + 1; |
| 2013 |
unzGoToNextFile(uf); |
| 2014 |
} |
| 2015 |
|
| 2016 |
buildBuffer = Z_Malloc( (gi.number_entry * sizeof( fileInPack_t )) + len ); |
| 2017 |
namePtr = ((char *) buildBuffer) + gi.number_entry * sizeof( fileInPack_t ); |
| 2018 |
fs_headerLongs = Z_Malloc( ( gi.number_entry + 1 ) * sizeof(int) ); |
| 2019 |
fs_headerLongs[ fs_numHeaderLongs++ ] = LittleLong( fs_checksumFeed ); |
| 2020 |
|
| 2021 |
|
| 2022 |
|
| 2023 |
for (i = 1; i <= MAX_FILEHASH_SIZE; i <<= 1) { |
| 2024 |
if (i > gi.number_entry) { |
| 2025 |
break; |
| 2026 |
} |
| 2027 |
} |
| 2028 |
|
| 2029 |
pack = Z_Malloc( sizeof( pack_t ) + i * sizeof(fileInPack_t *) ); |
| 2030 |
pack->hashSize = i; |
| 2031 |
pack->hashTable = (fileInPack_t **) (((char *) pack) + sizeof( pack_t )); |
| 2032 |
for(i = 0; i < pack->hashSize; i++) { |
| 2033 |
pack->hashTable[i] = NULL; |
| 2034 |
} |
| 2035 |
|
| 2036 |
Q_strncpyz( pack->pakFilename, zipfile, sizeof( pack->pakFilename ) ); |
| 2037 |
Q_strncpyz( pack->pakBasename, basename, sizeof( pack->pakBasename ) ); |
| 2038 |
|
| 2039 |
|
| 2040 |
if ( strlen( pack->pakBasename ) > 4 && !Q_stricmp( pack->pakBasename + strlen( pack->pakBasename ) - 4, ".pk3" ) ) { |
| 2041 |
pack->pakBasename[strlen( pack->pakBasename ) - 4] = 0; |
| 2042 |
} |
| 2043 |
|
| 2044 |
pack->handle = uf; |
| 2045 |
pack->numfiles = gi.number_entry; |
| 2046 |
unzGoToFirstFile(uf); |
| 2047 |
|
| 2048 |
for (i = 0; i < gi.number_entry; i++) |
| 2049 |
{ |
| 2050 |
err = unzGetCurrentFileInfo(uf, &file_info, filename_inzip, sizeof(filename_inzip), NULL, 0, NULL, 0); |
| 2051 |
if (err != UNZ_OK) { |
| 2052 |
break; |
| 2053 |
} |
| 2054 |
if (file_info.uncompressed_size > 0) { |
| 2055 |
fs_headerLongs[fs_numHeaderLongs++] = LittleLong(file_info.crc); |
| 2056 |
} |
| 2057 |
Q_strlwr( filename_inzip ); |
| 2058 |
hash = FS_HashFileName(filename_inzip, pack->hashSize); |
| 2059 |
buildBuffer[i].name = namePtr; |
| 2060 |
strcpy( buildBuffer[i].name, filename_inzip ); |
| 2061 |
namePtr += strlen(filename_inzip) + 1; |
| 2062 |
|
| 2063 |
buildBuffer[i].pos = unzGetOffset(uf); |
| 2064 |
buildBuffer[i].len = file_info.uncompressed_size; |
| 2065 |
buildBuffer[i].next = pack->hashTable[hash]; |
| 2066 |
pack->hashTable[hash] = &buildBuffer[i]; |
| 2067 |
unzGoToNextFile(uf); |
| 2068 |
} |
| 2069 |
|
| 2070 |
pack->checksum = Com_BlockChecksum( &fs_headerLongs[ 1 ], sizeof(*fs_headerLongs) * ( fs_numHeaderLongs - 1 ) ); |
| 2071 |
pack->pure_checksum = Com_BlockChecksum( fs_headerLongs, sizeof(*fs_headerLongs) * fs_numHeaderLongs ); |
| 2072 |
pack->checksum = LittleLong( pack->checksum ); |
| 2073 |
pack->pure_checksum = LittleLong( pack->pure_checksum ); |
| 2074 |
|
| 2075 |
Z_Free(fs_headerLongs); |
| 2076 |
|
| 2077 |
pack->buildBuffer = buildBuffer; |
| 2078 |
return pack; |
| 2079 |
} |
| 2080 |
|
| 2081 |
|
| 2082 |
|
| 2083 |
|
| 2084 |
|
| 2085 |
|
| 2086 |
|
| 2087 |
|
| 2088 |
|
| 2089 |
static void FS_FreePak(pack_t *thepak) |
| 2090 |
{ |
| 2091 |
unzClose(thepak->handle); |
| 2092 |
Z_Free(thepak->buildBuffer); |
| 2093 |
Z_Free(thepak); |
| 2094 |
} |
| 2095 |
|
| 2096 |
|
| 2097 |
|
| 2098 |
|
| 2099 |
|
| 2100 |
|
| 2101 |
|
| 2102 |
|
| 2103 |
qboolean FS_CompareZipChecksum(const char *zipfile) |
| 2104 |
{ |
| 2105 |
pack_t *thepak; |
| 2106 |
int index; |
| 2107 |
unsigned int checksum; |
| 2108 |
|
| 2109 |
thepak = FS_LoadZipFile(zipfile, ""); |
| 2110 |
|
| 2111 |
if(!thepak) |
| 2112 |
return qfalse; |
| 2113 |
|
| 2114 |
checksum = thepak->checksum; |
| 2115 |
FS_FreePak(thepak); |
| 2116 |
|
| 2117 |
for(index = 0; index < fs_numServerReferencedPaks; index++) |
| 2118 |
{ |
| 2119 |
if(checksum == fs_serverReferencedPaks[index]) |
| 2120 |
return qtrue; |
| 2121 |
} |
| 2122 |
|
| 2123 |
return qfalse; |
| 2124 |
} |
| 2125 |
|
| 2126 |
|
| 2127 |
|
| 2128 |
|
| 2129 |
|
| 2130 |
|
| 2131 |
|
| 2132 |
|
| 2133 |
|
| 2134 |
#define MAX_FOUND_FILES 0x1000 |
| 2135 |
|
| 2136 |
static int FS_ReturnPath( const char *zname, char *zpath, int *depth ) { |
| 2137 |
int len, at, newdep; |
| 2138 |
|
| 2139 |
newdep = 0; |
| 2140 |
zpath[0] = 0; |
| 2141 |
len = 0; |
| 2142 |
at = 0; |
| 2143 |
|
| 2144 |
while(zname[at] != 0) |
| 2145 |
{ |
| 2146 |
if (zname[at]=='/' || zname[at]=='\\') { |
| 2147 |
len = at; |
| 2148 |
newdep++; |
| 2149 |
} |
| 2150 |
at++; |
| 2151 |
} |
| 2152 |
strcpy(zpath, zname); |
| 2153 |
zpath[len] = 0; |
| 2154 |
*depth = newdep; |
| 2155 |
|
| 2156 |
return len; |
| 2157 |
} |
| 2158 |
|
| 2159 |
|
| 2160 |
|
| 2161 |
|
| 2162 |
|
| 2163 |
|
| 2164 |
static int FS_AddFileToList( char *name, char *list[MAX_FOUND_FILES], int nfiles ) { |
| 2165 |
int i; |
| 2166 |
|
| 2167 |
if ( nfiles == MAX_FOUND_FILES - 1 ) { |
| 2168 |
return nfiles; |
| 2169 |
} |
| 2170 |
for ( i = 0 ; i < nfiles ; i++ ) { |
| 2171 |
if ( !Q_stricmp( name, list[i] ) ) { |
| 2172 |
return nfiles; |
| 2173 |
} |
| 2174 |
} |
| 2175 |
list[nfiles] = CopyString( name ); |
| 2176 |
nfiles++; |
| 2177 |
|
| 2178 |
return nfiles; |
| 2179 |
} |
| 2180 |
|
| 2181 |
|
| 2182 |
|
| 2183 |
|
| 2184 |
|
| 2185 |
|
| 2186 |
|
| 2187 |
|
| 2188 |
|
| 2189 |
char **FS_ListFilteredFiles( const char *path, const char *extension, |
| 2190 |
char *filter, int *numfiles, qboolean stripPath, |
| 2191 |
qboolean allowNonPureFilesOnDisk ) { |
| 2192 |
int nfiles; |
| 2193 |
char **listCopy; |
| 2194 |
char *list[MAX_FOUND_FILES]; |
| 2195 |
searchpath_t *search; |
| 2196 |
int i; |
| 2197 |
int pathLength; |
| 2198 |
int extensionLength; |
| 2199 |
int length, pathDepth, pathSkip; |
| 2200 |
pack_t *pak; |
| 2201 |
fileInPack_t *buildBuffer; |
| 2202 |
char zpath[MAX_ZPATH]; |
| 2203 |
|
| 2204 |
if ( !fs_searchpaths ) { |
| 2205 |
Com_Error( ERR_FATAL, "Filesystem call made without initialization" ); |
| 2206 |
} |
| 2207 |
|
| 2208 |
if ( !path ) { |
| 2209 |
*numfiles = 0; |
| 2210 |
return NULL; |
| 2211 |
} |
| 2212 |
if ( !extension ) { |
| 2213 |
extension = ""; |
| 2214 |
} |
| 2215 |
|
| 2216 |
pathLength = strlen( path ); |
| 2217 |
if ( path[pathLength-1] == '\\' || path[pathLength-1] == '/' ) { |
| 2218 |
pathLength--; |
| 2219 |
} |
| 2220 |
extensionLength = strlen( extension ); |
| 2221 |
nfiles = 0; |
| 2222 |
FS_ReturnPath(path, zpath, &pathDepth); |
| 2223 |
|
| 2224 |
|
| 2225 |
|
| 2226 |
|
| 2227 |
for (search = fs_searchpaths ; search ; search = search->next) { |
| 2228 |
|
| 2229 |
if (search->pack) { |
| 2230 |
|
| 2231 |
|
| 2232 |
|
| 2233 |
if ( !FS_PakIsPure(search->pack) ) { |
| 2234 |
continue; |
| 2235 |
} |
| 2236 |
|
| 2237 |
|
| 2238 |
pak = search->pack; |
| 2239 |
buildBuffer = pak->buildBuffer; |
| 2240 |
for (i = 0; i < pak->numfiles; i++) { |
| 2241 |
char *name; |
| 2242 |
int zpathLen, depth; |
| 2243 |
|
| 2244 |
|
| 2245 |
name = buildBuffer[i].name; |
| 2246 |
|
| 2247 |
if (stripPath) { |
| 2248 |
pathSkip = pathLength; |
| 2249 |
if (pathLength) { |
| 2250 |
pathSkip++; |
| 2251 |
} |
| 2252 |
} else { |
| 2253 |
pathSkip = 0; |
| 2254 |
} |
| 2255 |
|
| 2256 |
if (filter) { |
| 2257 |
|
| 2258 |
if (!Com_FilterPath( filter, name, qfalse )) |
| 2259 |
continue; |
| 2260 |
|
| 2261 |
|
| 2262 |
nfiles = FS_AddFileToList( name + pathSkip, list, nfiles ); |
| 2263 |
} |
| 2264 |
else { |
| 2265 |
|
| 2266 |
zpathLen = FS_ReturnPath(name, zpath, &depth); |
| 2267 |
|
| 2268 |
if ( (depth-pathDepth)>2 || pathLength > zpathLen || Q_stricmpn( name, path, pathLength ) ) { |
| 2269 |
continue; |
| 2270 |
} |
| 2271 |
|
| 2272 |
|
| 2273 |
length = strlen( name ); |
| 2274 |
if ( length < extensionLength ) { |
| 2275 |
continue; |
| 2276 |
} |
| 2277 |
|
| 2278 |
if ( Q_stricmp( name + length - extensionLength, extension ) ) { |
| 2279 |
continue; |
| 2280 |
} |
| 2281 |
|
| 2282 |
|
| 2283 |
nfiles = FS_AddFileToList( name + pathSkip, list, nfiles ); |
| 2284 |
} |
| 2285 |
} |
| 2286 |
} else if (search->dir) { |
| 2287 |
char *netpath; |
| 2288 |
int numSysFiles; |
| 2289 |
char **sysFiles; |
| 2290 |
char *name; |
| 2291 |
|
| 2292 |
|
| 2293 |
if ( fs_numServerPaks && !allowNonPureFilesOnDisk ) { |
| 2294 |
continue; |
| 2295 |
} else { |
| 2296 |
netpath = FS_BuildOSPath( search->dir->path, search->dir->gamedir, path ); |
| 2297 |
sysFiles = Sys_ListFiles( netpath, extension, filter, &numSysFiles, qfalse ); |
| 2298 |
for ( i = 0 ; i < numSysFiles ; i++ ) { |
| 2299 |
|
| 2300 |
name = sysFiles[i]; |
| 2301 |
nfiles = FS_AddFileToList( name, list, nfiles ); |
| 2302 |
} |
| 2303 |
Sys_FreeFileList( sysFiles ); |
| 2304 |
} |
| 2305 |
} |
| 2306 |
} |
| 2307 |
|
| 2308 |
|
| 2309 |
*numfiles = nfiles; |
| 2310 |
|
| 2311 |
if ( !nfiles ) { |
| 2312 |
return NULL; |
| 2313 |
} |
| 2314 |
|
| 2315 |
listCopy = Z_Malloc( ( nfiles + 1 ) * sizeof( *listCopy ) ); |
| 2316 |
for ( i = 0 ; i < nfiles ; i++ ) { |
| 2317 |
listCopy[i] = list[i]; |
| 2318 |
} |
| 2319 |
listCopy[i] = NULL; |
| 2320 |
|
| 2321 |
return listCopy; |
| 2322 |
} |
| 2323 |
|
| 2324 |
|
| 2325 |
|
| 2326 |
|
| 2327 |
|
| 2328 |
|
| 2329 |
char **FS_ListFiles( const char *path, const char *extension, int *numfiles ) { |
| 2330 |
return FS_ListFilteredFiles( path, extension, NULL, numfiles, qtrue, qfalse ); |
| 2331 |
} |
| 2332 |
|
| 2333 |
|
| 2334 |
|
| 2335 |
|
| 2336 |
|
| 2337 |
|
| 2338 |
void FS_FreeFileList( char **list ) { |
| 2339 |
int i; |
| 2340 |
|
| 2341 |
if ( !fs_searchpaths ) { |
| 2342 |
Com_Error( ERR_FATAL, "Filesystem call made without initialization" ); |
| 2343 |
} |
| 2344 |
|
| 2345 |
if ( !list ) { |
| 2346 |
return; |
| 2347 |
} |
| 2348 |
|
| 2349 |
for ( i = 0 ; list[i] ; i++ ) { |
| 2350 |
Z_Free( list[i] ); |
| 2351 |
} |
| 2352 |
|
| 2353 |
Z_Free( list ); |
| 2354 |
} |
| 2355 |
|
| 2356 |
|
| 2357 |
|
| 2358 |
|
| 2359 |
|
| 2360 |
|
| 2361 |
|
| 2362 |
int FS_GetFileList( const char *path, const char *extension, char *listbuf, int bufsize ) { |
| 2363 |
int nFiles, i, nTotal, nLen; |
| 2364 |
char **pFiles = NULL; |
| 2365 |
|
| 2366 |
*listbuf = 0; |
| 2367 |
nFiles = 0; |
| 2368 |
nTotal = 0; |
| 2369 |
|
| 2370 |
if (Q_stricmp(path, "$modlist") == 0) { |
| 2371 |
return FS_GetModList(listbuf, bufsize); |
| 2372 |
} |
| 2373 |
|
| 2374 |
pFiles = FS_ListFiles(path, extension, &nFiles); |
| 2375 |
|
| 2376 |
for (i =0; i < nFiles; i++) { |
| 2377 |
nLen = strlen(pFiles[i]) + 1; |
| 2378 |
if (nTotal + nLen + 1 < bufsize) { |
| 2379 |
strcpy(listbuf, pFiles[i]); |
| 2380 |
listbuf += nLen; |
| 2381 |
nTotal += nLen; |
| 2382 |
} |
| 2383 |
else { |
| 2384 |
nFiles = i; |
| 2385 |
break; |
| 2386 |
} |
| 2387 |
} |
| 2388 |
|
| 2389 |
FS_FreeFileList(pFiles); |
| 2390 |
|
| 2391 |
return nFiles; |
| 2392 |
} |
| 2393 |
|
| 2394 |
|
| 2395 |
|
| 2396 |
|
| 2397 |
|
| 2398 |
|
| 2399 |
|
| 2400 |
|
| 2401 |
|
| 2402 |
|
| 2403 |
|
| 2404 |
|
| 2405 |
static unsigned int Sys_CountFileList(char **list) |
| 2406 |
{ |
| 2407 |
int i = 0; |
| 2408 |
|
| 2409 |
if (list) |
| 2410 |
{ |
| 2411 |
while (*list) |
| 2412 |
{ |
| 2413 |
list++; |
| 2414 |
i++; |
| 2415 |
} |
| 2416 |
} |
| 2417 |
return i; |
| 2418 |
} |
| 2419 |
|
| 2420 |
static char** Sys_ConcatenateFileLists( char **list0, char **list1 ) |
| 2421 |
{ |
| 2422 |
int totalLength = 0; |
| 2423 |
char** cat = NULL, **dst, **src; |
| 2424 |
|
| 2425 |
totalLength += Sys_CountFileList(list0); |
| 2426 |
totalLength += Sys_CountFileList(list1); |
| 2427 |
|
| 2428 |
|
| 2429 |
dst = cat = Z_Malloc( ( totalLength + 1 ) * sizeof( char* ) ); |
| 2430 |
|
| 2431 |
|
| 2432 |
if (list0) |
| 2433 |
{ |
| 2434 |
for (src = list0; *src; src++, dst++) |
| 2435 |
*dst = *src; |
| 2436 |
} |
| 2437 |
if (list1) |
| 2438 |
{ |
| 2439 |
for (src = list1; *src; src++, dst++) |
| 2440 |
*dst = *src; |
| 2441 |
} |
| 2442 |
|
| 2443 |
|
| 2444 |
*dst = NULL; |
| 2445 |
|
| 2446 |
|
| 2447 |
|
| 2448 |
if (list0) Z_Free( list0 ); |
| 2449 |
if (list1) Z_Free( list1 ); |
| 2450 |
|
| 2451 |
return cat; |
| 2452 |
} |
| 2453 |
|
| 2454 |
|
| 2455 |
|
| 2456 |
|
| 2457 |
|
| 2458 |
|
| 2459 |
void FS_GetModDescription( const char *modDir, char *description, int descriptionLen ) { |
| 2460 |
fileHandle_t descHandle; |
| 2461 |
char descPath[MAX_QPATH]; |
| 2462 |
int nDescLen; |
| 2463 |
FILE *file; |
| 2464 |
|
| 2465 |
Com_sprintf( descPath, sizeof ( descPath ), "%s%cdescription.txt", modDir, PATH_SEP ); |
| 2466 |
nDescLen = FS_BaseDir_FOpenFileRead( descPath, &descHandle ); |
| 2467 |
|
| 2468 |
if ( nDescLen > 0 ) { |
| 2469 |
file = FS_FileForHandle(descHandle); |
| 2470 |
Com_Memset( description, 0, descriptionLen ); |
| 2471 |
nDescLen = fread(description, 1, descriptionLen, file); |
| 2472 |
if (nDescLen >= 0) { |
| 2473 |
description[nDescLen] = '\0'; |
| 2474 |
} |
| 2475 |
} else { |
| 2476 |
Q_strncpyz( description, modDir, descriptionLen ); |
| 2477 |
} |
| 2478 |
|
| 2479 |
if ( descHandle ) { |
| 2480 |
FS_FCloseFile( descHandle ); |
| 2481 |
} |
| 2482 |
} |
| 2483 |
|
| 2484 |
|
| 2485 |
|
| 2486 |
|
| 2487 |
|
| 2488 |
|
| 2489 |
|
| 2490 |
|
| 2491 |
|
| 2492 |
int FS_GetModList( char *listbuf, int bufsize ) { |
| 2493 |
int nMods, i, j, k, nTotal, nLen, nPaks = 0, nDirs = 0, nPakDirs = 0, nPotential, nDescLen; |
| 2494 |
char **pFiles = NULL; |
| 2495 |
char **pPaks = NULL; |
| 2496 |
char **pDirs = NULL; |
| 2497 |
char *name, *path; |
| 2498 |
char description[MAX_OSPATH]; |
| 2499 |
|
| 2500 |
int dummy; |
| 2501 |
char **pFiles0 = NULL; |
| 2502 |
qboolean bDrop = qfalse; |
| 2503 |
|
| 2504 |
*listbuf = 0; |
| 2505 |
nMods = nTotal = 0; |
| 2506 |
|
| 2507 |
|
| 2508 |
for (i = 0; i < ARRAY_LEN(fs_pathVars); i++) { |
| 2509 |
const cvar_t *pathVar = fs_pathVars[i]; |
| 2510 |
|
| 2511 |
if (!pathVar || !pathVar->string[0]) { |
| 2512 |
continue; |
| 2513 |
} |
| 2514 |
|
| 2515 |
pFiles0 = Sys_ListFiles(pathVar->string, NULL, NULL, &dummy, qtrue); |
| 2516 |
|
| 2517 |
pFiles = Sys_ConcatenateFileLists(pFiles, pFiles0); |
| 2518 |
} |
| 2519 |
|
| 2520 |
nPotential = Sys_CountFileList(pFiles); |
| 2521 |
|
| 2522 |
for (i = 0; i < nPotential; i++) { |
| 2523 |
name = pFiles[i]; |
| 2524 |
|
| 2525 |
|
| 2526 |
if (i != 0) { |
| 2527 |
bDrop = qfalse; |
| 2528 |
for (j = 0; j < i; j++) { |
| 2529 |
if (Q_stricmp(pFiles[j], name) == 0) { |
| 2530 |
|
| 2531 |
bDrop = qtrue; |
| 2532 |
break; |
| 2533 |
} |
| 2534 |
} |
| 2535 |
} |
| 2536 |
|
| 2537 |
if (bDrop || Q_stricmp(name, com_basegame->string) == 0 || Q_stricmpn(name, ".", 1) == 0) { |
| 2538 |
continue; |
| 2539 |
} |
| 2540 |
|
| 2541 |
|
| 2542 |
|
| 2543 |
|
| 2544 |
for (j = 0; j < ARRAY_LEN(fs_pathVars); j++) { |
| 2545 |
const cvar_t *pathVar = fs_pathVars[j]; |
| 2546 |
|
| 2547 |
if (!pathVar || !pathVar->string[0]) { |
| 2548 |
continue; |
| 2549 |
} |
| 2550 |
|
| 2551 |
path = FS_BaseDir_BuildOSPath(pathVar->string, name); |
| 2552 |
nPaks = nDirs = nPakDirs = 0; |
| 2553 |
pPaks = Sys_ListFiles(path, ".pk3", NULL, &nPaks, qfalse); |
| 2554 |
pDirs = Sys_ListFiles(path, "/", NULL, &nDirs, qfalse); |
| 2555 |
for (k = 0; k < nDirs; k++) { |
| 2556 |
|
| 2557 |
if (FS_IsExt(pDirs[k], ".pk3dir", strlen(pDirs[k]))) { |
| 2558 |
nPakDirs++; |
| 2559 |
} |
| 2560 |
} |
| 2561 |
|
| 2562 |
Sys_FreeFileList(pPaks); |
| 2563 |
Sys_FreeFileList(pDirs); |
| 2564 |
|
| 2565 |
if (nPaks > 0 || nPakDirs > 0) { |
| 2566 |
break; |
| 2567 |
} |
| 2568 |
} |
| 2569 |
|
| 2570 |
if (nPaks > 0 || nPakDirs > 0) { |
| 2571 |
nLen = strlen(name) + 1; |
| 2572 |
|
| 2573 |
|
| 2574 |
FS_GetModDescription(name, description, sizeof(description)); |
| 2575 |
nDescLen = strlen(description) + 1; |
| 2576 |
|
| 2577 |
if (nTotal + nLen + 1 + nDescLen + 1 < bufsize) { |
| 2578 |
strcpy(listbuf, name); |
| 2579 |
listbuf += nLen; |
| 2580 |
strcpy(listbuf, description); |
| 2581 |
listbuf += nDescLen; |
| 2582 |
nTotal += nLen + nDescLen; |
| 2583 |
nMods++; |
| 2584 |
} else { |
| 2585 |
break; |
| 2586 |
} |
| 2587 |
} |
| 2588 |
} |
| 2589 |
Sys_FreeFileList( pFiles ); |
| 2590 |
|
| 2591 |
return nMods; |
| 2592 |
} |
| 2593 |
|
| 2594 |
|
| 2595 |
|
| 2596 |
|
| 2597 |
|
| 2598 |
|
| 2599 |
|
| 2600 |
|
| 2601 |
|
| 2602 |
|
| 2603 |
|
| 2604 |
void FS_Dir_f( void ) { |
| 2605 |
char *path; |
| 2606 |
char *extension; |
| 2607 |
char **dirnames; |
| 2608 |
int ndirs; |
| 2609 |
int i; |
| 2610 |
|
| 2611 |
if ( Cmd_Argc() < 2 || Cmd_Argc() > 3 ) { |
| 2612 |
Com_Printf( "usage: dir <directory> [extension]\n" ); |
| 2613 |
return; |
| 2614 |
} |
| 2615 |
|
| 2616 |
if ( Cmd_Argc() == 2 ) { |
| 2617 |
path = Cmd_Argv( 1 ); |
| 2618 |
extension = ""; |
| 2619 |
} else { |
| 2620 |
path = Cmd_Argv( 1 ); |
| 2621 |
extension = Cmd_Argv( 2 ); |
| 2622 |
} |
| 2623 |
|
| 2624 |
Com_Printf( "Directory of %s %s\n", path, extension ); |
| 2625 |
Com_Printf( "---------------\n" ); |
| 2626 |
|
| 2627 |
dirnames = FS_ListFiles( path, extension, &ndirs ); |
| 2628 |
|
| 2629 |
for ( i = 0; i < ndirs; i++ ) { |
| 2630 |
Com_Printf( "%s\n", dirnames[i] ); |
| 2631 |
} |
| 2632 |
FS_FreeFileList( dirnames ); |
| 2633 |
} |
| 2634 |
|
| 2635 |
|
| 2636 |
|
| 2637 |
|
| 2638 |
|
| 2639 |
|
| 2640 |
void FS_ConvertPath( char *s ) { |
| 2641 |
while (*s) { |
| 2642 |
if ( *s == '\\' || *s == ':' ) { |
| 2643 |
*s = '/'; |
| 2644 |
} |
| 2645 |
s++; |
| 2646 |
} |
| 2647 |
} |
| 2648 |
|
| 2649 |
|
| 2650 |
|
| 2651 |
|
| 2652 |
|
| 2653 |
|
| 2654 |
|
| 2655 |
|
| 2656 |
int FS_PathCmp( const char *s1, const char *s2 ) { |
| 2657 |
int c1, c2; |
| 2658 |
|
| 2659 |
do { |
| 2660 |
c1 = *s1++; |
| 2661 |
c2 = *s2++; |
| 2662 |
|
| 2663 |
if (c1 >= 'a' && c1 <= 'z') { |
| 2664 |
c1 -= ('a' - 'A'); |
| 2665 |
} |
| 2666 |
if (c2 >= 'a' && c2 <= 'z') { |
| 2667 |
c2 -= ('a' - 'A'); |
| 2668 |
} |
| 2669 |
|
| 2670 |
if ( c1 == '\\' || c1 == ':' ) { |
| 2671 |
c1 = '/'; |
| 2672 |
} |
| 2673 |
if ( c2 == '\\' || c2 == ':' ) { |
| 2674 |
c2 = '/'; |
| 2675 |
} |
| 2676 |
|
| 2677 |
if (c1 < c2) { |
| 2678 |
return -1; |
| 2679 |
} |
| 2680 |
if (c1 > c2) { |
| 2681 |
return 1; |
| 2682 |
} |
| 2683 |
} while (c1); |
| 2684 |
|
| 2685 |
return 0; |
| 2686 |
} |
| 2687 |
|
| 2688 |
|
| 2689 |
|
| 2690 |
|
| 2691 |
|
| 2692 |
|
| 2693 |
void FS_SortFileList(char **filelist, int numfiles) { |
| 2694 |
int i, j, k, numsortedfiles; |
| 2695 |
char **sortedlist; |
| 2696 |
|
| 2697 |
sortedlist = Z_Malloc( ( numfiles + 1 ) * sizeof( *sortedlist ) ); |
| 2698 |
sortedlist[0] = NULL; |
| 2699 |
numsortedfiles = 0; |
| 2700 |
for (i = 0; i < numfiles; i++) { |
| 2701 |
for (j = 0; j < numsortedfiles; j++) { |
| 2702 |
if (FS_PathCmp(filelist[i], sortedlist[j]) < 0) { |
| 2703 |
break; |
| 2704 |
} |
| 2705 |
} |
| 2706 |
for (k = numsortedfiles; k > j; k--) { |
| 2707 |
sortedlist[k] = sortedlist[k-1]; |
| 2708 |
} |
| 2709 |
sortedlist[j] = filelist[i]; |
| 2710 |
numsortedfiles++; |
| 2711 |
} |
| 2712 |
Com_Memcpy(filelist, sortedlist, numfiles * sizeof( *filelist ) ); |
| 2713 |
Z_Free(sortedlist); |
| 2714 |
} |
| 2715 |
|
| 2716 |
|
| 2717 |
|
| 2718 |
|
| 2719 |
|
| 2720 |
|
| 2721 |
void FS_NewDir_f( void ) { |
| 2722 |
char *filter; |
| 2723 |
char **dirnames; |
| 2724 |
int ndirs; |
| 2725 |
int i; |
| 2726 |
|
| 2727 |
if ( Cmd_Argc() < 2 ) { |
| 2728 |
Com_Printf( "usage: fdir <filter>\n" ); |
| 2729 |
Com_Printf( "example: fdir *q3dm*.bsp\n"); |
| 2730 |
return; |
| 2731 |
} |
| 2732 |
|
| 2733 |
filter = Cmd_Argv( 1 ); |
| 2734 |
|
| 2735 |
Com_Printf( "---------------\n" ); |
| 2736 |
|
| 2737 |
dirnames = FS_ListFilteredFiles( "", "", filter, &ndirs, qfalse, qfalse ); |
| 2738 |
|
| 2739 |
FS_SortFileList(dirnames, ndirs); |
| 2740 |
|
| 2741 |
for ( i = 0; i < ndirs; i++ ) { |
| 2742 |
FS_ConvertPath(dirnames[i]); |
| 2743 |
Com_Printf( "%s\n", dirnames[i] ); |
| 2744 |
} |
| 2745 |
Com_Printf( "%d files listed\n", ndirs ); |
| 2746 |
FS_FreeFileList( dirnames ); |
| 2747 |
} |
| 2748 |
|
| 2749 |
|
| 2750 |
|
| 2751 |
|
| 2752 |
|
| 2753 |
|
| 2754 |
|
| 2755 |
void FS_Path_f( void ) { |
| 2756 |
searchpath_t *s; |
| 2757 |
int i; |
| 2758 |
|
| 2759 |
Com_Printf ("We are looking in the current search path:\n"); |
| 2760 |
for (s = fs_searchpaths; s; s = s->next) { |
| 2761 |
if (s->pack) { |
| 2762 |
Com_Printf ("%s (%i files)\n", s->pack->pakFilename, s->pack->numfiles); |
| 2763 |
if ( fs_numServerPaks ) { |
| 2764 |
if ( !FS_PakIsPure(s->pack) ) { |
| 2765 |
Com_Printf( " not on the pure list\n" ); |
| 2766 |
} else { |
| 2767 |
Com_Printf( " on the pure list\n" ); |
| 2768 |
} |
| 2769 |
} |
| 2770 |
} else { |
| 2771 |
Com_Printf ("%s%c%s\n", s->dir->path, PATH_SEP, s->dir->gamedir ); |
| 2772 |
} |
| 2773 |
} |
| 2774 |
|
| 2775 |
|
| 2776 |
Com_Printf( "\n" ); |
| 2777 |
for ( i = 1 ; i < MAX_FILE_HANDLES ; i++ ) { |
| 2778 |
if ( fsh[i].handleFiles.file.o ) { |
| 2779 |
Com_Printf( "handle %i: %s\n", i, fsh[i].name ); |
| 2780 |
} |
| 2781 |
} |
| 2782 |
} |
| 2783 |
|
| 2784 |
|
| 2785 |
|
| 2786 |
|
| 2787 |
|
| 2788 |
|
| 2789 |
void FS_TouchFile_f( void ) { |
| 2790 |
fileHandle_t f; |
| 2791 |
|
| 2792 |
if ( Cmd_Argc() != 2 ) { |
| 2793 |
Com_Printf( "Usage: touchFile <file>\n" ); |
| 2794 |
return; |
| 2795 |
} |
| 2796 |
|
| 2797 |
FS_FOpenFileRead( Cmd_Argv( 1 ), &f, qfalse ); |
| 2798 |
if ( f ) { |
| 2799 |
FS_FCloseFile( f ); |
| 2800 |
} |
| 2801 |
} |
| 2802 |
|
| 2803 |
|
| 2804 |
|
| 2805 |
|
| 2806 |
|
| 2807 |
|
| 2808 |
|
| 2809 |
qboolean FS_Which(const char *filename, void *searchPath) |
| 2810 |
{ |
| 2811 |
searchpath_t *search = searchPath; |
| 2812 |
|
| 2813 |
if(FS_FOpenFileReadDir(filename, search, NULL, qfalse, qfalse) > 0) |
| 2814 |
{ |
| 2815 |
if(search->pack) |
| 2816 |
{ |
| 2817 |
Com_Printf("File \"%s\" found in \"%s\"\n", filename, search->pack->pakFilename); |
| 2818 |
return qtrue; |
| 2819 |
} |
| 2820 |
else if(search->dir) |
| 2821 |
{ |
| 2822 |
Com_Printf( "File \"%s\" found at \"%s\"\n", filename, search->dir->fullpath); |
| 2823 |
return qtrue; |
| 2824 |
} |
| 2825 |
} |
| 2826 |
|
| 2827 |
return qfalse; |
| 2828 |
} |
| 2829 |
|
| 2830 |
|
| 2831 |
|
| 2832 |
|
| 2833 |
|
| 2834 |
|
| 2835 |
void FS_Which_f( void ) { |
| 2836 |
searchpath_t *search; |
| 2837 |
char *filename; |
| 2838 |
|
| 2839 |
filename = Cmd_Argv(1); |
| 2840 |
|
| 2841 |
if ( !filename[0] ) { |
| 2842 |
Com_Printf( "Usage: which <file>\n" ); |
| 2843 |
return; |
| 2844 |
} |
| 2845 |
|
| 2846 |
|
| 2847 |
if ( filename[0] == '/' || filename[0] == '\\' ) { |
| 2848 |
filename++; |
| 2849 |
} |
| 2850 |
|
| 2851 |
|
| 2852 |
for(search = fs_searchpaths; search; search = search->next) |
| 2853 |
{ |
| 2854 |
if(FS_Which(filename, search)) |
| 2855 |
return; |
| 2856 |
} |
| 2857 |
|
| 2858 |
Com_Printf("File not found: \"%s\"\n", filename); |
| 2859 |
} |
| 2860 |
|
| 2861 |
|
| 2862 |
|
| 2863 |
|
| 2864 |
|
| 2865 |
static int QDECL paksort( const void *a, const void *b ) { |
| 2866 |
char *aa, *bb; |
| 2867 |
|
| 2868 |
aa = *(char **)a; |
| 2869 |
bb = *(char **)b; |
| 2870 |
|
| 2871 |
return FS_PathCmp( aa, bb ); |
| 2872 |
} |
| 2873 |
|
| 2874 |
|
| 2875 |
|
| 2876 |
|
| 2877 |
|
| 2878 |
|
| 2879 |
|
| 2880 |
|
| 2881 |
|
| 2882 |
static void FS_AddGameDirectory( const char *path, const char *dir ) { |
| 2883 |
searchpath_t *sp; |
| 2884 |
searchpath_t *search; |
| 2885 |
pack_t *pak; |
| 2886 |
char curpath[MAX_OSPATH + 1], *pakfile; |
| 2887 |
int numfiles; |
| 2888 |
char **pakfiles; |
| 2889 |
int pakfilesi; |
| 2890 |
char **pakfilestmp; |
| 2891 |
int numdirs; |
| 2892 |
char **pakdirs; |
| 2893 |
int pakdirsi; |
| 2894 |
char **pakdirstmp; |
| 2895 |
|
| 2896 |
int pakwhich; |
| 2897 |
int len; |
| 2898 |
|
| 2899 |
|
| 2900 |
for ( sp = fs_searchpaths ; sp ; sp = sp->next ) { |
| 2901 |
if ( sp->dir && !Q_stricmp(sp->dir->path, path) && !Q_stricmp(sp->dir->gamedir, dir)) { |
| 2902 |
return; |
| 2903 |
} |
| 2904 |
} |
| 2905 |
|
| 2906 |
Q_strncpyz( fs_gamedir, dir, sizeof( fs_gamedir ) ); |
| 2907 |
|
| 2908 |
|
| 2909 |
Q_strncpyz(curpath, FS_BaseDir_BuildOSPath(path, dir), sizeof(curpath)); |
| 2910 |
|
| 2911 |
|
| 2912 |
pakfiles = Sys_ListFiles(curpath, ".pk3", NULL, &numfiles, qfalse); |
| 2913 |
|
| 2914 |
if ( pakfiles ) { |
| 2915 |
qsort( pakfiles, numfiles, sizeof(char*), paksort ); |
| 2916 |
} |
| 2917 |
|
| 2918 |
if ( fs_numServerPaks ) { |
| 2919 |
numdirs = 0; |
| 2920 |
pakdirs = NULL; |
| 2921 |
} else { |
| 2922 |
|
| 2923 |
pakdirs = Sys_ListFiles(curpath, "/", NULL, &numdirs, qfalse); |
| 2924 |
|
| 2925 |
qsort( pakdirs, numdirs, sizeof(char *), paksort ); |
| 2926 |
} |
| 2927 |
|
| 2928 |
pakfilesi = 0; |
| 2929 |
pakdirsi = 0; |
| 2930 |
|
| 2931 |
while((pakfilesi < numfiles) || (pakdirsi < numdirs)) |
| 2932 |
{ |
| 2933 |
|
| 2934 |
if (pakfilesi >= numfiles) { |
| 2935 |
|
| 2936 |
pakwhich = 0; |
| 2937 |
} |
| 2938 |
else if (pakdirsi >= numdirs) { |
| 2939 |
|
| 2940 |
pakwhich = 1; |
| 2941 |
} |
| 2942 |
else { |
| 2943 |
|
| 2944 |
|
| 2945 |
pakfilestmp = &pakfiles[pakfilesi]; |
| 2946 |
pakdirstmp = &pakdirs[pakdirsi]; |
| 2947 |
pakwhich = (paksort(pakfilestmp, pakdirstmp) < 0); |
| 2948 |
} |
| 2949 |
|
| 2950 |
if (pakwhich) { |
| 2951 |
|
| 2952 |
pakfile = FS_BuildOSPath(path, dir, pakfiles[pakfilesi]); |
| 2953 |
if ((pak = FS_LoadZipFile(pakfile, pakfiles[pakfilesi])) == 0) { |
| 2954 |
|
| 2955 |
pakfilesi++; |
| 2956 |
continue; |
| 2957 |
} |
| 2958 |
|
| 2959 |
Q_strncpyz(pak->pakPathname, curpath, sizeof(pak->pakPathname)); |
| 2960 |
|
| 2961 |
Q_strncpyz(pak->pakGamename, dir, sizeof(pak->pakGamename)); |
| 2962 |
|
| 2963 |
fs_packFiles += pak->numfiles; |
| 2964 |
|
| 2965 |
search = Z_Malloc(sizeof(searchpath_t)); |
| 2966 |
search->pack = pak; |
| 2967 |
search->next = fs_searchpaths; |
| 2968 |
fs_searchpaths = search; |
| 2969 |
|
| 2970 |
pakfilesi++; |
| 2971 |
} |
| 2972 |
else { |
| 2973 |
|
| 2974 |
|
| 2975 |
len = strlen(pakdirs[pakdirsi]); |
| 2976 |
if (!FS_IsExt(pakdirs[pakdirsi], ".pk3dir", len)) { |
| 2977 |
|
| 2978 |
pakdirsi++; |
| 2979 |
continue; |
| 2980 |
} |
| 2981 |
|
| 2982 |
pakfile = FS_BuildOSPath(path, dir, pakdirs[pakdirsi]); |
| 2983 |
|
| 2984 |
|
| 2985 |
search = Z_Malloc(sizeof(searchpath_t)); |
| 2986 |
search->dir = Z_Malloc(sizeof(*search->dir)); |
| 2987 |
|
| 2988 |
Q_strncpyz(search->dir->path, curpath, sizeof(search->dir->path)); |
| 2989 |
Q_strncpyz(search->dir->fullpath, pakfile, sizeof(search->dir->fullpath)); |
| 2990 |
Q_strncpyz(search->dir->gamedir, pakdirs[pakdirsi], sizeof(search->dir->gamedir)); |
| 2991 |
|
| 2992 |
search->next = fs_searchpaths; |
| 2993 |
fs_searchpaths = search; |
| 2994 |
|
| 2995 |
pakdirsi++; |
| 2996 |
} |
| 2997 |
} |
| 2998 |
|
| 2999 |
|
| 3000 |
Sys_FreeFileList( pakfiles ); |
| 3001 |
Sys_FreeFileList( pakdirs ); |
| 3002 |
|
| 3003 |
|
| 3004 |
|
| 3005 |
|
| 3006 |
search = Z_Malloc (sizeof(searchpath_t)); |
| 3007 |
search->dir = Z_Malloc( sizeof( *search->dir ) ); |
| 3008 |
|
| 3009 |
Q_strncpyz(search->dir->path, path, sizeof(search->dir->path)); |
| 3010 |
Q_strncpyz(search->dir->fullpath, curpath, sizeof(search->dir->fullpath)); |
| 3011 |
Q_strncpyz(search->dir->gamedir, dir, sizeof(search->dir->gamedir)); |
| 3012 |
|
| 3013 |
search->next = fs_searchpaths; |
| 3014 |
fs_searchpaths = search; |
| 3015 |
} |
| 3016 |
|
| 3017 |
|
| 3018 |
|
| 3019 |
|
| 3020 |
|
| 3021 |
|
| 3022 |
static void FS_AddGameDirectories(const char *dir) |
| 3023 |
{ |
| 3024 |
|
| 3025 |
for(int i = ARRAY_LEN(fs_pathVars) - 1; i >= 0; i--) { |
| 3026 |
const cvar_t *pathVar = fs_pathVars[i]; |
| 3027 |
|
| 3028 |
if (!pathVar || !pathVar->string[0]) { |
| 3029 |
continue; |
| 3030 |
} |
| 3031 |
|
| 3032 |
FS_AddGameDirectory(pathVar->string, dir); |
| 3033 |
} |
| 3034 |
} |
| 3035 |
|
| 3036 |
|
| 3037 |
|
| 3038 |
|
| 3039 |
|
| 3040 |
|
| 3041 |
qboolean FS_idPak(char *pak, char *base, int numPaks) |
| 3042 |
{ |
| 3043 |
int i; |
| 3044 |
|
| 3045 |
for (i = 0; i < NUM_ID_PAKS; i++) { |
| 3046 |
if ( !FS_FilenameCompare(pak, va("%s/pak%d", base, i)) ) { |
| 3047 |
break; |
| 3048 |
} |
| 3049 |
} |
| 3050 |
if (i < numPaks) { |
| 3051 |
return qtrue; |
| 3052 |
} |
| 3053 |
return qfalse; |
| 3054 |
} |
| 3055 |
|
| 3056 |
|
| 3057 |
|
| 3058 |
|
| 3059 |
|
| 3060 |
|
| 3061 |
|
| 3062 |
|
| 3063 |
|
| 3064 |
|
| 3065 |
qboolean FS_CheckDirTraversal(const char *checkdir) |
| 3066 |
{ |
| 3067 |
if(strstr(checkdir, "../") || strstr(checkdir, "..\\")) |
| 3068 |
return qtrue; |
| 3069 |
|
| 3070 |
return qfalse; |
| 3071 |
} |
| 3072 |
|
| 3073 |
|
| 3074 |
|
| 3075 |
|
| 3076 |
|
| 3077 |
|
| 3078 |
|
| 3079 |
|
| 3080 |
|
| 3081 |
qboolean FS_InvalidGameDir( const char *gamedir ) { |
| 3082 |
if ( !strcmp( gamedir, "." ) || !strcmp( gamedir, ".." ) |
| 3083 |
|| strchr( gamedir, '/' ) || strchr( gamedir, '\\' ) ) { |
| 3084 |
return qtrue; |
| 3085 |
} |
| 3086 |
|
| 3087 |
return qfalse; |
| 3088 |
} |
| 3089 |
|
| 3090 |
|
| 3091 |
|
| 3092 |
|
| 3093 |
|
| 3094 |
|
| 3095 |
|
| 3096 |
|
| 3097 |
|
| 3098 |
|
| 3099 |
|
| 3100 |
|
| 3101 |
|
| 3102 |
|
| 3103 |
|
| 3104 |
|
| 3105 |
|
| 3106 |
|
| 3107 |
|
| 3108 |
|
| 3109 |
|
| 3110 |
|
| 3111 |
|
| 3112 |
|
| 3113 |
|
| 3114 |
|
| 3115 |
|
| 3116 |
qboolean FS_ComparePaks( char *neededpaks, int len, qboolean dlstring ) { |
| 3117 |
searchpath_t *sp; |
| 3118 |
qboolean havepak; |
| 3119 |
char *origpos = neededpaks; |
| 3120 |
int i; |
| 3121 |
|
| 3122 |
if (!fs_numServerReferencedPaks) |
| 3123 |
return qfalse; |
| 3124 |
|
| 3125 |
*neededpaks = 0; |
| 3126 |
|
| 3127 |
for ( i = 0 ; i < fs_numServerReferencedPaks ; i++ ) |
| 3128 |
{ |
| 3129 |
|
| 3130 |
havepak = qfalse; |
| 3131 |
|
| 3132 |
|
| 3133 |
if(FS_idPak(fs_serverReferencedPakNames[i], BASEGAME, NUM_ID_PAKS) |
| 3134 |
#ifndef STANDALONE |
| 3135 |
|| FS_idPak(fs_serverReferencedPakNames[i], BASETA, NUM_TA_PAKS) |
| 3136 |
#endif |
| 3137 |
) |
| 3138 |
{ |
| 3139 |
continue; |
| 3140 |
} |
| 3141 |
|
| 3142 |
|
| 3143 |
if(FS_CheckDirTraversal(fs_serverReferencedPakNames[i])) |
| 3144 |
{ |
| 3145 |
Com_Printf("WARNING: Invalid download name %s\n", fs_serverReferencedPakNames[i]); |
| 3146 |
continue; |
| 3147 |
} |
| 3148 |
|
| 3149 |
for ( sp = fs_searchpaths ; sp ; sp = sp->next ) { |
| 3150 |
if ( sp->pack && sp->pack->checksum == fs_serverReferencedPaks[i] ) { |
| 3151 |
havepak = qtrue; |
| 3152 |
break; |
| 3153 |
} |
| 3154 |
} |
| 3155 |
|
| 3156 |
if ( !havepak && fs_serverReferencedPakNames[i] && *fs_serverReferencedPakNames[i] ) { |
| 3157 |
|
| 3158 |
|
| 3159 |
if (dlstring) |
| 3160 |
{ |
| 3161 |
|
| 3162 |
|
| 3163 |
|
| 3164 |
|
| 3165 |
origpos += strlen(origpos); |
| 3166 |
|
| 3167 |
|
| 3168 |
Q_strcat( neededpaks, len, "@"); |
| 3169 |
Q_strcat( neededpaks, len, fs_serverReferencedPakNames[i] ); |
| 3170 |
Q_strcat( neededpaks, len, ".pk3" ); |
| 3171 |
|
| 3172 |
|
| 3173 |
Q_strcat( neededpaks, len, "@"); |
| 3174 |
|
| 3175 |
if ( FS_BaseDir_FileExists_HomeData( va( "%s.pk3", fs_serverReferencedPakNames[i] ) ) ) |
| 3176 |
{ |
| 3177 |
char st[MAX_ZPATH]; |
| 3178 |
|
| 3179 |
|
| 3180 |
Com_sprintf( st, sizeof( st ), "%s.%08x.pk3", fs_serverReferencedPakNames[i], fs_serverReferencedPaks[i] ); |
| 3181 |
Q_strcat( neededpaks, len, st ); |
| 3182 |
} |
| 3183 |
else |
| 3184 |
{ |
| 3185 |
Q_strcat( neededpaks, len, fs_serverReferencedPakNames[i] ); |
| 3186 |
Q_strcat( neededpaks, len, ".pk3" ); |
| 3187 |
} |
| 3188 |
|
| 3189 |
|
| 3190 |
|
| 3191 |
if(strlen(origpos) + (origpos - neededpaks) >= len - 1) |
| 3192 |
{ |
| 3193 |
*origpos = '\0'; |
| 3194 |
break; |
| 3195 |
} |
| 3196 |
} |
| 3197 |
else |
| 3198 |
{ |
| 3199 |
Q_strcat( neededpaks, len, fs_serverReferencedPakNames[i] ); |
| 3200 |
Q_strcat( neededpaks, len, ".pk3" ); |
| 3201 |
|
| 3202 |
if ( FS_BaseDir_FileExists_HomeData( va( "%s.pk3", fs_serverReferencedPakNames[i] ) ) ) |
| 3203 |
{ |
| 3204 |
Q_strcat( neededpaks, len, " (local file exists with wrong checksum)"); |
| 3205 |
} |
| 3206 |
Q_strcat( neededpaks, len, "\n"); |
| 3207 |
} |
| 3208 |
} |
| 3209 |
} |
| 3210 |
|
| 3211 |
if ( *neededpaks ) { |
| 3212 |
return qtrue; |
| 3213 |
} |
| 3214 |
|
| 3215 |
return qfalse; |
| 3216 |
} |
| 3217 |
|
| 3218 |
|
| 3219 |
|
| 3220 |
|
| 3221 |
|
| 3222 |
|
| 3223 |
|
| 3224 |
|
| 3225 |
void FS_Shutdown( qboolean closemfp ) { |
| 3226 |
searchpath_t *p, *next; |
| 3227 |
int i; |
| 3228 |
|
| 3229 |
for(i = 0; i < MAX_FILE_HANDLES; i++) { |
| 3230 |
if (fsh[i].fileSize) { |
| 3231 |
FS_FCloseFile(i); |
| 3232 |
} |
| 3233 |
} |
| 3234 |
|
| 3235 |
|
| 3236 |
for(p = fs_searchpaths; p; p = next) |
| 3237 |
{ |
| 3238 |
next = p->next; |
| 3239 |
|
| 3240 |
if(p->pack) |
| 3241 |
FS_FreePak(p->pack); |
| 3242 |
if (p->dir) |
| 3243 |
Z_Free(p->dir); |
| 3244 |
|
| 3245 |
Z_Free(p); |
| 3246 |
} |
| 3247 |
|
| 3248 |
|
| 3249 |
fs_searchpaths = NULL; |
| 3250 |
|
| 3251 |
Cmd_RemoveCommand( "path" ); |
| 3252 |
Cmd_RemoveCommand( "dir" ); |
| 3253 |
Cmd_RemoveCommand( "fdir" ); |
| 3254 |
Cmd_RemoveCommand( "touchFile" ); |
| 3255 |
Cmd_RemoveCommand( "which" ); |
| 3256 |
|
| 3257 |
#ifdef FS_MISSING |
| 3258 |
if (closemfp) { |
| 3259 |
fclose(missingFiles); |
| 3260 |
} |
| 3261 |
#endif |
| 3262 |
} |
| 3263 |
|
| 3264 |
#ifndef STANDALONE |
| 3265 |
void Com_AppendCDKey( const char *filename ); |
| 3266 |
void Com_ReadCDKey( const char *filename ); |
| 3267 |
#endif |
| 3268 |
|
| 3269 |
|
| 3270 |
|
| 3271 |
|
| 3272 |
|
| 3273 |
|
| 3274 |
|
| 3275 |
|
| 3276 |
static void FS_ReorderPurePaks( void ) |
| 3277 |
{ |
| 3278 |
searchpath_t *s; |
| 3279 |
int i; |
| 3280 |
searchpath_t **p_insert_index, |
| 3281 |
**p_previous; |
| 3282 |
|
| 3283 |
fs_reordered = qfalse; |
| 3284 |
|
| 3285 |
|
| 3286 |
if ( !fs_numServerPaks ) |
| 3287 |
return; |
| 3288 |
|
| 3289 |
p_insert_index = &fs_searchpaths; |
| 3290 |
for ( i = 0 ; i < fs_numServerPaks ; i++ ) { |
| 3291 |
p_previous = p_insert_index; |
| 3292 |
for (s = *p_insert_index; s; s = s->next) { |
| 3293 |
|
| 3294 |
if (s->pack && fs_serverPaks[i] == s->pack->checksum) { |
| 3295 |
fs_reordered = qtrue; |
| 3296 |
|
| 3297 |
*p_previous = s->next; |
| 3298 |
s->next = *p_insert_index; |
| 3299 |
*p_insert_index = s; |
| 3300 |
|
| 3301 |
p_insert_index = &s->next; |
| 3302 |
break; |
| 3303 |
} |
| 3304 |
p_previous = &s->next; |
| 3305 |
} |
| 3306 |
} |
| 3307 |
} |
| 3308 |
|
| 3309 |
|
| 3310 |
|
| 3311 |
|
| 3312 |
|
| 3313 |
|
| 3314 |
static void FS_AddPathVar( cvar_t *pathVar ) { |
| 3315 |
if( !pathVar || !*pathVar->string ) { |
| 3316 |
return; |
| 3317 |
} |
| 3318 |
|
| 3319 |
|
| 3320 |
for( int i = 0; i < ARRAY_LEN( fs_pathVars ); i++ ) { |
| 3321 |
if ( fs_pathVars[i] && !Q_stricmp( fs_pathVars[i]->string, pathVar->string ) ) { |
| 3322 |
return; |
| 3323 |
} |
| 3324 |
} |
| 3325 |
|
| 3326 |
|
| 3327 |
for( int i = 0; i < ARRAY_LEN( fs_pathVars ); i++ ) { |
| 3328 |
if ( !fs_pathVars[i] ) { |
| 3329 |
fs_pathVars[i] = pathVar; |
| 3330 |
return; |
| 3331 |
} |
| 3332 |
} |
| 3333 |
|
| 3334 |
Com_Error( ERR_FATAL, "FS_AddPathVar: exhausted fs_pathVars array" ); |
| 3335 |
} |
| 3336 |
|
| 3337 |
|
| 3338 |
|
| 3339 |
|
| 3340 |
|
| 3341 |
|
| 3342 |
static void FS_InitPathVars( void ) { |
| 3343 |
memset( fs_pathVars, 0, sizeof( fs_pathVars ) ); |
| 3344 |
|
| 3345 |
FS_AddPathVar( fs_homeconfigpath ); |
| 3346 |
FS_AddPathVar( fs_homedatapath ); |
| 3347 |
FS_AddPathVar( fs_homestatepath ); |
| 3348 |
FS_AddPathVar( fs_basepath ); |
| 3349 |
FS_AddPathVar( fs_apppath ); |
| 3350 |
FS_AddPathVar( fs_steampath ); |
| 3351 |
FS_AddPathVar( fs_gogpath ); |
| 3352 |
FS_AddPathVar( fs_microsoftstorepath ); |
| 3353 |
} |
| 3354 |
|
| 3355 |
|
| 3356 |
|
| 3357 |
|
| 3358 |
|
| 3359 |
|
| 3360 |
static void FS_Startup( const char *gameName ) |
| 3361 |
{ |
| 3362 |
cvar_t *fs_homepath = Cvar_Get("fs_homepath", "", CVAR_INIT|CVAR_PROTECTED); |
| 3363 |
const char *configPath = Sys_DefaultHomeConfigPath(); |
| 3364 |
const char *dataPath = Sys_DefaultHomeDataPath(); |
| 3365 |
const char *statePath = Sys_DefaultHomeStatePath(); |
| 3366 |
|
| 3367 |
if(*(fs_homepath)->string) { |
| 3368 |
|
| 3369 |
configPath = dataPath = statePath = fs_homepath->string; |
| 3370 |
} else if(!*configPath || !*dataPath || !*statePath) { |
| 3371 |
|
| 3372 |
configPath = dataPath = statePath = Sys_DefaultInstallPath(); |
| 3373 |
} |
| 3374 |
|
| 3375 |
Com_Printf( "----- FS_Startup -----\n" ); |
| 3376 |
|
| 3377 |
fs_packFiles = 0; |
| 3378 |
|
| 3379 |
fs_debug = Cvar_Get( "fs_debug", "0", 0 ); |
| 3380 |
fs_basepath = Cvar_Get ("fs_basepath", Sys_DefaultInstallPath(), CVAR_INIT|CVAR_PROTECTED ); |
| 3381 |
fs_basegame = Cvar_Get ("fs_basegame", "", CVAR_INIT ); |
| 3382 |
fs_homeconfigpath = Cvar_Get ("fs_homeconfigpath", configPath, CVAR_INIT|CVAR_PROTECTED ); |
| 3383 |
fs_homedatapath = Cvar_Get ("fs_homedatapath", dataPath, CVAR_INIT|CVAR_PROTECTED ); |
| 3384 |
fs_homestatepath = Cvar_Get ("fs_homestatepath", statePath, CVAR_INIT|CVAR_PROTECTED ); |
| 3385 |
fs_gamedirvar = Cvar_Get ("fs_game", "", CVAR_INIT|CVAR_SYSTEMINFO ); |
| 3386 |
fs_steampath = Cvar_Get ("fs_steampath", Sys_SteamPath(), CVAR_INIT|CVAR_PROTECTED ); |
| 3387 |
fs_gogpath = Cvar_Get ("fs_gogpath", Sys_GogPath(), CVAR_INIT|CVAR_PROTECTED ); |
| 3388 |
fs_microsoftstorepath = Cvar_Get ("fs_microsoftstorepath", Sys_MicrosoftStorePath(), CVAR_INIT|CVAR_PROTECTED ); |
| 3389 |
|
| 3390 |
#ifdef __APPLE__ |
| 3391 |
fs_apppath = Cvar_Get ("fs_apppath", Sys_DefaultAppPath(), CVAR_INIT|CVAR_PROTECTED ); |
| 3392 |
#endif |
| 3393 |
|
| 3394 |
FS_InitPathVars( ); |
| 3395 |
|
| 3396 |
if (!gameName[0]) { |
| 3397 |
Cvar_ForceReset( "com_basegame" ); |
| 3398 |
} |
| 3399 |
|
| 3400 |
if (!FS_FilenameCompare(fs_gamedirvar->string, gameName)) { |
| 3401 |
|
| 3402 |
|
| 3403 |
|
| 3404 |
Cvar_ForceReset( "fs_game" ); |
| 3405 |
} |
| 3406 |
|
| 3407 |
if (FS_InvalidGameDir(gameName)) { |
| 3408 |
Com_Error( ERR_DROP, "Invalid com_basegame '%s'", gameName ); |
| 3409 |
} |
| 3410 |
if (FS_InvalidGameDir(fs_basegame->string)) { |
| 3411 |
Com_Error( ERR_DROP, "Invalid fs_basegame '%s'", fs_basegame->string ); |
| 3412 |
} |
| 3413 |
if (FS_InvalidGameDir(fs_gamedirvar->string)) { |
| 3414 |
Com_Error( ERR_DROP, "Invalid fs_game '%s'", fs_gamedirvar->string ); |
| 3415 |
} |
| 3416 |
|
| 3417 |
FS_CreatePath(fs_homeconfigpath->string); |
| 3418 |
FS_CreatePath(fs_homedatapath->string); |
| 3419 |
FS_CreatePath(fs_homestatepath->string); |
| 3420 |
|
| 3421 |
FS_AddGameDirectories(gameName); |
| 3422 |
|
| 3423 |
|
| 3424 |
if ( fs_basegame->string[0] && Q_stricmp( fs_basegame->string, gameName ) ) { |
| 3425 |
FS_AddGameDirectories(fs_basegame->string); |
| 3426 |
} |
| 3427 |
|
| 3428 |
|
| 3429 |
if ( fs_gamedirvar->string[0] && Q_stricmp( fs_gamedirvar->string, gameName ) ) { |
| 3430 |
FS_AddGameDirectories(fs_gamedirvar->string); |
| 3431 |
} |
| 3432 |
|
| 3433 |
#ifndef STANDALONE |
| 3434 |
if (!com_standalone->integer) { |
| 3435 |
Com_ReadCDKey(BASEGAME); |
| 3436 |
if (fs_gamedirvar->string[0]) { |
| 3437 |
Com_AppendCDKey(fs_gamedirvar->string); |
| 3438 |
} |
| 3439 |
} |
| 3440 |
#endif |
| 3441 |
|
| 3442 |
|
| 3443 |
Cmd_AddCommand ("path", FS_Path_f); |
| 3444 |
Cmd_AddCommand ("dir", FS_Dir_f ); |
| 3445 |
Cmd_AddCommand ("fdir", FS_NewDir_f ); |
| 3446 |
Cmd_AddCommand ("touchFile", FS_TouchFile_f ); |
| 3447 |
Cmd_AddCommand ("which", FS_Which_f ); |
| 3448 |
|
| 3449 |
|
| 3450 |
|
| 3451 |
FS_ReorderPurePaks(); |
| 3452 |
|
| 3453 |
|
| 3454 |
FS_Path_f(); |
| 3455 |
|
| 3456 |
fs_gamedirvar->modified = qfalse; |
| 3457 |
|
| 3458 |
Com_Printf( "----------------------\n" ); |
| 3459 |
|
| 3460 |
#ifdef FS_MISSING |
| 3461 |
if (missingFiles == NULL) { |
| 3462 |
missingFiles = Sys_FOpen( "\\missing.txt", "ab" ); |
| 3463 |
} |
| 3464 |
#endif |
| 3465 |
Com_Printf( "%d files in pk3 files\n", fs_packFiles ); |
| 3466 |
} |
| 3467 |
|
| 3468 |
#ifndef STANDALONE |
| 3469 |
|
| 3470 |
|
| 3471 |
|
| 3472 |
|
| 3473 |
|
| 3474 |
static void FS_AppendUserFriendlyPakList( char *buf, size_t bufsize, int foundPakFiles, int numPakFiles ) |
| 3475 |
{ |
| 3476 |
int missingCount = 0; |
| 3477 |
int missingIndex = 0; |
| 3478 |
int missingMin = numPakFiles; |
| 3479 |
int missingMax = 0; |
| 3480 |
qboolean missingConsecutive = qtrue; |
| 3481 |
int i; |
| 3482 |
|
| 3483 |
for ( i = 0; i < numPakFiles; i++ ) { |
| 3484 |
if ( foundPakFiles & ( 1 << i ) ) { |
| 3485 |
continue; |
| 3486 |
} |
| 3487 |
|
| 3488 |
missingCount++; |
| 3489 |
|
| 3490 |
if ( missingMin > i ) { |
| 3491 |
missingMin = i; |
| 3492 |
} |
| 3493 |
if ( missingMax < i ) { |
| 3494 |
missingMax = i; |
| 3495 |
} |
| 3496 |
|
| 3497 |
if ( i > missingMin && ( foundPakFiles & ( 1<< ( i - 1 ) ) ) ) { |
| 3498 |
missingConsecutive = qfalse; |
| 3499 |
} |
| 3500 |
} |
| 3501 |
|
| 3502 |
if ( missingConsecutive && missingMax >= missingMin + 2 ) { |
| 3503 |
Q_strcat( buf, bufsize, |
| 3504 |
va( " \"pak%d.pk3\" through \"pak%d.pk3\"", |
| 3505 |
missingMin, missingMax ) ); |
| 3506 |
} else { |
| 3507 |
for ( i = 0; i < numPakFiles; i++ ) { |
| 3508 |
if ( foundPakFiles & (1<<i) ) { |
| 3509 |
continue; |
| 3510 |
} |
| 3511 |
|
| 3512 |
if ( missingIndex > 0 && missingCount > 2 ) { |
| 3513 |
Q_strcat( buf, bufsize, "," ); |
| 3514 |
} |
| 3515 |
|
| 3516 |
if ( missingIndex == missingCount - 1 && missingCount > 1 ) { |
| 3517 |
Q_strcat( buf, bufsize, " and" ); |
| 3518 |
} |
| 3519 |
|
| 3520 |
Q_strcat( buf, bufsize, va( " \"pak%d.pk3\"", i ) ); |
| 3521 |
|
| 3522 |
missingIndex++; |
| 3523 |
} |
| 3524 |
} |
| 3525 |
} |
| 3526 |
|
| 3527 |
|
| 3528 |
|
| 3529 |
|
| 3530 |
|
| 3531 |
|
| 3532 |
|
| 3533 |
|
| 3534 |
|
| 3535 |
|
| 3536 |
|
| 3537 |
|
| 3538 |
|
| 3539 |
static void FS_CheckPak0( void ) |
| 3540 |
{ |
| 3541 |
searchpath_t *path; |
| 3542 |
pack_t *curpack; |
| 3543 |
const char *pakBasename; |
| 3544 |
qboolean founddemo = qfalse; |
| 3545 |
unsigned int foundPak = 0, foundTA = 0; |
| 3546 |
qboolean installHome = qfalse; |
| 3547 |
char *installPath; |
| 3548 |
|
| 3549 |
for( path = fs_searchpaths; path; path = path->next ) |
| 3550 |
{ |
| 3551 |
if(!path->pack) |
| 3552 |
continue; |
| 3553 |
|
| 3554 |
curpack = path->pack; |
| 3555 |
pakBasename = curpack->pakBasename; |
| 3556 |
|
| 3557 |
if(!Q_stricmpn( curpack->pakGamename, "demoq3", MAX_OSPATH ) |
| 3558 |
&& !Q_stricmpn( pakBasename, "pak0", MAX_OSPATH )) |
| 3559 |
{ |
| 3560 |
if(curpack->checksum == DEMO_PAK0_CHECKSUM) |
| 3561 |
founddemo = qtrue; |
| 3562 |
} |
| 3563 |
|
| 3564 |
else if(!Q_stricmpn( curpack->pakGamename, BASEGAME, MAX_OSPATH ) |
| 3565 |
&& strlen(pakBasename) == 4 && !Q_stricmpn( pakBasename, "pak", 3 ) |
| 3566 |
&& pakBasename[3] >= '0' && pakBasename[3] <= '0' + NUM_ID_PAKS - 1) |
| 3567 |
{ |
| 3568 |
if( curpack->checksum != pak_checksums[pakBasename[3]-'0'] ) |
| 3569 |
{ |
| 3570 |
if(pakBasename[3] == '0') |
| 3571 |
{ |
| 3572 |
Com_Printf("\n\n" |
| 3573 |
"**************************************************\n" |
| 3574 |
"WARNING: " BASEGAME "/pak0.pk3 is present but its checksum (%u)\n" |
| 3575 |
"is not correct. Please re-copy pak0.pk3 from your\n" |
| 3576 |
"legitimate Q3 CDROM.\n" |
| 3577 |
"**************************************************\n\n\n", |
| 3578 |
curpack->checksum ); |
| 3579 |
} |
| 3580 |
else |
| 3581 |
{ |
| 3582 |
Com_Printf("\n\n" |
| 3583 |
"**************************************************\n" |
| 3584 |
"WARNING: " BASEGAME "/pak%d.pk3 is present but its checksum (%u)\n" |
| 3585 |
"is not correct. Please re-install the point release\n" |
| 3586 |
"**************************************************\n\n\n", |
| 3587 |
pakBasename[3]-'0', curpack->checksum ); |
| 3588 |
} |
| 3589 |
} |
| 3590 |
|
| 3591 |
foundPak |= 1<<(pakBasename[3]-'0'); |
| 3592 |
} |
| 3593 |
else if(!Q_stricmpn(curpack->pakGamename, BASETA, MAX_OSPATH) |
| 3594 |
&& strlen(pakBasename) == 4 && !Q_stricmpn(pakBasename, "pak", 3) |
| 3595 |
&& pakBasename[3] >= '0' && pakBasename[3] <= '0' + NUM_TA_PAKS - 1) |
| 3596 |
|
| 3597 |
{ |
| 3598 |
if(curpack->checksum != missionpak_checksums[pakBasename[3]-'0']) |
| 3599 |
{ |
| 3600 |
Com_Printf("\n\n" |
| 3601 |
"**************************************************\n" |
| 3602 |
"WARNING: " BASETA "/pak%d.pk3 is present but its checksum (%u)\n" |
| 3603 |
"is not correct. Please re-install Team Arena\n" |
| 3604 |
"**************************************************\n\n\n", |
| 3605 |
pakBasename[3]-'0', curpack->checksum ); |
| 3606 |
} |
| 3607 |
|
| 3608 |
foundTA |= 1 << (pakBasename[3]-'0'); |
| 3609 |
} |
| 3610 |
else |
| 3611 |
{ |
| 3612 |
int index; |
| 3613 |
|
| 3614 |
|
| 3615 |
|
| 3616 |
|
| 3617 |
for(index = 0; index < ARRAY_LEN(pak_checksums); index++) |
| 3618 |
{ |
| 3619 |
if(curpack->checksum == pak_checksums[index]) |
| 3620 |
{ |
| 3621 |
Com_Printf("\n\n" |
| 3622 |
"**************************************************\n" |
| 3623 |
"WARNING: %s is renamed pak file %s%cpak%d.pk3\n" |
| 3624 |
"Running in standalone mode won't work\n" |
| 3625 |
"Please rename, or remove this file\n" |
| 3626 |
"**************************************************\n\n\n", |
| 3627 |
curpack->pakFilename, BASEGAME, PATH_SEP, index); |
| 3628 |
|
| 3629 |
|
| 3630 |
foundPak |= 0x80000000; |
| 3631 |
} |
| 3632 |
} |
| 3633 |
|
| 3634 |
for(index = 0; index < ARRAY_LEN(missionpak_checksums); index++) |
| 3635 |
{ |
| 3636 |
if(curpack->checksum == missionpak_checksums[index]) |
| 3637 |
{ |
| 3638 |
Com_Printf("\n\n" |
| 3639 |
"**************************************************\n" |
| 3640 |
"WARNING: %s is renamed pak file %s%cpak%d.pk3\n" |
| 3641 |
"Running in standalone mode won't work\n" |
| 3642 |
"Please rename, or remove this file\n" |
| 3643 |
"**************************************************\n\n\n", |
| 3644 |
curpack->pakFilename, BASETA, PATH_SEP, index); |
| 3645 |
|
| 3646 |
foundTA |= 0x80000000; |
| 3647 |
} |
| 3648 |
} |
| 3649 |
} |
| 3650 |
} |
| 3651 |
|
| 3652 |
if(!foundPak && !foundTA && Q_stricmp(com_basegame->string, BASEGAME)) |
| 3653 |
{ |
| 3654 |
Cvar_Set("com_standalone", "1"); |
| 3655 |
} |
| 3656 |
else |
| 3657 |
Cvar_Set("com_standalone", "0"); |
| 3658 |
|
| 3659 |
if(!com_standalone->integer) |
| 3660 |
{ |
| 3661 |
if(!(foundPak & 0x01)) |
| 3662 |
{ |
| 3663 |
if(founddemo) |
| 3664 |
{ |
| 3665 |
Com_Printf( "\n\n" |
| 3666 |
"**************************************************\n" |
| 3667 |
"WARNING: It looks like you're using pak0.pk3\n" |
| 3668 |
"from the demo. This may work fine, but it is not\n" |
| 3669 |
"guaranteed or supported.\n" |
| 3670 |
"**************************************************\n\n\n" ); |
| 3671 |
|
| 3672 |
foundPak |= 0x01; |
| 3673 |
} |
| 3674 |
} |
| 3675 |
} |
| 3676 |
|
| 3677 |
#if defined(__linux__) |
| 3678 |
{ |
| 3679 |
const char *p; |
| 3680 |
|
| 3681 |
|
| 3682 |
if( ( p = getenv( "FLATPAK_ID" ) ) != NULL && *p != '\0' ) |
| 3683 |
installHome = qtrue; |
| 3684 |
} |
| 3685 |
#elif defined(__APPLE__) |
| 3686 |
|
| 3687 |
|
| 3688 |
if( strstr( fs_apppath->string, "Contents/MacOS" ) ) |
| 3689 |
installHome = qtrue; |
| 3690 |
#endif |
| 3691 |
|
| 3692 |
if(installHome) |
| 3693 |
installPath = fs_homedatapath->string; |
| 3694 |
else |
| 3695 |
installPath = fs_basepath->string; |
| 3696 |
|
| 3697 |
if(!com_standalone->integer && (foundPak & ((1<<NUM_ID_PAKS)-1)) != ((1<<NUM_ID_PAKS)-1)) |
| 3698 |
{ |
| 3699 |
char errorText[MAX_STRING_CHARS] = ""; |
| 3700 |
char gamePath[MAX_OSPATH]; |
| 3701 |
|
| 3702 |
Com_sprintf(gamePath, sizeof(gamePath), "%s%c%s%c", |
| 3703 |
installPath, PATH_SEP, BASEGAME, PATH_SEP); |
| 3704 |
|
| 3705 |
Q_strcat(errorText, sizeof(errorText), |
| 3706 |
"Quake 3 data files are missing. Please copy"); |
| 3707 |
|
| 3708 |
FS_AppendUserFriendlyPakList(errorText, sizeof(errorText), foundPak, NUM_ID_PAKS); |
| 3709 |
|
| 3710 |
Q_strcat(errorText, sizeof(errorText), |
| 3711 |
va(" from the \"%s\" directory in your Quake 3 install or CD-ROM to:\n\n" |
| 3712 |
"%s\n\n", BASEGAME, gamePath)); |
| 3713 |
|
| 3714 |
Q_strcat(errorText, sizeof(errorText), |
| 3715 |
"Quake 3 must be purchased to legitimately obtain pak0. " |
| 3716 |
"Quake 3 1.32 point release files (pak1 through pak8) " |
| 3717 |
"are freely available. For details see:\n\n" |
| 3718 |
"https://buy.ioquake3.org\n\n"); |
| 3719 |
|
| 3720 |
if(installHome) |
| 3721 |
{ |
| 3722 |
Q_strcat(errorText, sizeof(errorText), |
| 3723 |
va("Also check that every file " |
| 3724 |
"in the \"%s\" directory is present and readable", BASEGAME)); |
| 3725 |
} |
| 3726 |
else |
| 3727 |
{ |
| 3728 |
Q_strcat(errorText, sizeof(errorText), |
| 3729 |
va("Also check that your ioq3 executable is in " |
| 3730 |
"the correct place and that every file " |
| 3731 |
"in the \"%s\" directory is present and readable", BASEGAME)); |
| 3732 |
} |
| 3733 |
|
| 3734 |
Sys_OpenFolderInFileManager(gamePath, qtrue); |
| 3735 |
Com_Error(ERR_FATAL, "%s", errorText); |
| 3736 |
} |
| 3737 |
|
| 3738 |
if(!com_standalone->integer && (foundTA & ((1<<NUM_TA_PAKS)-1)) != ((1<<NUM_TA_PAKS)-1) |
| 3739 |
&& (!Q_stricmp(fs_gamedirvar->string, BASETA) || !Q_stricmp(fs_basegame->string, BASETA))) |
| 3740 |
{ |
| 3741 |
char errorText[MAX_STRING_CHARS] = ""; |
| 3742 |
char gamePath[MAX_OSPATH]; |
| 3743 |
|
| 3744 |
Com_sprintf(gamePath, sizeof(gamePath), "%s%c%s%c", |
| 3745 |
installPath, PATH_SEP, BASETA, PATH_SEP); |
| 3746 |
|
| 3747 |
Q_strcat(errorText, sizeof(errorText), |
| 3748 |
"Quake 3 Team Arena data files are missing. Please copy"); |
| 3749 |
|
| 3750 |
FS_AppendUserFriendlyPakList(errorText, sizeof(errorText), foundTA, NUM_TA_PAKS); |
| 3751 |
|
| 3752 |
Q_strcat(errorText, sizeof(errorText), |
| 3753 |
va(" from the \"%s\" directory in your Quake 3 Team Arena install or CD-ROM to:\n\n" |
| 3754 |
"%s\n\n", BASETA, gamePath)); |
| 3755 |
|
| 3756 |
Q_strcat(errorText, sizeof(errorText), |
| 3757 |
"Quake 3 Team Arena must be purchased to legitimately obtain pak0. " |
| 3758 |
"Quake 3 Team Arena point release files (pak1 through pak3) " |
| 3759 |
"are freely available. For details see:\n\n" |
| 3760 |
"https://buy.ioquake3.org\n\n"); |
| 3761 |
|
| 3762 |
if(installHome) |
| 3763 |
{ |
| 3764 |
Q_strcat(errorText, sizeof(errorText), |
| 3765 |
va("Also check that every file " |
| 3766 |
"in the \"%s\" directory is present and readable", BASETA)); |
| 3767 |
} |
| 3768 |
else |
| 3769 |
{ |
| 3770 |
Q_strcat(errorText, sizeof(errorText), |
| 3771 |
va("Also check that your ioq3 executable is in " |
| 3772 |
"the correct place and that every file " |
| 3773 |
"in the \"%s\" directory is present and readable", BASETA)); |
| 3774 |
} |
| 3775 |
|
| 3776 |
Sys_OpenFolderInFileManager(gamePath, qtrue); |
| 3777 |
Com_Error(ERR_FATAL, "%s", errorText); |
| 3778 |
} |
| 3779 |
} |
| 3780 |
#endif |
| 3781 |
|
| 3782 |
|
| 3783 |
|
| 3784 |
|
| 3785 |
|
| 3786 |
|
| 3787 |
|
| 3788 |
|
| 3789 |
|
| 3790 |
const char *FS_LoadedPakChecksums( void ) { |
| 3791 |
static char info[BIG_INFO_STRING]; |
| 3792 |
searchpath_t *search; |
| 3793 |
|
| 3794 |
info[0] = 0; |
| 3795 |
|
| 3796 |
for ( search = fs_searchpaths ; search ; search = search->next ) { |
| 3797 |
|
| 3798 |
if ( !search->pack ) { |
| 3799 |
continue; |
| 3800 |
} |
| 3801 |
|
| 3802 |
Q_strcat( info, sizeof( info ), va("%i ", search->pack->checksum ) ); |
| 3803 |
} |
| 3804 |
|
| 3805 |
return info; |
| 3806 |
} |
| 3807 |
|
| 3808 |
|
| 3809 |
|
| 3810 |
|
| 3811 |
|
| 3812 |
|
| 3813 |
|
| 3814 |
|
| 3815 |
|
| 3816 |
const char *FS_LoadedPakNames( void ) { |
| 3817 |
static char info[BIG_INFO_STRING]; |
| 3818 |
searchpath_t *search; |
| 3819 |
|
| 3820 |
info[0] = 0; |
| 3821 |
|
| 3822 |
for ( search = fs_searchpaths ; search ; search = search->next ) { |
| 3823 |
|
| 3824 |
if ( !search->pack ) { |
| 3825 |
continue; |
| 3826 |
} |
| 3827 |
|
| 3828 |
if (*info) { |
| 3829 |
Q_strcat(info, sizeof( info ), " " ); |
| 3830 |
} |
| 3831 |
Q_strcat( info, sizeof( info ), search->pack->pakBasename ); |
| 3832 |
} |
| 3833 |
|
| 3834 |
return info; |
| 3835 |
} |
| 3836 |
|
| 3837 |
|
| 3838 |
|
| 3839 |
|
| 3840 |
|
| 3841 |
|
| 3842 |
|
| 3843 |
|
| 3844 |
|
| 3845 |
|
| 3846 |
const char *FS_LoadedPakPureChecksums( void ) { |
| 3847 |
static char info[BIG_INFO_STRING]; |
| 3848 |
searchpath_t *search; |
| 3849 |
|
| 3850 |
info[0] = 0; |
| 3851 |
|
| 3852 |
for ( search = fs_searchpaths ; search ; search = search->next ) { |
| 3853 |
|
| 3854 |
if ( !search->pack ) { |
| 3855 |
continue; |
| 3856 |
} |
| 3857 |
|
| 3858 |
Q_strcat( info, sizeof( info ), va("%i ", search->pack->pure_checksum ) ); |
| 3859 |
} |
| 3860 |
|
| 3861 |
return info; |
| 3862 |
} |
| 3863 |
|
| 3864 |
|
| 3865 |
|
| 3866 |
|
| 3867 |
|
| 3868 |
|
| 3869 |
|
| 3870 |
|
| 3871 |
|
| 3872 |
const char *FS_ReferencedPakChecksums( void ) { |
| 3873 |
static char info[BIG_INFO_STRING]; |
| 3874 |
searchpath_t *search; |
| 3875 |
|
| 3876 |
info[0] = 0; |
| 3877 |
|
| 3878 |
|
| 3879 |
for ( search = fs_searchpaths ; search ; search = search->next ) { |
| 3880 |
|
| 3881 |
if ( search->pack ) { |
| 3882 |
if (search->pack->referenced || Q_stricmpn(search->pack->pakGamename, com_basegame->string, strlen(com_basegame->string))) { |
| 3883 |
Q_strcat( info, sizeof( info ), va("%i ", search->pack->checksum ) ); |
| 3884 |
} |
| 3885 |
} |
| 3886 |
} |
| 3887 |
|
| 3888 |
return info; |
| 3889 |
} |
| 3890 |
|
| 3891 |
|
| 3892 |
|
| 3893 |
|
| 3894 |
|
| 3895 |
|
| 3896 |
|
| 3897 |
|
| 3898 |
|
| 3899 |
|
| 3900 |
|
| 3901 |
const char *FS_ReferencedPakPureChecksums( void ) { |
| 3902 |
static char info[BIG_INFO_STRING]; |
| 3903 |
searchpath_t *search; |
| 3904 |
int nFlags, numPaks, checksum; |
| 3905 |
|
| 3906 |
info[0] = 0; |
| 3907 |
|
| 3908 |
checksum = fs_checksumFeed; |
| 3909 |
numPaks = 0; |
| 3910 |
for (nFlags = FS_CGAME_REF; nFlags; nFlags = nFlags >> 1) { |
| 3911 |
if (nFlags & FS_GENERAL_REF) { |
| 3912 |
|
| 3913 |
|
| 3914 |
info[strlen(info)+1] = '\0'; |
| 3915 |
info[strlen(info)+2] = '\0'; |
| 3916 |
info[strlen(info)] = '@'; |
| 3917 |
info[strlen(info)] = ' '; |
| 3918 |
} |
| 3919 |
for ( search = fs_searchpaths ; search ; search = search->next ) { |
| 3920 |
|
| 3921 |
if ( search->pack && (search->pack->referenced & nFlags)) { |
| 3922 |
Q_strcat( info, sizeof( info ), va("%i ", search->pack->pure_checksum ) ); |
| 3923 |
if (nFlags & (FS_CGAME_REF | FS_UI_REF)) { |
| 3924 |
break; |
| 3925 |
} |
| 3926 |
checksum ^= search->pack->pure_checksum; |
| 3927 |
numPaks++; |
| 3928 |
} |
| 3929 |
} |
| 3930 |
} |
| 3931 |
|
| 3932 |
checksum ^= numPaks; |
| 3933 |
Q_strcat( info, sizeof( info ), va("%i ", checksum ) ); |
| 3934 |
|
| 3935 |
return info; |
| 3936 |
} |
| 3937 |
|
| 3938 |
|
| 3939 |
|
| 3940 |
|
| 3941 |
|
| 3942 |
|
| 3943 |
|
| 3944 |
|
| 3945 |
|
| 3946 |
const char *FS_ReferencedPakNames( void ) { |
| 3947 |
static char info[BIG_INFO_STRING]; |
| 3948 |
searchpath_t *search; |
| 3949 |
|
| 3950 |
info[0] = 0; |
| 3951 |
|
| 3952 |
|
| 3953 |
|
| 3954 |
for ( search = fs_searchpaths ; search ; search = search->next ) { |
| 3955 |
|
| 3956 |
if ( search->pack ) { |
| 3957 |
if (search->pack->referenced || Q_stricmpn(search->pack->pakGamename, com_basegame->string, strlen(com_basegame->string))) { |
| 3958 |
if (*info) { |
| 3959 |
Q_strcat(info, sizeof( info ), " " ); |
| 3960 |
} |
| 3961 |
Q_strcat( info, sizeof( info ), search->pack->pakGamename ); |
| 3962 |
Q_strcat( info, sizeof( info ), "/" ); |
| 3963 |
Q_strcat( info, sizeof( info ), search->pack->pakBasename ); |
| 3964 |
} |
| 3965 |
} |
| 3966 |
} |
| 3967 |
|
| 3968 |
return info; |
| 3969 |
} |
| 3970 |
|
| 3971 |
|
| 3972 |
|
| 3973 |
|
| 3974 |
|
| 3975 |
|
| 3976 |
void FS_ClearPakReferences( int flags ) { |
| 3977 |
searchpath_t *search; |
| 3978 |
|
| 3979 |
if ( !flags ) { |
| 3980 |
flags = -1; |
| 3981 |
} |
| 3982 |
for ( search = fs_searchpaths; search; search = search->next ) { |
| 3983 |
|
| 3984 |
if ( search->pack ) { |
| 3985 |
search->pack->referenced &= ~flags; |
| 3986 |
} |
| 3987 |
} |
| 3988 |
} |
| 3989 |
|
| 3990 |
|
| 3991 |
|
| 3992 |
|
| 3993 |
|
| 3994 |
|
| 3995 |
|
| 3996 |
|
| 3997 |
|
| 3998 |
|
| 3999 |
|
| 4000 |
|
| 4001 |
void FS_PureServerSetLoadedPaks( const char *pakSums, const char *pakNames ) { |
| 4002 |
int i, c, d; |
| 4003 |
|
| 4004 |
Cmd_TokenizeString( pakSums ); |
| 4005 |
|
| 4006 |
c = Cmd_Argc(); |
| 4007 |
if ( c > MAX_SEARCH_PATHS ) { |
| 4008 |
c = MAX_SEARCH_PATHS; |
| 4009 |
} |
| 4010 |
|
| 4011 |
fs_numServerPaks = c; |
| 4012 |
|
| 4013 |
for ( i = 0 ; i < c ; i++ ) { |
| 4014 |
fs_serverPaks[i] = atoi( Cmd_Argv( i ) ); |
| 4015 |
} |
| 4016 |
|
| 4017 |
if (fs_numServerPaks) { |
| 4018 |
Com_DPrintf( "Connected to a pure server.\n" ); |
| 4019 |
} |
| 4020 |
else |
| 4021 |
{ |
| 4022 |
if (fs_reordered) |
| 4023 |
{ |
| 4024 |
|
| 4025 |
|
| 4026 |
Com_DPrintf( "FS search reorder is required\n" ); |
| 4027 |
FS_Restart(fs_checksumFeed); |
| 4028 |
return; |
| 4029 |
} |
| 4030 |
} |
| 4031 |
|
| 4032 |
for ( i = 0 ; i < c ; i++ ) { |
| 4033 |
if (fs_serverPakNames[i]) { |
| 4034 |
Z_Free(fs_serverPakNames[i]); |
| 4035 |
} |
| 4036 |
fs_serverPakNames[i] = NULL; |
| 4037 |
} |
| 4038 |
if ( pakNames && *pakNames ) { |
| 4039 |
Cmd_TokenizeString( pakNames ); |
| 4040 |
|
| 4041 |
d = Cmd_Argc(); |
| 4042 |
if ( d > MAX_SEARCH_PATHS ) { |
| 4043 |
d = MAX_SEARCH_PATHS; |
| 4044 |
} |
| 4045 |
|
| 4046 |
for ( i = 0 ; i < d ; i++ ) { |
| 4047 |
fs_serverPakNames[i] = CopyString( Cmd_Argv( i ) ); |
| 4048 |
} |
| 4049 |
} |
| 4050 |
} |
| 4051 |
|
| 4052 |
|
| 4053 |
|
| 4054 |
|
| 4055 |
|
| 4056 |
|
| 4057 |
|
| 4058 |
|
| 4059 |
|
| 4060 |
|
| 4061 |
void FS_PureServerSetReferencedPaks( const char *pakSums, const char *pakNames ) { |
| 4062 |
int i, c, d = 0; |
| 4063 |
|
| 4064 |
Cmd_TokenizeString( pakSums ); |
| 4065 |
|
| 4066 |
c = Cmd_Argc(); |
| 4067 |
if ( c > MAX_SEARCH_PATHS ) { |
| 4068 |
c = MAX_SEARCH_PATHS; |
| 4069 |
} |
| 4070 |
|
| 4071 |
for ( i = 0 ; i < c ; i++ ) { |
| 4072 |
fs_serverReferencedPaks[i] = atoi( Cmd_Argv( i ) ); |
| 4073 |
} |
| 4074 |
|
| 4075 |
for (i = 0 ; i < ARRAY_LEN(fs_serverReferencedPakNames); i++) |
| 4076 |
{ |
| 4077 |
if(fs_serverReferencedPakNames[i]) |
| 4078 |
Z_Free(fs_serverReferencedPakNames[i]); |
| 4079 |
|
| 4080 |
fs_serverReferencedPakNames[i] = NULL; |
| 4081 |
} |
| 4082 |
|
| 4083 |
if ( pakNames && *pakNames ) { |
| 4084 |
Cmd_TokenizeString( pakNames ); |
| 4085 |
|
| 4086 |
d = Cmd_Argc(); |
| 4087 |
|
| 4088 |
if(d > c) |
| 4089 |
d = c; |
| 4090 |
|
| 4091 |
for ( i = 0 ; i < d ; i++ ) { |
| 4092 |
fs_serverReferencedPakNames[i] = CopyString( Cmd_Argv( i ) ); |
| 4093 |
} |
| 4094 |
} |
| 4095 |
|
| 4096 |
|
| 4097 |
if(d < c) |
| 4098 |
c = d; |
| 4099 |
|
| 4100 |
fs_numServerReferencedPaks = c; |
| 4101 |
} |
| 4102 |
|
| 4103 |
|
| 4104 |
|
| 4105 |
|
| 4106 |
|
| 4107 |
|
| 4108 |
|
| 4109 |
|
| 4110 |
|
| 4111 |
void FS_InitFilesystem( void ) { |
| 4112 |
|
| 4113 |
|
| 4114 |
|
| 4115 |
|
| 4116 |
Com_StartupVariable("fs_basepath"); |
| 4117 |
Com_StartupVariable("fs_homepath"); |
| 4118 |
Com_StartupVariable("fs_homeconfigpath"); |
| 4119 |
Com_StartupVariable("fs_homedatapath"); |
| 4120 |
Com_StartupVariable("fs_homestatepath"); |
| 4121 |
Com_StartupVariable("fs_game"); |
| 4122 |
|
| 4123 |
if(!FS_FilenameCompare(Cvar_VariableString("fs_game"), com_basegame->string)) |
| 4124 |
Cvar_Set("fs_game", ""); |
| 4125 |
|
| 4126 |
|
| 4127 |
FS_Startup(com_basegame->string); |
| 4128 |
|
| 4129 |
#ifndef STANDALONE |
| 4130 |
FS_CheckPak0( ); |
| 4131 |
#endif |
| 4132 |
|
| 4133 |
|
| 4134 |
|
| 4135 |
|
| 4136 |
if ( FS_ReadFile( "default.cfg", NULL ) <= 0 ) { |
| 4137 |
Com_Error( ERR_FATAL, "Couldn't load default.cfg" ); |
| 4138 |
} |
| 4139 |
|
| 4140 |
Q_strncpyz(lastValidBase, fs_basepath->string, sizeof(lastValidBase)); |
| 4141 |
Q_strncpyz(lastValidComBaseGame, com_basegame->string, sizeof(lastValidComBaseGame)); |
| 4142 |
Q_strncpyz(lastValidFsBaseGame, fs_basegame->string, sizeof(lastValidFsBaseGame)); |
| 4143 |
Q_strncpyz(lastValidGame, fs_gamedirvar->string, sizeof(lastValidGame)); |
| 4144 |
} |
| 4145 |
|
| 4146 |
|
| 4147 |
|
| 4148 |
|
| 4149 |
|
| 4150 |
|
| 4151 |
|
| 4152 |
void FS_Restart( int checksumFeed ) { |
| 4153 |
const char *lastGameDir; |
| 4154 |
|
| 4155 |
|
| 4156 |
FS_Shutdown(qfalse); |
| 4157 |
|
| 4158 |
|
| 4159 |
fs_checksumFeed = checksumFeed; |
| 4160 |
|
| 4161 |
|
| 4162 |
FS_ClearPakReferences(0); |
| 4163 |
|
| 4164 |
|
| 4165 |
FS_Startup(com_basegame->string); |
| 4166 |
|
| 4167 |
#ifndef STANDALONE |
| 4168 |
FS_CheckPak0( ); |
| 4169 |
#endif |
| 4170 |
|
| 4171 |
|
| 4172 |
|
| 4173 |
|
| 4174 |
if ( FS_ReadFile( "default.cfg", NULL ) <= 0 ) { |
| 4175 |
|
| 4176 |
|
| 4177 |
if (lastValidBase[0]) { |
| 4178 |
FS_PureServerSetLoadedPaks("", ""); |
| 4179 |
Cvar_Set("fs_basepath", lastValidBase); |
| 4180 |
Cvar_Set("com_basegame", lastValidComBaseGame); |
| 4181 |
Cvar_Set("fs_basegame", lastValidFsBaseGame); |
| 4182 |
Cvar_Set("fs_game", lastValidGame); |
| 4183 |
lastValidBase[0] = '\0'; |
| 4184 |
lastValidComBaseGame[0] = '\0'; |
| 4185 |
lastValidFsBaseGame[0] = '\0'; |
| 4186 |
lastValidGame[0] = '\0'; |
| 4187 |
FS_Restart(checksumFeed); |
| 4188 |
Com_Error( ERR_DROP, "Invalid game folder" ); |
| 4189 |
return; |
| 4190 |
} |
| 4191 |
Com_Error( ERR_FATAL, "Couldn't load default.cfg" ); |
| 4192 |
} |
| 4193 |
|
| 4194 |
lastGameDir = ( lastValidGame[0] ) ? lastValidGame : lastValidComBaseGame; |
| 4195 |
|
| 4196 |
if ( Q_stricmp( FS_GetCurrentGameDir(), lastGameDir ) ) { |
| 4197 |
Sys_RemovePIDFile( lastGameDir ); |
| 4198 |
Sys_InitPIDFile( FS_GetCurrentGameDir() ); |
| 4199 |
|
| 4200 |
|
| 4201 |
if ( !Com_SafeMode() ) { |
| 4202 |
Cbuf_AddText ("exec " Q3CONFIG_CFG "\n"); |
| 4203 |
} |
| 4204 |
} |
| 4205 |
|
| 4206 |
Q_strncpyz(lastValidBase, fs_basepath->string, sizeof(lastValidBase)); |
| 4207 |
Q_strncpyz(lastValidComBaseGame, com_basegame->string, sizeof(lastValidComBaseGame)); |
| 4208 |
Q_strncpyz(lastValidFsBaseGame, fs_basegame->string, sizeof(lastValidFsBaseGame)); |
| 4209 |
Q_strncpyz(lastValidGame, fs_gamedirvar->string, sizeof(lastValidGame)); |
| 4210 |
|
| 4211 |
} |
| 4212 |
|
| 4213 |
|
| 4214 |
|
| 4215 |
|
| 4216 |
|
| 4217 |
|
| 4218 |
|
| 4219 |
|
| 4220 |
|
| 4221 |
qboolean FS_ConditionalRestart(int checksumFeed, qboolean disconnect) |
| 4222 |
{ |
| 4223 |
if(fs_gamedirvar->modified) |
| 4224 |
{ |
| 4225 |
if(FS_FilenameCompare(lastValidGame, fs_gamedirvar->string) && |
| 4226 |
(*lastValidGame || FS_FilenameCompare(fs_gamedirvar->string, com_basegame->string)) && |
| 4227 |
(*fs_gamedirvar->string || FS_FilenameCompare(lastValidGame, com_basegame->string))) |
| 4228 |
{ |
| 4229 |
Com_GameRestart(checksumFeed, disconnect); |
| 4230 |
return qtrue; |
| 4231 |
} |
| 4232 |
else |
| 4233 |
fs_gamedirvar->modified = qfalse; |
| 4234 |
} |
| 4235 |
|
| 4236 |
if(checksumFeed != fs_checksumFeed) |
| 4237 |
FS_Restart(checksumFeed); |
| 4238 |
else if(fs_numServerPaks && !fs_reordered) |
| 4239 |
FS_ReorderPurePaks(); |
| 4240 |
|
| 4241 |
return qfalse; |
| 4242 |
} |
| 4243 |
|
| 4244 |
|
| 4245 |
|
| 4246 |
|
| 4247 |
|
| 4248 |
|
| 4249 |
|
| 4250 |
|
| 4251 |
|
| 4252 |
int FS_FOpenFileByMode( const char *qpath, fileHandle_t *f, fsMode_t mode ) { |
| 4253 |
int r; |
| 4254 |
qboolean sync; |
| 4255 |
|
| 4256 |
sync = qfalse; |
| 4257 |
|
| 4258 |
switch( mode ) { |
| 4259 |
case FS_READ: |
| 4260 |
r = FS_FOpenFileRead( qpath, f, qtrue ); |
| 4261 |
break; |
| 4262 |
case FS_WRITE: |
| 4263 |
*f = FS_FOpenFileWrite_HomeData( qpath ); |
| 4264 |
r = 0; |
| 4265 |
if (*f == 0) { |
| 4266 |
r = -1; |
| 4267 |
} |
| 4268 |
break; |
| 4269 |
case FS_APPEND_SYNC: |
| 4270 |
sync = qtrue; |
| 4271 |
case FS_APPEND: |
| 4272 |
*f = FS_FOpenFileAppend_HomeData( qpath ); |
| 4273 |
r = 0; |
| 4274 |
if (*f == 0) { |
| 4275 |
r = -1; |
| 4276 |
} |
| 4277 |
break; |
| 4278 |
default: |
| 4279 |
Com_Error( ERR_FATAL, "FS_FOpenFileByMode: bad mode" ); |
| 4280 |
return -1; |
| 4281 |
} |
| 4282 |
|
| 4283 |
if (!f) { |
| 4284 |
return r; |
| 4285 |
} |
| 4286 |
|
| 4287 |
if ( *f ) { |
| 4288 |
fsh[*f].fileSize = r; |
| 4289 |
} |
| 4290 |
fsh[*f].handleSync = sync; |
| 4291 |
|
| 4292 |
return r; |
| 4293 |
} |
| 4294 |
|
| 4295 |
int FS_FTell( fileHandle_t f ) { |
| 4296 |
int pos; |
| 4297 |
if (fsh[f].zipFile == qtrue) { |
| 4298 |
pos = unztell(fsh[f].handleFiles.file.z); |
| 4299 |
} else { |
| 4300 |
pos = ftell(fsh[f].handleFiles.file.o); |
| 4301 |
} |
| 4302 |
return pos; |
| 4303 |
} |
| 4304 |
|
| 4305 |
void FS_Flush( fileHandle_t f ) { |
| 4306 |
fflush(fsh[f].handleFiles.file.o); |
| 4307 |
} |
| 4308 |
|
| 4309 |
void FS_FilenameCompletion( const char *dir, const char *ext, char *filter, |
| 4310 |
qboolean stripExt, void(*callback)(const char *s), qboolean allowNonPureFilesOnDisk ) { |
| 4311 |
char **filenames; |
| 4312 |
int nfiles; |
| 4313 |
int i; |
| 4314 |
char filename[ MAX_STRING_CHARS ]; |
| 4315 |
|
| 4316 |
filenames = FS_ListFilteredFiles( dir, ext, filter, |
| 4317 |
&nfiles, qtrue, allowNonPureFilesOnDisk ); |
| 4318 |
|
| 4319 |
FS_SortFileList( filenames, nfiles ); |
| 4320 |
|
| 4321 |
for( i = 0; i < nfiles; i++ ) { |
| 4322 |
FS_ConvertPath( filenames[ i ] ); |
| 4323 |
Q_strncpyz( filename, filenames[ i ], MAX_STRING_CHARS ); |
| 4324 |
|
| 4325 |
if( stripExt ) { |
| 4326 |
COM_StripExtension(filename, filename, sizeof(filename)); |
| 4327 |
} |
| 4328 |
|
| 4329 |
callback( filename ); |
| 4330 |
} |
| 4331 |
FS_FreeFileList( filenames ); |
| 4332 |
} |
| 4333 |
|
| 4334 |
const char *FS_GetCurrentGameDir(void) |
| 4335 |
{ |
| 4336 |
if(fs_gamedirvar->string[0]) |
| 4337 |
return fs_gamedirvar->string; |
| 4338 |
|
| 4339 |
return com_basegame->string; |
| 4340 |
} |