| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
#define PSAPI_VERSION 1 |
| 25 |
|
| 26 |
#include "../qcommon/q_shared.h" |
| 27 |
#include "../qcommon/qcommon.h" |
| 28 |
#include "sys_local.h" |
| 29 |
|
| 30 |
#include <windows.h> |
| 31 |
#include <lmerr.h> |
| 32 |
#include <lmcons.h> |
| 33 |
#include <lmwksta.h> |
| 34 |
#include <errno.h> |
| 35 |
#include <fcntl.h> |
| 36 |
#include <stdio.h> |
| 37 |
#include <direct.h> |
| 38 |
#include <io.h> |
| 39 |
#include <conio.h> |
| 40 |
#include <wincrypt.h> |
| 41 |
#include <shlobj.h> |
| 42 |
#include <psapi.h> |
| 43 |
#include <float.h> |
| 44 |
|
| 45 |
#ifndef KEY_WOW64_32KEY |
| 46 |
#define KEY_WOW64_32KEY 0x0200 |
| 47 |
#endif |
| 48 |
|
| 49 |
#ifndef DEDICATED |
| 50 |
static UINT timerResolution = 0; |
| 51 |
#endif |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
#ifndef _RC_CHOP |
| 61 |
|
| 62 |
|
| 63 |
#define _MCW_EM 0x0008001fU |
| 64 |
#define _MCW_RC 0x00000300U |
| 65 |
#define _MCW_PC 0x00030000U |
| 66 |
#define _RC_NEAR 0x00000000U |
| 67 |
#define _PC_53 0x00010000U |
| 68 |
|
| 69 |
unsigned int _controlfp(unsigned int new, unsigned int mask); |
| 70 |
#endif |
| 71 |
|
| 72 |
#define FPUCWMASK1 (_MCW_RC | _MCW_EM) |
| 73 |
#define FPUCW (_RC_NEAR | _MCW_EM | _PC_53) |
| 74 |
|
| 75 |
#if idx64 |
| 76 |
#define FPUCWMASK (FPUCWMASK1) |
| 77 |
#else |
| 78 |
#define FPUCWMASK (FPUCWMASK1 | _MCW_PC) |
| 79 |
#endif |
| 80 |
|
| 81 |
void Sys_SetFloatEnv(void) |
| 82 |
{ |
| 83 |
_controlfp(FPUCW, FPUCWMASK); |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
static char *Sys_DefaultHomePath( void ) |
| 92 |
{ |
| 93 |
static char homePath[ MAX_OSPATH ] = { 0 }; |
| 94 |
|
| 95 |
if(!*homePath && com_homepath) |
| 96 |
{ |
| 97 |
TCHAR szPath[MAX_PATH]; |
| 98 |
|
| 99 |
if( !SUCCEEDED( SHGetFolderPathA( NULL, CSIDL_APPDATA, |
| 100 |
NULL, 0, szPath ) ) ) |
| 101 |
{ |
| 102 |
Com_Printf("Unable to detect CSIDL_APPDATA\n"); |
| 103 |
return NULL; |
| 104 |
} |
| 105 |
|
| 106 |
Com_sprintf(homePath, sizeof(homePath), "%s%c", szPath, PATH_SEP); |
| 107 |
|
| 108 |
if(com_homepath->string[0]) |
| 109 |
Q_strcat(homePath, sizeof(homePath), com_homepath->string); |
| 110 |
else |
| 111 |
Q_strcat(homePath, sizeof(homePath), HOMEPATH_NAME); |
| 112 |
} |
| 113 |
|
| 114 |
return homePath; |
| 115 |
} |
| 116 |
|
| 117 |
char *Sys_DefaultHomeConfigPath(void) { return Sys_DefaultHomePath(); } |
| 118 |
char *Sys_DefaultHomeDataPath(void) { return Sys_DefaultHomePath(); } |
| 119 |
char *Sys_DefaultHomeStatePath(void) { return Sys_DefaultHomePath(); } |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
char *Sys_SteamPath( void ) |
| 127 |
{ |
| 128 |
#ifndef STANDALONE |
| 129 |
|
| 130 |
#define STEAMPATH_NAME "Quake 3 Arena" |
| 131 |
#define STEAMPATH_APPID "2200" |
| 132 |
|
| 133 |
static char steamPath[ MAX_OSPATH ] = { 0 }; |
| 134 |
|
| 135 |
HKEY steamRegKey; |
| 136 |
DWORD pathLen = MAX_OSPATH; |
| 137 |
qboolean finishPath = qfalse; |
| 138 |
|
| 139 |
|
| 140 |
if (!steamPath[0] && !RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Steam App " |
| 141 |
STEAMPATH_APPID, 0, KEY_QUERY_VALUE | KEY_WOW64_32KEY, &steamRegKey)) |
| 142 |
{ |
| 143 |
pathLen = MAX_OSPATH; |
| 144 |
if (RegQueryValueEx(steamRegKey, "InstallLocation", NULL, NULL, (LPBYTE)steamPath, &pathLen)) |
| 145 |
steamPath[0] = '\0'; |
| 146 |
|
| 147 |
RegCloseKey(steamRegKey); |
| 148 |
} |
| 149 |
|
| 150 |
if (!steamPath[0] && !RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Valve\\Steam", 0, KEY_QUERY_VALUE, &steamRegKey)) |
| 151 |
{ |
| 152 |
pathLen = MAX_OSPATH; |
| 153 |
if (RegQueryValueEx(steamRegKey, "SteamPath", NULL, NULL, (LPBYTE)steamPath, &pathLen)) |
| 154 |
if (RegQueryValueEx(steamRegKey, "InstallPath", NULL, NULL, (LPBYTE)steamPath, &pathLen)) |
| 155 |
steamPath[0] = '\0'; |
| 156 |
|
| 157 |
if (steamPath[0]) |
| 158 |
finishPath = qtrue; |
| 159 |
|
| 160 |
RegCloseKey(steamRegKey); |
| 161 |
} |
| 162 |
|
| 163 |
if (steamPath[0]) |
| 164 |
{ |
| 165 |
if (pathLen == MAX_OSPATH) |
| 166 |
pathLen--; |
| 167 |
|
| 168 |
steamPath[pathLen] = '\0'; |
| 169 |
|
| 170 |
if (finishPath) |
| 171 |
Q_strcat(steamPath, MAX_OSPATH, "\\SteamApps\\common\\" STEAMPATH_NAME ); |
| 172 |
} |
| 173 |
|
| 174 |
return steamPath; |
| 175 |
#else |
| 176 |
return ""; |
| 177 |
#endif |
| 178 |
} |
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
char *Sys_GogPath( void ) |
| 186 |
{ |
| 187 |
#ifndef STANDALONE |
| 188 |
|
| 189 |
#define GOGPATH_ID "1441704920" |
| 190 |
|
| 191 |
static char gogPath[ MAX_OSPATH ] = { 0 }; |
| 192 |
|
| 193 |
HKEY gogRegKey; |
| 194 |
DWORD pathLen = MAX_OSPATH; |
| 195 |
|
| 196 |
if (!gogPath[0] && !RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\GOG.com\\Games\\" GOGPATH_ID, 0, KEY_QUERY_VALUE | KEY_WOW64_32KEY, &gogRegKey)) |
| 197 |
{ |
| 198 |
pathLen = MAX_OSPATH; |
| 199 |
if (RegQueryValueEx(gogRegKey, "PATH", NULL, NULL, (LPBYTE)gogPath, &pathLen)) |
| 200 |
gogPath[0] = '\0'; |
| 201 |
|
| 202 |
RegCloseKey(gogRegKey); |
| 203 |
} |
| 204 |
|
| 205 |
if (gogPath[0]) |
| 206 |
{ |
| 207 |
if (pathLen == MAX_OSPATH) |
| 208 |
pathLen--; |
| 209 |
|
| 210 |
gogPath[pathLen] = '\0'; |
| 211 |
} |
| 212 |
|
| 213 |
return gogPath; |
| 214 |
#else |
| 215 |
return ""; |
| 216 |
#endif |
| 217 |
} |
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
char* Sys_MicrosoftStorePath(void) |
| 225 |
{ |
| 226 |
#ifndef STANDALONE |
| 227 |
|
| 228 |
#define MSSTORE_PATH "Quake 3" |
| 229 |
|
| 230 |
static char microsoftStorePath[MAX_OSPATH] = { 0 }; |
| 231 |
|
| 232 |
if (!microsoftStorePath[0]) |
| 233 |
{ |
| 234 |
TCHAR szPath[MAX_PATH]; |
| 235 |
|
| 236 |
if( !SUCCEEDED( SHGetFolderPathA( NULL, CSIDL_PROGRAM_FILES, |
| 237 |
NULL, 0, szPath ) ) ) |
| 238 |
{ |
| 239 |
Com_Printf("Unable to detect CSIDL_PROGRAM_FILES\n"); |
| 240 |
return microsoftStorePath; |
| 241 |
} |
| 242 |
|
| 243 |
|
| 244 |
Com_sprintf(microsoftStorePath, sizeof(microsoftStorePath), "%s%cModifiableWindowsApps%c%s%cEN", szPath, PATH_SEP, PATH_SEP, MSSTORE_PATH, PATH_SEP); |
| 245 |
} |
| 246 |
|
| 247 |
return microsoftStorePath; |
| 248 |
#else |
| 249 |
return ""; |
| 250 |
#endif |
| 251 |
} |
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
int sys_timeBase; |
| 259 |
int Sys_Milliseconds (void) |
| 260 |
{ |
| 261 |
int sys_curtime; |
| 262 |
static qboolean initialized = qfalse; |
| 263 |
|
| 264 |
if (!initialized) { |
| 265 |
sys_timeBase = timeGetTime(); |
| 266 |
initialized = qtrue; |
| 267 |
} |
| 268 |
sys_curtime = timeGetTime() - sys_timeBase; |
| 269 |
|
| 270 |
return sys_curtime; |
| 271 |
} |
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
qboolean Sys_RandomBytes( byte *string, int len ) |
| 279 |
{ |
| 280 |
HCRYPTPROV prov; |
| 281 |
|
| 282 |
if( !CryptAcquireContext( &prov, NULL, NULL, |
| 283 |
PROV_RSA_FULL, CRYPT_VERIFYCONTEXT ) ) { |
| 284 |
|
| 285 |
return qfalse; |
| 286 |
} |
| 287 |
|
| 288 |
if( !CryptGenRandom( prov, len, (BYTE *)string ) ) { |
| 289 |
CryptReleaseContext( prov, 0 ); |
| 290 |
return qfalse; |
| 291 |
} |
| 292 |
CryptReleaseContext( prov, 0 ); |
| 293 |
return qtrue; |
| 294 |
} |
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
char *Sys_GetCurrentUser( void ) |
| 302 |
{ |
| 303 |
static char s_userName[1024]; |
| 304 |
unsigned long size = sizeof( s_userName ); |
| 305 |
|
| 306 |
if( !GetUserName( s_userName, &size ) ) |
| 307 |
strcpy( s_userName, "player" ); |
| 308 |
|
| 309 |
if( !s_userName[0] ) |
| 310 |
{ |
| 311 |
strcpy( s_userName, "player" ); |
| 312 |
} |
| 313 |
|
| 314 |
return s_userName; |
| 315 |
} |
| 316 |
|
| 317 |
#define MEM_THRESHOLD 96*1024*1024 |
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
qboolean Sys_LowPhysicalMemory( void ) |
| 325 |
{ |
| 326 |
MEMORYSTATUS stat; |
| 327 |
GlobalMemoryStatus (&stat); |
| 328 |
return (stat.dwTotalPhys <= MEM_THRESHOLD) ? qtrue : qfalse; |
| 329 |
} |
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
const char *Sys_Basename( char *path ) |
| 337 |
{ |
| 338 |
static char base[ MAX_OSPATH ] = { 0 }; |
| 339 |
int length; |
| 340 |
|
| 341 |
length = strlen( path ) - 1; |
| 342 |
|
| 343 |
|
| 344 |
while( length > 0 && path[ length ] == '\\' ) |
| 345 |
length--; |
| 346 |
|
| 347 |
while( length > 0 && path[ length - 1 ] != '\\' ) |
| 348 |
length--; |
| 349 |
|
| 350 |
Q_strncpyz( base, &path[ length ], sizeof( base ) ); |
| 351 |
|
| 352 |
length = strlen( base ) - 1; |
| 353 |
|
| 354 |
|
| 355 |
while( length > 0 && base[ length ] == '\\' ) |
| 356 |
base[ length-- ] = '\0'; |
| 357 |
|
| 358 |
return base; |
| 359 |
} |
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
const char *Sys_Dirname( char *path ) |
| 367 |
{ |
| 368 |
static char dir[ MAX_OSPATH ] = { 0 }; |
| 369 |
int length; |
| 370 |
|
| 371 |
Q_strncpyz( dir, path, sizeof( dir ) ); |
| 372 |
length = strlen( dir ) - 1; |
| 373 |
|
| 374 |
while( length > 0 && dir[ length ] != '\\' ) |
| 375 |
length--; |
| 376 |
|
| 377 |
dir[ length ] = '\0'; |
| 378 |
|
| 379 |
return dir; |
| 380 |
} |
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
FILE *Sys_FOpen( const char *ospath, const char *mode ) { |
| 388 |
size_t length; |
| 389 |
|
| 390 |
|
| 391 |
length = strlen( ospath ); |
| 392 |
if ( length == 0 || ospath[length-1] == ' ' || ospath[length-1] == '.' ) { |
| 393 |
return NULL; |
| 394 |
} |
| 395 |
|
| 396 |
return fopen( ospath, mode ); |
| 397 |
} |
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
qboolean Sys_Mkdir( const char *path ) |
| 405 |
{ |
| 406 |
if( !CreateDirectory( path, NULL ) ) |
| 407 |
{ |
| 408 |
if( GetLastError( ) != ERROR_ALREADY_EXISTS ) |
| 409 |
return qfalse; |
| 410 |
} |
| 411 |
|
| 412 |
return qtrue; |
| 413 |
} |
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
FILE *Sys_Mkfifo( const char *ospath ) |
| 422 |
{ |
| 423 |
return NULL; |
| 424 |
} |
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
char *Sys_Cwd( void ) { |
| 432 |
static char cwd[MAX_OSPATH]; |
| 433 |
|
| 434 |
_getcwd( cwd, sizeof( cwd ) - 1 ); |
| 435 |
cwd[MAX_OSPATH-1] = 0; |
| 436 |
|
| 437 |
return cwd; |
| 438 |
} |
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
char *Sys_BinaryPathRelative(const char *relative) |
| 446 |
{ |
| 447 |
static char resolved[MAX_OSPATH]; |
| 448 |
char combined[MAX_OSPATH]; |
| 449 |
|
| 450 |
snprintf(combined, sizeof(combined), "%s\\%s", Sys_BinaryPath(), relative); |
| 451 |
|
| 452 |
DWORD len = GetFullPathNameA(combined, MAX_OSPATH, resolved, NULL); |
| 453 |
if (len == 0 || len >= MAX_OSPATH) |
| 454 |
return NULL; |
| 455 |
|
| 456 |
return resolved; |
| 457 |
} |
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
#define MAX_FOUND_FILES 0x1000 |
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
void Sys_ListFilteredFiles( const char *basedir, char *subdirs, char *filter, char **list, int *numfiles ) |
| 475 |
{ |
| 476 |
char search[MAX_OSPATH], newsubdirs[MAX_OSPATH]; |
| 477 |
char filename[MAX_OSPATH]; |
| 478 |
intptr_t findhandle; |
| 479 |
struct _finddata_t findinfo; |
| 480 |
|
| 481 |
if ( *numfiles >= MAX_FOUND_FILES - 1 ) { |
| 482 |
return; |
| 483 |
} |
| 484 |
|
| 485 |
if ( basedir[0] == '\0' ) { |
| 486 |
return; |
| 487 |
} |
| 488 |
|
| 489 |
if (strlen(subdirs)) { |
| 490 |
Com_sprintf( search, sizeof(search), "%s\\%s\\*", basedir, subdirs ); |
| 491 |
} |
| 492 |
else { |
| 493 |
Com_sprintf( search, sizeof(search), "%s\\*", basedir ); |
| 494 |
} |
| 495 |
|
| 496 |
findhandle = _findfirst (search, &findinfo); |
| 497 |
if (findhandle == -1) { |
| 498 |
return; |
| 499 |
} |
| 500 |
|
| 501 |
do { |
| 502 |
if (findinfo.attrib & _A_SUBDIR) { |
| 503 |
if (Q_stricmp(findinfo.name, ".") && Q_stricmp(findinfo.name, "..")) { |
| 504 |
if (strlen(subdirs)) { |
| 505 |
Com_sprintf( newsubdirs, sizeof(newsubdirs), "%s\\%s", subdirs, findinfo.name); |
| 506 |
} |
| 507 |
else { |
| 508 |
Com_sprintf( newsubdirs, sizeof(newsubdirs), "%s", findinfo.name); |
| 509 |
} |
| 510 |
Sys_ListFilteredFiles( basedir, newsubdirs, filter, list, numfiles ); |
| 511 |
} |
| 512 |
} |
| 513 |
if ( *numfiles >= MAX_FOUND_FILES - 1 ) { |
| 514 |
break; |
| 515 |
} |
| 516 |
Com_sprintf( filename, sizeof(filename), "%s\\%s", subdirs, findinfo.name ); |
| 517 |
if (!Com_FilterPath( filter, filename, qfalse )) |
| 518 |
continue; |
| 519 |
list[ *numfiles ] = CopyString( filename ); |
| 520 |
(*numfiles)++; |
| 521 |
} while ( _findnext (findhandle, &findinfo) != -1 ); |
| 522 |
|
| 523 |
_findclose (findhandle); |
| 524 |
} |
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
static qboolean strgtr(const char *s0, const char *s1) |
| 532 |
{ |
| 533 |
int l0, l1, i; |
| 534 |
|
| 535 |
l0 = strlen(s0); |
| 536 |
l1 = strlen(s1); |
| 537 |
|
| 538 |
if (l1<l0) { |
| 539 |
l0 = l1; |
| 540 |
} |
| 541 |
|
| 542 |
for(i=0;i<l0;i++) { |
| 543 |
if (s1[i] > s0[i]) { |
| 544 |
return qtrue; |
| 545 |
} |
| 546 |
if (s1[i] < s0[i]) { |
| 547 |
return qfalse; |
| 548 |
} |
| 549 |
} |
| 550 |
return qfalse; |
| 551 |
} |
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
char **Sys_ListFiles( const char *directory, const char *extension, char *filter, int *numfiles, qboolean wantsubs ) |
| 559 |
{ |
| 560 |
char search[MAX_OSPATH]; |
| 561 |
int nfiles; |
| 562 |
char **listCopy; |
| 563 |
char *list[MAX_FOUND_FILES]; |
| 564 |
struct _finddata_t findinfo; |
| 565 |
intptr_t findhandle; |
| 566 |
int flag; |
| 567 |
int i; |
| 568 |
int extLen; |
| 569 |
|
| 570 |
if (filter) { |
| 571 |
|
| 572 |
nfiles = 0; |
| 573 |
Sys_ListFilteredFiles( directory, "", filter, list, &nfiles ); |
| 574 |
|
| 575 |
list[ nfiles ] = 0; |
| 576 |
*numfiles = nfiles; |
| 577 |
|
| 578 |
if (!nfiles) |
| 579 |
return NULL; |
| 580 |
|
| 581 |
listCopy = Z_Malloc( ( nfiles + 1 ) * sizeof( *listCopy ) ); |
| 582 |
for ( i = 0 ; i < nfiles ; i++ ) { |
| 583 |
listCopy[i] = list[i]; |
| 584 |
} |
| 585 |
listCopy[i] = NULL; |
| 586 |
|
| 587 |
return listCopy; |
| 588 |
} |
| 589 |
|
| 590 |
if ( directory[0] == '\0' ) { |
| 591 |
*numfiles = 0; |
| 592 |
return NULL; |
| 593 |
} |
| 594 |
|
| 595 |
if ( !extension) { |
| 596 |
extension = ""; |
| 597 |
} |
| 598 |
|
| 599 |
|
| 600 |
if ( extension[0] == '/' && extension[1] == 0 ) { |
| 601 |
extension = ""; |
| 602 |
flag = 0; |
| 603 |
} else { |
| 604 |
flag = _A_SUBDIR; |
| 605 |
} |
| 606 |
|
| 607 |
extLen = strlen( extension ); |
| 608 |
|
| 609 |
Com_sprintf( search, sizeof(search), "%s\\*%s", directory, extension ); |
| 610 |
|
| 611 |
|
| 612 |
nfiles = 0; |
| 613 |
|
| 614 |
findhandle = _findfirst (search, &findinfo); |
| 615 |
if (findhandle == -1) { |
| 616 |
*numfiles = 0; |
| 617 |
return NULL; |
| 618 |
} |
| 619 |
|
| 620 |
do { |
| 621 |
if ( (!wantsubs && flag ^ ( findinfo.attrib & _A_SUBDIR )) || (wantsubs && findinfo.attrib & _A_SUBDIR) ) { |
| 622 |
if (*extension) { |
| 623 |
if ( strlen( findinfo.name ) < extLen || |
| 624 |
Q_stricmp( |
| 625 |
findinfo.name + strlen( findinfo.name ) - extLen, |
| 626 |
extension ) ) { |
| 627 |
continue; |
| 628 |
} |
| 629 |
} |
| 630 |
if ( nfiles == MAX_FOUND_FILES - 1 ) { |
| 631 |
break; |
| 632 |
} |
| 633 |
list[ nfiles ] = CopyString( findinfo.name ); |
| 634 |
nfiles++; |
| 635 |
} |
| 636 |
} while ( _findnext (findhandle, &findinfo) != -1 ); |
| 637 |
|
| 638 |
list[ nfiles ] = 0; |
| 639 |
|
| 640 |
_findclose (findhandle); |
| 641 |
|
| 642 |
|
| 643 |
*numfiles = nfiles; |
| 644 |
|
| 645 |
if ( !nfiles ) { |
| 646 |
return NULL; |
| 647 |
} |
| 648 |
|
| 649 |
listCopy = Z_Malloc( ( nfiles + 1 ) * sizeof( *listCopy ) ); |
| 650 |
for ( i = 0 ; i < nfiles ; i++ ) { |
| 651 |
listCopy[i] = list[i]; |
| 652 |
} |
| 653 |
listCopy[i] = NULL; |
| 654 |
|
| 655 |
do { |
| 656 |
flag = 0; |
| 657 |
for(i=1; i<nfiles; i++) { |
| 658 |
if (strgtr(listCopy[i-1], listCopy[i])) { |
| 659 |
char *temp = listCopy[i]; |
| 660 |
listCopy[i] = listCopy[i-1]; |
| 661 |
listCopy[i-1] = temp; |
| 662 |
flag = 1; |
| 663 |
} |
| 664 |
} |
| 665 |
} while(flag); |
| 666 |
|
| 667 |
return listCopy; |
| 668 |
} |
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
void Sys_FreeFileList( char **list ) |
| 676 |
{ |
| 677 |
int i; |
| 678 |
|
| 679 |
if ( !list ) { |
| 680 |
return; |
| 681 |
} |
| 682 |
|
| 683 |
for ( i = 0 ; list[i] ; i++ ) { |
| 684 |
Z_Free( list[i] ); |
| 685 |
} |
| 686 |
|
| 687 |
Z_Free( list ); |
| 688 |
} |
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
void Sys_Sleep( int msec ) |
| 699 |
{ |
| 700 |
if( msec == 0 ) |
| 701 |
return; |
| 702 |
|
| 703 |
#ifdef DEDICATED |
| 704 |
if( msec < 0 ) |
| 705 |
WaitForSingleObject( GetStdHandle( STD_INPUT_HANDLE ), INFINITE ); |
| 706 |
else |
| 707 |
WaitForSingleObject( GetStdHandle( STD_INPUT_HANDLE ), msec ); |
| 708 |
#else |
| 709 |
|
| 710 |
if( msec < 0 ) |
| 711 |
return; |
| 712 |
|
| 713 |
Sleep( msec ); |
| 714 |
#endif |
| 715 |
} |
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
void Sys_ErrorDialog( const char *error ) |
| 725 |
{ |
| 726 |
Sys_Print( va( "%s\n", error ) ); |
| 727 |
|
| 728 |
if( Sys_Dialog( DT_YES_NO, va( "%s. Copy console log to clipboard?", error ), |
| 729 |
"Error" ) == DR_YES ) |
| 730 |
{ |
| 731 |
HGLOBAL memoryHandle; |
| 732 |
char *clipMemory; |
| 733 |
|
| 734 |
memoryHandle = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, CON_LogSize( ) + 1 ); |
| 735 |
clipMemory = (char *)GlobalLock( memoryHandle ); |
| 736 |
|
| 737 |
if( clipMemory ) |
| 738 |
{ |
| 739 |
char *p = clipMemory; |
| 740 |
char buffer[ 1024 ]; |
| 741 |
unsigned int size; |
| 742 |
|
| 743 |
while( ( size = CON_LogRead( buffer, sizeof( buffer ) ) ) > 0 ) |
| 744 |
{ |
| 745 |
Com_Memcpy( p, buffer, size ); |
| 746 |
p += size; |
| 747 |
} |
| 748 |
|
| 749 |
*p = '\0'; |
| 750 |
|
| 751 |
if( OpenClipboard( NULL ) && EmptyClipboard( ) ) |
| 752 |
SetClipboardData( CF_TEXT, memoryHandle ); |
| 753 |
|
| 754 |
GlobalUnlock( clipMemory ); |
| 755 |
CloseClipboard( ); |
| 756 |
} |
| 757 |
} |
| 758 |
} |
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
dialogResult_t Sys_Dialog( dialogType_t type, const char *message, const char *title ) |
| 768 |
{ |
| 769 |
UINT uType; |
| 770 |
|
| 771 |
switch( type ) |
| 772 |
{ |
| 773 |
default: |
| 774 |
case DT_INFO: uType = MB_ICONINFORMATION|MB_OK; break; |
| 775 |
case DT_WARNING: uType = MB_ICONWARNING|MB_OK; break; |
| 776 |
case DT_ERROR: uType = MB_ICONERROR|MB_OK; break; |
| 777 |
case DT_YES_NO: uType = MB_ICONQUESTION|MB_YESNO; break; |
| 778 |
case DT_OK_CANCEL: uType = MB_ICONWARNING|MB_OKCANCEL; break; |
| 779 |
} |
| 780 |
|
| 781 |
switch( MessageBox( NULL, message, title, uType ) ) |
| 782 |
{ |
| 783 |
default: |
| 784 |
case IDOK: return DR_OK; |
| 785 |
case IDCANCEL: return DR_CANCEL; |
| 786 |
case IDYES: return DR_YES; |
| 787 |
case IDNO: return DR_NO; |
| 788 |
} |
| 789 |
} |
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
void Sys_GLimpSafeInit( void ) |
| 799 |
{ |
| 800 |
} |
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
void Sys_GLimpInit( void ) |
| 810 |
{ |
| 811 |
} |
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
void Sys_PlatformInit( void ) |
| 821 |
{ |
| 822 |
#ifndef DEDICATED |
| 823 |
TIMECAPS ptc; |
| 824 |
#endif |
| 825 |
|
| 826 |
Sys_SetFloatEnv(); |
| 827 |
|
| 828 |
#ifndef DEDICATED |
| 829 |
if(timeGetDevCaps(&ptc, sizeof(ptc)) == MMSYSERR_NOERROR) |
| 830 |
{ |
| 831 |
timerResolution = ptc.wPeriodMin; |
| 832 |
|
| 833 |
if(timerResolution > 1) |
| 834 |
{ |
| 835 |
Com_Printf("Warning: Minimum supported timer resolution is %ums " |
| 836 |
"on this system, recommended resolution 1ms\n", timerResolution); |
| 837 |
} |
| 838 |
|
| 839 |
timeBeginPeriod(timerResolution); |
| 840 |
} |
| 841 |
else |
| 842 |
timerResolution = 0; |
| 843 |
#endif |
| 844 |
} |
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
|
| 852 |
|
| 853 |
void Sys_PlatformExit( void ) |
| 854 |
{ |
| 855 |
#ifndef DEDICATED |
| 856 |
if(timerResolution) |
| 857 |
timeEndPeriod(timerResolution); |
| 858 |
#endif |
| 859 |
} |
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
void Sys_SetEnv(const char *name, const char *value) |
| 869 |
{ |
| 870 |
if(value) |
| 871 |
_putenv(va("%s=%s", name, value)); |
| 872 |
else |
| 873 |
_putenv(va("%s=", name)); |
| 874 |
} |
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
int Sys_PID( void ) |
| 882 |
{ |
| 883 |
return GetCurrentProcessId( ); |
| 884 |
} |
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
|
| 889 |
|
| 890 |
|
| 891 |
qboolean Sys_PIDIsRunning( int pid ) |
| 892 |
{ |
| 893 |
DWORD processes[ 1024 ]; |
| 894 |
DWORD numBytes, numProcesses; |
| 895 |
int i; |
| 896 |
|
| 897 |
if( !EnumProcesses( processes, sizeof( processes ), &numBytes ) ) |
| 898 |
return qfalse; |
| 899 |
|
| 900 |
numProcesses = numBytes / sizeof( DWORD ); |
| 901 |
|
| 902 |
|
| 903 |
for( i = 0; i < numProcesses; i++ ) |
| 904 |
{ |
| 905 |
if( (int)processes[ i ] == pid ) |
| 906 |
return qtrue; |
| 907 |
} |
| 908 |
|
| 909 |
return qfalse; |
| 910 |
} |
| 911 |
|
| 912 |
|
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
qboolean Sys_DllExtension( const char *name ) { |
| 920 |
return COM_CompareExtension( name, DLL_EXT ); |
| 921 |
} |
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
qboolean Sys_OpenFolderInPlatformFileManager( const char *path ) |
| 929 |
{ |
| 930 |
return ShellExecute( NULL, "explore", path, NULL, NULL, SW_SHOWDEFAULT ) > (HINSTANCE)32; |
| 931 |
} |
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
qboolean Sys_SetMaxFileLimit( void ) |
| 939 |
{ |
| 940 |
return qtrue; |
| 941 |
} |